forms.js 2.2 KB

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