saving.spec.ts 1.8 KB

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