Passed
Push — master ( 98c614...0a4358 )
by Christian
25:18 queued 14:30
created

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

Complexity

Total Complexity 24
Complexity/F 1.2

Size

Lines of Code 197
Function Count 20

Duplication

Duplicated Lines 197
Ratio 100 %

Importance

Changes 0
Metric Value
wmc 24
eloc 117
mnd 4
bc 4
fnc 20
dl 197
loc 197
rs 10
bpm 0.2
cpm 1.2
noi 21
c 0
b 0
f 0

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
// / <reference types="Cypress" />
2
3 View Code Duplication
import SettingsPageObject from '../../../support/pages/module/sw-settings.page-object';
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
4
5
describe('Unit: Test acl privileges', () => {
6
    beforeEach(() => {
7
        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...
8
            .then(() => {
9
                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...
10
            })
11
            .then(() => {
12
                return cy.createDefaultFixture('unit');
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...
13
            })
14
            .then(() => {
15
                cy.openInitialPage(`${Cypress.env('admin')}#/sw/dashboard/index`);
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...
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...
16
            });
17
    });
18
19
    it('@settings @unit: has no access to scale unit module', () => {
20
        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...
21
            if (!win.Shopware.Feature.isActive('FEATURE_NEXT_3722')) {
22
                return;
23
            }
24
25
            cy.loginAsUserWithPermissions([
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...
26
                {
27
                    key: 'product',
28
                    role: 'viewer'
29
                }
30
            ]).then(() => {
31
                cy.visit(`${Cypress.env('admin')}#/sw/settings/units/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...
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) => {
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...
46
            if (!win.Shopware.Feature.isActive('FEATURE_NEXT_3722')) {
47
                return;
48
            }
49
50
            const page = new SettingsPageObject();
51
52
            cy.loginAsUserWithPermissions([
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...
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`);
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...
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...
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) => {
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...
102
            if (!win.Shopware.Feature.isActive('FEATURE_NEXT_3722')) {
103
                return;
104
            }
105
106
            const page = new SettingsPageObject();
107
108
            cy.loginAsUserWithPermissions([
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...
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`);
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...
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...
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) => {
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...
153
            if (!win.Shopware.Feature.isActive('FEATURE_NEXT_3722')) {
154
                return;
155
            }
156
157
            const page = new SettingsPageObject();
158
159
            cy.loginAsUserWithPermissions([
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...
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`);
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...
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