Passed
Push — master ( 87f5a4...2b77b2 )
by Christian
12:13 queued 10s
created

src/Administration/Resources/app/administration/test/e2e/cypress/integration/order/sw-order/edit-add-credit-note.spec.js   A

Complexity

Total Complexity 11
Complexity/F 1

Size

Lines of Code 121
Function Count 11

Duplication

Duplicated Lines 24
Ratio 19.83 %

Importance

Changes 0
Metric Value
wmc 11
eloc 79
mnd 0
bc 0
fnc 11
dl 24
loc 121
rs 10
bpm 0
cpm 1
noi 9
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
import OrderPageObject from '../../../support/pages/module/sw-order.page-object';
4
5
describe('Order: Create credit note', () => {
6 View Code Duplication
    beforeEach(() => {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
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.createProductFixture();
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
                return cy.searchViaAdminApi({
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...
16
                    endpoint: 'product',
17
                    data: {
18
                        field: 'name',
19
                        value: 'Product name'
20
                    }
21
                });
22
            })
23
            .then((result) => {
24
                return cy.createGuestOrder(result.id);
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...
25
            })
26
            .then(() => {
27
                cy.openInitialPage(`${Cypress.env('admin')}#/sw/order/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...
28
            });
29
    });
30
31
    it('@base @order: create credit note', () => {
32
        const page = new OrderPageObject();
33
34
        cy.route({
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
            url: `${Cypress.env('apiPath')}/_action/order/**/recalculate`,
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...
36
            method: 'post'
37
        }).as('orderRecalculateCall');
38
39
        cy.route({
40
            url: `${Cypress.env('apiPath')}/_action/order/*/document/invoice`,
41
            method: 'post'
42
        }).as('createInvoice');
43
44
        cy.route({
45
            url: `${Cypress.env('apiPath')}/_action/order/*/document/credit_note`,
46
            method: 'post'
47
        }).as('createCreditNote');
48
49
        cy.get(`${page.elements.dataGridRow}--0`).contains('Max Mustermann');
50
        cy.clickContextMenuItem(
51
            '.sw-order-list__order-view-action',
52
            page.elements.contextMenuButton,
53
            `${page.elements.dataGridRow}--0`
54
        );
55
56
        cy.get(`${page.elements.userMetadata}-user-name`)
57
            .contains('Max Mustermann');
58
        cy.get('.sw-order-detail__smart-bar-edit-button').click();
59
        cy.get('.sw-context-button .sw-button--ghost').click();
60
        cy.get('.sw-order-line-items-grid__can-create-discounts-button').click();
61
62
        cy.get('.sw-data-grid__row--0').dblclick();
63
        cy.get('#sw-field--item-label').type('Discount 100 Euro');
64
        cy.get('#sw-field--item-priceDefinition-price').clear().type('-100');
65
66
        cy.get('.sw-data-grid__inline-edit-save').click();
67
68
        cy.wait('@orderRecalculateCall').then((xhr) => {
69
            expect(xhr).to.have.property('status', 204);
70
        });
71
72
        cy.get('.sw-order-detail__smart-bar-save-button').click();
73
74
75
        // Open Invoice modal
76
        cy.get('.sw-order-detail-base__document-grid').scrollIntoView();
77
        cy.get('.sw-order-detail-base__document-grid').should('be.visible');
78
        cy.get(page.elements.loader).should('not.exist');
79
        cy.clickContextMenuItem(
80
            '.sw-context-menu-item',
81
            '.sw-order-document-grid-button',
82
            null,
83
            'Invoice'
84
        );
85
86
        // Generate invoice
87
        cy.get('.sw-order-document-settings-modal__settings-modal').should('be.visible');
88
        cy.get('#sw-field--documentConfig-documentComment').type('New invoice');
89
        cy.get('.sw-order-document-settings-modal__settings-modal .sw-button--primary').click();
90
91
        cy.wait('@createInvoice').then((xhr) => {
92
            expect(xhr).to.have.property('status', 200);
93
        });
94
95
        // Open create edit note modal
96
        cy.get('.sw-order-detail-base__document-grid').scrollIntoView();
97
        cy.get('.sw-order-detail-base__document-grid').should('be.visible');
98
        cy.get(page.elements.loader).should('not.exist');
99
100
        cy.reload();
101
        cy.get('.sw-order-detail-base__document-grid').scrollIntoView();
102
103
        cy.clickContextMenuItem(
104
            '.sw-context-menu-item',
105
            '.sw-order-document-grid-button',
106
            null,
107
            'Credit note'
108
        );
109
110
        cy.get('#sw-field--documentConfig-custom-invoiceNumber').select('1000');
111
112
        cy.get('.sw-modal__footer button.sw-button--primary').should('be.visible');
113
        cy.get('.sw-modal__footer button.sw-button--primary').click();
114
115
        cy.wait('@createCreditNote').then((xhr) => {
116
            expect(xhr).to.have.property('status', 200);
117
        });
118
119
        // check exsits credit note
120
        cy.get('.sw-simple-search-field--form input[placeholder="Search all documents..."]').type('Credit note');
121
        cy.get('.sw-data-grid__row.sw-data-grid__row--0').contains('Credit note');
122
    });
123
});
124