Passed
Push — master ( f464a9...c131ba )
by Christian
13:24 queued 10s
created

src/Storefront/Resources/app/storefront/test/e2e/cypress/integration/contact/contact-form.spec.js   A

Complexity

Total Complexity 14
Complexity/F 1.08

Size

Lines of Code 91
Function Count 13

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 14
eloc 57
mnd 1
bc 1
fnc 13
dl 0
loc 91
rs 10
bpm 0.0769
cpm 1.0769
noi 13
c 0
b 0
f 0

4 Functions

Rating   Name   Duplication   Size   Complexity  
A contact-form.spec.js ➔ submitContactForm 0 13 2
A contact-form.spec.js ➔ fillOutContactForm 0 12 2
A contact-form.spec.js ➔ openContactForm 0 19 4
A contact-form.spec.js ➔ checkForCorrectlyLabelledPrivacyInformationCheckbox 0 8 3
1
const selector = {
2
    footerLinkContact: '.footer-contact-form a[data-toggle="modal"]',
3
    formContact: 'form[action="/form/contact"]',
4
    formContactSalutation: '#form-Salutation',
5
    formContactFirstName: '#form-firstName',
6
    formContactLastName: '#form-lastName',
7
    formContactMail: '#form-email',
8
    formContactPhone: '#form-phone',
9
    formContactSubject: '#form-subject',
10
    formContactComment: '#form-comment',
11
    formContactDataProtectionCheckbox: '.privacy-notice input[type="checkbox"]',
12
    formContactButtonSubmit: 'button[type="submit"]',
13
    modalButtonDismiss: 'button[data-dismiss="modal"]'
14
}
15
16
describe('Contact form', () => {
17
    function openContactForm(callback) {
0 ignored issues
show
Bug introduced by
The function openContactForm is declared conditionally. This is not supported by all runtimes. Consider moving it to root scope or using var openContactForm = function() { /* ... */ }; instead.
Loading history...
18
        cy.visit('/');
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
20
        cy.server();
21
        cy.route({
22
            url: '/widgets/cms/*',
23
            method: 'GET'
24
        }).as('contactFormRequest');
25
26
        cy.get(selector.footerLinkContact).click();
27
28
        cy.wait('@contactFormRequest').then(() => {
29
            cy.get(selector.modalButtonDismiss).should('be.visible');
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...
30
31
            if (typeof callback === 'function') {
32
                callback(arguments);
33
            }
34
        });
35
    }
36
37
    function fillOutContactForm() {
0 ignored issues
show
Bug introduced by
The function fillOutContactForm is declared conditionally. This is not supported by all runtimes. Consider moving it to root scope or using var fillOutContactForm = function() { /* ... */ }; instead.
Loading history...
38
        cy.get(selector.formContact).within(() => {
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...
39
            cy.get(selector.formContactSalutation).select('Not specified');
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...
40
            cy.get(selector.formContactFirstName).type('Foo');
41
            cy.get(selector.formContactLastName).type('Bar');
42
            cy.get(selector.formContactMail).type('[email protected]');
43
            cy.get(selector.formContactPhone).type('+123456789');
44
            cy.get(selector.formContactSubject).type('Lorem ipsum');
45
            cy.get(selector.formContactComment).type('Dolor sit amet.');
46
            cy.get(selector.formContactDataProtectionCheckbox).check({force: true});
47
        });
48
    }
49
50
    function submitContactForm(callback) {
0 ignored issues
show
Bug introduced by
The function submitContactForm is declared conditionally. This is not supported by all runtimes. Consider moving it to root scope or using var submitContactForm = function() { /* ... */ }; instead.
Loading history...
51
        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...
52
        cy.route({
53
            url: '/form/contact',
54
            method: 'POST'
55
        }).as('contactFormPostRequest');
56
57
        cy.get(selector.formContact).within(() => {
58
            cy.get(selector.formContactButtonSubmit).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...
59
        });
60
61
        cy.wait('@contactFormPostRequest').then(callback);
62
    }
63
64
    function checkForCorrectlyLabelledPrivacyInformationCheckbox() {
0 ignored issues
show
Bug introduced by
The function checkForCorrectlyLabelle...vacyInformationCheckbox is declared conditionally. This is not supported by all runtimes. Consider moving it to root scope or using var checkForCorrectlyLab...nction() { /* ... */ }; instead.
Loading history...
65
        cy.get(selector.formContact).within(() => {
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...
66
            cy.get(selector.formContactDataProtectionCheckbox).invoke('attr', '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...
67
                .then((id) => {
68
                    cy.get(`label[for="${id}"]`).should('be.visible');
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...
69
                });
70
        });
71
    }
72
73
    before(() => {
74
        openContactForm();
75
    });
76
77
    it('@contact: Should be possible to fill out and submit the contact form', () => {
78
        /**
79
         * This is a regression test for NEXT-12092.
80
         *
81
         * @see https://issues.shopware.com/issues/NEXT-12092
82
         */
83
        checkForCorrectlyLabelledPrivacyInformationCheckbox();
84
85
        fillOutContactForm();
86
87
        submitContactForm((response) => {
88
            expect(response).to.have.property('status', 200);
89
        });
90
    });
91
});
92