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