Passed
Push — master ( 3ab250...d456bb )
by Christian
12:04 queued 14s
created

src/Administration/Resources/app/administration/test/e2e/cypress/integration/settings/sw-settings-snippets/acl.spec.js   A

Complexity

Total Complexity 23
Complexity/F 1.21

Size

Lines of Code 202
Function Count 19

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 23
eloc 114
mnd 4
bc 4
fnc 19
dl 0
loc 202
bpm 0.2105
cpm 1.2105
noi 20
c 0
b 0
f 0
rs 10
1
// / <reference types="Cypress" />
2
3
describe('Snippets: Test acl privileges', () => {
4
    beforeEach(() => {
5
        cy.setToInitialState()
0 ignored issues
show
Bug introduced by
The variable cy seems to be never declared. If this is a global, consider adding a /** global: cy */ comment.

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.

Loading history...
6
            .then(() => {
7
                cy.loginViaApi();
0 ignored issues
show
Bug introduced by
The variable cy seems to be never declared. If this is a global, consider adding a /** global: cy */ comment.

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.

Loading history...
8
            })
9
            .then(() => {
10
                return cy.createSnippetFixture();
0 ignored issues
show
Bug introduced by
The variable cy seems to be never declared. If this is a global, consider adding a /** global: cy */ comment.

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.

Loading history...
11
            })
12
            .then(() => {
13
                cy.openInitialPage(`${Cypress.env('admin')}#/sw/settings/snippet/index`);
0 ignored issues
show
Bug introduced by
The variable Cypress seems to be never declared. If this is a global, consider adding a /** global: Cypress */ comment.

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.

Loading history...
Bug introduced by
The variable cy seems to be never declared. If this is a global, consider adding a /** global: cy */ comment.

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.

Loading history...
14
            });
15
    });
16
17
    it('@base @settings: Read snippets', () => {
18
        cy.window().then((win) => {
0 ignored issues
show
Bug introduced by
The variable cy seems to be never declared. If this is a global, consider adding a /** global: cy */ comment.

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.

Loading history...
19
            if (!win.Shopware.Feature.isActive('FEATURE_NEXT_3722')) {
20
                cy.log('Skipping test because of deactivated feature flag: "FEATURE_NEXT_3722"');
0 ignored issues
show
Bug introduced by
The variable cy seems to be never declared. If this is a global, consider adding a /** global: cy */ comment.

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.

Loading history...
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`);
0 ignored issues
show
Bug introduced by
The variable Cypress seems to be never declared. If this is a global, consider adding a /** global: Cypress */ comment.

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.

Loading history...
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'));
0 ignored issues
show
Bug introduced by
The variable cy seems to be never declared. If this is a global, consider adding a /** global: cy */ comment.

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.

Loading history...
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(''));
0 ignored issues
show
Bug introduced by
The variable cy seems to be never declared. If this is a global, consider adding a /** global: cy */ comment.

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.

Loading history...
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(''));
0 ignored issues
show
Bug introduced by
The variable cy seems to be never declared. If this is a global, consider adding a /** global: cy */ comment.

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.

Loading history...
62
        });
63
    });
64
65
66
    it('@base @settings: Edit snippets', () => {
67
        cy.window().then((win) => {
0 ignored issues
show
Bug introduced by
The variable cy seems to be never declared. If this is a global, consider adding a /** global: cy */ comment.

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.

Loading history...
68
            if (!win.Shopware.Feature.isActive('FEATURE_NEXT_3722')) {
69
                cy.log('Skipping test because of deactivated feature flag: "FEATURE_NEXT_3722"');
0 ignored issues
show
Bug introduced by
The variable cy seems to be never declared. If this is a global, consider adding a /** global: cy */ comment.

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.

Loading history...
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`);
0 ignored issues
show
Bug introduced by
The variable Cypress seems to be never declared. If this is a global, consider adding a /** global: Cypress */ comment.

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.

Loading history...
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) => {
0 ignored issues
show
Bug introduced by
The variable cy seems to be never declared. If this is a global, consider adding a /** global: cy */ comment.

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.

Loading history...
115
            if (!win.Shopware.Feature.isActive('FEATURE_NEXT_3722')) {
116
                cy.log('Skipping test because of deactivated feature flag: "FEATURE_NEXT_3722"');
0 ignored issues
show
Bug introduced by
The variable cy seems to be never declared. If this is a global, consider adding a /** global: cy */ comment.

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.

Loading history...
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`);
0 ignored issues
show
Bug introduced by
The variable Cypress seems to be never declared. If this is a global, consider adding a /** global: Cypress */ comment.

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.

Loading history...
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) => {
0 ignored issues
show
Bug introduced by
The variable cy seems to be never declared. If this is a global, consider adding a /** global: cy */ comment.

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.

Loading history...
167
            if (!win.Shopware.Feature.isActive('FEATURE_NEXT_3722')) {
168
                cy.log('Skipping test because of deactivated feature flag: "FEATURE_NEXT_3722"');
0 ignored issues
show
Bug introduced by
The variable cy seems to be never declared. If this is a global, consider adding a /** global: cy */ comment.

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.

Loading history...
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`);
0 ignored issues
show
Bug introduced by
The variable Cypress seems to be never declared. If this is a global, consider adding a /** global: Cypress */ comment.

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.

Loading history...
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