23-editor--with-navigation.cy.ts 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. import path from 'path-browserify';
  2. function openEditor() {
  3. cy.get('#grw-page-editor-mode-manager').as('pageEditorModeManager').should('be.visible');
  4. cy.waitUntil(() => {
  5. // do
  6. cy.get('@pageEditorModeManager').within(() => {
  7. cy.get('button:nth-child(2)').click();
  8. });
  9. // until
  10. return cy.get('.layout-root').then($elem => $elem.hasClass('editing'));
  11. })
  12. cy.get('.CodeMirror').should('be.visible');
  13. }
  14. context('Editor while uploading to a new page', () => {
  15. const ssPrefix = 'editor-while-uploading-';
  16. beforeEach(() => {
  17. // login
  18. cy.fixture("user-admin.json").then(user => {
  19. cy.login(user.username, user.password);
  20. });
  21. });
  22. /**
  23. * for the issues:
  24. * @see https://redmine.weseek.co.jp/issues/122040
  25. * @see https://redmine.weseek.co.jp/issues/124281
  26. */
  27. it('should not be cleared and should prevent GrantSelector from modified', { scrollBehavior: false }, () => {
  28. cy.visit('/Sandbox/for-122040');
  29. openEditor();
  30. cy.screenshot(`${ssPrefix}-prevent-grantselector-modified-1`);
  31. // input the body
  32. const body = 'Hello World!';
  33. cy.get('.CodeMirror textarea').type(body + '\n\n', { force: true });
  34. cy.get('.CodeMirror-code').should('contain.text', body);
  35. // open GrantSelector
  36. cy.waitUntil(() => {
  37. // do
  38. cy.getByTestid('grw-grant-selector').within(() => {
  39. cy.get('button.dropdown-toggle').click({force: true});
  40. });
  41. // wait until
  42. return cy.getByTestid('grw-grant-selector').within(() => {
  43. return Cypress.$('.dropdown-menu.show').is(':visible');
  44. });
  45. });
  46. // Select "Only me"
  47. cy.getByTestid('grw-grant-selector').within(() => {
  48. // click "Only me"
  49. cy.get('.dropdown-menu.show').find('.dropdown-item').should('have.length', 4).then((menuItems) => {
  50. menuItems[2].click();
  51. });
  52. });
  53. cy.getByTestid('grw-grant-selector').find('.dropdown-toggle').should('contain.text', 'Only me');
  54. cy.screenshot(`${ssPrefix}-prevent-grantselector-modified-2`);
  55. // intercept API req/res for fixing labels
  56. const dummyAttachmentId = '64b000000000000000000000';
  57. let uploadedAttachmentId = '';
  58. cy.intercept('POST', '/_api/attachments.add', (req) => {
  59. req.continue((res) => {
  60. // store the attachment id
  61. uploadedAttachmentId = res.body.attachment._id;
  62. // overwrite filePathProxied
  63. res.body.attachment.filePathProxied = `/attachment/${dummyAttachmentId}`;
  64. });
  65. }).as('attachmentsAdd');
  66. cy.intercept('GET', `/_api/v3/attachment?attachmentId=${dummyAttachmentId}`, (req) => {
  67. // replace attachmentId query
  68. req.url = req.url.replace(dummyAttachmentId, uploadedAttachmentId);
  69. req.continue((res) => {
  70. // overwrite the attachment createdAt
  71. res.body.attachment.createdAt = new Date('2023-07-01T00:00:00');
  72. });
  73. });
  74. // drag-drop a file
  75. const filePath = path.relative('/', path.resolve(Cypress.spec.relative, '../assets/example.txt'));
  76. cy.get('.dropzone').selectFile(filePath, { action: 'drag-drop' });
  77. cy.wait('@attachmentsAdd');
  78. cy.screenshot(`${ssPrefix}-prevent-grantselector-modified-3`);
  79. // Update page using shortcut keys
  80. cy.get('.CodeMirror').click().type('{ctrl+s}');
  81. cy.screenshot(`${ssPrefix}-prevent-grantselector-modified-4`);
  82. // expect
  83. cy.get('.Toastify__toast').should('contain.text', 'Saved successfully');
  84. cy.get('.CodeMirror-code').should('contain.text', body);
  85. cy.get('.CodeMirror-code').should('contain.text', '[example.txt](/attachment/64b000000000000000000000');
  86. cy.getByTestid('grw-grant-selector').find('.dropdown-toggle').should('contain.text', 'Only me');
  87. cy.screenshot(`${ssPrefix}-prevent-grantselector-modified-5`);
  88. });
  89. });
  90. context.skip('Editor while navigation', () => {
  91. const ssPrefix = 'editor-while-navigation-';
  92. beforeEach(() => {
  93. // login
  94. cy.fixture("user-admin.json").then(user => {
  95. cy.login(user.username, user.password);
  96. });
  97. });
  98. /**
  99. * for the issue:
  100. * @see https://redmine.weseek.co.jp/issues/115285
  101. */
  102. it('Successfully updating the page body', { scrollBehavior: false }, () => {
  103. const page1Path = '/Sandbox/for-115285/page1';
  104. const page2Path = '/Sandbox/for-115285/page2';
  105. cy.visit(page1Path);
  106. openEditor();
  107. // page1
  108. const bodyHello = 'hello';
  109. cy.get('.CodeMirror').type(bodyHello);
  110. cy.get('.CodeMirror').should('contain.text', bodyHello);
  111. cy.get('.page-editor-preview-body').should('contain.text', bodyHello);
  112. cy.getByTestid('page-editor').should('be.visible');
  113. cy.get('.CodeMirror').screenshot(`${ssPrefix}-editor-for-page1`);
  114. // save page1
  115. cy.getByTestid('save-page-btn').click();
  116. // open duplicate modal
  117. cy.waitUntil(() => {
  118. // do
  119. cy.getByTestid('grw-contextual-sub-nav').within(() => {
  120. cy.getByTestid('open-page-item-control-btn').find('button').click({force: true});
  121. });
  122. // wait until
  123. return cy.getByTestid('page-item-control-menu').then($elem => $elem.is(':visible'))
  124. });
  125. cy.getByTestid('open-page-duplicate-modal-btn').filter(':visible').click({force: true});
  126. // duplicate and navigate to page1
  127. cy.getByTestid('page-duplicate-modal').should('be.visible').within(() => {
  128. cy.get('input.form-control').clear();
  129. cy.get('input.form-control').type(page2Path);
  130. cy.getByTestid('btn-duplicate').click();
  131. })
  132. openEditor();
  133. cy.get('.CodeMirror').screenshot(`${ssPrefix}-editor-for-page2`);
  134. // type (without save)
  135. const bodyWorld = ' world!!'
  136. cy.get('.CodeMirror').type(`${bodyWorld}`);
  137. cy.get('.CodeMirror').should('contain.text', `${bodyHello}${bodyWorld}`);
  138. cy.get('.page-editor-preview-body').should('contain.text', `${bodyHello}${bodyWorld}`);
  139. cy.get('.CodeMirror').screenshot(`${ssPrefix}-editor-for-page2-modified`);
  140. // create a link to page1
  141. cy.get('.CodeMirror').type('\n\n[page1](./page1)');
  142. // go to page1
  143. cy.get('.page-editor-preview-body').within(() => {
  144. cy.get("a:contains('page1')").click();
  145. });
  146. openEditor();
  147. cy.get('.CodeMirror').screenshot(`${ssPrefix}-editor-for-page1-returned`);
  148. // expect
  149. cy.get('.CodeMirror').should('contain.text', bodyHello);
  150. cy.get('.CodeMirror').should('not.contain.text', bodyWorld); // text that added to page2
  151. cy.get('.CodeMirror').should('not.contain.text', 'page1'); // text that added to page2
  152. });
  153. });