Skip to content

Commit

Permalink
fix: fix on preview
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Oct 23, 2024
1 parent 9506828 commit cb717ab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
7 changes: 4 additions & 3 deletions packages/browser/src/client/tester/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function triggerCommand<T>(command: string, ...args: any[]) {

export function createUserEvent(__tl_user_event_base__?: TestingLibraryUserEvent, options?: TestingLibraryOptions): UserEvent {
let __tl_user_event__ = __tl_user_event_base__?.setup(options ?? {})
let clipboardData: any
const keyboard = {
unreleased: [] as string[],
}
Expand Down Expand Up @@ -129,21 +130,21 @@ export function createUserEvent(__tl_user_event_base__?: TestingLibraryUserEvent
},
async copy() {
if (typeof __tl_user_event__ !== 'undefined') {
await __tl_user_event__.copy()
clipboardData = await __tl_user_event__.copy()
return
}
await userEvent.keyboard(`{${modifier}>}{c}{/${modifier}}`)
},
async cut() {
if (typeof __tl_user_event__ !== 'undefined') {
await __tl_user_event__.cut()
clipboardData = await __tl_user_event__.cut()
return
}
await userEvent.keyboard(`{${modifier}>}{x}{/${modifier}}`)
},
async paste() {
if (typeof __tl_user_event__ !== 'undefined') {
await __tl_user_event__.paste()
await __tl_user_event__.paste(clipboardData)
return
}
await userEvent.keyboard(`{${modifier}>}{v}{/${modifier}}`)
Expand Down
15 changes: 12 additions & 3 deletions test/browser/fixtures/user-event/clipboard.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test } from 'vitest';
import { page, userEvent } from '@vitest/browser/context';
import { page, userEvent, server } from '@vitest/browser/context';

test('clipboard', async () => {
// make it smaller since webdriverio fails when scaled
Expand All @@ -11,10 +11,19 @@ test('clipboard', async () => {
<input placeholder="third" />
`;

async function selectall() {
if (server.provider === 'preview') {
// TODO: support selectall on preview?
await userEvent.keyboard('{Control>}{a}{/Control}')
} else {
await userEvent.keyboard('{selectall}')
}
}

// write first "hello" and copy to clipboard
await userEvent.click(page.getByPlaceholder('first'));
await userEvent.keyboard('hello');
await userEvent.keyboard(`{selectall}`);
await selectall()
await userEvent.copy();

// paste twice into second
Expand All @@ -25,7 +34,7 @@ test('clipboard', async () => {
// append first "world" and cut
await userEvent.click(page.getByPlaceholder('first'));
await userEvent.keyboard('world');
await userEvent.keyboard(`{selectall}`);
await selectall()
await userEvent.cut();

// paste it to third
Expand Down

0 comments on commit cb717ab

Please sign in to comment.