1
0

logseq-url.spec.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { expect } from '@playwright/test'
  2. import { test } from './fixtures'
  3. import { createRandomPage, lastBlock, IsMac, IsLinux } from './utils'
  4. test("Logseq URLs (same graph)", async ({ page, block }) => {
  5. let paste_key = IsMac ? 'Meta+v' : 'Control+v'
  6. // create a page with identify block
  7. let identify_text = "URL redirect target"
  8. let page_title = await createRandomPage(page)
  9. await block.mustFill(identify_text)
  10. // paste current page's URL to another page, then redirect through the URL
  11. await page.click('.ui__dropdown-trigger .toolbar-dots-btn')
  12. await page.locator("text=Copy page URL").click()
  13. await createRandomPage(page)
  14. await block.mustFill("") // to enter editing mode
  15. await page.keyboard.press(paste_key)
  16. // paste returns a promise which is async, so we need give it a little bit
  17. // more time
  18. await page.waitForTimeout(100)
  19. let cursor_locator = page.locator('textarea >> nth=0')
  20. expect(await cursor_locator.inputValue()).toContain("page=" + page_title)
  21. await cursor_locator.press("Enter")
  22. if (IsMac) { // FIXME: support Logseq URL on Linux (XDG)
  23. page.locator('a.external-link >> nth=0').click()
  24. await page.waitForNavigation()
  25. await page.waitForTimeout(500)
  26. cursor_locator = await lastBlock(page)
  27. expect(await cursor_locator.inputValue()).toBe(identify_text)
  28. }
  29. // paste the identify block's URL to another page, then redirect through the URL
  30. await page.click('span.bullet >> nth=0', { button: "right" })
  31. await page.locator("text=Copy block URL").click()
  32. await createRandomPage(page)
  33. await block.mustFill("") // to enter editing mode
  34. await page.keyboard.press(paste_key)
  35. await page.waitForTimeout(100)
  36. cursor_locator = page.locator('textarea >> nth=0')
  37. expect(await cursor_locator.inputValue()).toContain("block-id=")
  38. await cursor_locator.press("Enter")
  39. if (IsMac) { // FIXME: support Logseq URL on Linux (XDG)
  40. page.locator('a.external-link >> nth=0').click()
  41. await page.waitForNavigation()
  42. await page.waitForTimeout(500)
  43. cursor_locator = await lastBlock(page)
  44. expect(await cursor_locator.inputValue()).toBe(identify_text)
  45. }
  46. })