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

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