20-basic-features--access-to-page.cy.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. function openEditor() {
  2. cy.get('#grw-page-editor-mode-manager').as('pageEditorModeManager').should('be.visible');
  3. cy.waitUntil(() => {
  4. // do
  5. cy.get('@pageEditorModeManager').within(() => {
  6. cy.get('button:nth-child(2)').click();
  7. });
  8. // until
  9. return cy.get('.layout-root').then($elem => $elem.hasClass('editing'));
  10. });
  11. cy.get('.CodeMirror').should('be.visible');
  12. }
  13. context('Access to page', () => {
  14. const ssPrefix = 'access-to-page-';
  15. beforeEach(() => {
  16. // login
  17. cy.fixture("user-admin.json").then(user => {
  18. cy.login(user.username, user.password);
  19. });
  20. });
  21. // TODO: https://redmine.weseek.co.jp/issues/109939
  22. it('/Sandbox with anchor hash is successfully loaded', () => {
  23. cy.visit('/Sandbox#headers');
  24. cy.collapseSidebar(true);
  25. // for check download toc data
  26. // https://redmine.weseek.co.jp/issues/111384
  27. // cy.get('.toc-link').should('be.visible');
  28. // assert the element is in viewport
  29. cy.get('#headers').should('be.inViewport');
  30. // remove animation for screenshot
  31. // remove 'blink' class because ::after element cannot be operated
  32. // https://stackoverflow.com/questions/5041494/selecting-and-manipulating-css-pseudo-elements-such-as-before-and-after-usin/21709814#21709814
  33. cy.get('#headers').invoke('removeClass', 'blink');
  34. cy.waitUntilSkeletonDisappear();
  35. cy.screenshot(`${ssPrefix}-sandbox-headers`);
  36. });
  37. it('/Sandbox/Math is successfully loaded', () => {
  38. cy.visit('/Sandbox/Math');
  39. cy.collapseSidebar(true);
  40. // for check download toc data
  41. // https://redmine.weseek.co.jp/issues/111384
  42. // cy.get('.toc-link').should('be.visible');
  43. cy.get('.math').should('be.visible');
  44. cy.waitUntilSkeletonDisappear();
  45. cy.screenshot(`${ssPrefix}-sandbox-math`);
  46. });
  47. it('/Sandbox with edit is successfully loaded', () => {
  48. cy.visit('/Sandbox#edit');
  49. cy.collapseSidebar(true);
  50. cy.getByTestid('navbar-editor').should('be.visible');
  51. cy.get('.grw-editor-navbar-bottom').should('be.visible');
  52. cy.getByTestid('save-page-btn').should('be.visible');
  53. cy.get('.grw-grant-selector').should('be.visible');
  54. cy.waitUntilSkeletonDisappear();
  55. cy.screenshot(`${ssPrefix}-Sandbox-edit-page`);
  56. })
  57. const body1 = 'hello';
  58. const body2 = ' world!';
  59. it('Edit and save with save-page-btn', () => {
  60. cy.visit('/Sandbox/testForUseEditingMarkdown');
  61. openEditor();
  62. // check edited contents after save
  63. cy.appendTextToEditorUntilContains(body1);
  64. cy.get('.page-editor-preview-body').should('contain.text', body1);
  65. cy.getByTestid('page-editor').should('be.visible');
  66. cy.getByTestid('save-page-btn').click();
  67. cy.get('.wiki').should('be.visible');
  68. cy.get('.wiki').children().first().should('have.text', body1);
  69. cy.screenshot(`${ssPrefix}-edit-and-save-with-save-page-btn`);
  70. })
  71. it('Edit and save with shortcut key', () => {
  72. const savePageShortcutKey = '{ctrl+s}';
  73. cy.visit('/Sandbox/testForUseEditingMarkdown');
  74. openEditor();
  75. // check editing contents with shortcut key
  76. cy.appendTextToEditorUntilContains(body2);
  77. cy.get('.page-editor-preview-body').should('contain.text', body1+body2);
  78. cy.get('.CodeMirror').click().type(savePageShortcutKey);
  79. cy.get('.CodeMirror-code').should('contain.text', body1+body2);
  80. cy.get('.page-editor-preview-body').should('contain.text', body1+body2);
  81. cy.screenshot(`${ssPrefix}-edit-and-save-with-shortcut-key`);
  82. })
  83. it('/user/admin is successfully loaded', () => {
  84. cy.visit('/user/admin');
  85. cy.collapseSidebar(true);
  86. // for check download toc data
  87. // https://redmine.weseek.co.jp/issues/111384
  88. // cy.get('.toc-link').should('be.visible');
  89. // eslint-disable-next-line cypress/no-unnecessary-waiting
  90. cy.wait(2000); // wait for calcViewHeight and rendering
  91. cy.waitUntilSkeletonDisappear();
  92. cy.screenshot(`${ssPrefix}-user-admin`);
  93. });
  94. });
  95. context('Access to special pages', () => {
  96. const ssPrefix = 'access-to-special-pages-';
  97. beforeEach(() => {
  98. // login
  99. cy.fixture("user-admin.json").then(user => {
  100. cy.login(user.username, user.password);
  101. });
  102. });
  103. it('/trash is successfully loaded', () => {
  104. cy.visit('/trash');
  105. cy.getByTestid('trash-page-list').should('contain.text', 'There are no pages under this page.');
  106. cy.collapseSidebar(true);
  107. cy.screenshot(`${ssPrefix}-trash`);
  108. });
  109. it('/tags is successfully loaded', { scrollBehavior: false } ,() => {
  110. // open sidebar
  111. // cy.collapseSidebar(false);
  112. cy.visit('/tags');
  113. // cy.getByTestid('grw-sidebar-content-tags').within(() => {
  114. // cy.getByTestid('grw-tags-list').should('be.visible');
  115. // cy.getByTestid('grw-tags-list').contains('You have no tag, You can set tags on pages');
  116. // })
  117. cy.getByTestid('tags-page').within(() => {
  118. cy.getByTestid('grw-tags-list').should('be.visible');
  119. cy.getByTestid('grw-tags-list').should('contain.text', 'You have no tag, You can set tags on pages');
  120. });
  121. cy.collapseSidebar(true);
  122. cy.screenshot(`${ssPrefix}-tags`);
  123. });
  124. });
  125. context('Access to Template Editing Mode', () => {
  126. const ssPrefix = 'access-to-template-page-';
  127. const templateBody1 = 'Template for children';
  128. const templateBody2 = 'Template for descendants';
  129. const createPageFromPageTreeTest = (newPagePath: string, parentPagePath: string, expectedBody: string) => {
  130. cy.visit('/');
  131. cy.waitUntilSkeletonDisappear();
  132. // Open sidebar
  133. cy.collapseSidebar(false);
  134. cy.getByTestid('grw-sidebar-contents').should('be.visible');
  135. cy.waitUntilSkeletonDisappear();
  136. // If PageTree is not active when the sidebar is opened, make it active
  137. cy.getByTestid('grw-sidebar-nav-primary-page-tree').should('be.visible')
  138. .then($elem => {
  139. if (!$elem.hasClass('active')) {
  140. cy.getByTestid('grw-sidebar-nav-primary-page-tree').click();
  141. }
  142. });
  143. // Create page (/{parentPath}}/{newPagePath}) from PageTree
  144. cy.getByTestid('grw-sidebar-contents').within(() => {
  145. cy.get('.grw-pagetree-item-children').first().as('pagetreeItem').within(() => {
  146. cy.get('#page-create-button-in-page-tree').first().click({force: true})
  147. });
  148. });
  149. cy.get('@pagetreeItem').within(() => {
  150. cy.getByTestid('autosize-submittable-input').type(newPagePath).type('{enter}');
  151. })
  152. cy.visit(`/${parentPagePath}/${newPagePath}`);
  153. cy.collapseSidebar(true);
  154. cy.getByTestid('grw-contextual-sub-nav').should('be.visible');
  155. cy.waitUntilSkeletonDisappear();
  156. // Check if the template is applied
  157. cy.getByTestid('search-result-base').within(() => {
  158. cy.get('.wiki').should('be.visible');
  159. cy.get('.wiki').children().first().should('have.text', expectedBody);
  160. })
  161. cy.screenshot(`${ssPrefix}-page(${newPagePath})-to-which-template-is-applied`)
  162. }
  163. beforeEach(() => {
  164. // login
  165. cy.fixture("user-admin.json").then(user => {
  166. cy.login(user.username, user.password);
  167. });
  168. });
  169. it("Successfully created template for children", () => {
  170. cy.visit('/Sandbox');
  171. cy.waitUntilSkeletonDisappear();
  172. cy.waitUntil(() => {
  173. // do
  174. cy.getByTestid('grw-contextual-sub-nav').within(() => {
  175. cy.getByTestid('open-page-item-control-btn').find('button').click({force: true});
  176. });
  177. // wait until
  178. return cy.getByTestid('page-item-control-menu').then($elem => $elem.is(':visible'))
  179. });
  180. cy.getByTestid('open-page-template-modal-btn').filter(':visible').click({force: true});
  181. cy.getByTestid('page-template-modal').should('be.visible');
  182. cy.screenshot(`${ssPrefix}-open-page-template-modal`);
  183. cy.getByTestid('template-button-children').click(({force: true}))
  184. cy.waitUntilSkeletonDisappear();
  185. cy.getByTestid('navbar-editor').should('be.visible').then(()=>{
  186. cy.url().should('include', '/_template#edit');
  187. cy.screenshot(`${ssPrefix}-open-template-page-for-children-in-editor-mode`);
  188. });
  189. cy.appendTextToEditorUntilContains(templateBody1);
  190. cy.get('.page-editor-preview-body').should('contain.text', templateBody1);
  191. cy.getByTestid('page-editor').should('be.visible');
  192. cy.getByTestid('save-page-btn').click();
  193. });
  194. it('Template is applied to pages created from PageTree (template for children 1)', () => {
  195. createPageFromPageTreeTest('template-test-page1', '/Sandbox' ,templateBody1);
  196. });
  197. it('Successfully created template for descendants', () => {
  198. cy.visit('/Sandbox');
  199. cy.waitUntilSkeletonDisappear();
  200. cy.waitUntil(() => {
  201. // do
  202. cy.getByTestid('grw-contextual-sub-nav').within(() => {
  203. cy.getByTestid('open-page-item-control-btn').find('button').click({force: true});
  204. });
  205. // Wait until
  206. return cy.getByTestid('page-item-control-menu').then($elem => $elem.is(':visible'))
  207. });
  208. cy.getByTestid('open-page-template-modal-btn').filter(':visible').click({force: true});
  209. cy.getByTestid('page-template-modal').should('be.visible');
  210. cy.getByTestid('template-button-descendants').click(({force: true}))
  211. cy.waitUntilSkeletonDisappear();
  212. cy.getByTestid('navbar-editor').should('be.visible').then(()=>{
  213. cy.url().should('include', '/__template#edit');
  214. cy.screenshot(`${ssPrefix}-open-template-page-for-descendants-in-editor-mode`);
  215. })
  216. cy.appendTextToEditorUntilContains(templateBody2);
  217. cy.get('.page-editor-preview-body').should('contain.text', templateBody2);
  218. cy.getByTestid('page-editor').should('be.visible');
  219. cy.getByTestid('save-page-btn').click();
  220. });
  221. it('Template is applied to pages created from PageTree (template for children 2)', () => {
  222. createPageFromPageTreeTest('template-test-page2','Sandbox',templateBody1);
  223. });
  224. it('Template is applied to pages created from PageTree (template for descendants)', () => {
  225. // delete /Sandbox/_template
  226. cy.visit('/Sandbox/_template');
  227. cy.waitUntil(() => {
  228. //do
  229. cy.getByTestid('grw-contextual-sub-nav').within(() => {
  230. cy.getByTestid('open-page-item-control-btn').find('button').click({force: true});
  231. });
  232. // wait until
  233. return cy.getByTestid('page-item-control-menu').then($elem => $elem.is(':visible'))
  234. });
  235. cy.getByTestid('open-page-delete-modal-btn').filter(':visible').click({force: true});
  236. cy.getByTestid('page-delete-modal').should('be.visible').within(() => {
  237. cy.intercept('POST', '/_api/pages.remove').as('remove');
  238. cy.getByTestid('delete-page-button').click();
  239. cy.wait('@remove')
  240. });
  241. createPageFromPageTreeTest('template-test-page3','Sandbox',`${templateBody1}\n${templateBody2}`);
  242. })
  243. });
  244. context('Access to /me/all-in-app-notifications', () => {
  245. const ssPrefix = 'in-app-notifications-';
  246. beforeEach(() => {
  247. // login
  248. cy.fixture("user-admin.json").then(user => {
  249. cy.login(user.username, user.password);
  250. });
  251. });
  252. it('All In-App Notification list is successfully loaded', { scrollBehavior: false },() => {
  253. cy.visit('/');
  254. cy.get('.notification-wrapper').click();
  255. cy.get('.notification-wrapper > .dropdown-menu > a').click();
  256. cy.getByTestid('grw-in-app-notification-page').should('be.visible');
  257. cy.getByTestid('grw-in-app-notification-page-spinner').should('not.exist');
  258. cy.collapseSidebar(true);
  259. cy.screenshot(`${ssPrefix}-see-all`);
  260. cy.get('.grw-custom-nav-tab > div > ul > li:nth-child(2) > a').click();
  261. cy.getByTestid('grw-in-app-notification-page-spinner').should('not.exist');
  262. cy.collapseSidebar(true);
  263. cy.screenshot(`${ssPrefix}-see-unread`);
  264. });
  265. })