access-to-page.spec.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import { test, expect, type Page } 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(text);
  5. };
  6. test('has title', async({ page }) => {
  7. await page.goto('/Sandbox');
  8. // Expect a title "to contain" a substring.
  9. await expect(page).toHaveTitle(/Sandbox/);
  10. });
  11. test('get h1', async({ page }) => {
  12. await page.goto('/Sandbox');
  13. // Expects page to have a heading with the name of Installation.
  14. await expect(page.getByRole('heading').filter({ hasText: /\/Sandbox/ })).toBeVisible();
  15. });
  16. test('/Sandbox/Math is successfully loaded', async({ page }) => {
  17. await page.goto('/Sandbox/Math');
  18. // Expect the Math-specific elements to be present
  19. await expect(page.locator('.math').first()).toBeVisible();
  20. });
  21. test('Sandbox with edit is successfully loaded', async({ page }) => {
  22. await page.goto('/Sandbox#edit');
  23. // Expect the Editor-specific elements to be present
  24. await expect(page.getByTestId('grw-editor-navbar-bottom')).toBeVisible();
  25. await expect(page.getByTestId('save-page-btn')).toBeVisible();
  26. await expect(page.getByTestId('grw-grant-selector')).toBeVisible();
  27. });
  28. test.describe.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(body1);
  45. await appendTextToEditorUntilContains(page, body1 + body2);
  46. await page.keyboard.press(savePageShortcutKey);
  47. await page.getByTestId('view-button').click();
  48. await expect(page.locator('.wiki').first()).toContainText(body1 + body2);
  49. });
  50. });
  51. test('Access to /me page', async({ page }) => {
  52. await page.goto('/me');
  53. // Expect the UserSettgins-specific elements to be present when accessing /me (UserSettgins)
  54. await expect(page.getByTestId('grw-user-settings')).toBeVisible();
  55. });
  56. test('All In-App Notification list is successfully loaded', async({ page }) => {
  57. await page.goto('/me/all-in-app-notifications');
  58. // Expect the In-App Notification-specific elements to be present when accessing /me/all-in-app-notifications
  59. await expect(page.getByTestId('grw-in-app-notification-page')).toBeVisible();
  60. });
  61. test('/trash is successfully loaded', async({ page }) => {
  62. await page.goto('/trash');
  63. await expect(page.getByTestId('trash-page-list')).toContainText('There are no pages under this page.');
  64. });
  65. test('/tags is successfully loaded', async({ page }) => {
  66. await page.goto('/tags');
  67. await expect(page.getByTestId('grw-tags-list')).toContainText('You have no tag, You can set tags on pages');
  68. });
  69. test.describe.serial('Access to Template Editing Mode', () => {
  70. const templateBody1 = 'Template for children';
  71. const templateBody2 = 'Template for descendants';
  72. test('Successfully created template for children', async({ page }) => {
  73. await page.goto('/Sandbox');
  74. await expect(page.getByTestId('grw-contextual-sub-nav')).toBeVisible();
  75. await page.getByTestId('grw-contextual-sub-nav').getByTestId('open-page-item-control-btn').click();
  76. await page.getByTestId('open-page-template-modal-btn').click();
  77. expect(page.getByTestId('page-template-modal')).toBeVisible();
  78. await page.getByTestId('template-button-children').click();
  79. await appendTextToEditorUntilContains(page, templateBody1);
  80. await page.getByTestId('save-page-btn').click();
  81. await expect(page.locator('.wiki').first()).toContainText(templateBody1);
  82. });
  83. test('Template is applied to pages created (template for children)', async({ page }) => {
  84. await page.goto('/Sandbox');
  85. await page.getByTestId('grw-page-create-button').click();
  86. await expect(page.locator('.cm-content')).toContainText(templateBody1);
  87. await expect(page.getByTestId('page-editor-preview-body')).toContainText(templateBody1);
  88. });
  89. test('Successfully created template for descendants', async({ page }) => {
  90. await page.goto('/Sandbox');
  91. await expect(page.getByTestId('grw-contextual-sub-nav')).toBeVisible();
  92. await page.getByTestId('grw-contextual-sub-nav').getByTestId('open-page-item-control-btn').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-descendants').click();
  96. await appendTextToEditorUntilContains(page, templateBody2);
  97. await page.getByTestId('save-page-btn').click();
  98. await expect(page.locator('.wiki').first()).toContainText(templateBody2);
  99. });
  100. test('Template is applied to pages created (template for descendants)', async({ page }) => {
  101. await page.goto('/Sandbox/Bootstrap5');
  102. await page.getByTestId('grw-page-create-button').click();
  103. await expect(page.locator('.cm-content')).toContainText(templateBody2);
  104. await expect(page.getByTestId('page-editor-preview-body')).toContainText(templateBody2);
  105. });
  106. });