hotkey.spec.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { expect } from '@playwright/test'
  2. import { test } from './fixtures'
  3. import { createRandomPage, newBlock, lastBlock, IsMac, IsLinux } from './utils'
  4. test('open search dialog', async ({ page }) => {
  5. if (IsMac) {
  6. await page.keyboard.press('Meta+k')
  7. } else if (IsLinux) {
  8. await page.keyboard.press('Control+k')
  9. } else {
  10. expect(false, "TODO: test on Windows and other platforms").toBeTruthy()
  11. }
  12. await page.waitForSelector('[placeholder="Search or create page"]')
  13. await page.keyboard.press('Escape')
  14. await page.waitForSelector('[placeholder="Search or create page"]', { state: 'hidden' })
  15. })
  16. // See-also: https://github.com/logseq/logseq/issues/3278
  17. test('insert link', async ({ page }) => {
  18. await createRandomPage(page)
  19. let hotKey = 'Control+l'
  20. let selectAll = 'Control+a'
  21. if (IsMac) {
  22. hotKey = 'Meta+l'
  23. selectAll = 'Meta+a'
  24. }
  25. // Case 1: empty link
  26. await lastBlock(page)
  27. await page.press('textarea >> nth=0', hotKey)
  28. expect(await page.inputValue('textarea >> nth=0')).toBe('[]()')
  29. await page.type('textarea >> nth=0', 'Logseq Website')
  30. expect(await page.inputValue('textarea >> nth=0')).toBe('[Logseq Website]()')
  31. await page.fill('textarea >> nth=0', '[Logseq Website](https://logseq.com)')
  32. // Case 2: link with label
  33. await newBlock(page)
  34. await page.type('textarea >> nth=0', 'Logseq')
  35. await page.press('textarea >> nth=0', selectAll)
  36. await page.press('textarea >> nth=0', hotKey)
  37. expect(await page.inputValue('textarea >> nth=0')).toBe('[Logseq]()')
  38. await page.type('textarea >> nth=0', 'https://logseq.com/')
  39. expect(await page.inputValue('textarea >> nth=0')).toBe('[Logseq](https://logseq.com/)')
  40. // Case 3: link with URL
  41. await newBlock(page)
  42. await page.type('textarea >> nth=0', 'https://logseq.com/')
  43. await page.press('textarea >> nth=0', selectAll)
  44. await page.press('textarea >> nth=0', hotKey)
  45. expect(await page.inputValue('textarea >> nth=0')).toBe('[](https://logseq.com/)')
  46. await page.type('textarea >> nth=0', 'Logseq')
  47. expect(await page.inputValue('textarea >> nth=0')).toBe('[Logseq](https://logseq.com/)')
  48. })