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

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