Sfoglia il codice sorgente

test(e2e): addressing #3251 and #3440

Junyi Du 3 anni fa
parent
commit
2cfa95d17b
2 ha cambiato i file con 252 aggiunte e 15 eliminazioni
  1. 32 14
      e2e-tests/editor.spec.ts
  2. 220 1
      e2e-tests/util/keyboard-events.ts

+ 32 - 14
e2e-tests/editor.spec.ts

@@ -1,20 +1,38 @@
 import { expect } from '@playwright/test'
 import { test } from './fixtures'
 import { createRandomPage, IsMac } from './utils'
-import { press_with_events, macos_pinyin_left_full_bracket } from './util/keyboard-events'
-
-test('keyboard related issues', async ({ page }) => {
-  await createRandomPage(page)
-  await page.type(':nth-match(textarea, 1)', 'without events: ')
-  await page.type(':nth-match(textarea, 1)', "【")
-  await page.type(':nth-match(textarea, 1)', "【")
-
-  await page.type(':nth-match(textarea, 1)', ' | with events: ')
-  await page.type(':nth-match(textarea, 1)', "【")
-  await press_with_events(page, ':nth-match(textarea, 1)', macos_pinyin_left_full_bracket)
-  await page.type(':nth-match(textarea, 1)', "【")
-  await press_with_events(page, ':nth-match(textarea, 1)', macos_pinyin_left_full_bracket)
-})
+import { dispatch_kb_events, press_with_events, macos_pinyin_left_full_bracket } from './util/keyboard-events'
+import * as kb_events from './util/keyboard-events'
+
+test(
+  "press Chinese parenthesis 【 by 2 times #3251 should trigger [[]], " +
+  "but dont trigger RIME #3440 ",
+  // cases should trigger [[]]
+  async ({ page }) => {
+    for (let left_full_bracket of [
+      kb_events.macos_pinyin_left_full_bracket,
+      kb_events.win10_pinyin_left_full_bracket,
+      // TODO: support #3741
+      // kb_events.win10_legacy_pinyin_left_full_bracket,
+    ]) {
+      await createRandomPage(page)
+      await page.type(':nth-match(textarea, 1)', "【")
+      await dispatch_kb_events(page, ':nth-match(textarea, 1)', left_full_bracket)
+      expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('【')
+      await page.type(':nth-match(textarea, 1)', "【")
+      await dispatch_kb_events(page, ':nth-match(textarea, 1)', left_full_bracket)
+      expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('[[]]')
+    }
+
+    // cases should NOT trigger [[]]
+    await createRandomPage(page)
+    await page.type(':nth-match(textarea, 1)', "【")
+    await dispatch_kb_events(page, ':nth-match(textarea, 1)', kb_events.win10_RIME_left_full_bracket)
+    expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('【')
+    await page.type(':nth-match(textarea, 1)', "【")
+    await dispatch_kb_events(page, ':nth-match(textarea, 1)', kb_events.win10_RIME_left_full_bracket)
+    expect(await page.inputValue(':nth-match(textarea, 1)')).toBe('【【')
+  })
 
 test('hashtag and quare brackets in same line #4178', async ({ page }) => {
   await createRandomPage(page)

+ 220 - 1
e2e-tests/util/keyboard-events.ts

@@ -1,7 +1,7 @@
 
 
 // typing 【
-export let press_with_events = async function (page, selector, keyboard_events ){
+export let dispatch_kb_events = async function (page, selector, keyboard_events ){
     for (let idx in keyboard_events){
       let { event_type, event } = keyboard_events[idx]
       await page.dispatchEvent(selector, event_type, event)
@@ -40,4 +40,223 @@ export let macos_pinyin_left_full_bracket = [
       "composed": true
     }
   }
+]
+
+export let win10_pinyin_left_full_bracket = [
+  {
+    "event_type": "keydown",
+    "event": {
+      "key": "Process",
+      "code": "BracketLeft",
+      "location": 0,
+      "ctrlKey": false,
+      "shiftKey": false,
+      "altKey": false,
+      "metaKey": false,
+      "repeat": false,
+      "isComposing": false,
+      "composed": true
+    }
+  },
+  {
+    "event_type": "keyup",
+    "event": {
+      "key": "Process",
+      "code": "BracketLeft",
+      "location": 0,
+      "ctrlKey": false,
+      "shiftKey": false,
+      "altKey": false,
+      "metaKey": false,
+      "repeat": false,
+      "isComposing": false,
+      "composed": true
+    }
+  },
+  {
+    "event_type": "keyup",
+    "event": {
+      "key": "[",
+      "code": "BracketLeft",
+      "location": 0,
+      "ctrlKey": false,
+      "shiftKey": false,
+      "altKey": false,
+      "metaKey": false,
+      "repeat": false,
+      "isComposing": false,
+      "composed": true
+    }
+  }
+]
+
+export let win10_legacy_pinyin_left_full_bracket = [
+  {
+    "event_type": "keydown",
+    "event": {
+      "key": "Process",
+      "code": "BracketLeft",
+      "location": 0,
+      "ctrlKey": false,
+      "shiftKey": false,
+      "altKey": false,
+      "metaKey": false,
+      "repeat": false,
+      "isComposing": false,
+      "composed": true
+    }
+  },
+  {
+    "event_type": "keyup",
+    "event": {
+      "key": "Process",
+      "code": "BracketLeft",
+      "location": 0,
+      "ctrlKey": false,
+      "shiftKey": false,
+      "altKey": false,
+      "metaKey": false,
+      "repeat": false,
+      "isComposing": false,
+      "composed": true
+    }
+  }
+]
+
+export let win10_RIME_left_full_bracket = [
+  {
+    "event_type": "keydown",
+    "event": {
+      "key": "Process",
+      "code": "BracketLeft",
+      "location": 0,
+      "ctrlKey": false,
+      "shiftKey": false,
+      "altKey": false,
+      "metaKey": false,
+      "repeat": false,
+      "isComposing": false,
+      "composed": true
+    }
+  },
+  {
+    "event_type": "keyup",
+    "event": {
+      "key": "Process",
+      "code": "BracketLeft",
+      "location": 0,
+      "ctrlKey": false,
+      "shiftKey": false,
+      "altKey": false,
+      "metaKey": false,
+      "repeat": false,
+      "isComposing": true,
+      "composed": true
+    }
+  },
+  {
+    "event_type": "keyup",
+    "event": {
+      "key": "[",
+      "code": "BracketLeft",
+      "location": 0,
+      "ctrlKey": false,
+      "shiftKey": false,
+      "altKey": false,
+      "metaKey": false,
+      "repeat": false,
+      "isComposing": true,
+      "composed": true
+    }
+  },
+  {
+    "event_type": "keydown",
+    "event": {
+      "key": "Process",
+      "code": "BracketLeft",
+      "location": 0,
+      "ctrlKey": false,
+      "shiftKey": false,
+      "altKey": false,
+      "metaKey": false,
+      "repeat": false,
+      "isComposing": true,
+      "composed": true
+    }
+  },
+  {
+    "event_type": "keyup",
+    "event": {
+      "key": "Process",
+      "code": "BracketLeft",
+      "location": 0,
+      "ctrlKey": false,
+      "shiftKey": false,
+      "altKey": false,
+      "metaKey": false,
+      "repeat": false,
+      "isComposing": true,
+      "composed": true
+    }
+  },
+  {
+    "event_type": "keyup",
+    "event": {
+      "key": "[",
+      "code": "BracketLeft",
+      "location": 0,
+      "ctrlKey": false,
+      "shiftKey": false,
+      "altKey": false,
+      "metaKey": false,
+      "repeat": false,
+      "isComposing": true,
+      "composed": true
+    }
+  },
+  {
+    "event_type": "keydown",
+    "event": {
+      "key": "Process",
+      "code": "Space",
+      "location": 0,
+      "ctrlKey": false,
+      "shiftKey": false,
+      "altKey": false,
+      "metaKey": false,
+      "repeat": false,
+      "isComposing": true,
+      "composed": true
+    }
+  },
+  {
+    "event_type": "keyup",
+    "event": {
+      "key": "Process",
+      "code": "Space",
+      "location": 0,
+      "ctrlKey": false,
+      "shiftKey": false,
+      "altKey": false,
+      "metaKey": false,
+      "repeat": false,
+      "isComposing": false,
+      "composed": true
+    }
+  },
+  {
+    "event_type": "keyup",
+    "event": {
+      "key": " ",
+      "code": "Space",
+      "location": 0,
+      "ctrlKey": false,
+      "shiftKey": false,
+      "altKey": false,
+      "metaKey": false,
+      "repeat": false,
+      "isComposing": false,
+      "composed": true
+    }
+  }
 ]