Skip to content

Commit b411a96

Browse files
fix: Use correctly-cased postcode in Nightwatch tests, as per new validation (#383)
* Use correctly cased postcode in Nightwatch tests, as per new validation * Fix cypress tests * Specify CY version * fix nightwatch tests * fix nightwatch tests --------- Co-authored-by: Krupa Pammi <krupa.pammi@gmail.com>
1 parent 4798b5a commit b411a96

15 files changed

Lines changed: 64 additions & 63 deletions

File tree

cypress/integration/submit_spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ describe('e2e test', () => {
7878
cy.get('#field-input--postcode').clear();
7979
cy.get('#postcode_button').click();
8080
cy.get('#field-error--postcode>span').should('contain','No postcode provided');
81-
cy.get('#field-input--postcode').clear().type('s66%');
81+
cy.get('#field-input--postcode').clear().type('hp2 6lq'); // Lowercase
8282
cy.get('#field-error--postcode>span').should('contain','Please enter a valid UK postcode, using a space and capital letters');
83-
cy.get('#field-input--postcode').clear().type('s66');
83+
cy.get('#field-input--postcode').clear().type('HP26LQ'); // No space
8484
cy.get('#field-error--postcode>span').should('contain','Please enter a valid UK postcode, using a space and capital letters');
8585
cy.get('#field-input--postcode').clear().type('HP2 6LQ');
8686
cy.get('#postcode_button').click();

cypress/integration/update_spec.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ describe('e2e test typing transaction ID and choosing "yes" to claim gift aid on
9595
it('postcode field validation', () => {
9696
cy.get('#postcode_button').click();
9797
cy.get('#field-error--postcode>span').should('contain','No postcode provided');
98-
cy.get('#field-input--postcode').clear().type('s66%');
98+
cy.get('#field-input--postcode').clear().type('hp2 6lq'); // Lowercase
9999
cy.get('#field-error--postcode>span').should('contain','Please enter a valid UK postcode, using a space and capital letters');
100-
cy.get('#field-input--postcode').clear().type('s66');
100+
cy.get('#field-input--postcode').clear().type('HP26LQ');// No space
101101
cy.get('#field-error--postcode>span').should('contain','Please enter a valid UK postcode, using a space and capital letters');
102-
cy.get('#field-input--postcode').clear().type('se1 7tp');
102+
cy.get('#field-input--postcode').clear();
103103
cy.get('button[type=submit]').click();
104104

105105
cy.get('#field-error--addressDetails > span').should('contain','Please fill in your address');
@@ -127,7 +127,7 @@ describe('e2e test typing transaction ID and choosing "yes" to claim gift aid on
127127
cy.get('#giftAidClaimChoice > legend').should('contain','Can we claim Gift Aid on your donation?');
128128
cy.get('button[type=submit]').click();
129129
cy.get('#field-error--giftAidClaimChoice > span').should('contain','This field is required');
130-
cy.get('input[type="radio"]').check('1').should('be.checked');
130+
cy.get('input[type="radio"][value^="1"]').check().should('be.checked');
131131
cy.get('#field-error--giftAidClaimChoice > span').should('not.exist')
132132
});
133133

@@ -159,7 +159,7 @@ describe('e2e test typing transaction ID and choosing "No" to claim gift aid on
159159
cy.get('#field-input--postcode').clear().type('HP2 6LQ');
160160
cy.get('#postcode_button').click();
161161
cy.get('#field-select--addressSelect').should('be.visible').select('112 ST. AGNELLS LANE');
162-
cy.get('input[type="radio"]').check('0').should('be.checked');
162+
cy.get('input[type="radio"][value^="0"]').check().should('be.checked');
163163
cy.get('button[type=submit]').click().url('/success');
164164
cy.contains('Thanks for letting us know');
165165
cy.get('div.success-wrapper--inner > div > p').should('contain', successNoMessage)
@@ -174,14 +174,14 @@ describe('Giftaid test when user comes from sms,online or call centre', () => {
174174
cy.get('#form > div:nth-child(1) > h2').should('contain','Edit your Gift Aid declaration');
175175
cy.get('p.transaction-id').should('contain','Transaction ID: 3D787A59-716B-440D-BD23-50ED301DD9BA');
176176
cy.get('h3.form--update__title--donation').should('contain','How did you make the donation?');
177-
cy.get('input[type="radio"]').check('sms').should('be.checked');
177+
cy.get('input[type="radio"][value^="sms"]').check().should('be.checked');
178178
cy.get('#field-input--firstname').clear().type(firstName);
179179
cy.get('#field-input--lastname').clear().type(lastName);
180180
cy.get('#field-input--email').clear().type('giftaid-staging@email.sls.comicrelief.com');
181181
cy.get('#field-input--postcode').clear().type('HP2 6LQ');
182182
cy.get('#postcode_button').click();
183183
cy.get('#field-select--addressSelect').should('be.visible').select('112 ST. AGNELLS LANE');
184-
cy.get('input[type="radio"]').check('1').should('be.checked');
184+
cy.get('input[type="radio"][value^="1"]').check().should('be.checked');
185185
cy.get('button[type=submit]').click().url('/success');
186186
cy.get('.success-wrapper').should('contain', 'Thank you,').and('contain', `${firstName}!`);
187187
cy.get('div.success-wrapper--inner > div > p').should('contain',successYesMessage)
@@ -193,14 +193,14 @@ describe('Giftaid test when user comes from sms,online or call centre', () => {
193193
cy.get('#form > div:nth-child(1) > h2').should('contain','Edit your Gift Aid declaration');
194194
cy.get('p.transaction-id').should('contain','Transaction ID: bb9aa5c9-5d93-4a34-a102-aaf378d16a73');
195195
cy.get('h3.form--update__title--donation').should('contain','How did you make the donation?');
196-
cy.get('input[type="radio"]').check('online').should('be.checked');
196+
cy.get('input[type="radio"][value^="online"]').check().should('be.checked');
197197
cy.get('#field-input--firstname').clear().type(firstName);
198198
cy.get('#field-input--lastname').clear().type(lastName);
199199
cy.get('#field-input--email').clear().type('giftaid-staging@email.sls.comicrelief.com');
200200
cy.get('#field-input--postcode').clear().type('HP2 6LQ');
201201
cy.get('#postcode_button').click();
202202
cy.get('#field-select--addressSelect').should('be.visible').select('112 ST. AGNELLS LANE');
203-
cy.get('input[type="radio"]').check('1').should('be.checked');
203+
cy.get('input[type="radio"][value^="1"]').check().should('be.checked');
204204
cy.get('button[type=submit]').click().url('/success');
205205
cy.get('.success-wrapper').should('contain', 'Thank you,').and('contain', `${firstName}!`);
206206
cy.get('div.success-wrapper--inner > div > p').should('contain',successYesMessage)
@@ -220,7 +220,7 @@ describe('Giftaid test when user comes from sms,online or call centre', () => {
220220
cy.get('#field-input--postcode').clear().type('HP2 6LQ');
221221
cy.get('#postcode_button').click();
222222
cy.get('#field-select--addressSelect').should('be.visible').select('112 ST. AGNELLS LANE');
223-
cy.get('input[type="radio"]').check('1').should('be.checked');
223+
cy.get('input[type="radio"][value^="1"]').check().should('be.checked');
224224
cy.get('button[type=submit]').click().url('/success');
225225
cy.get('.success-wrapper').should('contain', 'Thank you,').and('contain', `${firstName}!`);
226226
cy.get('div.success-wrapper--inner > div > p').should('contain',successYesMessage)
@@ -273,7 +273,7 @@ describe('Ensure url validation if string is less than 5 characters', () => {
273273
cy.get('#form > div:nth-child(1) > h2').should('contain','Edit your Gift Aid declaration');
274274
cy.get('p.transaction-id').should('contain','Transaction ID: test');
275275
cy.get('h3.form--update__title--donation').should('contain','How did you make the donation?');
276-
cy.get('input[type="radio"]').check('online').should('be.checked');
276+
cy.get('input[type="radio"][value^="online"]').check().should('be.checked');
277277
cy.get('#field-input--firstname').clear().type(firstName);
278278
cy.get('#field-input--lastname').clear().type(lastName);
279279
cy.get('#field-input--email').clear().type('giftaid-staging@email.sls.comicrelief.com');

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"chalk": "2.4.1",
1414
"classnames": "^2.2.5",
1515
"core-js": "^2.5.7",
16-
"cypress": "^7.2.0",
16+
"cypress": "7.7.0",
1717
"dotenv": "5.0.1",
1818
"dotenv-expand": "4.2.0",
1919
"fs-extra": "5.0.0",

tests/commands/form.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const commands = {
2222
{
2323
firstName = 'test',
2424
lastName = 'user',
25-
postcode = 'sw19 1ne',
25+
postcode = 'SW19 1NE',
2626
address1 = '21 test road',
2727
town = 'London',
2828
} = {},
@@ -49,7 +49,7 @@ const commands = {
4949
{
5050
firstName = 'test',
5151
lastName = 'user',
52-
postcode = 'sw19 1ne',
52+
postcode = 'SW19 1NE',
5353
} = {},
5454
) {
5555
return client
@@ -131,7 +131,7 @@ const commands = {
131131
firstName = 'test',
132132
lastName = 'user',
133133
email = 'donate-staging@email.sls.comicrelief.com',
134-
postcode = 'sw19 1ne',
134+
postcode = 'SW19 1NE',
135135
address1 = '21 test road',
136136
town = 'London',
137137
} = {},

tests/commands/giftaid.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const updateCommands = {
1212
return client
1313
.setValue('#field-input--firstname', 'test')
1414
.setValue('#field-input--lastname', 'user' + randomString)
15-
.setValue('#field-input--postcode', 'se1 7tp')
15+
.setValue('#field-input--postcode', 'SE1 7TP')
1616
.click('a[aria-describedby=field-error--addressDetails]')
1717
.pause(200)
1818
.setValue('#field-input--address1', '21 test road')
@@ -31,7 +31,7 @@ const updateCommands = {
3131
.setValue('#field-input--firstname', 'test')
3232
.setValue('#field-input--lastname', 'user' + randomString)
3333
.setValue('#field-input--email', `giftaid-staging-${randomString}@email.sls.comicrelief.com`)
34-
.setValue('#field-input--postcode', 'se1 7tp')
34+
.setValue('#field-input--postcode', 'SE1 7TP')
3535
.click('a[aria-describedby=field-error--addressDetails]')
3636
.pause(200)
3737
.setValue('#field-input--address1', '21 test road')

tests/feature/submit/address.js

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = {
1010
client.setValue('#field-input--mobile', '07123456789');
1111
client.setValue('#field-input--firstname', 'test');
1212
client.setValue('#field-input--lastname', 'user');
13-
client.setValue('#field-input--postcode', 'se17tp');
13+
client.setValue('#field-input--postcode', 'SE1 7TP');
1414
client.click('#postcode_button');
1515
client.waitForElementVisible('select#field-select--addressSelect', 1000);
1616
client.expect.element('label#field-label--addressSelect').text.to.equal('Select your address');
@@ -32,7 +32,7 @@ module.exports = {
3232
client.setValue('#field-input--mobile', '07123456789');
3333
client.setValue('#field-input--firstname', 'test');
3434
client.setValue('#field-input--lastname', 'user');
35-
client.setValue('#field-input--postcode', 'se17tp');
35+
client.setValue('#field-input--postcode', 'SE1 7TP');
3636
client.click('a[aria-describedby=field-error--addressDetails]');
3737
client.waitForElementPresent('#field-input--address1', 1000);
3838
client.setValue('#field-input--address1', '21 test road');
@@ -54,62 +54,63 @@ module.exports = {
5454
client.setValue('#field-input--mobile', '07123456789');
5555
client.setValue('#field-input--firstname', 'test');
5656
client.setValue('#field-input--lastname', 'user');
57-
// postcode entered in lowercase should not show error message
57+
58+
// postcode entered in lowercase should show error message
5859
client.setValue('#field-input--postcode', 'se17tp');
59-
client.click('#postcode_button');
60-
client.assert.not.elementPresent('div#field-error--postcode > span');
60+
client.assert.textContains('div#field-error--postcode > span', 'Please enter a valid UK postcode, using a space and capital letters');
6161
client.clearValue('#field-input--postcode');
62-
// postcode entered in uppercase should not show error message
62+
63+
// postcode entered in uppercase should show error message
6364
client.setValue('#field-input--postcode', 'SE17TP');
64-
client.click('#postcode_button');
65-
client.assert.not.elementPresent('div#field-error--postcode > span');
65+
client.assert.textContains('div#field-error--postcode > span', 'Please enter a valid UK postcode, using a space and capital letters');
6666
client.clearValue('#field-input--postcode');
67+
6768
// postcode with valid spaces should not show error message
6869
client.setValue('#field-input--postcode', 'SE1 7TP');
69-
client.click('#postcode_button');
7070
client.assert.not.elementPresent('div#field-error--postcode > span');
7171
client.clearValue('#field-input--postcode');
72-
// postcode with extra spaces as long as the value is right should not show error message
72+
73+
// postcode with extra spaces should not show error message
7374
client.setValue('#field-input--postcode', 'SE 1 7TP');
74-
client.click('#postcode_button');
75-
client.assert.not.elementPresent('div#field-error--postcode > span');
75+
client.assert.textContains('div#field-error--postcode > span', 'Please enter a valid UK postcode, using a space and capital letters');
7676
client.clearValue('#field-input--postcode');
77+
7778
// postcode with extra numbers in first part should show error message
7879
client.setValue('#field-input--postcode', 'SE 134 7TP');
79-
client.click('#postcode_button');
8080
client.expect.element('div#field-error--postcode > span').text.to.equal('Please enter a valid UK postcode, using a space and capital letters');
8181
client.clearValue('#field-input--postcode');
82+
8283
// postcode with 3 numbers in second part should show error message
8384
client.setValue('#field-input--postcode', 'SE1 777TP');
84-
client.click('#postcode_button');
8585
client.expect.element('div#field-error--postcode > span').text.to.equal('Please enter a valid UK postcode, using a space and capital letters');
8686
client.clearValue('#field-input--postcode');
87+
8788
// postcode with 2 numbers in second part should show error message
8889
client.setValue('#field-input--postcode', 'SE1 77TP');
89-
client.click('#postcode_button');
90-
client.expect.element('div#field-error--postcode > span').text.to.equal('Sorry, we could not find any addresses in that postcode, please check the postcode, or use the manual entry');
90+
client.expect.element('div#field-error--postcode > span').text.to.equal('Please enter a valid UK postcode, using a space and capital letters');
91+
client.clearValue('#field-input--postcode');
92+
93+
// postcode with special characters should show error message
94+
client.setValue('#field-input--postcode', 'SE1@£7tp');
95+
client.expect.element('div#field-error--postcode > span').text.to.equal('Please enter a valid UK postcode, using a space and capital letters');
96+
client.clearValue('#field-input--postcode');
97+
98+
// valid postcode with lower and uppercase characters should not show error message
99+
client.setValue('#field-input--postcode', 'sE17tP');
100+
client.expect.element('div#field-error--postcode > span').text.to.equal('Please enter a valid UK postcode, using a space and capital letters');
91101
client.clearValue('#field-input--postcode');
92102

93-
// TODO: commenting out validation steps temporarily
94-
// // postcode with special characters should show error message
95-
// client.setValue('#field-input--postcode', 'SE1@£7tp');
96-
// client.click('#postcode_button');
97-
// client.expect.element('div#field-error--postcode > span').text.to.equal('Please enter a valid postcode');
98-
// client.clearValue('#field-input--postcode');
99-
// // valid postcode with lower and uppercase characters should not show error message
100-
// client.setValue('#field-input--postcode', 'sE17tP');
101-
// client.click('#postcode_button');
102-
// client.assert.not.elementPresent('div#field-error--postcode > span');
103-
// client.clearValue('#field-input--postcode');
104103
// submit form with valid postcode but not entering address field should show error messages on address fields
105-
client.setValue('#field-input--postcode', 'SE17TP');
104+
client.setValue('#field-input--postcode', 'SE1 7TP');
106105
client.click('button[type="submit"]');
107-
client.expect.element('div#field-error--addressSelect > span').text.to.equal('Please select your address');
108-
client.expect.element('a[aria-describedby=field-error--addressDetails]').text.to.equal('Or enter your address manually');
106+
client.expect.element('div#field-error--addressDetails > span').text.to.equal('Please fill in your address');
107+
109108
// click enter address manually link to see the error messages
109+
client.expect.element('a[aria-describedby=field-error--addressDetails]').text.to.equal('Or enter your address manually');
110110
client.click('a[aria-describedby=field-error--addressDetails]');
111111
client.expect.element('div#field-error--address1 > span').text.to.equal('Please fill in your address line 1');
112112
client.expect.element('div#field-error--town > span').text.to.equal('Please fill in your town/city');
113+
113114
// enter address fields with valid inputs should not show error messages
114115
client.setValue('input#field-input--address1', 'COMIC RELIEF');
115116
client.assert.not.elementPresent('div#field-error--address1 > span');

tests/feature/submit/erp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = {
1919
.setValue('#field-input--mobile', mobile)
2020
.setValue('#field-input--firstname', firstName)
2121
.setValue('#field-input--lastname', lastName)
22-
.setValue('#field-input--postcode', 'se1 7tp')
22+
.setValue('#field-input--postcode', 'SE1 7TP')
2323
.click('a[aria-describedby=field-error--addressDetails]')
2424
.pause(200)
2525
.setValue('#field-input--address1', '21 test road')

tests/feature/submit/error.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
22

3-
'@tags': ['sanity', 'error'],
3+
'@tags': ['sanity', 'submitError'],
44

55
'Verify error messages on empty giftaid submission': function (client) {
66
client.url(process.env.BASE_URL).maximizeWindow().waitForElementVisible('body', 1000);
@@ -23,7 +23,7 @@ module.exports = {
2323
client.setValue('#field-input--mobile', '07123456789');
2424
client.setValue('#field-input--firstname', 'test');
2525
client.setValue('#field-input--lastname', 'user');
26-
client.setValue('#field-input--postcode', 'se1 7tp');
26+
client.setValue('#field-input--postcode', 'SE1 7TP');
2727
client.click('#postcode_button');
2828
client.click('#field-select--addressSelect');
2929
client.click('#field-select--addressSelect>option:nth-child(6)');
@@ -40,7 +40,7 @@ module.exports = {
4040
client.click('#field-label--giftaid');
4141
client.setValue('#field-input--firstname', 'test');
4242
client.setValue('#field-input--lastname', 'user');
43-
client.setValue('#field-input--postcode', 'se1 7tp');
43+
client.setValue('#field-input--postcode', 'SE1 7TP');
4444
client.click('#postcode_button');
4545
client.click('#field-select--addressSelect');
4646
client.click('#field-select--addressSelect>option:nth-child(6)');
@@ -57,7 +57,7 @@ module.exports = {
5757
client.click('#field-label--giftaid');
5858
client.setValue('#field-input--mobile', '07123456789');
5959
client.setValue('#field-input--lastname', 'user');
60-
client.setValue('#field-input--postcode', 'se1 7tp');
60+
client.setValue('#field-input--postcode', 'SE1 7TP');
6161
client.click('#postcode_button');
6262
client.click('#field-select--addressSelect');
6363
client.click('#field-select--addressSelect>option:nth-child(6)');
@@ -74,7 +74,7 @@ module.exports = {
7474
client.click('#field-label--giftaid');
7575
client.setValue('#field-input--mobile', '07123456789');
7676
client.setValue('#field-input--firstname', 'test');
77-
client.setValue('#field-input--postcode', 'se1 7tp');
77+
client.setValue('#field-input--postcode', 'SE1 7TP');
7878
client.click('#postcode_button');
7979
client.click('#field-select--addressSelect');
8080
client.click('#field-select--addressSelect>option:nth-child(6)');
@@ -106,7 +106,7 @@ module.exports = {
106106
client.setValue('#field-input--mobile', '07123456789');
107107
client.setValue('#field-input--firstname', 'test');
108108
client.setValue('#field-input--lastname', 'user');
109-
client.setValue('#field-input--postcode', 'se1 7tp');
109+
client.setValue('#field-input--postcode', 'SE1 7TP');
110110
client.click('a[aria-describedby=field-error--addressDetails]');
111111
client.pause(200);
112112
client.setValue('#field-input--address1', '21 test road');

tests/feature/submit/marketingPreferencesData.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const testData = {
1414
address1: faker.address.streetName(),
1515
address2: faker.address.streetAddress(),
1616
address3: faker.address.city(),
17-
postcode: 'SE17TP',
17+
postcode: 'SE1 7TP',
1818
town: faker.address.county(),
1919
country: 'GB',
2020
};

tests/feature/submit/marketingPreferencesValidation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = {
1818
client.setValue('#field-input--mobile', mobile);
1919
client.setValue('#field-input--firstname', 'test');
2020
client.setValue('#field-input--lastname', 'user');
21-
client.setValue('#field-input--postcode', 'se1 7tp');
21+
client.setValue('#field-input--postcode', 'SE1 7TP');
2222
client.click('a[aria-describedby=field-error--addressDetails]');
2323
client.waitForElementPresent('#field-input--address1', 1000);
2424
client.setValue('#field-input--address1', '21 test road');

0 commit comments

Comments
 (0)