Skip to content

Commit

Permalink
newsletter e2e specs
Browse files Browse the repository at this point in the history
  • Loading branch information
tsubik committed Feb 7, 2024
1 parent 09c921e commit 9b0eeaa
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 19 deletions.
1 change: 1 addition & 0 deletions components/users/newsletter.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const NewsletterForm = ({ language }) => {

const handleSubmit = () => {
formRef.current.submit();
return Promise.resolve();
}

const formInitialState = {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 61 additions & 0 deletions e2e/cypress/e2e/newsletter.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
describe('Newsletter page', () => {
beforeEach(() => {
cy.visit('/newsletter');
});

it('displays content', function () {
cy.contains('Newsletter');
cy.contains('First Name');
cy.contains('Last Name');
cy.contains('Email');
cy.contains('Organization');
cy.contains('Country');
});

it('matches visually', function () {
cy.matchImage();
});

it.only('can submit form', function () {
cy.intercept('https://api.db-ip.com/v2/free/self', {
body: {
ipAddress: '85.34.21.23'
}
});
cy.contains('Sign up').click();
cy.get('.rrt-text').should('have.text', 'Fill all the required fields');
cy.get('input[name=first_name] ~ .error').should('have.text', 'The field is required');
cy.get('input[name=last_name] ~ .error').should('have.text', 'The field is required');
cy.get('input[name=email] ~ .error').should('have.text', 'The field is requiredThe field should be a valid email address');
cy.get('input[name=organization] ~ .error').should('have.text', 'The field is required');
cy.get('#select-country ~ .error').should('have.text', 'The field is required');

cy.get('input[name=first_name]').type('John');
cy.get('input[name=last_name]').type('Example');
cy.get('input[name=email]').type('[email protected]');
cy.get('input[name=organization]').type('Example Inc');
cy.selectOption('[name=country]', 'Po', 'Poland');

cy.intercept('POST', 'https://ortto.wri.org/custom-forms', (req) => {
const formData = new URLSearchParams(req.body);

expect(formData.get('website')).to.equal('opentimberportal.org');
expect(formData.get('form-name')).to.equal('Open Timber Portal Newsletter Signup');
expect(formData.get('list')).to.equal('FOR - OTP - Open Timber Portal Newsletter – LIST');
expect(formData.get('interests')).to.equal('Forests');
expect(formData.get('preferred_language')).to.equal('en');
expect(formData.get('ip_addr')).to.equal('85.34.21.23');
expect(formData.get('first_name')).to.equal('John');
expect(formData.get('last_name')).to.equal('Example');
expect(formData.get('email')).to.equal('[email protected]');
expect(formData.get('organization')).to.equal('Example Inc');
expect(formData.get('country')).to.equal('Poland');

req.reply({ statusCode: 302, headers: { location: 'http://localhost:4000/newsletter/thank-you' } });
}).as('submitForm');

cy.get('button').contains('Sign up').click();
cy.wait('@submitForm');
cy.contains('You are now signed up to receive updates from the Open Timber Portal.');
});
})
19 changes: 0 additions & 19 deletions e2e/cypress/e2e/pages.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,4 @@ describe('Pages', () => {
cy.contains('List of Cookies that May Be Set');
})
})

describe('Newsletter page', () => {
beforeEach(() => {
cy.visit('/newsletter');
})

it('displays content', function () {
cy.contains('Newsletter');
cy.contains('First Name');
cy.contains('Last Name');
cy.contains('Email');
cy.contains('Organization');
cy.contains('Country');
})

it('matches visually', function () {
cy.matchImage();
})
})
});

0 comments on commit 9b0eeaa

Please sign in to comment.