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

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