|
1 | | -import DataHubListAction from '@datahub/components/helpers/DataHubListAction.tsx' |
2 | | -import type { CombinedPolicy } from '@datahub/types.ts' |
3 | | -import { PolicyType } from '@datahub/types.ts' |
4 | 1 | import { mockDataPolicy } from '@datahub/api/hooks/DataHubDataPoliciesService/__handlers__' |
5 | 2 | import { mockBehaviorPolicy } from '@datahub/api/hooks/DataHubBehaviorPoliciesService/__handlers__' |
| 3 | +import DataHubListAction from '@datahub/components/helpers/DataHubListAction.tsx' |
| 4 | +import { type CombinedPolicy, PolicyType } from '@datahub/types.ts' |
6 | 5 |
|
7 | 6 | describe('DataHubListAction', () => { |
8 | 7 | beforeEach(() => { |
9 | 8 | cy.viewport(800, 800) |
10 | 9 | }) |
11 | 10 |
|
12 | | - it('should render the actions for DRAFT', () => { |
13 | | - const policy: CombinedPolicy = { |
14 | | - type: PolicyType.CREATE_POLICY, |
15 | | - ...mockDataPolicy, |
16 | | - } |
17 | | - cy.mountWithProviders( |
18 | | - <DataHubListAction policy={policy} onEdit={cy.stub().as('onEdit')} onDelete={cy.stub().as('onDelete')} /> |
19 | | - ) |
20 | | - |
21 | | - cy.get('button').should('have.length', 2) |
22 | | - cy.getByTestId('list-action-view').should('have.attr', 'aria-label', 'Continue on draft') |
23 | | - cy.getByTestId('list-action-view').should('not.be.disabled') |
24 | | - |
25 | | - cy.get('@onDelete').should('not.have.been.called') |
26 | | - cy.getByTestId('list-action-delete').should('have.attr', 'aria-label', 'Delete') |
27 | | - cy.getByTestId('list-action-delete').click() |
28 | | - cy.get('@onDelete').should('have.been.called') |
| 11 | + context('DRAFT', () => { |
| 12 | + it('should render the actions for DRAFT', () => { |
| 13 | + const policy: CombinedPolicy = { |
| 14 | + type: PolicyType.CREATE_POLICY, |
| 15 | + ...mockDataPolicy, |
| 16 | + } |
| 17 | + cy.mountWithProviders( |
| 18 | + <DataHubListAction policy={policy} onEdit={cy.stub().as('onEdit')} onDelete={cy.stub().as('onDelete')} /> |
| 19 | + ) |
| 20 | + |
| 21 | + cy.get('button').should('have.length', 2) |
| 22 | + cy.getByTestId('list-action-view').should('have.attr', 'aria-label', 'Continue on draft') |
| 23 | + cy.getByTestId('list-action-view').should('not.be.disabled') |
| 24 | + |
| 25 | + cy.get('@onDelete').should('not.have.been.called') |
| 26 | + cy.getByTestId('list-action-delete').should('have.attr', 'aria-label', 'Delete') |
| 27 | + cy.getByTestId('list-action-delete').click() |
| 28 | + cy.get('@onDelete').should('have.been.called') |
| 29 | + }) |
29 | 30 | }) |
30 | 31 |
|
31 | | - it('should render the actions for resources', () => { |
32 | | - cy.mountWithProviders( |
33 | | - <DataHubListAction |
34 | | - policy={undefined} |
35 | | - onDownload={cy.stub().as('onDownload')} |
36 | | - onDelete={cy.stub().as('onDelete')} |
37 | | - /> |
38 | | - ) |
39 | | - |
40 | | - cy.get('button').should('have.length', 2) |
41 | | - cy.getByTestId('list-action-download').should('not.be.disabled') |
42 | | - |
43 | | - cy.get('@onDownload').should('not.have.been.called') |
44 | | - cy.getByTestId('list-action-download').should('have.attr', 'aria-label', 'Download') |
45 | | - cy.getByTestId('list-action-download').click() |
46 | | - cy.get('@onDownload').should('have.been.called') |
47 | | - |
48 | | - cy.get('@onDelete').should('not.have.been.called') |
49 | | - cy.getByTestId('list-action-delete').should('have.attr', 'aria-label', 'Delete') |
50 | | - cy.getByTestId('list-action-delete').click() |
51 | | - cy.get('@onDelete').should('have.been.called') |
| 32 | + context('SCRIPT and SCHEMA', () => { |
| 33 | + it('should render the actions for single version', () => { |
| 34 | + cy.mountWithProviders( |
| 35 | + <DataHubListAction |
| 36 | + policy={undefined} |
| 37 | + onDownload={cy.stub().as('onDownload')} |
| 38 | + onDelete={cy.stub().as('onDelete')} |
| 39 | + onEdit={cy.stub().as('onEdit')} |
| 40 | + /> |
| 41 | + ) |
| 42 | + |
| 43 | + cy.get('button').should('have.length', 2) |
| 44 | + |
| 45 | + cy.get('@onDownload').should('not.have.been.called') |
| 46 | + cy.getByTestId('list-action-download').should('not.be.disabled') |
| 47 | + cy.getByTestId('list-action-download').should('have.attr', 'aria-label', 'Download') |
| 48 | + cy.getByTestId('list-action-download').click() |
| 49 | + cy.get('@onDownload').should('have.been.called') |
| 50 | + |
| 51 | + cy.get('@onDelete').should('not.have.been.called') |
| 52 | + cy.getByTestId('list-action-delete').should('have.attr', 'aria-label', 'Delete') |
| 53 | + cy.getByTestId('list-action-delete').click() |
| 54 | + cy.get('@onDelete').should('have.been.called') |
| 55 | + |
| 56 | + cy.getByTestId('list-action-draft').should('not.exist') |
| 57 | + cy.getByTestId('list-action-view-edit').should('not.exist') |
| 58 | + }) |
| 59 | + |
| 60 | + it('should render the actions for multiple versions', () => { |
| 61 | + cy.mountWithProviders( |
| 62 | + <DataHubListAction |
| 63 | + policy={undefined} |
| 64 | + onDownload={cy.stub().as('onDownload')} |
| 65 | + onDelete={cy.stub().as('onDelete')} |
| 66 | + onEdit={cy.stub().as('onEdit')} |
| 67 | + /> |
| 68 | + ) |
| 69 | + |
| 70 | + cy.get('button').should('have.length', 2) |
| 71 | + |
| 72 | + cy.get('@onDownload').should('not.have.been.called') |
| 73 | + cy.getByTestId('list-action-download').should('have.attr', 'aria-label', 'Download') |
| 74 | + cy.getByTestId('list-action-download').click() |
| 75 | + cy.get('@onDownload').should('have.been.called') |
| 76 | + |
| 77 | + cy.get('@onDelete').should('not.have.been.called') |
| 78 | + cy.getByTestId('list-action-delete').should('have.attr', 'aria-label', 'Delete') |
| 79 | + cy.getByTestId('list-action-delete').click() |
| 80 | + cy.get('@onDelete').should('have.been.called') |
| 81 | + |
| 82 | + cy.getByTestId('list-action-draft').should('not.exist') |
| 83 | + cy.getByTestId('list-action-view-edit').should('not.exist') |
| 84 | + }) |
52 | 85 | }) |
53 | 86 |
|
54 | | - it('should render the actions for DATA_POLICY', () => { |
55 | | - const policy: CombinedPolicy = { |
56 | | - type: PolicyType.DATA_POLICY, |
57 | | - ...mockDataPolicy, |
58 | | - } |
59 | | - cy.mountWithProviders( |
60 | | - <DataHubListAction |
61 | | - policy={policy} |
62 | | - onEdit={cy.stub().as('onEdit')} |
63 | | - onDownload={cy.stub().as('onDownload')} |
64 | | - onDelete={cy.stub().as('onDelete')} |
65 | | - /> |
66 | | - ) |
67 | | - |
68 | | - cy.get('button').should('have.length', 3) |
69 | | - cy.getByTestId('list-action-view').should('not.be.disabled') |
70 | | - |
71 | | - cy.get('@onEdit').should('not.have.been.called') |
72 | | - cy.getByTestId('list-action-view').should('have.attr', 'aria-label', 'View / Edit') |
73 | | - cy.getByTestId('list-action-view').click() |
74 | | - cy.get('@onEdit').should('have.been.called') |
75 | | - |
76 | | - cy.get('@onDownload').should('not.have.been.called') |
77 | | - cy.getByTestId('list-action-download').should('have.attr', 'aria-label', 'Download') |
78 | | - cy.getByTestId('list-action-download').click() |
79 | | - cy.get('@onDownload').should('have.been.called') |
80 | | - |
81 | | - cy.get('@onDelete').should('not.have.been.called') |
82 | | - cy.getByTestId('list-action-delete').should('have.attr', 'aria-label', 'Delete') |
83 | | - cy.getByTestId('list-action-delete').click() |
84 | | - cy.get('@onDelete').should('have.been.called') |
| 87 | + context('DATA_POLICY', () => { |
| 88 | + it('should render the actions for DATA_POLICY', () => { |
| 89 | + const policy: CombinedPolicy = { |
| 90 | + type: PolicyType.DATA_POLICY, |
| 91 | + ...mockDataPolicy, |
| 92 | + } |
| 93 | + cy.mountWithProviders( |
| 94 | + <DataHubListAction |
| 95 | + policy={policy} |
| 96 | + onEdit={cy.stub().as('onEdit')} |
| 97 | + onDownload={cy.stub().as('onDownload')} |
| 98 | + onDelete={cy.stub().as('onDelete')} |
| 99 | + /> |
| 100 | + ) |
| 101 | + |
| 102 | + cy.get('button').should('have.length', 3) |
| 103 | + cy.getByTestId('list-action-view').should('not.be.disabled') |
| 104 | + |
| 105 | + cy.get('@onEdit').should('not.have.been.called') |
| 106 | + cy.getByTestId('list-action-view').should('have.attr', 'aria-label', 'View / Edit') |
| 107 | + cy.getByTestId('list-action-view').click() |
| 108 | + cy.get('@onEdit').should('have.been.called') |
| 109 | + |
| 110 | + cy.get('@onDownload').should('not.have.been.called') |
| 111 | + cy.getByTestId('list-action-download').should('have.attr', 'aria-label', 'Download') |
| 112 | + cy.getByTestId('list-action-download').click() |
| 113 | + cy.get('@onDownload').should('have.been.called') |
| 114 | + |
| 115 | + cy.get('@onDelete').should('not.have.been.called') |
| 116 | + cy.getByTestId('list-action-delete').should('have.attr', 'aria-label', 'Delete') |
| 117 | + cy.getByTestId('list-action-delete').click() |
| 118 | + cy.get('@onDelete').should('have.been.called') |
| 119 | + }) |
85 | 120 | }) |
86 | 121 |
|
87 | | - it('should render the actions for BEHAVIOR_POLICY', () => { |
88 | | - const policy: CombinedPolicy = { |
89 | | - type: PolicyType.BEHAVIOR_POLICY, |
90 | | - ...mockBehaviorPolicy, |
91 | | - } |
92 | | - cy.mountWithProviders( |
93 | | - <DataHubListAction |
94 | | - policy={policy} |
95 | | - onEdit={cy.stub().as('onEdit')} |
96 | | - onDownload={cy.stub().as('onDownload')} |
97 | | - onDelete={cy.stub().as('onDelete')} |
98 | | - /> |
99 | | - ) |
100 | | - |
101 | | - cy.get('button').should('have.length', 3) |
102 | | - cy.getByTestId('list-action-view').should('not.be.disabled') |
103 | | - |
104 | | - cy.get('@onEdit').should('not.have.been.called') |
105 | | - cy.getByTestId('list-action-view').should('have.attr', 'aria-label', 'View / Edit') |
106 | | - cy.getByTestId('list-action-view').click() |
107 | | - cy.get('@onEdit').should('have.been.called') |
108 | | - |
109 | | - cy.get('@onDownload').should('not.have.been.called') |
110 | | - cy.getByTestId('list-action-download').should('have.attr', 'aria-label', 'Download') |
111 | | - cy.getByTestId('list-action-download').click() |
112 | | - cy.get('@onDownload').should('have.been.called') |
113 | | - |
114 | | - cy.get('@onDelete').should('not.have.been.called') |
115 | | - cy.getByTestId('list-action-delete').should('have.attr', 'aria-label', 'Delete') |
116 | | - cy.getByTestId('list-action-delete').click() |
117 | | - cy.get('@onDelete').should('have.been.called') |
| 122 | + context('BEHAVIOR_POLICY', () => { |
| 123 | + it('should render the actions for BEHAVIOR_POLICY', () => { |
| 124 | + const policy: CombinedPolicy = { |
| 125 | + type: PolicyType.BEHAVIOR_POLICY, |
| 126 | + ...mockBehaviorPolicy, |
| 127 | + } |
| 128 | + cy.mountWithProviders( |
| 129 | + <DataHubListAction |
| 130 | + policy={policy} |
| 131 | + onEdit={cy.stub().as('onEdit')} |
| 132 | + onDownload={cy.stub().as('onDownload')} |
| 133 | + onDelete={cy.stub().as('onDelete')} |
| 134 | + /> |
| 135 | + ) |
| 136 | + |
| 137 | + cy.get('button').should('have.length', 3) |
| 138 | + cy.getByTestId('list-action-view').should('not.be.disabled') |
| 139 | + |
| 140 | + cy.get('@onEdit').should('not.have.been.called') |
| 141 | + cy.getByTestId('list-action-view').should('have.attr', 'aria-label', 'View / Edit') |
| 142 | + cy.getByTestId('list-action-view').click() |
| 143 | + cy.get('@onEdit').should('have.been.called') |
| 144 | + |
| 145 | + cy.get('@onDownload').should('not.have.been.called') |
| 146 | + cy.getByTestId('list-action-download').should('have.attr', 'aria-label', 'Download') |
| 147 | + cy.getByTestId('list-action-download').click() |
| 148 | + cy.get('@onDownload').should('have.been.called') |
| 149 | + |
| 150 | + cy.get('@onDelete').should('not.have.been.called') |
| 151 | + cy.getByTestId('list-action-delete').should('have.attr', 'aria-label', 'Delete') |
| 152 | + cy.getByTestId('list-action-delete').click() |
| 153 | + cy.get('@onDelete').should('have.been.called') |
| 154 | + }) |
118 | 155 | }) |
119 | 156 |
|
120 | 157 | it('should be accessible', () => { |
|
0 commit comments