1
|
|
|
// / <reference types="Cypress" /> |
2
|
|
|
|
3
|
|
|
describe('Snippets: Test acl privileges', () => { |
4
|
|
|
beforeEach(() => { |
5
|
|
|
cy.setToInitialState() |
|
|
|
|
6
|
|
|
.then(() => { |
7
|
|
|
cy.loginViaApi(); |
|
|
|
|
8
|
|
|
}) |
9
|
|
|
.then(() => { |
10
|
|
|
return cy.createSnippetFixture(); |
|
|
|
|
11
|
|
|
}) |
12
|
|
|
.then(() => { |
13
|
|
|
cy.openInitialPage(`${Cypress.env('admin')}#/sw/settings/snippet/index`); |
|
|
|
|
14
|
|
|
}); |
15
|
|
|
}); |
16
|
|
|
|
17
|
|
|
it('@base @settings: Read snippets', () => { |
18
|
|
|
cy.window().then((win) => { |
|
|
|
|
19
|
|
|
if (!win.Shopware.Feature.isActive('FEATURE_NEXT_3722')) { |
20
|
|
|
cy.log('Skipping test because of deactivated feature flag: "FEATURE_NEXT_3722"'); |
|
|
|
|
21
|
|
|
|
22
|
|
|
return; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
cy.loginAsUserWithPermissions([ |
26
|
|
|
{ |
27
|
|
|
key: 'snippet', |
28
|
|
|
role: 'viewer' |
29
|
|
|
} |
30
|
|
|
]); |
31
|
|
|
|
32
|
|
|
// visiting settings page to prove that snippets element is visible |
33
|
|
|
cy.visit(`${Cypress.env('admin')}#/sw/settings/snippet/index`); |
|
|
|
|
34
|
|
|
|
35
|
|
|
// go to snippet list |
36
|
|
|
cy.get('.sw-grid__row--0 > .sw-settings-snippet-set__column-name > .sw-grid__cell-content > a').click(); |
37
|
|
|
|
38
|
|
|
cy.get('.sw-data-grid-skeleton').should('not.exist'); |
39
|
|
|
|
40
|
|
|
// go to snippet detail page |
41
|
|
|
cy.get('.sw-data-grid__row--0 > .sw-data-grid__cell--id > .sw-data-grid__cell-content > a').click(); |
42
|
|
|
|
43
|
|
|
// check that card loading state got removed |
44
|
|
|
cy.get(':nth-child(1) > .sw-card__content > .sw-loader').should('not.exist'); |
45
|
|
|
cy.get(':nth-child(2) > .sw-card__content > .sw-loader').should('not.exist'); |
46
|
|
|
|
47
|
|
|
// check content and disabled state of input fields |
48
|
|
|
cy.get('#sw-field--translationKey') |
49
|
|
|
.should('to.have.prop', 'disabled', true) |
50
|
|
|
.invoke('val') |
51
|
|
|
.then(content => cy.expect(content).to.contain('aWonderful.customSnip')); |
|
|
|
|
52
|
|
|
|
53
|
|
|
cy.get(':nth-child(2) > .sw-field > .sw-block-field__block > #sw-field--snippet-value') |
54
|
|
|
.should('to.have.prop', 'disabled', true) |
55
|
|
|
.invoke('val') |
56
|
|
|
.then(content => cy.expect(content).to.contain('')); |
|
|
|
|
57
|
|
|
|
58
|
|
|
cy.get(':nth-child(1) > .sw-field > .sw-block-field__block > #sw-field--snippet-value') |
59
|
|
|
.should('to.have.prop', 'disabled', true) |
60
|
|
|
.invoke('val') |
61
|
|
|
.then(content => cy.expect(content).to.contain('')); |
|
|
|
|
62
|
|
|
}); |
63
|
|
|
}); |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
it('@base @settings: Edit snippets', () => { |
67
|
|
|
cy.window().then((win) => { |
|
|
|
|
68
|
|
|
if (!win.Shopware.Feature.isActive('FEATURE_NEXT_3722')) { |
69
|
|
|
cy.log('Skipping test because of deactivated feature flag: "FEATURE_NEXT_3722"'); |
|
|
|
|
70
|
|
|
|
71
|
|
|
return; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
cy.loginAsUserWithPermissions([ |
75
|
|
|
{ |
76
|
|
|
key: 'snippet', |
77
|
|
|
role: 'editor' |
78
|
|
|
} |
79
|
|
|
]); |
80
|
|
|
|
81
|
|
|
cy.server(); |
82
|
|
|
cy.route({ |
83
|
|
|
url: '/api/v*/snippet/*', |
84
|
|
|
method: 'patch' |
85
|
|
|
}).as('saveData'); |
86
|
|
|
|
87
|
|
|
// visiting settings page to prove that snippets element is visible |
88
|
|
|
cy.visit(`${Cypress.env('admin')}#/sw/settings/snippet/index`); |
|
|
|
|
89
|
|
|
|
90
|
|
|
cy.get('.sw-grid__row--0 > .sw-settings-snippet-set__column-name > .sw-grid__cell-content > a').click(); |
91
|
|
|
|
92
|
|
|
cy.get('.sw-data-grid-skeleton').should('not.exist'); |
93
|
|
|
|
94
|
|
|
// go to snippet detail page |
95
|
|
|
cy.get('.sw-data-grid__row--0 > .sw-data-grid__cell--id > .sw-data-grid__cell-content > a').click(); |
96
|
|
|
|
97
|
|
|
// check that card loading state got removed |
98
|
|
|
cy.get(':nth-child(1) > .sw-card__content > .sw-loader').should('not.exist'); |
99
|
|
|
cy.get(':nth-child(2) > .sw-card__content > .sw-loader').should('not.exist'); |
100
|
|
|
|
101
|
|
|
cy.get(':nth-child(1) > .sw-field > .sw-block-field__block > #sw-field--snippet-value').typeAndCheck('Gogoat'); |
102
|
|
|
|
103
|
|
|
// save changes |
104
|
|
|
cy.get('.sw-tooltip--wrapper > .sw-button').click(); |
105
|
|
|
|
106
|
|
|
// check request |
107
|
|
|
cy.wait('@saveData').then((xhr) => { |
108
|
|
|
expect(xhr).to.have.property('status', 204); |
109
|
|
|
}); |
110
|
|
|
}); |
111
|
|
|
}); |
112
|
|
|
|
113
|
|
|
it('@base @settings: Create snippets', () => { |
114
|
|
|
cy.window().then((win) => { |
|
|
|
|
115
|
|
|
if (!win.Shopware.Feature.isActive('FEATURE_NEXT_3722')) { |
116
|
|
|
cy.log('Skipping test because of deactivated feature flag: "FEATURE_NEXT_3722"'); |
|
|
|
|
117
|
|
|
|
118
|
|
|
return; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
cy.loginAsUserWithPermissions([ |
122
|
|
|
{ |
123
|
|
|
key: 'snippet', |
124
|
|
|
role: 'creator' |
125
|
|
|
} |
126
|
|
|
]); |
127
|
|
|
|
128
|
|
|
cy.server(); |
129
|
|
|
cy.route({ |
130
|
|
|
url: '/api/v*/snippet', |
131
|
|
|
method: 'post' |
132
|
|
|
}).as('saveData'); |
133
|
|
|
|
134
|
|
|
cy.visit(`${Cypress.env('admin')}#/sw/settings/snippet/index`); |
|
|
|
|
135
|
|
|
|
136
|
|
|
cy.get('.sw-grid__row--0 > .sw-settings-snippet-set__column-name > .sw-grid__cell-content > a').click(); |
137
|
|
|
|
138
|
|
|
// clicking snippet create button |
139
|
|
|
cy.get('.sw-tooltip--wrapper > .sw-button') |
140
|
|
|
.should('be.visible') |
141
|
|
|
.click(); |
142
|
|
|
|
143
|
|
|
// check if elements |
144
|
|
|
cy.get(':nth-child(1) > .sw-card__content > .sw-loader').should('not.be.exist'); |
145
|
|
|
cy.get(':nth-child(2) > .sw-card__content > .sw-loader').should('not.be.exist'); |
146
|
|
|
|
147
|
|
|
// fill out input fields |
148
|
|
|
cy.get('#sw-field--translationKey').typeAndCheck('random.snippet'); |
149
|
|
|
|
150
|
|
|
cy.get(':nth-child(1) > .sw-field > .sw-block-field__block > #sw-field--snippet-value').typeAndCheck('Zufällig'); |
151
|
|
|
|
152
|
|
|
cy.get(':nth-child(2) > .sw-field > .sw-block-field__block > #sw-field--snippet-value').typeAndCheck('Random'); |
153
|
|
|
|
154
|
|
|
// save new snippet |
155
|
|
|
cy.get('.sw-tooltip--wrapper > .sw-button') |
156
|
|
|
.should('be.visible') |
157
|
|
|
.click(); |
158
|
|
|
|
159
|
|
|
cy.wait('@saveData').then((xhr) => { |
160
|
|
|
expect(xhr).to.have.property('status', 204); |
161
|
|
|
}); |
162
|
|
|
}); |
163
|
|
|
}); |
164
|
|
|
|
165
|
|
|
it('@base @settings: Create snippet set', () => { |
166
|
|
|
cy.window().then((win) => { |
|
|
|
|
167
|
|
|
if (!win.Shopware.Feature.isActive('FEATURE_NEXT_3722')) { |
168
|
|
|
cy.log('Skipping test because of deactivated feature flag: "FEATURE_NEXT_3722"'); |
|
|
|
|
169
|
|
|
|
170
|
|
|
return; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
cy.loginAsUserWithPermissions([ |
174
|
|
|
{ |
175
|
|
|
key: 'snippet', |
176
|
|
|
role: 'creator' |
177
|
|
|
} |
178
|
|
|
]); |
179
|
|
|
|
180
|
|
|
cy.server(); |
181
|
|
|
cy.route({ |
182
|
|
|
url: '/api/v*/snippet-set', |
183
|
|
|
method: 'post' |
184
|
|
|
}).as('saveData'); |
185
|
|
|
|
186
|
|
|
cy.visit(`${Cypress.env('admin')}#/sw/settings/snippet/index`); |
|
|
|
|
187
|
|
|
|
188
|
|
|
cy.get('.sw-settings-snippet-set-list__action-add') |
189
|
|
|
.should('be.visible') |
190
|
|
|
.click(); |
191
|
|
|
|
192
|
|
|
cy.get('.sw-grid__row--0 > .sw-settings-snippet-set__column-name > .sw-grid__cell-inline-editing > .sw-field > .sw-block-field__block > #sw-field--item-name') |
193
|
|
|
.typeAndCheck('Custom de-DE'); |
194
|
|
|
|
195
|
|
|
cy.get('.sw-grid__row--0 > .sw-grid-row__actions > .sw-grid-row__inline-edit-action') |
196
|
|
|
.should('be.visible') |
197
|
|
|
.click(); |
198
|
|
|
|
199
|
|
|
cy.wait('@saveData').then((xhr) => { |
200
|
|
|
expect(xhr).to.have.property('status', 204); |
201
|
|
|
}); |
202
|
|
|
}); |
203
|
|
|
}); |
204
|
|
|
}); |
205
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.