lists.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. describe('Lists', () => {
  2. it('Opens lists page', () => {
  3. cy.resetDB();
  4. cy.loginAndVisit('/lists');
  5. });
  6. it('Counts subscribers in default lists', () => {
  7. cy.get('tbody td[data-label=Subscribers]').contains('1');
  8. });
  9. it('Creates campaign for list', () => {
  10. cy.get('tbody a[data-cy=btn-campaign]').first().click();
  11. cy.location('pathname').should('contain', '/campaigns/new');
  12. cy.get('.list-tags .tag').contains('Default list');
  13. cy.clickMenu('lists', 'all-lists');
  14. });
  15. it('Creates opt-in campaign for list', () => {
  16. cy.get('tbody a[data-cy=btn-send-optin-campaign]').click();
  17. cy.get('.modal button.is-primary').click();
  18. cy.location('pathname').should('contain', '/campaigns/2');
  19. cy.clickMenu('lists', 'all-lists');
  20. });
  21. it('Checks individual subscribers in lists', () => {
  22. const subs = [{ listID: 1, email: 'john@example.com' },
  23. { listID: 2, email: 'anon@example.com' }];
  24. // Click on each list on the lists page, go the the subscribers page
  25. // for that list, and check the subscriber details.
  26. subs.forEach((s, n) => {
  27. cy.get('tbody td[data-label=Subscribers] a').eq(n).click();
  28. cy.location('pathname').should('contain', `/subscribers/lists/${s.listID}`);
  29. cy.get('tbody tr').its('length').should('eq', 1);
  30. cy.get('tbody td[data-label="E-mail"]').contains(s.email);
  31. cy.clickMenu('lists', 'all-lists');
  32. });
  33. });
  34. it('Edits lists', () => {
  35. // Open the edit popup and edit the default lists.
  36. cy.get('[data-cy=btn-edit]').each(($el, n) => {
  37. cy.wrap($el).click();
  38. cy.get('input[name=name]').clear().type(`list-${n}`);
  39. cy.get('select[name=type]').select('public');
  40. cy.get('select[name=optin]').select('double');
  41. cy.get('input[name=tags]').clear().type(`tag${n}`);
  42. cy.get('button[type=submit]').click();
  43. });
  44. cy.wait(250);
  45. // Confirm the edits.
  46. cy.get('tbody tr').each(($el, n) => {
  47. cy.wrap($el).find('td[data-label=Name]').contains(`list-${n}`);
  48. cy.wrap($el).find('.tags')
  49. .should('contain', 'test')
  50. .and('contain', `tag${n}`);
  51. });
  52. });
  53. it('Deletes lists', () => {
  54. // Delete all visible lists.
  55. cy.get('tbody tr').each(() => {
  56. cy.get('tbody a[data-cy=btn-delete]').first().click();
  57. cy.get('.modal button.is-primary').click();
  58. });
  59. // Confirm deletion.
  60. cy.get('table tr.is-empty');
  61. });
  62. // Add new lists.
  63. it('Adds new lists', () => {
  64. // Open the list form and create lists of multiple type/optin combinations.
  65. const types = ['private', 'public'];
  66. const optin = ['single', 'double'];
  67. let n = 0;
  68. types.forEach((t) => {
  69. optin.forEach((o) => {
  70. const name = `list-${t}-${o}-${n}`;
  71. cy.get('[data-cy=btn-new]').click();
  72. cy.get('input[name=name]').type(name);
  73. cy.get('select[name=type]').select(t);
  74. cy.get('select[name=optin]').select(o);
  75. cy.get('input[name=tags]').type(`tag${n}{enter}${t}{enter}${o}{enter}`);
  76. cy.get('button[type=submit]').click();
  77. cy.wait(200);
  78. // Confirm the addition by inspecting the newly created list row.
  79. const tr = `tbody tr:nth-child(${n + 1})`;
  80. cy.get(`${tr} td[data-label=Name]`).contains(name);
  81. cy.get(`${tr} td[data-label=Type] .tag[data-cy=type-${t}]`);
  82. cy.get(`${tr} td[data-label=Type] .tag[data-cy=optin-${o}]`);
  83. cy.get(`${tr} .tags`)
  84. .should('contain', `tag${n}`)
  85. .and('contain', t, { matchCase: false })
  86. .and('contain', o, { matchCase: false });
  87. n++;
  88. });
  89. });
  90. });
  91. // Sort lists by clicking on various headers. At this point, there should be four
  92. // lists with IDs = [3, 4, 5, 6]. Sort the items be columns and match them with
  93. // the expected order of IDs.
  94. it('Sorts lists', () => {
  95. cy.sortTable('thead th.cy-name', [4, 3, 6, 5]);
  96. cy.sortTable('thead th.cy-name', [5, 6, 3, 4]);
  97. cy.sortTable('thead th.cy-type', [5, 6, 4, 3]);
  98. cy.sortTable('thead th.cy-type', [4, 3, 5, 6]);
  99. cy.sortTable('thead th.cy-created_at', [3, 4, 5, 6]);
  100. cy.sortTable('thead th.cy-created_at', [6, 5, 4, 3]);
  101. cy.sortTable('thead th.cy-updated_at', [3, 4, 5, 6]);
  102. cy.sortTable('thead th.cy-updated_at', [6, 5, 4, 3]);
  103. });
  104. });