lists.cy.js 5.1 KB

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