saving.spec.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { expect, type Page, test } from '@playwright/test';
  2. import path from 'path';
  3. const appendTextToEditorUntilContains = async (page: Page, text: string) => {
  4. await page.locator('.cm-content').fill(text);
  5. await expect(page.getByTestId('page-editor-preview-body')).toContainText(
  6. text,
  7. );
  8. };
  9. test('Successfully create page under specific path', async ({ page }) => {
  10. const newPagePath = '/child';
  11. const openPageCreateModalShortcutKey = 'c';
  12. await page.goto('/Sandbox');
  13. await page.keyboard.press(openPageCreateModalShortcutKey);
  14. await expect(page.getByTestId('page-create-modal')).toBeVisible();
  15. page
  16. .getByTestId('page-create-modal')
  17. .locator('.rbt-input-main')
  18. .fill(newPagePath);
  19. page.getByTestId('btn-create-page-under-below').click();
  20. await page.getByTestId('view-button').click();
  21. const createdPageId = path.basename(page.url());
  22. expect(createdPageId.length).toBe(24);
  23. });
  24. test('Successfully updating a page using a shortcut on a previously created page', async ({
  25. page,
  26. }) => {
  27. const body1 = 'hello';
  28. const body2 = ' world!';
  29. const savePageShortcutKey = 'Control+s';
  30. await page.goto('/Sandbox/child');
  31. // 1st
  32. await page.getByTestId('editor-button').click();
  33. await expect(page.getByTestId('grw-editor-navbar-bottom')).toBeVisible();
  34. await appendTextToEditorUntilContains(page, body1);
  35. await page.keyboard.press(savePageShortcutKey);
  36. await page.getByTestId('view-button').click();
  37. await expect(page.locator('.main')).toContainText(body1);
  38. // 2nd
  39. await page.getByTestId('editor-button').click();
  40. await expect(page.getByTestId('grw-editor-navbar-bottom')).toBeVisible();
  41. await appendTextToEditorUntilContains(page, body1 + body2);
  42. await page.keyboard.press(savePageShortcutKey);
  43. await page.getByTestId('view-button').click();
  44. await expect(page.locator('.main')).toContainText(body1 + body2);
  45. });