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

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