Passed
Push — master ( f484f2...13f225 )
by Christian
12:08
created

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

Complexity

Total Complexity 28
Complexity/F 1.33

Size

Lines of Code 205
Function Count 21

Duplication

Duplicated Lines 205
Ratio 100 %

Importance

Changes 0
Metric Value
wmc 28
eloc 131
dl 205
loc 205
rs 10
c 0
b 0
f 0
mnd 7
bc 7
fnc 21
bpm 0.3333
cpm 1.3333
noi 27

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 MediaPageObject from "../../../support/pages/module/sw-media.page-object";
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
4
5
describe('Property: 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
                cy.openInitialPage(`${Cypress.env('admin')}#/sw/media/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...
13
            });
14
    });
15
16
    it('@media: has no access to media module', () => {
17
        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...
18
            if (!win.Shopware.Feature.isActive('FEATURE_NEXT_3722')) {
19
                return;
20
            }
21
22
            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...
23
                {
24
                    key: 'property',
25
                    role: 'viewer'
26
                }
27
            ]).then(() => {
28
                cy.openInitialPage(`${Cypress.env('admin')}#/sw/media/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...
29
            });
30
31
            // open media-payment without permissions
32
            cy.get('.sw-privilege-error__access-denied-image').should('be.visible');
33
            cy.get('h1').contains('Access denied');
34
            cy.get('.sw-media-library').should('not.exist');
35
36
            // see menu without media-payment menu item
37
            cy.get('.sw-content > span.sw-admin-menu__navigation-link').click();
38
            cy.get('.sw-admin-menu__navigation-list-item.sw-media').should('not.exist');
39
        });
40
    });
41
42
    it('@media: can view media', () => {
43
        const page = new MediaPageObject();
44
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
            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...
51
                {
52
                    key: 'media',
53
                    role: 'viewer'
54
                }
55
            ]).then(() => {
56
                cy.visit(`${Cypress.env('admin')}#/sw/media/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...
57
            });
58
59
            // check upload
60
            cy.get('.sw-media-upload-v2__button-compact-upload').should('be.disabled');
61
            cy.get('.sw-media-upload-v2__button-context-menu').should('be.disabled');
62
63
            cy.clickContextMenuItem(
64
                '.sw-media-context-item__show-media-action',
65
                page.elements.contextMenuButton,
66
                '.sw-media-grid-item__item--0'
67
            );
68
            cy.get('.sw-media-sidebar__quickaction--disabled.quickaction--move').should('be.visible');
69
        });
70
    });
71
72
    it('@media: can edit media', () => {
73
        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...
74
            if (!win.Shopware.Feature.isActive('FEATURE_NEXT_3722')) {
75
                return;
76
            }
77
78
            // Request we want to wait for later
79
            cy.server();
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...
80
            cy.route({
81
                url: '/api/v*/media-method/*',
82
                method: 'patch'
83
            }).as('savePayment');
84
85
            const page = new MediaPageObject();
86
87
            cy.loginAsUserWithPermissions([
88
                {
89
                    key: 'media',
90
                    role: 'viewer'
91
                }, {
92
                    key: 'media',
93
                    role: 'editor'
94
                }
95
            ]).then(() => {
96
                cy.visit(`${Cypress.env('admin')}#/sw/media/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...
97
            });
98
            cy.get('.sw-media-upload-v2__button-compact-upload').should('be.disabled');
99
            cy.get('.sw-media-upload-v2__button-context-menu').should('be.disabled');
100
101
            // open media method
102
            cy.clickContextMenuItem(
103
                '.sw-media-context-item__show-media-action',
104
                page.elements.contextMenuButton,
105
                '.sw-media-grid-item__item--0'
106
            );
107
            cy.get('.sw-media-sidebar__quickaction--disabled.quickaction--move').should('not.exist');
108
        });
109
    });
110
111
    it('@media: can create media', () => {
112
        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...
113
            if (!win.Shopware.Feature.isActive('FEATURE_NEXT_3722')) {
114
                return;
115
            }
116
117
            cy.server();
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...
118
            cy.route({
119
                url: `${Cypress.env('apiPath')}/_action/media/**/upload?extension=png&fileName=sw-login-background`,
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...
120
                method: 'post'
121
            }).as('saveDataFileUpload');
122
123
            cy.route({
124
                url: `${Cypress.env('apiPath')}/_action/media/**/upload?extension=png&fileName=sw_logo_white`,
125
                method: 'post'
126
            }).as('saveDataUrlUpload');
127
128
            const page = new MediaPageObject();
129
130
            cy.loginAsUserWithPermissions([
131
                {
132
                    key: 'media',
133
                    role: 'viewer'
134
                }, {
135
                    key: 'media',
136
                    role: 'editor'
137
                }, {
138
                    key: 'media',
139
                    role: 'creator'
140
                }
141
            ]).then(() => {
142
                cy.visit(`${Cypress.env('admin')}#/sw/media/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...
143
            });
144
145
            cy.get('.sw-media-upload-v2__button-compact-upload').should('be.enabled');
146
            cy.get('.sw-media-upload-v2__button-context-menu').should('be.enabled');
147
148
            if (Cypress.isBrowser({ family: 'chromium' })) {
149
                page.uploadImageUsingFileUpload('img/sw-login-background.png', 'sw-login-background.png');
150
151
                cy.wait('@saveDataFileUpload').then((xhr) => {
152
                    cy.awaitAndCheckNotification('File has been saved.');
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
                    expect(xhr).to.have.property('status', 204);
154
                });
155
                cy.get('.sw-media-base-item__name[title="sw-login-background.png"]')
156
                    .should('be.visible');
157
            }
158
159
            if (Cypress.isBrowser('firefox')) {
160
                // Upload medium
161
                cy.clickContextMenuItem(
162
                    '.sw-media-upload-v2__button-url-upload',
163
                    '.sw-media-upload-v2__button-context-menu'
164
                );
165
                page.uploadImageUsingUrl('http://assets.shopware.com/sw_logo_white.png');
166
167
                cy.wait('@saveDataUrlUpload').then((xhr) => {
168
                    cy.awaitAndCheckNotification('File has been saved.');
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
                    expect(xhr).to.have.property('status', 204);
170
                });
171
                cy.get('.sw-media-base-item__name[title="sw_logo_white.png"]')
172
                    .should('be.visible');
173
174
            }
175
        });
176
    });
177
178
    it('@media: can delete media', () => {
179
        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...
180
            if (!win.Shopware.Feature.isActive('FEATURE_NEXT_3722')) {
181
                return;
182
            }
183
            const page = new MediaPageObject();
184
185
            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...
186
                {
187
                    key: 'media',
188
                    role: 'deleter'
189
                }
190
            ]).then(() => {
191
                cy.visit(`${Cypress.env('admin')}#/sw/media/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...
192
            });
193
194
            // check upload
195
            cy.get('.sw-media-upload-v2__button-compact-upload').should('be.disabled');
196
            cy.get('.sw-media-upload-v2__button-context-menu').should('be.disabled');
197
198
            cy.clickContextMenuItem(
199
                '.sw-media-context-item__show-media-action',
200
                page.elements.contextMenuButton,
201
                '.sw-media-grid-item__item--0'
202
            );
203
            cy.get('.sw-media-sidebar__quickaction--disabled.quickaction--move').should('be.visible');
204
            cy.get('.sw-media-sidebar__quickaction--disabled.quickaction--deleter').should('not.exist');
205
        });
206
    });
207
});
208