|
| 1 | +import { expect, test } from '@playwright/test' |
| 2 | +import { expectKeyboardShown, getBox, init, tapKeyboard } from './util' |
| 3 | + |
| 4 | +test('Focus, blink and blur', async ({ page }) => { |
| 5 | + await init(page) |
| 6 | + |
| 7 | + const caret = page.locator('.fcitx-mobile-caret') |
| 8 | + await expect(caret).not.toBeInViewport() |
| 9 | + |
| 10 | + const textarea = page.locator('textarea') |
| 11 | + await textarea.tap() |
| 12 | + await expect(caret).toHaveCSS('opacity', '1') |
| 13 | + await expect(caret).toHaveCSS('opacity', '0') |
| 14 | + await expect(caret).toHaveCSS('opacity', '1') |
| 15 | + |
| 16 | + await page.locator('button').tap() |
| 17 | + await expect(caret).not.toBeInViewport() |
| 18 | +}) |
| 19 | + |
| 20 | +test('Input and Backspace', async ({ page }) => { |
| 21 | + await init(page) |
| 22 | + |
| 23 | + const textarea = page.locator('textarea') |
| 24 | + await textarea.tap() |
| 25 | + await expectKeyboardShown(page) |
| 26 | + const caret = page.locator('.fcitx-mobile-caret') |
| 27 | + const { x: x0 } = await getBox(caret) |
| 28 | + |
| 29 | + await tapKeyboard(page, 'a@') |
| 30 | + const { x: x1 } = await getBox(caret) |
| 31 | + expect(x1).toBeGreaterThan(x0) |
| 32 | + |
| 33 | + await tapKeyboard(page, page.locator('.fcitx-keyboard-key.fcitx-keyboard-backspace')) |
| 34 | + const { x } = await getBox(caret) |
| 35 | + expect(x).toEqual(x0) |
| 36 | +}) |
| 37 | + |
| 38 | +test('Touch', async ({ page }) => { |
| 39 | + await init(page) |
| 40 | + const textarea = page.locator('textarea') |
| 41 | + await textarea.tap() |
| 42 | + await expectKeyboardShown(page) |
| 43 | + const caret = page.locator('.fcitx-mobile-caret') |
| 44 | + const { x: x0 } = await getBox(caret) |
| 45 | + |
| 46 | + await tapKeyboard(page, 'a@') |
| 47 | + await textarea.evaluate((el: HTMLTextAreaElement) => el.selectionStart = el.selectionEnd = 0) |
| 48 | + const { x } = await getBox(caret) |
| 49 | + expect(x).toEqual(x0) |
| 50 | + |
| 51 | + await textarea.tap() |
| 52 | + const { x: x1 } = await getBox(caret) |
| 53 | + expect(x1, 'Tapping on center should effectively change caret position').toBeGreaterThan(x0) |
| 54 | +}) |
0 commit comments