Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/components/carousel/carousel-indicator-container.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { defineComponents } from '../common/definitions/defineComponents.js';
import { first } from '../common/util.js';
import {
simulateClick,
simulateFocusOut,
simulateKeyboard,
simulatePointerDown,
simulatePointerUp,
Expand Down Expand Up @@ -100,7 +101,7 @@ describe('Carousel Indicator Container', () => {
</div>`
);

first(buttons).dispatchEvent(new FocusEvent('focusout', { bubbles: true }));
simulateFocusOut(first(buttons));
await elementUpdated(container);

expect(container).shadowDom.to.equal(
Expand All @@ -127,9 +128,7 @@ describe('Carousel Indicator Container', () => {
</igc-carousel-indicator>`
);

first(buttons).dispatchEvent(
new FocusEvent('focusout', { bubbles: true, relatedTarget: indicator })
);
simulateFocusOut(first(buttons), { relatedTarget: indicator });
await elementUpdated(container);

expect(container).shadowDom.to.equal(
Expand Down
5 changes: 3 additions & 2 deletions src/components/carousel/carousel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { defineComponents } from '../common/definitions/defineComponents.js';
import {
finishAnimationsFor,
simulateClick,
simulateFocusOut,
simulateKeyboard,
simulateLostPointerCapture,
simulatePointerDown,
Expand Down Expand Up @@ -763,7 +764,7 @@ describe('Carousel', () => {
await elementUpdated(carousel);

// loose focus
carousel.dispatchEvent(new FocusEvent('focusout'));
simulateFocusOut(carousel);
await elementUpdated(carousel);

expect(carousel.isPlaying).to.be.false;
Expand Down Expand Up @@ -820,7 +821,7 @@ describe('Carousel', () => {
expect(carousel.current).to.equal(0);

// loose focus
carousel.dispatchEvent(new FocusEvent('focusout'));
simulateFocusOut(carousel);
await elementUpdated(carousel);

await clock.tickAsync(200);
Expand Down
5 changes: 2 additions & 3 deletions src/components/common/controllers/focus-ring.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { css, LitElement } from 'lit';
import { partMap } from '../part-map.js';
import {
simulateClick,
simulateFocusOut,
simulateKeyboard,
simulatePointerDown,
simulatePointerUp,
Expand Down Expand Up @@ -79,9 +80,7 @@ describe('Focus ring controller', () => {

expect(hasKeyboardFocusStyles(instance.button)).to.be.true;

instance.button.dispatchEvent(
new FocusEvent('focusout', { bubbles: true, composed: true })
);
simulateFocusOut(instance.button);
await elementUpdated(instance);

expect(hasKeyboardFocusStyles(instance.button)).to.be.false;
Expand Down
2 changes: 2 additions & 0 deletions src/components/common/controllers/key-bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export const arrowLeft = 'ArrowLeft' as const;
export const arrowRight = 'ArrowRight' as const;
export const arrowUp = 'ArrowUp' as const;
export const arrowDown = 'ArrowDown' as const;
export const backspaceKey = 'Backspace' as const;
export const deleteKey = 'Delete' as const;
export const enterKey = 'Enter' as const;
export const spaceBar = ' ' as const;
export const escapeKey = 'Escape' as const;
Expand Down
22 changes: 22 additions & 0 deletions src/components/common/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,15 @@ export function simulateBlur(node: Element): void {
node.dispatchEvent(new FocusEvent('blur'));
}

export function simulateFocusOut(
node: Element,
options?: FocusEventInit
): void {
node.dispatchEvent(
new FocusEvent('focusout', { bubbles: true, composed: true, ...options })
);
}

export function simulatePointerDown(
node: Element,
options?: PointerEventInit,
Expand Down Expand Up @@ -428,6 +437,19 @@ export function simulateDoubleClick(node: Element): void {
);
}

export function simulatePaste(node: Element, pastedText: string): void {
const clipboardData = new DataTransfer();
clipboardData.setData('text/plain', pastedText);

node.dispatchEvent(
new ClipboardEvent('paste', {
bubbles: true,
composed: true,
clipboardData,
})
);
}

/**
* Returns an array of all Animation objects affecting this element or which are scheduled to do so in the future.
* It can optionally return Animation objects for descendant elements too.
Expand Down
Loading
Loading