1
|
|
|
// / <reference types="Cypress" /> |
2
|
|
|
|
3
|
|
View Code Duplication |
import SettingsPageObject from '../../../support/pages/module/sw-settings.page-object'; |
|
|
|
|
4
|
|
|
|
5
|
|
|
describe('Unit: Test acl privileges', () => { |
6
|
|
|
beforeEach(() => { |
7
|
|
|
cy.setToInitialState() |
|
|
|
|
8
|
|
|
.then(() => { |
9
|
|
|
cy.loginViaApi(); |
|
|
|
|
10
|
|
|
}) |
11
|
|
|
.then(() => { |
12
|
|
|
return cy.createDefaultFixture('unit'); |
|
|
|
|
13
|
|
|
}) |
14
|
|
|
.then(() => { |
15
|
|
|
cy.openInitialPage(`${Cypress.env('admin')}#/sw/dashboard/index`); |
|
|
|
|
16
|
|
|
}); |
17
|
|
|
}); |
18
|
|
|
|
19
|
|
|
it('@settings @unit: has no access to scale unit module', () => { |
20
|
|
|
cy.window().then((win) => { |
|
|
|
|
21
|
|
|
if (!win.Shopware.Feature.isActive('FEATURE_NEXT_3722')) { |
22
|
|
|
return; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
cy.loginAsUserWithPermissions([ |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
key: 'product', |
28
|
|
|
role: 'viewer' |
29
|
|
|
} |
30
|
|
|
]).then(() => { |
31
|
|
|
cy.visit(`${Cypress.env('admin')}#/sw/settings/units/index`); |
|
|
|
|
32
|
|
|
}); |
33
|
|
|
|
34
|
|
|
// open custom field without permissions |
35
|
|
|
cy.get('.sw-privilege-error__access-denied-image').should('be.visible'); |
36
|
|
|
cy.get('h1').contains('Access denied'); |
37
|
|
|
cy.get('.sw-settings-units-grid').should('not.exist'); |
38
|
|
|
|
39
|
|
|
// see no settings |
40
|
|
|
cy.get('.sw-admin-menu__item--sw-settings').should('not.exist'); |
41
|
|
|
}); |
42
|
|
|
}); |
43
|
|
|
|
44
|
|
|
it('@settings @unit: create and read unit', () => { |
45
|
|
|
cy.window().then((win) => { |
|
|
|
|
46
|
|
|
if (!win.Shopware.Feature.isActive('FEATURE_NEXT_3722')) { |
47
|
|
|
return; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
const page = new SettingsPageObject(); |
51
|
|
|
|
52
|
|
|
cy.loginAsUserWithPermissions([ |
|
|
|
|
53
|
|
|
{ |
54
|
|
|
key: 'scale_unit', |
55
|
|
|
role: 'viewer' |
56
|
|
|
}, |
57
|
|
|
{ |
58
|
|
|
key: 'scale_unit', |
59
|
|
|
role: 'editor' |
60
|
|
|
}, |
61
|
|
|
{ |
62
|
|
|
key: 'scale_unit', |
63
|
|
|
role: 'creator' |
64
|
|
|
} |
65
|
|
|
]).then(() => { |
66
|
|
|
cy.visit(`${Cypress.env('admin')}#/sw/settings/units/index`); |
|
|
|
|
67
|
|
|
}); |
68
|
|
|
|
69
|
|
|
// Request we want to wait for later |
70
|
|
|
cy.server(); |
71
|
|
|
cy.route({ |
72
|
|
|
url: '/api/v*/unit', |
73
|
|
|
method: 'post' |
74
|
|
|
}).as('saveData'); |
75
|
|
|
|
76
|
|
|
// Go to unit module |
77
|
|
|
cy.get('.sw-admin-menu__item--sw-settings').click(); |
78
|
|
|
cy.get('#sw-settings-units').click(); |
79
|
|
|
|
80
|
|
|
// Create unit |
81
|
|
|
cy.get('.sw-settings-units-grid').should('be.visible'); |
82
|
|
|
cy.get('.sw-settings-units__create-action').click(); |
83
|
|
|
|
84
|
|
|
cy.get('.sw-data-grid__cell--name #sw-field--currentValue').type('Kilogramm'); |
85
|
|
|
cy.get('.sw-data-grid__cell--shortCode #sw-field--currentValue').type('kg'); |
86
|
|
|
|
87
|
|
|
cy.get('.sw-data-grid__inline-edit-save').click(); |
88
|
|
|
|
89
|
|
|
// Verify creation |
90
|
|
|
cy.wait('@saveData').then((xhr) => { |
91
|
|
|
expect(xhr).to.have.property('status', 204); |
92
|
|
|
}); |
93
|
|
|
|
94
|
|
|
cy.get(`${page.elements.dataGridRow}--1 .sw-data-grid__cell--name`) |
95
|
|
|
.should('be.visible') |
96
|
|
|
.contains('Kilogramm'); |
97
|
|
|
}); |
98
|
|
|
}); |
99
|
|
|
|
100
|
|
|
it('@settings @unit: update and read scale unit', () => { |
101
|
|
|
cy.window().then((win) => { |
|
|
|
|
102
|
|
|
if (!win.Shopware.Feature.isActive('FEATURE_NEXT_3722')) { |
103
|
|
|
return; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
const page = new SettingsPageObject(); |
107
|
|
|
|
108
|
|
|
cy.loginAsUserWithPermissions([ |
|
|
|
|
109
|
|
|
{ |
110
|
|
|
key: 'scale_unit', |
111
|
|
|
role: 'viewer' |
112
|
|
|
}, |
113
|
|
|
{ |
114
|
|
|
key: 'scale_unit', |
115
|
|
|
role: 'editor' |
116
|
|
|
} |
117
|
|
|
]).then(() => { |
118
|
|
|
cy.visit(`${Cypress.env('admin')}#/sw/settings/units/index`); |
|
|
|
|
119
|
|
|
}); |
120
|
|
|
|
121
|
|
|
// Request we want to wait for later |
122
|
|
|
cy.server(); |
123
|
|
|
cy.route({ |
124
|
|
|
url: '/api/v*/unit/*', |
125
|
|
|
method: 'patch' |
126
|
|
|
}).as('saveData'); |
127
|
|
|
|
128
|
|
|
// Go to unit module |
129
|
|
|
cy.get('.sw-admin-menu__item--sw-settings').click(); |
130
|
|
|
cy.get('#sw-settings-units').click(); |
131
|
|
|
|
132
|
|
|
// Create unit |
133
|
|
|
cy.get('.sw-settings-units-grid').should('be.visible'); |
134
|
|
|
cy.get('.sw-data-grid__row--0 > .sw-data-grid__cell--name').dblclick(); |
135
|
|
|
|
136
|
|
|
cy.get('.sw-data-grid__cell--name #sw-field--currentValue').type('KG'); |
137
|
|
|
|
138
|
|
|
cy.get('.sw-data-grid__inline-edit-save').click(); |
139
|
|
|
|
140
|
|
|
// Verify creation |
141
|
|
|
cy.wait('@saveData').then((xhr) => { |
142
|
|
|
expect(xhr).to.have.property('status', 204); |
143
|
|
|
}); |
144
|
|
|
|
145
|
|
|
cy.get(`${page.elements.dataGridRow}--0 .sw-data-grid__cell--name`) |
146
|
|
|
.should('be.visible') |
147
|
|
|
.contains('KG'); |
148
|
|
|
}); |
149
|
|
|
}); |
150
|
|
|
|
151
|
|
|
it('@settings @unit: delete scale unit', () => { |
152
|
|
|
cy.window().then((win) => { |
|
|
|
|
153
|
|
|
if (!win.Shopware.Feature.isActive('FEATURE_NEXT_3722')) { |
154
|
|
|
return; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
const page = new SettingsPageObject(); |
158
|
|
|
|
159
|
|
|
cy.loginAsUserWithPermissions([ |
|
|
|
|
160
|
|
|
{ |
161
|
|
|
key: 'scale_unit', |
162
|
|
|
role: 'viewer' |
163
|
|
|
}, |
164
|
|
|
{ |
165
|
|
|
key: 'scale_unit', |
166
|
|
|
role: 'deleter' |
167
|
|
|
} |
168
|
|
|
]).then(() => { |
169
|
|
|
cy.visit(`${Cypress.env('admin')}#/sw/settings/units/index`); |
|
|
|
|
170
|
|
|
}); |
171
|
|
|
|
172
|
|
|
// Request we want to wait for later |
173
|
|
|
cy.server(); |
174
|
|
|
cy.route({ |
175
|
|
|
url: '/api/v*/unit/*', |
176
|
|
|
method: 'delete' |
177
|
|
|
}).as('deleteData'); |
178
|
|
|
|
179
|
|
|
// Go to unit module |
180
|
|
|
cy.get('.sw-admin-menu__item--sw-settings').click(); |
181
|
|
|
cy.get('#sw-settings-units').click(); |
182
|
|
|
|
183
|
|
|
// Create unit |
184
|
|
|
cy.get('.sw-settings-units-grid').should('be.visible'); |
185
|
|
|
cy.clickContextMenuItem( |
186
|
|
|
`${page.elements.contextMenu}-item--danger`, |
187
|
|
|
page.elements.contextMenuButton, |
188
|
|
|
`${page.elements.dataGridRow}--0` |
189
|
|
|
); |
190
|
|
|
|
191
|
|
|
// Verify creation |
192
|
|
|
cy.wait('@deleteData').then((xhr) => { |
193
|
|
|
expect(xhr).to.have.property('status', 204); |
194
|
|
|
}); |
195
|
|
|
|
196
|
|
|
cy.get('.sw-empty-state').should('be.visible') |
197
|
|
|
}); |
198
|
|
|
}); |
199
|
|
|
}); |
200
|
|
|
|