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

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