Passed
Push — master ( 17e648...ef4458 )
by Christian
16:52 queued 10s
created

  A

Complexity

Conditions 2

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 13
dl 0
loc 19
rs 9.75
c 0
b 0
f 0
1
/// <reference types="Cypress" />
2
import variantProduct from '../../../fixtures/variant-product.js';
3
4
function uploadImageUsingFileUpload(path, name) {
5
    cy.fixture(path).then(fileContent => {
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
        cy.get('.sw-cms-slot__config-modal .sw-media-upload-v2__file-input').upload(
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...
7
            {
8
                fileContent,
9
                fileName: name,
10
                mimeType: 'image/png'
11
            }, {
12
                subjectType: 'input'
13
            }
14
        );
15
    });
16
17
    const altValue = name.substr(0, name.lastIndexOf('.'));
18
19
    cy.get('.sw-media-preview-v2__item')
20
        .should('be.visible')
21
        .should('have.attr', 'alt', altValue);
22
}
23
24
describe('CMS: Check usage and editing of buy box elements', () => {
25
    beforeEach(() => {
26
        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...
27
            .then(() => {
28
                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...
29
            })
30
            .then(() => {
31
                return cy.createCmsFixture();
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...
32
            })
33
            .then(() => {
34
                return cy.createProductFixture(variantProduct);
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...
35
            })
36
            .then(() => {
37
                cy.viewport(1920, 1080);
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...
38
                cy.openInitialPage(`${Cypress.env('admin')}#/sw/cms/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...
39
            });
40
    });
41
42
    it('@base @content: use simple buy box element', () => {
43
        cy.onlyOnFeature('FEATURE_NEXT_10078');
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...
44
45
        cy.server();
46
        cy.route({
47
            url: `${Cypress.env('apiPath')}/cms-page/*`,
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...
48
            method: 'patch'
49
        }).as('saveData');
50
51
        cy.route({
52
            url: `${Cypress.env('apiPath')}/category/*`,
53
            method: 'patch'
54
        }).as('saveCategory');
55
56
        cy.server().route('GET', '/widgets/cms/buybox/**').as('loadData');
57
58
        cy.get('.sw-cms-list-item--0').click();
59
        cy.get('.sw-cms-section__empty-stage').should('be.visible');
60
61
        // Add a text block
62
        cy.get('.sw-cms-section__empty-stage').click();
63
        cy.get('#sw-field--currentBlockCategory').select('Text');
64
        cy.get('.sw-cms-preview-text').should('be.visible');
65
        cy.get('.sw-cms-preview-text').dragTo('.sw-cms-section__empty-stage');
66
        cy.get('.sw-cms-block__config-overlay').invoke('show');
67
        cy.get('.sw-cms-block__config-overlay').should('be.visible');
68
        cy.get('.sw-cms-block__config-overlay').click();
69
        cy.get('.sw-cms-block__config-overlay.is--active').should('be.visible');
70
        cy.get('.sw-cms-slot .sw-cms-slot__overlay').invoke('show');
71
72
        // Replace current element with buy box element
73
        cy.get('.sw-cms-slot .sw-cms-slot__element-action').first().click();
74
        cy.get('.sw-cms-slot__element-selection').should('be.visible');
75
        cy.get('.sw-cms-el-preview-buy-box').click();
76
77
        // Configure element product
78
        cy.get('.sw-cms-slot .sw-cms-slot__settings-action').click();
79
        cy.get('.sw-cms-slot__config-modal').should('be.visible');
80
        cy.get('.sw-cms-el-config-buy-box .sw-entity-single-select').type('Variant product');
81
        cy.get('.sw-product-variant-info__specification').contains('green').click();
82
        cy.get('.sw-cms-slot__config-modal .sw-button--primary').click();
83
        cy.get('.sw-cms-el-buy-box__price').first().contains('111,00');
84
85
        // Save new page layout
86
        cy.get('.sw-cms-detail__save-action').click();
87
        cy.wait('@saveData').then((xhr) => {
88
            expect(xhr).to.have.property('status', 204);
89
            cy.get('.sw-cms-detail__back-btn').click();
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...
90
        });
91
92
        // Assign layout to root category
93
        cy.visit(`${Cypress.env('admin')}#/sw/category/index`);
94
        cy.get('.sw-tree-item__element').contains('Home').click();
95
        cy.get('.sw-card.sw-category-layout-card').scrollIntoView();
96
        cy.get('.sw-category-detail-layout__change-layout-action').click();
97
        cy.get('.sw-modal__dialog').should('be.visible');
98
        cy.get('.sw-cms-layout-modal__content-item--0 .sw-field--checkbox').click();
99
        cy.get('.sw-modal .sw-button--primary').click();
100
        cy.get('.sw-card.sw-category-layout-card .sw-category-layout-card__desc-headline').contains('Vierte Wand');
101
        cy.get('.sw-category-detail__save-action').click();
102
103
        cy.wait('@saveCategory').then((response) => {
104
            expect(response).to.have.property('status', 204);
105
        });
106
107
        // Verify layout in Storefront
108
        cy.visit('/');
109
        cy.get('.product-detail-price').contains('111');
110
        cy.get('.product-detail-ordernumber').contains('TEST.2');
111
        cy.get('.product-detail-configurator-option-label[title="red"]').click();
112
113
        // Wait for reloading product variant
114
        cy.wait('@loadData').then((response) => {
115
            expect(response).to.have.property('status', 200);
116
            cy.get('.product-detail-ordernumber').contains('TEST.1');
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
119
        // Off canvas
120
        cy.get('.btn-buy').click();
121
        cy.get('.offcanvas').should('be.visible');
122
        cy.get('.cart-item-price').contains('111');
123
        cy.get('.cart-item-characteristics').contains('color');
124
        cy.get('.cart-item-characteristics-option').contains('red');
125
        cy.get('.cart-item-label[title="Variant product"]').should('be.visible');
126
    });
127
128
    it('@base @content: use simple gallery buy box block', () => {
129
        cy.onlyOnFeature('FEATURE_NEXT_10078');
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...
130
131
        cy.server();
132
        cy.route({
133
            url: `${Cypress.env('apiPath')}/cms-page/*`,
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...
134
            method: 'patch'
135
        }).as('saveData');
136
137
        cy.route({
138
            url: `${Cypress.env('apiPath')}/category/*`,
139
            method: 'patch'
140
        }).as('saveCategory');
141
142
        cy.route({
143
            url: `${Cypress.env('apiPath')}/_action/media/**/upload?extension=png&fileName=sw-login-background`,
144
            method: 'post'
145
        }).as('saveDataFileUpload');
146
147
        cy.get('.sw-cms-list-item--0').click();
148
        cy.get('.sw-cms-section__empty-stage').should('be.visible');
149
150
        // Add gallery buybox block
151
        cy.get('.sw-cms-section__empty-stage').click();
152
        cy.get('#sw-field--currentBlockCategory').select('Commerce');
153
        cy.get('.sw-cms-preview-gallery-buybox').should('be.visible');
154
        cy.get('.sw-cms-preview-gallery-buybox').dragTo('.sw-cms-section__empty-stage');
155
        cy.get('.sw-cms-block__config-overlay').invoke('show');
156
        cy.get('.sw-cms-block__config-overlay').should('be.visible');
157
        cy.get('.sw-cms-block__config-overlay').click();
158
        cy.get('.sw-cms-block__config-overlay.is--active').should('be.visible');
159
        cy.get('.sw-cms-slot .sw-cms-slot__overlay').invoke('show');
160
161
        // Configure element image gallery
162
        cy.get('.sw-cms-slot .sw-cms-slot__settings-action').first().click();
163
        cy.get('.sw-cms-slot__config-modal').should('be.visible');
164
165
        // Upload image
166
        uploadImageUsingFileUpload('img/sw-login-background.png', 'sw-login-background.png');
167
168
        cy.wait('@saveDataFileUpload').then((xhr) => {
169
            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...
170
            expect(xhr).to.have.property('status', 204);
171
        });
172
173
        cy.get('.sw-cms-slot__config-modal .sw-modal__footer .sw-button--primary').click();
174
175
        // Configure element product
176
        cy.get('.sw-cms-slot:nth-of-type(2) .sw-cms-slot__settings-action').click();
177
        cy.get('.sw-cms-slot__config-modal').should('be.visible');
178
        cy.get('.sw-cms-el-config-buy-box .sw-entity-single-select').type('Variant product');
179
        cy.get('.sw-product-variant-info__specification').contains('blue').click();
180
        cy.get('.sw-cms-slot__config-modal .sw-button--primary').click();
181
        cy.get('.sw-cms-el-buy-box__price').first().contains('111,00');
182
183
        // Save new page layout
184
        cy.get('.sw-cms-detail__save-action').click();
185
        cy.wait('@saveData').then((xhr) => {
186
            expect(xhr).to.have.property('status', 204);
187
            cy.get('.sw-cms-detail__back-btn').click();
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...
188
        });
189
190
        // Assign layout to root category
191
        cy.visit(`${Cypress.env('admin')}#/sw/category/index`);
192
        cy.get('.sw-tree-item__element').contains('Home').click();
193
        cy.get('.sw-card.sw-category-layout-card').scrollIntoView();
194
        cy.get('.sw-category-detail-layout__change-layout-action').click();
195
        cy.get('.sw-modal__dialog').should('be.visible');
196
        cy.get('.sw-cms-layout-modal__content-item--0 .sw-field--checkbox').click();
197
        cy.get('.sw-modal .sw-button--primary').click();
198
        cy.get('.sw-card.sw-category-layout-card .sw-category-layout-card__desc-headline').contains('Vierte Wand');
199
        cy.get('.sw-category-detail__save-action').click();
200
201
        cy.wait('@saveCategory').then((response) => {
202
            expect(response).to.have.property('status', 204);
203
        });
204
205
        // Verify layout in Storefront
206
        cy.visit('/');
207
        cy.get('.gallery-slider-image')
208
            .should('have.attr', 'src')
209
            .and('match', /sw-login-background/);
210
        cy.get('.product-detail-price').contains('111');
211
        cy.get('.product-detail-ordernumber').contains('TEST.3');
212
    });
213
});
214