-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
90 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
packages/core/src/helpers/useKeyPressed/useKeyPressed.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { renderSetup } from '@test-utils/index'; | ||
import { useKeyPressed } from './useKeyPressed'; | ||
import { fireEvent } from '@testing-library/vue'; | ||
import { nextTick, ref } from 'vue'; | ||
|
||
describe('ref is true as long as the key is held', () => { | ||
test('accepts single key string', async () => { | ||
const { isPressed } = await renderSetup(() => { | ||
return { isPressed: useKeyPressed('ShiftLeft') }; | ||
}); | ||
|
||
expect(isPressed.value).toBe(false); | ||
await fireEvent.keyDown(window, { code: 'ShiftLeft' }); | ||
expect(isPressed.value).toBe(true); | ||
await fireEvent.keyUp(window, { code: 'ShiftLeft' }); | ||
expect(isPressed.value).toBe(false); | ||
}); | ||
|
||
test('accepts multiple key strings', async () => { | ||
const { isPressed } = await renderSetup(() => { | ||
return { isPressed: useKeyPressed(['KeyK', 'KeyL']) }; | ||
}); | ||
|
||
expect(isPressed.value).toBe(false); | ||
await fireEvent.keyDown(window, { code: 'KeyK' }); | ||
expect(isPressed.value).toBe(true); | ||
await fireEvent.keyUp(window, { code: 'KeyK' }); | ||
expect(isPressed.value).toBe(false); | ||
|
||
await fireEvent.keyDown(window, { code: 'KeyL' }); | ||
expect(isPressed.value).toBe(true); | ||
await fireEvent.keyUp(window, { code: 'KeyL' }); | ||
expect(isPressed.value).toBe(false); | ||
}); | ||
|
||
test('accepts a predicate', async () => { | ||
const { isPressed } = await renderSetup(() => { | ||
return { isPressed: useKeyPressed(e => e.code === 'KeyK') }; | ||
}); | ||
|
||
expect(isPressed.value).toBe(false); | ||
await fireEvent.keyDown(window, { code: 'KeyK' }); | ||
expect(isPressed.value).toBe(true); | ||
await fireEvent.keyUp(window, { code: 'KeyK' }); | ||
expect(isPressed.value).toBe(false); | ||
}); | ||
}); | ||
|
||
test('can be disabled', async () => { | ||
const isDisabled = ref(true); | ||
const { isPressed } = await renderSetup(() => { | ||
return { isPressed: useKeyPressed('KeyK', isDisabled) }; | ||
}); | ||
|
||
expect(isPressed.value).toBe(false); | ||
await fireEvent.keyDown(window, { code: 'KeyK' }); | ||
expect(isPressed.value).toBe(false); | ||
await fireEvent.keyUp(window, { code: 'KeyK' }); | ||
expect(isPressed.value).toBe(false); | ||
|
||
isDisabled.value = false; | ||
await nextTick(); | ||
|
||
expect(isPressed.value).toBe(false); | ||
await fireEvent.keyDown(window, { code: 'KeyK' }); | ||
expect(isPressed.value).toBe(true); | ||
await fireEvent.keyUp(window, { code: 'KeyK' }); | ||
expect(isPressed.value).toBe(false); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/core/src/helpers/usePopoverController/usePopoverController.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters