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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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 /me page', () => {
  96. const ssPrefix = 'access-to-me-page-';
  97. beforeEach(() => {
  98. // login
  99. cy.fixture("user-admin.json").then(user => {
  100. cy.login(user.username, user.password);
  101. });
  102. });
  103. it('/me is successfully loaded', () => {
  104. cy.visit('/me');
  105. cy.getByTestid('grw-user-settings').should('be.visible');
  106. cy.collapseSidebar(true);
  107. cy.screenshot(`${ssPrefix}-me`);
  108. });
  109. // it('Draft page is successfully shown', () => {
  110. // cy.visit('/me/drafts');
  111. // cy.screenshot(`${ssPrefix}-draft-page`);
  112. // });
  113. });
  114. context('Access to special pages', () => {
  115. const ssPrefix = 'access-to-special-pages-';
  116. beforeEach(() => {
  117. // login
  118. cy.fixture("user-admin.json").then(user => {
  119. cy.login(user.username, user.password);
  120. });
  121. });
  122. it('/trash is successfully loaded', () => {
  123. cy.visit('/trash');
  124. cy.getByTestid('trash-page-list').should('contain.text', 'There are no pages under this page.');
  125. cy.collapseSidebar(true);
  126. cy.screenshot(`${ssPrefix}-trash`);
  127. });
  128. it('/tags is successfully loaded', { scrollBehavior: false } ,() => {
  129. // open sidebar
  130. // cy.collapseSidebar(false);
  131. cy.visit('/tags');
  132. // cy.getByTestid('grw-sidebar-content-tags').within(() => {
  133. // cy.getByTestid('grw-tags-list').should('be.visible');
  134. // cy.getByTestid('grw-tags-list').contains('You have no tag, You can set tags on pages');
  135. // })
  136. cy.getByTestid('tags-page').within(() => {
  137. cy.getByTestid('grw-tags-list').should('be.visible');
  138. cy.getByTestid('grw-tags-list').should('contain.text', 'You have no tag, You can set tags on pages');
  139. });
  140. cy.collapseSidebar(true);
  141. cy.screenshot(`${ssPrefix}-tags`);
  142. });
  143. });
  144. context('Access to Template Editing Mode', () => {
  145. const ssPrefix = 'access-to-template-page-';
  146. const templateBody1 = 'Template for children';
  147. const templateBody2 = 'Template for descendants';
  148. const createPageFromPageTreeTest = (newPagePath: string, parentPagePath: string, expectedBody: string) => {
  149. cy.visit('/');
  150. cy.waitUntilSkeletonDisappear();
  151. // Open sidebar
  152. cy.collapseSidebar(false);
  153. cy.getByTestid('grw-sidebar-contents').should('be.visible');
  154. cy.waitUntilSkeletonDisappear();
  155. // If PageTree is not active when the sidebar is opened, make it active
  156. cy.getByTestid('grw-sidebar-nav-primary-page-tree').should('be.visible')
  157. .then($elem => {
  158. if (!$elem.hasClass('active')) {
  159. cy.getByTestid('grw-sidebar-nav-primary-page-tree').click();
  160. }
  161. });
  162. // Create page (/{parentPath}}/{newPagePath}) from PageTree
  163. cy.getByTestid('grw-sidebar-contents').within(() => {
  164. cy.get('.grw-pagetree-item-children').first().as('pagetreeItem').within(() => {
  165. cy.get('#page-create-button-in-page-tree').first().click({force: true})
  166. });
  167. });
  168. cy.get('@pagetreeItem').within(() => {
  169. cy.getByTestid('autosize-submittable-input').type(newPagePath).type('{enter}');
  170. })
  171. cy.visit(`/${parentPagePath}/${newPagePath}`);
  172. cy.collapseSidebar(true);
  173. cy.getByTestid('grw-contextual-sub-nav').should('be.visible');
  174. cy.waitUntilSkeletonDisappear();
  175. // Check if the template is applied
  176. cy.getByTestid('search-result-base').within(() => {
  177. cy.get('.wiki').should('be.visible');
  178. cy.get('.wiki').children().first().should('have.text', expectedBody);
  179. })
  180. cy.screenshot(`${ssPrefix}-page(${newPagePath})-to-which-template-is-applied`)
  181. }
  182. beforeEach(() => {
  183. // login
  184. cy.fixture("user-admin.json").then(user => {
  185. cy.login(user.username, user.password);
  186. });
  187. });
  188. it("Successfully created template for children", () => {
  189. cy.visit('/Sandbox');
  190. cy.waitUntilSkeletonDisappear();
  191. cy.waitUntil(() => {
  192. // do
  193. cy.getByTestid('grw-contextual-sub-nav').within(() => {
  194. cy.getByTestid('open-page-item-control-btn').find('button').click({force: true});
  195. });
  196. // wait until
  197. return cy.getByTestid('page-item-control-menu').then($elem => $elem.is(':visible'))
  198. });
  199. cy.getByTestid('open-page-template-modal-btn').filter(':visible').click({force: true});
  200. cy.getByTestid('page-template-modal').should('be.visible');
  201. cy.screenshot(`${ssPrefix}-open-page-template-modal`);
  202. cy.getByTestid('template-button-children').click(({force: true}))
  203. cy.waitUntilSkeletonDisappear();
  204. cy.getByTestid('navbar-editor').should('be.visible').then(()=>{
  205. cy.url().should('include', '/_template#edit');
  206. cy.screenshot(`${ssPrefix}-open-template-page-for-children-in-editor-mode`);
  207. });
  208. cy.appendTextToEditorUntilContains(templateBody1);
  209. cy.get('.page-editor-preview-body').should('contain.text', templateBody1);
  210. cy.getByTestid('page-editor').should('be.visible');
  211. cy.getByTestid('save-page-btn').click();
  212. });
  213. it('Template is applied to pages created from PageTree (template for children 1)', () => {
  214. createPageFromPageTreeTest('template-test-page1', '/Sandbox' ,templateBody1);
  215. });
  216. it('Successfully created template for descendants', () => {
  217. cy.visit('/Sandbox');
  218. cy.waitUntilSkeletonDisappear();
  219. cy.waitUntil(() => {
  220. // do
  221. cy.getByTestid('grw-contextual-sub-nav').within(() => {
  222. cy.getByTestid('open-page-item-control-btn').find('button').click({force: true});
  223. });
  224. // Wait until
  225. return cy.getByTestid('page-item-control-menu').then($elem => $elem.is(':visible'))
  226. });
  227. cy.getByTestid('open-page-template-modal-btn').filter(':visible').click({force: true});
  228. cy.getByTestid('page-template-modal').should('be.visible');
  229. cy.getByTestid('template-button-descendants').click(({force: true}))
  230. cy.waitUntilSkeletonDisappear();
  231. cy.getByTestid('navbar-editor').should('be.visible').then(()=>{
  232. cy.url().should('include', '/__template#edit');
  233. cy.screenshot(`${ssPrefix}-open-template-page-for-descendants-in-editor-mode`);
  234. })
  235. cy.appendTextToEditorUntilContains(templateBody2);
  236. cy.get('.page-editor-preview-body').should('contain.text', templateBody2);
  237. cy.getByTestid('page-editor').should('be.visible');
  238. cy.getByTestid('save-page-btn').click();
  239. });
  240. it('Template is applied to pages created from PageTree (template for children 2)', () => {
  241. createPageFromPageTreeTest('template-test-page2','Sandbox',templateBody1);
  242. });
  243. it('Template is applied to pages created from PageTree (template for descendants)', () => {
  244. // delete /Sandbox/_template
  245. cy.visit('/Sandbox/_template');
  246. cy.waitUntil(() => {
  247. //do
  248. cy.getByTestid('grw-contextual-sub-nav').within(() => {
  249. cy.getByTestid('open-page-item-control-btn').find('button').click({force: true});
  250. });
  251. // wait until
  252. return cy.getByTestid('page-item-control-menu').then($elem => $elem.is(':visible'))
  253. });
  254. cy.getByTestid('open-page-delete-modal-btn').filter(':visible').click({force: true});
  255. cy.getByTestid('page-delete-modal').should('be.visible').within(() => {
  256. cy.intercept('POST', '/_api/pages.remove').as('remove');
  257. cy.getByTestid('delete-page-button').click();
  258. cy.wait('@remove')
  259. });
  260. createPageFromPageTreeTest('template-test-page3','Sandbox',`${templateBody1}\n${templateBody2}`);
  261. })
  262. });
  263. context('Access to /me/all-in-app-notifications', () => {
  264. const ssPrefix = 'in-app-notifications-';
  265. beforeEach(() => {
  266. // login
  267. cy.fixture("user-admin.json").then(user => {
  268. cy.login(user.username, user.password);
  269. });
  270. });
  271. it('All In-App Notification list is successfully loaded', { scrollBehavior: false },() => {
  272. cy.visit('/');
  273. cy.get('.notification-wrapper').click();
  274. cy.get('.notification-wrapper > .dropdown-menu > a').click();
  275. cy.getByTestid('grw-in-app-notification-page').should('be.visible');
  276. cy.getByTestid('grw-in-app-notification-page-spinner').should('not.exist');
  277. cy.collapseSidebar(true);
  278. cy.screenshot(`${ssPrefix}-see-all`);
  279. cy.get('.grw-custom-nav-tab > div > ul > li:nth-child(2) > a').click();
  280. cy.getByTestid('grw-in-app-notification-page-spinner').should('not.exist');
  281. cy.collapseSidebar(true);
  282. cy.screenshot(`${ssPrefix}-see-unread`);
  283. });
  284. })