logseq-url.spec.ts 2.2 KB

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