templates.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. describe('Templates', () => {
  2. it('Opens templates page', () => {
  3. cy.resetDB();
  4. cy.loginAndVisit('/campaigns/templates');
  5. });
  6. it('Counts default templates', () => {
  7. cy.get('tbody td[data-label=Name]').should('have.length', 1);
  8. });
  9. it('Clones template', () => {
  10. // Clone the campaign.
  11. cy.get('[data-cy=btn-clone]').first().click();
  12. cy.get('.modal input').clear().type('cloned').click();
  13. cy.get('.modal button.is-primary').click();
  14. cy.wait(250);
  15. // Verify the newly created row.
  16. cy.get('tbody td[data-label="Name"]').eq(1).contains('cloned');
  17. });
  18. it('Edits template', () => {
  19. cy.get('tbody td.actions [data-cy=btn-edit]').first().click();
  20. cy.wait(250);
  21. cy.get('input[name=name]').clear().type('edited');
  22. cy.get('code-flask').shadow().find('.codeflask textarea').invoke('val', '<span>test</span> {{ template "content" . }}').trigger('input');
  23. cy.get('.modal-card-foot button.is-primary').click();
  24. cy.wait(250);
  25. cy.get('tbody td[data-label="Name"] a').contains('edited');
  26. });
  27. it('Previews templates', () => {
  28. // Edited one sould have a bare body.
  29. cy.get('tbody [data-cy=btn-preview').eq(0).click();
  30. cy.wait(500);
  31. cy.get('.modal-card-body iframe').iframe(() => {
  32. cy.get('span').first().contains('test');
  33. cy.get('p').first().contains('Hi there');
  34. });
  35. cy.get('.modal-card-foot button').click();
  36. // Cloned one should have the full template.
  37. cy.get('tbody [data-cy=btn-preview').eq(1).click();
  38. cy.wait(500);
  39. cy.get('.modal-card-body iframe').iframe(() => {
  40. cy.get('.wrap p').first().contains('Hi there');
  41. cy.get('.footer a').first().contains('Unsubscribe');
  42. });
  43. cy.get('.modal-card-foot button').click();
  44. });
  45. it('Sets default', () => {
  46. cy.get('tbody td.actions').eq(1).find('[data-cy=btn-set-default]').click();
  47. cy.get('.modal button.is-primary').click();
  48. // The original default shouldn't have default and the new one should have.
  49. cy.get('tbody td.actions').eq(0).then((el) => {
  50. cy.wrap(el).find('[data-cy=btn-delete]').should('exist');
  51. cy.wrap(el).find('[data-cy=btn-set-default]').should('exist');
  52. });
  53. cy.get('tbody td.actions').eq(1).then((el) => {
  54. cy.wrap(el).find('[data-cy=btn-delete]').should('not.exist');
  55. cy.wrap(el).find('[data-cy=btn-set-default]').should('not.exist');
  56. });
  57. });
  58. it('Deletes template', () => {
  59. cy.wait(250);
  60. cy.get('tbody td.actions [data-cy=btn-delete]').first().click();
  61. cy.get('.modal button.is-primary').click();
  62. cy.wait(250);
  63. cy.get('tbody td.actions').should('have.length', 1);
  64. });
  65. });