|
| 1 | +function generateRandomEmail() { |
| 2 | + const chars = 'abcdefghijklmnopqrstuvwxyz0123456789'; |
| 3 | + let email = ''; |
| 4 | + for (let i = 0; i < 16; i++) { |
| 5 | + email += chars.charAt(Math.floor(Math.random() * chars.length)); |
| 6 | + } |
| 7 | + return email + '@example.com'; |
| 8 | +} |
| 9 | + |
1 | 10 | describe('Check newsletter subribe', () => { |
2 | 11 | it('Test empty input', () => { |
3 | 12 | cy.visit('/') |
4 | 13 | cy.get('#newsletter-validate-detail button[type="submit"]').click(); |
5 | 14 | cy.get('#advice-required-entry-newsletter').should('include.text', 'This is a required field.'); |
6 | 15 | }) |
7 | 16 |
|
8 | | - it('Test invalid input', () => { |
| 17 | + it('Test valid input twice', () => { |
| 18 | + const randomEmail = generateRandomEmail(); |
9 | 19 | cy.visit('/') |
10 | | - cy.get('#newsletter').type('notvalidemail'); |
| 20 | + cy.get('#newsletter').type(randomEmail); |
11 | 21 | cy.get('#newsletter-validate-detail button[type="submit"]').click(); |
12 | | - cy.get('.success-msg').should('include.text', 'Please enter a valid email address.'); |
13 | | - }) |
| 22 | + cy.get('.success-msg').should('include.text', 'Thank you for your subscription.'); |
14 | 23 |
|
15 | | - it('Test valid input', () => { |
16 | | - cy.visit('/') |
17 | | - cy.get('#newsletter').type('[email protected]'); |
| 24 | + cy.get('#newsletter').type(randomEmail); |
18 | 25 | cy.get('#newsletter-validate-detail button[type="submit"]').click(); |
19 | | - cy.get('.success-msg').should('include.text', 'Thank you for your subscription.'); |
| 26 | + cy.get('.success-msg').should('include.text', 'There was a problem with the subscription: This email address is already registered.'); |
20 | 27 | }) |
21 | 28 | }) |
0 commit comments