From 5ac142fb02da19ebb51a7776073600f0238f1cfb Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Wed, 27 Nov 2024 12:27:53 +0100 Subject: [PATCH] test keyboard interaction --- .../lib/uui-color-swatch.test.ts | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/packages/uui-color-swatch/lib/uui-color-swatch.test.ts b/packages/uui-color-swatch/lib/uui-color-swatch.test.ts index fbb512d48..7b1b2e8a8 100644 --- a/packages/uui-color-swatch/lib/uui-color-swatch.test.ts +++ b/packages/uui-color-swatch/lib/uui-color-swatch.test.ts @@ -1,6 +1,6 @@ import { html, fixture, expect, elementUpdated } from '@open-wc/testing'; import { UUIColorSwatchElement } from './uui-color-swatch.element'; -import { sendMouse } from '@web/test-runner-commands'; +import { sendMouse, sendKeys } from '@web/test-runner-commands'; describe('UUIColorSwatchElement', () => { let element: UUIColorSwatchElement; @@ -55,5 +55,35 @@ describe('UUIColorSwatchElement', () => { }); expect(element.selected).to.be.false; }); + + it('can be selected with Space key', async () => { + await sendKeys({ + press: 'Tab', + }); + await sendKeys({ + press: 'Space', + }); + expect(element.selected).to.be.true; + + await sendKeys({ + press: 'Space', + }); + expect(element.selected).to.be.false; + }); + + it('can be selected with Enter key', async () => { + await sendKeys({ + press: 'Tab', + }); + await sendKeys({ + press: 'Enter', + }); + expect(element.selected).to.be.true; + + await sendKeys({ + press: 'Enter', + }); + expect(element.selected).to.be.false; + }); }); });