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