history.spec.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { expect } from '@playwright/test'
  2. import { test } from './fixtures'
  3. import { createRandomPage, modKey, searchAndJumpToPage, renamePage, randomString } from './utils'
  4. test('undo/redo on a page should work as expected', async ({ page, block }) => {
  5. const page1 = await createRandomPage(page)
  6. await block.mustType('text 1')
  7. await page.waitForTimeout(500) // Wait for 500ms autosave period to expire
  8. await expect(page.locator('text="text 1"')).toHaveCount(1)
  9. await page.keyboard.press(modKey + '+z')
  10. await page.waitForTimeout(100)
  11. await expect(page.locator('text="text 1"')).toHaveCount(0)
  12. await page.keyboard.press(modKey + '+Shift+z')
  13. await page.waitForTimeout(100)
  14. await expect(page.locator('text="text 1"')).toHaveCount(1)
  15. })
  16. test('should navigate to corresponding page on undo', async ({ page, block }) => {
  17. const page1 = await createRandomPage(page)
  18. await block.mustType('text 1')
  19. await page.waitForTimeout(500) // Wait for 500ms autosave period to expire
  20. const page2 = await createRandomPage(page)
  21. await page.keyboard.press(modKey + '+z')
  22. await page.waitForTimeout(100)
  23. expect(await page.innerText('.page-title .title')).toBe(page1)
  24. await page.keyboard.press(modKey + '+z')
  25. await page.waitForTimeout(100)
  26. await expect(page.locator('text="text 1"')).toHaveCount(0)
  27. })
  28. test('undo/redo of a renamed page should be preserved', async ({ page, block }) => {
  29. const page1 = await createRandomPage(page)
  30. await block.mustType('text 1')
  31. await page.waitForTimeout(500) // Wait for 500ms autosave period to expire
  32. await renamePage(page, randomString(10))
  33. await page.keyboard.press(modKey + '+z') // undo rename page
  34. await page.waitForTimeout(100)
  35. await page.keyboard.press(modKey + '+z') // undo text edit
  36. await page.waitForTimeout(100)
  37. await expect(page.locator('text="text 1"')).toHaveCount(0)
  38. })