access-to-page.spec.ts 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. import { expect, type Page, test } from '@playwright/test';
  2. const appendTextToEditorUntilContains = async (page: Page, text: string) => {
  3. await page.locator('.cm-content').fill(text);
  4. await expect(page.getByTestId('page-editor-preview-body')).toContainText(
  5. text,
  6. );
  7. };
  8. test('has title', async ({ page }) => {
  9. await page.goto('/Sandbox');
  10. // Expect a title "to contain" a substring.
  11. await expect(page).toHaveTitle(/Sandbox/);
  12. });
  13. test('get h1', async ({ page }) => {
  14. await page.goto('/Sandbox');
  15. // Expects page to have a heading with the name of Installation.
  16. await expect(
  17. page.getByRole('heading').filter({ hasText: /\/Sandbox/ }),
  18. ).toBeVisible();
  19. });
  20. test('/Sandbox/Math is successfully loaded', async ({ page }) => {
  21. await page.goto('/Sandbox/Math');
  22. // Expect the Math-specific elements to be present
  23. await expect(page.locator('.katex').first()).toBeVisible();
  24. });
  25. test('Sandbox with edit is successfully loaded', async ({ page }) => {
  26. await page.goto('/Sandbox#edit');
  27. // Expect the Editor-specific elements to be present
  28. await expect(page.getByTestId('grw-editor-navbar-bottom')).toBeVisible();
  29. await expect(page.getByTestId('save-page-btn')).toBeVisible();
  30. await expect(page.getByTestId('grw-grant-selector')).toBeVisible();
  31. });
  32. test.describe
  33. .serial('PageEditor', () => {
  34. const body1 = 'hello';
  35. const body2 = ' world!';
  36. const targetPath = '/Sandbox/testForUseEditingMarkdown';
  37. test('Edit and save with save-page-btn', async ({ page }) => {
  38. await page.goto(targetPath);
  39. await page.getByTestId('editor-button').click();
  40. await appendTextToEditorUntilContains(page, body1);
  41. await page.getByTestId('save-page-btn').click();
  42. await expect(page.locator('.wiki').first()).toContainText(body1);
  43. });
  44. test('Edit and save with shortcut key', async ({ page }) => {
  45. const savePageShortcutKey = 'Control+s';
  46. await page.goto(targetPath);
  47. await page.getByTestId('editor-button').click();
  48. await expect(page.locator('.cm-content')).toContainText(body1);
  49. await expect(page.getByTestId('page-editor-preview-body')).toContainText(
  50. body1,
  51. );
  52. await appendTextToEditorUntilContains(page, body1 + body2);
  53. await page.keyboard.press(savePageShortcutKey);
  54. await page.getByTestId('view-button').click();
  55. await expect(page.locator('.wiki').first()).toContainText(body1 + body2);
  56. });
  57. });
  58. test('Access to /me page', async ({ page }) => {
  59. await page.goto('/me');
  60. // Expect the UserSettgins-specific elements to be present when accessing /me (UserSettgins)
  61. await expect(page.getByTestId('grw-user-settings')).toBeVisible();
  62. });
  63. test('All In-App Notification list is successfully loaded', async ({
  64. page,
  65. }) => {
  66. await page.goto('/me/all-in-app-notifications');
  67. // Expect the In-App Notification-specific elements to be present when accessing /me/all-in-app-notifications
  68. await expect(page.getByTestId('grw-in-app-notification-page')).toBeVisible();
  69. });
  70. test('/trash is successfully loaded', async ({ page }) => {
  71. await page.goto('/trash');
  72. await expect(page.getByTestId('trash-page-list')).toContainText(
  73. 'There are no pages under this page.',
  74. );
  75. });
  76. test('/tags is successfully loaded', async ({ page }) => {
  77. await page.goto('/tags');
  78. await expect(page.getByTestId('grw-tags-list')).toContainText(
  79. 'You have no tag, You can set tags on pages',
  80. );
  81. });
  82. test.describe
  83. .serial('Access to Template Editing Mode', () => {
  84. const templateBody1 = 'Template for children';
  85. const templateBody2 = 'Template for descendants';
  86. test('Successfully created template for children', async ({ page }) => {
  87. await page.goto('/Sandbox');
  88. await expect(page.getByTestId('grw-contextual-sub-nav')).toBeVisible();
  89. await page
  90. .getByTestId('grw-contextual-sub-nav')
  91. .getByTestId('open-page-item-control-btn')
  92. .click();
  93. await page.getByTestId('open-page-template-modal-btn').click();
  94. expect(page.getByTestId('page-template-modal')).toBeVisible();
  95. await page.getByTestId('template-button-children').click();
  96. await appendTextToEditorUntilContains(page, templateBody1);
  97. await page.getByTestId('save-page-btn').click();
  98. await expect(page.locator('.wiki').first()).toContainText(templateBody1);
  99. });
  100. test('Template is applied to pages created (template for children)', async ({
  101. page,
  102. }) => {
  103. await page.goto('/Sandbox');
  104. await page.getByTestId('grw-page-create-button').click();
  105. await expect(page.locator('.cm-content')).toContainText(templateBody1);
  106. await expect(page.getByTestId('page-editor-preview-body')).toContainText(
  107. templateBody1,
  108. );
  109. });
  110. test('Successfully created template for descendants', async ({ page }) => {
  111. await page.goto('/Sandbox');
  112. await expect(page.getByTestId('grw-contextual-sub-nav')).toBeVisible();
  113. await page
  114. .getByTestId('grw-contextual-sub-nav')
  115. .getByTestId('open-page-item-control-btn')
  116. .click();
  117. await page.getByTestId('open-page-template-modal-btn').click();
  118. expect(page.getByTestId('page-template-modal')).toBeVisible();
  119. await page.getByTestId('template-button-descendants').click();
  120. await appendTextToEditorUntilContains(page, templateBody2);
  121. await page.getByTestId('save-page-btn').click();
  122. await expect(page.locator('.wiki').first()).toContainText(templateBody2);
  123. });
  124. test('Template is applied to pages created (template for descendants)', async ({
  125. page,
  126. }) => {
  127. await page.goto('/Sandbox/Bootstrap5');
  128. await page.getByTestId('grw-page-create-button').click();
  129. await expect(page.locator('.cm-content')).toContainText(templateBody2);
  130. await expect(page.getByTestId('page-editor-preview-body')).toContainText(
  131. templateBody2,
  132. );
  133. });
  134. });