editor.spec.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import { expect } from '@playwright/test'
  2. import { test } from './fixtures'
  3. import { createRandomPage, IsMac } from './utils'
  4. import { dispatch_kb_events, press_with_events, macos_pinyin_left_full_bracket } from './util/keyboard-events'
  5. import * as kb_events from './util/keyboard-events'
  6. test(
  7. "press Chinese parenthesis 【 by 2 times #3251 should trigger [[]], " +
  8. "but dont trigger RIME #3440 ",
  9. // cases should trigger [[]] #3251
  10. async ({ page }) => {
  11. for (let left_full_bracket of [
  12. kb_events.macos_pinyin_left_full_bracket,
  13. kb_events.win10_pinyin_left_full_bracket,
  14. // TODO: support #3741
  15. // kb_events.win10_legacy_pinyin_left_full_bracket,
  16. ]) {
  17. await createRandomPage(page)
  18. await page.type(':nth-match(textarea, 1)', "【")
  19. await dispatch_kb_events(page, ':nth-match(textarea, 1)', left_full_bracket)
  20. expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('【')
  21. await page.type(':nth-match(textarea, 1)', "【")
  22. await dispatch_kb_events(page, ':nth-match(textarea, 1)', left_full_bracket)
  23. expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('[[]]')
  24. };
  25. // dont trigger RIME #3440
  26. for (let [idx, selecting_candidate_left_bracket] of [
  27. kb_events.macos_pinyin_selecting_candidate_left_bracket,
  28. kb_events.win10_RIME_selecting_candidate_left_bracket
  29. ].entries()) {
  30. await createRandomPage(page)
  31. let prefix = "#3440 test " + idx + ": "
  32. await page.type(':nth-match(textarea, 1)', prefix + "【")
  33. await dispatch_kb_events(page, ':nth-match(textarea, 1)', selecting_candidate_left_bracket)
  34. expect(await page.inputValue(':nth-match(textarea, 1)')).toBe(prefix + '【')
  35. await page.type(':nth-match(textarea, 1)', "【")
  36. await dispatch_kb_events(page, ':nth-match(textarea, 1)', selecting_candidate_left_bracket)
  37. expect(await page.inputValue(':nth-match(textarea, 1)')).toBe(prefix + '【【')
  38. }
  39. })
  40. test('hashtag and quare brackets in same line #4178', async ({ page }) => {
  41. await createRandomPage(page)
  42. await page.type(':nth-match(textarea, 1)', '#foo bar')
  43. await page.press(':nth-match(textarea, 1)', 'Enter')
  44. await page.type(':nth-match(textarea, 1)', 'bar [[blah]]')
  45. for (let i = 0; i < 12; i++) {
  46. await page.press(':nth-match(textarea, 1)', 'ArrowLeft')
  47. }
  48. await page.type(':nth-match(textarea, 1)', ' ')
  49. await page.press(':nth-match(textarea, 1)', 'ArrowLeft')
  50. await page.type(':nth-match(textarea, 1)', '#')
  51. await page.waitForSelector('text="Search for a page"', { state: 'visible' })
  52. await page.type(':nth-match(textarea, 1)', 'fo')
  53. await page.click('.absolute >> text=' + 'foo')
  54. expect(await page.inputValue(':nth-match(textarea, 1)')).toBe(
  55. '#foo bar [[blah]]'
  56. )
  57. })
  58. // FIXME: ClipboardItem is not defined when running with this test
  59. // test('copy & paste block ref and replace its content', async ({ page }) => {
  60. // await createRandomPage(page)
  61. // await page.type(':nth-match(textarea, 1)', 'Some random text')
  62. // if (IsMac) {
  63. // await page.keyboard.press('Meta+c')
  64. // } else {
  65. // await page.keyboard.press('Control+c')
  66. // }
  67. // await page.pause()
  68. // await page.press(':nth-match(textarea, 1)', 'Enter')
  69. // if (IsMac) {
  70. // await page.keyboard.press('Meta+v')
  71. // } else {
  72. // await page.keyboard.press('Control+v')
  73. // }
  74. // await page.keyboard.press('Escape')
  75. // const blockRef$ = page.locator('.block-ref >> text="Some random text"');
  76. // // Check if the newly created block-ref has the same referenced content
  77. // await expect(blockRef$).toHaveCount(1);
  78. // // Edit the last block
  79. // await blockRef$.press('Enter')
  80. // // Move cursor into the block ref
  81. // for (let i = 0; i < 4; i++) {
  82. // await page.press(':nth-match(textarea, 1)', 'ArrowLeft')
  83. // }
  84. // // Trigger replace-block-reference-with-content-at-point
  85. // if (IsMac) {
  86. // await page.keyboard.press('Meta+Shift+r')
  87. // } else {
  88. // await page.keyboard.press('Control+Shift+v')
  89. // }
  90. // })