23-editor--saving.cy.ts 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. context('PageCreateModal', () => {
  2. const ssPrefix = 'page-create-modal-';
  3. beforeEach(() => {
  4. // login
  5. cy.fixture("user-admin.json").then(user => {
  6. cy.login(user.username, user.password);
  7. });
  8. });
  9. it("PageCreateModal is shown and closed successfully", () => {
  10. cy.visit('/');
  11. cy.collapseSidebar(true, true);
  12. cy.waitUntil(() => {
  13. // do
  14. cy.getByTestid('newPageBtn').click({force: true});
  15. // wait until
  16. return cy.getByTestid('page-create-modal').then($elem => $elem.is(':visible'));
  17. });
  18. cy.getByTestid('page-create-modal').should('be.visible').within(() => {
  19. cy.screenshot(`${ssPrefix}new-page-modal-opened`);
  20. cy.get('button.close').click();
  21. });
  22. cy.screenshot(`${ssPrefix}page-create-modal-closed`);
  23. });
  24. it("Successfully Create Today's page", () => {
  25. const pageName = "Today's page";
  26. cy.visit('/');
  27. cy.collapseSidebar(true);
  28. cy.waitUntil(() => {
  29. // do
  30. cy.getByTestid('newPageBtn').click({force: true});
  31. // wait until
  32. return cy.getByTestid('page-create-modal').then($elem => $elem.is(':visible'));
  33. });
  34. cy.getByTestid('page-create-modal').should('be.visible').within(() => {
  35. cy.get('.page-today-input2').type(pageName);
  36. cy.screenshot(`${ssPrefix}today-add-page-name`);
  37. cy.getByTestid('btn-create-memo').click();
  38. });
  39. cy.getByTestid('page-editor').should('be.visible');
  40. cy.getByTestid('save-page-btn').as('save-page-btn').should('be.visible');
  41. cy.waitUntil(() => {
  42. // do
  43. cy.get('@save-page-btn').click();
  44. // wait until
  45. return cy.get('@save-page-btn').then($elem => $elem.is(':disabled'));
  46. });
  47. cy.get('.layout-root').should('not.have.class', 'editing');
  48. cy.waitUntilSkeletonDisappear();
  49. cy.screenshot(`${ssPrefix}create-today-page`);
  50. });
  51. it('Successfully create page under specific path', () => {
  52. const pageName = 'child';
  53. cy.visit('/foo/bar');
  54. cy.collapseSidebar(true);
  55. cy.waitUntil(() => {
  56. // do
  57. cy.getByTestid('newPageBtn').click({force: true});
  58. // wait until
  59. return cy.get('body').within(() => {
  60. return Cypress.$('[data-testid=page-create-modal]').is(':visible');
  61. });
  62. });
  63. cy.getByTestid('page-create-modal').should('be.visible').within(() => {
  64. cy.get('.rbt-input-main').should('have.value', '/foo/bar/');
  65. cy.get('.rbt-input-main').type(pageName);
  66. cy.screenshot(`${ssPrefix}under-path-add-page-name`);
  67. cy.getByTestid('btn-create-page-under-below').click();
  68. });
  69. cy.getByTestid('page-editor').should('be.visible');
  70. cy.getByTestid('save-page-btn').as('save-page-btn').should('be.visible');
  71. cy.waitUntil(() => {
  72. // do
  73. cy.get('@save-page-btn').click();
  74. // wait until
  75. return cy.get('@save-page-btn').then($elem => $elem.is(':disabled'));
  76. });
  77. cy.get('.layout-root').should('not.have.class', 'editing');
  78. cy.getByTestid('grw-contextual-sub-nav').should('be.visible');
  79. cy.waitUntilSkeletonDisappear();
  80. cy.screenshot(`${ssPrefix}create-page-under-specific-page`);
  81. });
  82. it('Trying to create template page under the root page fail', () => {
  83. cy.visit('/');
  84. cy.collapseSidebar(true);
  85. cy.waitUntil(() => {
  86. // do
  87. cy.getByTestid('newPageBtn').click({force: true});
  88. // wait until
  89. return cy.getByTestid('page-create-modal').then($elem => $elem.is(':visible'));
  90. });
  91. cy.getByTestid('page-create-modal').should('be.visible').within(() => {
  92. cy.getByTestid('grw-page-create-modal-path-name').should('have.text', '/');
  93. cy.get('#template-type').click();
  94. cy.get('#template-type').next().find('button:eq(0)').click({force: true});
  95. cy.getByTestid('grw-btn-edit-page').should('be.visible').click();
  96. });
  97. cy.get('.Toastify__toast').should('be.visible');
  98. cy.screenshot(`${ssPrefix}create-template-for-children-error`);
  99. cy.get('.Toastify__toast').should('be.visible').within(() => {
  100. cy.get('.Toastify__close-button').should('be.visible').click();
  101. cy.get('.Toastify__progress-bar').invoke('attr', 'style', 'display: none')
  102. });
  103. cy.getByTestid('page-create-modal').should('be.visible').within(() => {
  104. cy.get('#template-type').click();
  105. cy.get('#template-type').next().find('button:eq(1)').click({force: true});
  106. cy.getByTestid('grw-btn-edit-page').should('be.visible').click();
  107. });
  108. cy.get('.Toastify__toast').should('be.visible');
  109. cy.screenshot(`${ssPrefix}create-template-for-descendants-error`);
  110. });
  111. });
  112. context('Shortcuts', () => {
  113. const ssPrefix = 'shortcuts';
  114. beforeEach(() => {
  115. // login
  116. cy.fixture("user-admin.json").then(user => {
  117. cy.login(user.username, user.password);
  118. });
  119. });
  120. it('Successfully updating a page using a shortcut on a previously created page', { scrollBehavior: false }, () => {
  121. const body1 = 'hello';
  122. const body2 = ' world!';
  123. const savePageShortcutKey = '{ctrl+s}';
  124. cy.visit('/Sandbox/child');
  125. cy.get('#grw-page-editor-mode-manager').as('pageEditorModeManager').should('be.visible');
  126. cy.waitUntil(() => {
  127. // do
  128. cy.get('@pageEditorModeManager').within(() => {
  129. cy.get('button:nth-child(2)').click();
  130. });
  131. // until
  132. return cy.get('.layout-root').then($elem => $elem.hasClass('editing'));
  133. })
  134. cy.get('.grw-editor-navbar-bottom').should('be.visible');
  135. // 1st
  136. cy.get('.CodeMirror').type(body1);
  137. cy.get('.CodeMirror').contains(body1);
  138. cy.get('.page-editor-preview-body').contains(body1);
  139. cy.get('.CodeMirror').type(savePageShortcutKey);
  140. cy.get('.Toastify__toast').should('be.visible').within(() => {
  141. cy.get('.Toastify__close-button').should('be.visible').click();
  142. cy.get('.Toastify__progress-bar').invoke('attr', 'style', 'display: none')
  143. });
  144. cy.screenshot(`${ssPrefix}-update-page-1`);
  145. cy.get('.Toastify').should('not.be.visible');
  146. // 2nd
  147. cy.get('.CodeMirror').type(body2);
  148. cy.get('.CodeMirror').contains(body2);
  149. cy.get('.page-editor-preview-body').contains(body2);
  150. cy.get('.CodeMirror').type(savePageShortcutKey);
  151. cy.get('.Toastify__toast').should('be.visible').within(() => {
  152. cy.get('.Toastify__close-button').should('be.visible').click();
  153. cy.get('.Toastify__progress-bar').invoke('attr', 'style', 'display: none')
  154. });
  155. cy.screenshot(`${ssPrefix}-update-page-2`);
  156. });
  157. });