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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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').type(body + '\n\n');
  34. cy.get('.CodeMirror').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. // drag-drop a file
  56. cy.intercept('POST', '/_api/attachments.add').as('attachmentsAdd');
  57. const filePath = path.relative('/', path.resolve(Cypress.spec.relative, '../assets/example.txt'));
  58. cy.get('.dropzone').selectFile(filePath, { action: 'drag-drop' });
  59. cy.wait('@attachmentsAdd')
  60. // Update page using shortcut keys
  61. cy.get('.CodeMirror').type('{ctrl+s}');
  62. // expect
  63. cy.get('.Toastify__toast').should('contain.text', 'Saved successfully');
  64. cy.get('.CodeMirror').should('contain.text', body);
  65. cy.get('.CodeMirror').should('contain.text', '[example.txt](/attachment/');
  66. cy.getByTestid('grw-grant-selector').find('.dropdown-toggle').should('contain.text', 'Only me');
  67. cy.screenshot(`${ssPrefix}-prevent-grantselector-modified-3`);
  68. });
  69. });
  70. context.skip('Editor while navigation', () => {
  71. const ssPrefix = 'editor-while-navigation-';
  72. beforeEach(() => {
  73. // login
  74. cy.fixture("user-admin.json").then(user => {
  75. cy.login(user.username, user.password);
  76. });
  77. });
  78. /**
  79. * for the issue:
  80. * @see https://redmine.weseek.co.jp/issues/115285
  81. */
  82. it('Successfully updating the page body', { scrollBehavior: false }, () => {
  83. const page1Path = '/Sandbox/for-115285/page1';
  84. const page2Path = '/Sandbox/for-115285/page2';
  85. cy.visit(page1Path);
  86. openEditor();
  87. // page1
  88. const bodyHello = 'hello';
  89. cy.get('.CodeMirror').type(bodyHello);
  90. cy.get('.CodeMirror').should('contain.text', bodyHello);
  91. cy.get('.page-editor-preview-body').should('contain.text', bodyHello);
  92. cy.getByTestid('page-editor').should('be.visible');
  93. cy.get('.CodeMirror').screenshot(`${ssPrefix}-editor-for-page1`);
  94. // save page1
  95. cy.getByTestid('save-page-btn').click();
  96. // open duplicate modal
  97. cy.waitUntil(() => {
  98. // do
  99. cy.get('#grw-subnav-container').within(() => {
  100. cy.getByTestid('open-page-item-control-btn').find('button').click({force: true});
  101. });
  102. // wait until
  103. return cy.getByTestid('page-item-control-menu').then($elem => $elem.is(':visible'))
  104. });
  105. cy.getByTestid('open-page-duplicate-modal-btn').filter(':visible').click({force: true});
  106. // duplicate and navigate to page1
  107. cy.getByTestid('page-duplicate-modal').should('be.visible').within(() => {
  108. cy.get('input.form-control').clear();
  109. cy.get('input.form-control').type(page2Path);
  110. cy.getByTestid('btn-duplicate').click();
  111. })
  112. openEditor();
  113. cy.get('.CodeMirror').screenshot(`${ssPrefix}-editor-for-page2`);
  114. // type (without save)
  115. const bodyWorld = ' world!!'
  116. cy.get('.CodeMirror').type(`${bodyWorld}`);
  117. cy.get('.CodeMirror').should('contain.text', `${bodyHello}${bodyWorld}`);
  118. cy.get('.page-editor-preview-body').should('contain.text', `${bodyHello}${bodyWorld}`);
  119. cy.get('.CodeMirror').screenshot(`${ssPrefix}-editor-for-page2-modified`);
  120. // create a link to page1
  121. cy.get('.CodeMirror').type('\n\n[page1](./page1)');
  122. // go to page1
  123. cy.get('.page-editor-preview-body').within(() => {
  124. cy.get("a:contains('page1')").click();
  125. });
  126. openEditor();
  127. cy.get('.CodeMirror').screenshot(`${ssPrefix}-editor-for-page1-returned`);
  128. // expect
  129. cy.get('.CodeMirror').should('contain.text', bodyHello);
  130. cy.get('.CodeMirror').should('not.contain.text', bodyWorld); // text that added to page2
  131. cy.get('.CodeMirror').should('not.contain.text', 'page1'); // text that added to page2
  132. });
  133. });