forms.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. const apiUrl = Cypress.env('apiUrl');
  2. describe('Forms', () => {
  3. it('Opens forms page', () => {
  4. cy.resetDB();
  5. cy.loginAndVisit('/lists/forms');
  6. });
  7. it('Checks form URL', () => {
  8. cy.get('a[data-cy=url]').contains('http://localhost:9000');
  9. });
  10. it('Checks public lists', () => {
  11. cy.get('ul[data-cy=lists] li')
  12. .should('contain', 'Opt-in list')
  13. .its('length')
  14. .should('eq', 1);
  15. cy.get('[data-cy=form] pre').should('not.exist');
  16. });
  17. it('Selects public list', () => {
  18. // Click the list checkbox.
  19. cy.get('ul[data-cy=lists] .checkbox').click();
  20. // Make sure the <pre> form HTML has appeared.
  21. cy.get('[data-cy=form] pre').then(($pre) => {
  22. // Check that the ID of the list in the checkbox appears in the HTML.
  23. cy.get('ul[data-cy=lists] input').then(($inp) => {
  24. cy.wrap($pre).contains($inp.val());
  25. });
  26. });
  27. // Click the list checkbox.
  28. cy.get('ul[data-cy=lists] .checkbox').click();
  29. cy.get('[data-cy=form] pre').should('not.exist');
  30. });
  31. it('Subscribes from public form page', () => {
  32. // Create a public test list.
  33. cy.request('POST', `${apiUrl}/api/lists`, { name: 'test-list', type: 'public', optin: 'single' });
  34. // Open the public page and subscribe to alternating lists multiple times.
  35. // There should be no errors and two new subscribers should be subscribed to two lists.
  36. for (let i = 0; i < 2; i++) {
  37. for (let j = 0; j < 2; j++) {
  38. cy.loginAndVisit(`${apiUrl}/subscription/form`);
  39. cy.get('input[name=email]').clear().type(`test${i}@test.com`);
  40. cy.get('input[name=name]').clear().type(`test${i}`);
  41. cy.get('input[type=checkbox]').eq(j).click();
  42. cy.get('button').click();
  43. cy.wait(250);
  44. cy.get('.wrap').contains(/has been sent|successfully/);
  45. }
  46. }
  47. // Verify form subscriptions.
  48. cy.request(`${apiUrl}/api/subscribers`).should((response) => {
  49. const { data } = response.body;
  50. // Two new + two dummy subscribers that are there by default.
  51. expect(data.total).to.equal(4);
  52. // The two new subscribers should each have two list subscriptions.
  53. for (let i = 0; i < 2; i++) {
  54. expect(data.results.find((s) => s.email === `test${i}@test.com`).lists.length).to.equal(2);
  55. }
  56. });
  57. });
  58. });