access-to-page.spec.ts 5.7 KB

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