saving.spec.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 expect(async () => {
  14. await page.keyboard.press(openPageCreateModalShortcutKey);
  15. await expect(page.getByTestId('page-create-modal')).toBeVisible({
  16. timeout: 1000,
  17. });
  18. }).toPass();
  19. page
  20. .getByTestId('page-create-modal')
  21. .locator('.rbt-input-main')
  22. .fill(newPagePath);
  23. page.getByTestId('btn-create-page-under-below').click();
  24. await page.getByTestId('view-button').click();
  25. const createdPageId = path.basename(page.url());
  26. expect(createdPageId.length).toBe(24);
  27. });
  28. test('Successfully updating a page using a shortcut on a previously created page', async ({
  29. page,
  30. }) => {
  31. const body1 = 'hello';
  32. const body2 = ' world!';
  33. const savePageShortcutKey = 'Control+s';
  34. await page.goto('/Sandbox/child');
  35. // 1st
  36. await page.getByTestId('editor-button').click();
  37. await expect(page.getByTestId('grw-editor-navbar-bottom')).toBeVisible();
  38. await appendTextToEditorUntilContains(page, body1);
  39. await page.keyboard.press(savePageShortcutKey);
  40. await page.getByTestId('view-button').click();
  41. await expect(page.locator('.main')).toContainText(body1);
  42. // 2nd
  43. await page.getByTestId('editor-button').click();
  44. await expect(page.getByTestId('grw-editor-navbar-bottom')).toBeVisible();
  45. await appendTextToEditorUntilContains(page, body1 + body2);
  46. await page.keyboard.press(savePageShortcutKey);
  47. await page.getByTestId('view-button').click();
  48. await expect(page.locator('.main')).toContainText(body1 + body2);
  49. });