history.spec.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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.click('.ui__confirm-modal button')
  34. await page.keyboard.press(modKey + '+z')
  35. await page.waitForTimeout(100)
  36. await expect(page.locator('text="text 1"')).toHaveCount(0)
  37. })