mirror of
https://github.com/material-components/material-web.git
synced 2024-10-27 14:07:17 +03:00
chore(testing): rename harness methods
PiperOrigin-RevId: 449506213
This commit is contained in:
parent
16e0cf7098
commit
5d469720c7
@ -17,8 +17,8 @@ export class ButtonHarness extends Harness<Button> {
|
|||||||
return this.element.renderRoot.querySelector('.md3-button') as HTMLElement;
|
return this.element.renderRoot.querySelector('.md3-button') as HTMLElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
override async clickWithMouseStart(init: PointerEventInit = {}) {
|
override async startClickWithMouse(init: PointerEventInit = {}) {
|
||||||
await super.clickWithMouseStart(init);
|
await super.startClickWithMouse(init);
|
||||||
// The ripple adapter unconditionally returns true for
|
// The ripple adapter unconditionally returns true for
|
||||||
// `containsEventTarget`, which effectively blocks simultaneous ripple
|
// `containsEventTarget`, which effectively blocks simultaneous ripple
|
||||||
// activations. We need simulatenous activations for testing though, so
|
// activations. We need simulatenous activations for testing though, so
|
||||||
|
@ -105,7 +105,7 @@ describe('ActionController', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('calls beginPress on down', async () => {
|
it('calls beginPress on down', async () => {
|
||||||
await harness.clickWithMouseStart();
|
await harness.startClickWithMouse();
|
||||||
expect(el.lastBegin).toBeDefined();
|
expect(el.lastBegin).toBeDefined();
|
||||||
expect(el.lastBegin!.positionEvent).toBeInstanceOf(PointerEvent);
|
expect(el.lastBegin!.positionEvent).toBeInstanceOf(PointerEvent);
|
||||||
expect(el.lastBegin!.positionEvent).toBeInstanceOf(PointerEvent);
|
expect(el.lastBegin!.positionEvent).toBeInstanceOf(PointerEvent);
|
||||||
@ -126,16 +126,16 @@ describe('ActionController', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('goes through the expected phases during a press', async () => {
|
it('goes through the expected phases during a press', async () => {
|
||||||
await harness.clickWithMouseStart();
|
await harness.startClickWithMouse();
|
||||||
const ac = el.actionController as unknown as ActionControllerInternals;
|
const ac = el.actionController as unknown as ActionControllerInternals;
|
||||||
expect(ac.phase).toEqual('WAITING_FOR_MOUSE_CLICK');
|
expect(ac.phase).toEqual('WAITING_FOR_MOUSE_CLICK');
|
||||||
await harness.clickWithMouseEnd();
|
await harness.endClickWithMouse();
|
||||||
expect(ac.phase).toEqual('INACTIVE');
|
expect(ac.phase).toEqual('INACTIVE');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('cancels press if cursor leaves element during press', async () => {
|
it('cancels press if cursor leaves element during press', async () => {
|
||||||
await harness.clickWithMouseStart();
|
await harness.startClickWithMouse();
|
||||||
await harness.hoverLeave();
|
await harness.endHover();
|
||||||
expect(el.lastEnd).toEqual({cancelled: true});
|
expect(el.lastEnd).toEqual({cancelled: true});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -156,7 +156,7 @@ describe('ActionController', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('cancels when removed from dom', async () => {
|
it('cancels when removed from dom', async () => {
|
||||||
await harness.clickWithMouseStart();
|
await harness.startClickWithMouse();
|
||||||
expect(el.lastBegin).toBeDefined();
|
expect(el.lastBegin).toBeDefined();
|
||||||
expect(el.lastBegin!.positionEvent).toBeInstanceOf(PointerEvent);
|
expect(el.lastBegin!.positionEvent).toBeInstanceOf(PointerEvent);
|
||||||
el.remove();
|
el.remove();
|
||||||
@ -203,7 +203,7 @@ describe('ActionController', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('calls beginPress on down after hysteresis', async () => {
|
it('calls beginPress on down after hysteresis', async () => {
|
||||||
await harness.tapStart();
|
await harness.startTap();
|
||||||
await new Promise((resolve) => {
|
await new Promise((resolve) => {
|
||||||
setTimeout(resolve, TOUCH_DELAY_MS);
|
setTimeout(resolve, TOUCH_DELAY_MS);
|
||||||
});
|
});
|
||||||
@ -222,7 +222,7 @@ describe('ActionController', () => {
|
|||||||
it('goes through the expected phases during a long press', async () => {
|
it('goes through the expected phases during a long press', async () => {
|
||||||
const ac = el.actionController as unknown as ActionControllerInternals;
|
const ac = el.actionController as unknown as ActionControllerInternals;
|
||||||
expect(ac.phase).toEqual('INACTIVE');
|
expect(ac.phase).toEqual('INACTIVE');
|
||||||
await harness.tapStart();
|
await harness.startTap();
|
||||||
expect(ac.phase).toEqual('TOUCH_DELAY');
|
expect(ac.phase).toEqual('TOUCH_DELAY');
|
||||||
await new Promise((resolve) => {
|
await new Promise((resolve) => {
|
||||||
setTimeout(resolve, TOUCH_DELAY_MS);
|
setTimeout(resolve, TOUCH_DELAY_MS);
|
||||||
@ -230,9 +230,9 @@ describe('ActionController', () => {
|
|||||||
expect(ac.phase).toEqual('HOLDING');
|
expect(ac.phase).toEqual('HOLDING');
|
||||||
expect(el.lastBegin).toBeDefined();
|
expect(el.lastBegin).toBeDefined();
|
||||||
expect(el.lastBegin!.positionEvent).toBeInstanceOf(PointerEvent);
|
expect(el.lastBegin!.positionEvent).toBeInstanceOf(PointerEvent);
|
||||||
await harness.tapEnd();
|
await harness.endTap();
|
||||||
expect(ac.phase).toEqual('WAITING_FOR_MOUSE_CLICK');
|
expect(ac.phase).toEqual('WAITING_FOR_MOUSE_CLICK');
|
||||||
await harness.tapEndClick();
|
await harness.endTapClick();
|
||||||
expect(ac.phase).toEqual('INACTIVE');
|
expect(ac.phase).toEqual('INACTIVE');
|
||||||
expect(el.lastEnd).toEqual({cancelled: false});
|
expect(el.lastEnd).toEqual({cancelled: false});
|
||||||
});
|
});
|
||||||
@ -240,21 +240,21 @@ describe('ActionController', () => {
|
|||||||
it('goes through the expected phases during a short press', async () => {
|
it('goes through the expected phases during a short press', async () => {
|
||||||
const ac = el.actionController as unknown as ActionControllerInternals;
|
const ac = el.actionController as unknown as ActionControllerInternals;
|
||||||
expect(ac.phase).toEqual('INACTIVE');
|
expect(ac.phase).toEqual('INACTIVE');
|
||||||
await harness.tapStart();
|
await harness.startTap();
|
||||||
expect(ac.phase).toEqual('TOUCH_DELAY');
|
expect(ac.phase).toEqual('TOUCH_DELAY');
|
||||||
expect(el.lastBegin).not.toBeDefined();
|
expect(el.lastBegin).not.toBeDefined();
|
||||||
await harness.tapEnd();
|
await harness.endTap();
|
||||||
expect(el.lastBegin).toBeDefined();
|
expect(el.lastBegin).toBeDefined();
|
||||||
expect(el.lastBegin!.positionEvent).toBeInstanceOf(PointerEvent);
|
expect(el.lastBegin!.positionEvent).toBeInstanceOf(PointerEvent);
|
||||||
expect(ac.phase).toEqual('WAITING_FOR_MOUSE_CLICK');
|
expect(ac.phase).toEqual('WAITING_FOR_MOUSE_CLICK');
|
||||||
await harness.tapEndClick();
|
await harness.endTapClick();
|
||||||
expect(ac.phase).toEqual('INACTIVE');
|
expect(ac.phase).toEqual('INACTIVE');
|
||||||
expect(el.lastEnd).toEqual({cancelled: false});
|
expect(el.lastEnd).toEqual({cancelled: false});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('cancels press if a held press is very long', async () => {
|
it('cancels press if a held press is very long', async () => {
|
||||||
await harness.tapStart();
|
await harness.startTap();
|
||||||
await harness.tapEnd();
|
await harness.endTap();
|
||||||
expect(el.lastBegin).toBeDefined();
|
expect(el.lastBegin).toBeDefined();
|
||||||
expect(el.lastBegin!.positionEvent).toBeInstanceOf(PointerEvent);
|
expect(el.lastBegin!.positionEvent).toBeInstanceOf(PointerEvent);
|
||||||
await new Promise((resolve) => {
|
await new Promise((resolve) => {
|
||||||
@ -272,19 +272,19 @@ describe('ActionController', () => {
|
|||||||
describe('contextmenu', () => {
|
describe('contextmenu', () => {
|
||||||
it('ignores the interaction if the context menu opens during a short press',
|
it('ignores the interaction if the context menu opens during a short press',
|
||||||
async () => {
|
async () => {
|
||||||
await harness.tapStart();
|
await harness.startTap();
|
||||||
await harness.tapStartContextMenu();
|
await harness.startTapContextMenu();
|
||||||
expect(el.lastBegin).not.toBeDefined();
|
expect(el.lastBegin).not.toBeDefined();
|
||||||
expect(el.lastEnd).not.toBeDefined();
|
expect(el.lastEnd).not.toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('cancels press if the context menu opens during a longer press',
|
it('cancels press if the context menu opens during a longer press',
|
||||||
async () => {
|
async () => {
|
||||||
await harness.tapStart();
|
await harness.startTap();
|
||||||
await new Promise((resolve) => {
|
await new Promise((resolve) => {
|
||||||
setTimeout(resolve, TOUCH_DELAY_MS);
|
setTimeout(resolve, TOUCH_DELAY_MS);
|
||||||
});
|
});
|
||||||
await harness.tapStartContextMenu();
|
await harness.startTapContextMenu();
|
||||||
expect(el.lastBegin).toBeDefined();
|
expect(el.lastBegin).toBeDefined();
|
||||||
expect(el.lastBegin!.positionEvent).toBeInstanceOf(PointerEvent);
|
expect(el.lastBegin!.positionEvent).toBeInstanceOf(PointerEvent);
|
||||||
expect(el.lastEnd).toEqual({cancelled: true});
|
expect(el.lastEnd).toEqual({cancelled: true});
|
||||||
@ -292,11 +292,11 @@ describe('ActionController', () => {
|
|||||||
|
|
||||||
it('ignores out of bounds downs after the contextmenu opens',
|
it('ignores out of bounds downs after the contextmenu opens',
|
||||||
async () => {
|
async () => {
|
||||||
await harness.tapStart();
|
await harness.startTap();
|
||||||
await harness.tapStartContextMenu();
|
await harness.startTapContextMenu();
|
||||||
// set a _way out of bounds_ position, which would indicate pressing
|
// set a _way out of bounds_ position, which would indicate pressing
|
||||||
// on a different element
|
// on a different element
|
||||||
await harness.tapStart({clientX: 9000, clientY: 9000});
|
await harness.startTap({clientX: 9000, clientY: 9000});
|
||||||
await new Promise((resolve) => {
|
await new Promise((resolve) => {
|
||||||
setTimeout(resolve, TOUCH_DELAY_MS);
|
setTimeout(resolve, TOUCH_DELAY_MS);
|
||||||
});
|
});
|
||||||
@ -307,21 +307,21 @@ describe('ActionController', () => {
|
|||||||
describe('cancel', () => {
|
describe('cancel', () => {
|
||||||
it('ignores the interaction if `pointercancel` happens during a short press',
|
it('ignores the interaction if `pointercancel` happens during a short press',
|
||||||
async () => {
|
async () => {
|
||||||
await harness.tapStart();
|
await harness.startTap();
|
||||||
await harness.tapCancel();
|
await harness.cancelTap();
|
||||||
expect(el.lastBegin).not.toBeDefined();
|
expect(el.lastBegin).not.toBeDefined();
|
||||||
expect(el.lastEnd).not.toBeDefined();
|
expect(el.lastEnd).not.toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('cancels press if a `pointercancel` event fires during a longer press',
|
it('cancels press if a `pointercancel` event fires during a longer press',
|
||||||
async () => {
|
async () => {
|
||||||
await harness.tapStart();
|
await harness.startTap();
|
||||||
await new Promise((resolve) => {
|
await new Promise((resolve) => {
|
||||||
setTimeout(resolve, TOUCH_DELAY_MS);
|
setTimeout(resolve, TOUCH_DELAY_MS);
|
||||||
});
|
});
|
||||||
expect(el.lastBegin).toBeDefined();
|
expect(el.lastBegin).toBeDefined();
|
||||||
expect(el.lastBegin!.positionEvent).toBeInstanceOf(PointerEvent);
|
expect(el.lastBegin!.positionEvent).toBeInstanceOf(PointerEvent);
|
||||||
await harness.tapCancel();
|
await harness.cancelTap();
|
||||||
expect(el.lastEnd).toEqual({cancelled: true});
|
expect(el.lastEnd).toEqual({cancelled: true});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -344,7 +344,7 @@ describe('ActionController', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('cancels press when disabled', async () => {
|
it('cancels press when disabled', async () => {
|
||||||
await harness.clickWithMouseStart();
|
await harness.startClickWithMouse();
|
||||||
expect(ac.pressed).toEqual(true);
|
expect(ac.pressed).toEqual(true);
|
||||||
expect(el.lastBegin).toBeDefined();
|
expect(el.lastBegin).toBeDefined();
|
||||||
el.disabled = true;
|
el.disabled = true;
|
||||||
|
@ -91,30 +91,30 @@ export class Harness<E extends HTMLElement = HTMLElement> {
|
|||||||
* @param init Additional event options.
|
* @param init Additional event options.
|
||||||
*/
|
*/
|
||||||
async clickWithMouse(init: PointerEventInit = {}) {
|
async clickWithMouse(init: PointerEventInit = {}) {
|
||||||
await this.clickWithMouseStart(init);
|
await this.startClickWithMouse(init);
|
||||||
await this.clickWithMouseEnd(init);
|
await this.endClickWithMouse(init);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Begins a click with a mouse. Use this along with `clickWithMouseEnd()` to
|
* Begins a click with a mouse. Use this along with `endClickWithMouse()` to
|
||||||
* customize the length of the click.
|
* customize the length of the click.
|
||||||
*
|
*
|
||||||
* @param init Additional event options.
|
* @param init Additional event options.
|
||||||
*/
|
*/
|
||||||
async clickWithMouseStart(init: PointerEventInit = {}) {
|
async startClickWithMouse(init: PointerEventInit = {}) {
|
||||||
const element = await this.getInteractiveElement();
|
const element = await this.getInteractiveElement();
|
||||||
await this.hoverEnter();
|
await this.startHover();
|
||||||
this.simulateMousePress(element, init);
|
this.simulateMousePress(element, init);
|
||||||
this.simulatePointerFocus(element);
|
this.simulatePointerFocus(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finishes a click with a mouse. Use this along with `clickWithMouseStart()`
|
* Finishes a click with a mouse. Use this along with `startClickWithMouse()`
|
||||||
* to customize the length of the click. This will generate a `click` event.
|
* to customize the length of the click. This will generate a `click` event.
|
||||||
*
|
*
|
||||||
* @param init Additional event options.
|
* @param init Additional event options.
|
||||||
*/
|
*/
|
||||||
async clickWithMouseEnd(init: PointerEventInit = {}) {
|
async endClickWithMouse(init: PointerEventInit = {}) {
|
||||||
const element = await this.getInteractiveElement();
|
const element = await this.getInteractiveElement();
|
||||||
this.simulateMouseRelease(element, init);
|
this.simulateMouseRelease(element, init);
|
||||||
if ((init?.button ?? 0) === 0) {
|
if ((init?.button ?? 0) === 0) {
|
||||||
@ -131,18 +131,18 @@ export class Harness<E extends HTMLElement = HTMLElement> {
|
|||||||
*/
|
*/
|
||||||
async clickWithKeyboard(init: KeyboardEventInit = {}) {
|
async clickWithKeyboard(init: KeyboardEventInit = {}) {
|
||||||
const element = await this.getInteractiveElement();
|
const element = await this.getInteractiveElement();
|
||||||
await this.clickWithKeyboardStart(init);
|
await this.startClickWithKeyboard(init);
|
||||||
await this.clickWithKeyboardEnd(init);
|
await this.endClickWithKeyboard(init);
|
||||||
this.simulateClick(element, init);
|
this.simulateClick(element, init);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Begins a click with the keyboard (defaults to spacebar). Use this along
|
* Begins a click with the keyboard (defaults to spacebar). Use this along
|
||||||
* with `clickWithKeyboardEnd()` to customize the length of the click.
|
* with `endClickWithKeyboard()` to customize the length of the click.
|
||||||
*
|
*
|
||||||
* @param init Additional event options.
|
* @param init Additional event options.
|
||||||
*/
|
*/
|
||||||
async clickWithKeyboardStart(init: KeyboardEventInit = {}) {
|
async startClickWithKeyboard(init: KeyboardEventInit = {}) {
|
||||||
const element = await this.getInteractiveElement();
|
const element = await this.getInteractiveElement();
|
||||||
await this.focusWithKeyboard(init);
|
await this.focusWithKeyboard(init);
|
||||||
this.simulateKeydown(element, init.key ?? ' ', init);
|
this.simulateKeydown(element, init.key ?? ' ', init);
|
||||||
@ -151,11 +151,11 @@ export class Harness<E extends HTMLElement = HTMLElement> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Finishes a click with the keyboard (defaults to spacebar). Use this along
|
* Finishes a click with the keyboard (defaults to spacebar). Use this along
|
||||||
* with `clickWithKeyboardStart()` to customize the length of the click.
|
* with `startClickWithKeyboard()` to customize the length of the click.
|
||||||
*
|
*
|
||||||
* @param init Additional event options.
|
* @param init Additional event options.
|
||||||
*/
|
*/
|
||||||
async clickWithKeyboardEnd(init: KeyboardEventInit = {}) {
|
async endClickWithKeyboard(init: KeyboardEventInit = {}) {
|
||||||
const element = await this.getInteractiveElement();
|
const element = await this.getInteractiveElement();
|
||||||
this.simulateKeyup(element, init.key ?? ' ', init);
|
this.simulateKeyup(element, init.key ?? ' ', init);
|
||||||
this.simulateClick(element, init);
|
this.simulateClick(element, init);
|
||||||
@ -168,7 +168,7 @@ export class Harness<E extends HTMLElement = HTMLElement> {
|
|||||||
async rightClickWithMouse() {
|
async rightClickWithMouse() {
|
||||||
const element = await this.getInteractiveElement();
|
const element = await this.getInteractiveElement();
|
||||||
const rightMouseButton = {button: 2, buttons: 2};
|
const rightMouseButton = {button: 2, buttons: 2};
|
||||||
await this.clickWithMouseStart(rightMouseButton);
|
await this.startClickWithMouse(rightMouseButton);
|
||||||
// Note: contextmenu right clicks do not generate the up events
|
// Note: contextmenu right clicks do not generate the up events
|
||||||
this.simulateContextmenu(element, rightMouseButton);
|
this.simulateContextmenu(element, rightMouseButton);
|
||||||
}
|
}
|
||||||
@ -186,35 +186,35 @@ export class Harness<E extends HTMLElement = HTMLElement> {
|
|||||||
this.simulateTouchRelease(element, init, touchInit);
|
this.simulateTouchRelease(element, init, touchInit);
|
||||||
if ((init?.isPrimary ?? true) === true) {
|
if ((init?.isPrimary ?? true) === true) {
|
||||||
// Dispatch a click for primary touches only (default).
|
// Dispatch a click for primary touches only (default).
|
||||||
await this.tapEndClick(init);
|
await this.endTapClick(init);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Begins a touch tap. Use this along with `tapEnd()` to customize the length
|
* Begins a touch tap. Use this along with `endTap()` to customize the length
|
||||||
* or number of taps.
|
* or number of taps.
|
||||||
*
|
*
|
||||||
* @param init Additional event options.
|
* @param init Additional event options.
|
||||||
* @param touchInit Additional touch event options.
|
* @param touchInit Additional touch event options.
|
||||||
*/
|
*/
|
||||||
async tapStart(init: PointerEventInit = {}, touchInit: TouchEventInit = {}) {
|
async startTap(init: PointerEventInit = {}, touchInit: TouchEventInit = {}) {
|
||||||
const element = await this.getInteractiveElement();
|
const element = await this.getInteractiveElement();
|
||||||
this.simulateTouchPress(element, init, touchInit);
|
this.simulateTouchPress(element, init, touchInit);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simulates a `contextmenu` event for touch. Use this along with `tapStart()`
|
* Simulates a `contextmenu` event for touch. Use this along with `startTap()`
|
||||||
* to generate a tap-and-hold context menu interaction.
|
* to generate a tap-and-hold context menu interaction.
|
||||||
*
|
*
|
||||||
* @param init Additional event options.
|
* @param init Additional event options.
|
||||||
*/
|
*/
|
||||||
async tapStartContextMenu(init: MouseEventInit = {}) {
|
async startTapContextMenu(init: MouseEventInit = {}) {
|
||||||
const element = await this.getInteractiveElement();
|
const element = await this.getInteractiveElement();
|
||||||
this.simulateContextmenu(element, init);
|
this.simulateContextmenu(element, init);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finished a touch tap. Use this along with `tapStart()` to customize the
|
* Finished a touch tap. Use this along with `startTap()` to customize the
|
||||||
* length or number of taps.
|
* length or number of taps.
|
||||||
*
|
*
|
||||||
* This will NOT generate a `click` event.
|
* This will NOT generate a `click` event.
|
||||||
@ -222,18 +222,18 @@ export class Harness<E extends HTMLElement = HTMLElement> {
|
|||||||
* @param init Additional event options.
|
* @param init Additional event options.
|
||||||
* @param touchInit Additional touch event options.
|
* @param touchInit Additional touch event options.
|
||||||
*/
|
*/
|
||||||
async tapEnd(init: PointerEventInit = {}, touchInit: TouchEventInit = {}) {
|
async endTap(init: PointerEventInit = {}, touchInit: TouchEventInit = {}) {
|
||||||
const element = await this.getInteractiveElement();
|
const element = await this.getInteractiveElement();
|
||||||
this.simulateTouchRelease(element, init, touchInit);
|
this.simulateTouchRelease(element, init, touchInit);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simulates a `click` event for touch. Use this along with `tapEnd()` to
|
* Simulates a `click` event for touch. Use this along with `endTap()` to
|
||||||
* control the timing of tap and click events.
|
* control the timing of tap and click events.
|
||||||
*
|
*
|
||||||
* @param init Additional event options.
|
* @param init Additional event options.
|
||||||
*/
|
*/
|
||||||
async tapEndClick(init: PointerEventInit = {}) {
|
async endTapClick(init: PointerEventInit = {}) {
|
||||||
const element = await this.getInteractiveElement();
|
const element = await this.getInteractiveElement();
|
||||||
this.simulateClick(element, {
|
this.simulateClick(element, {
|
||||||
pointerType: 'touch',
|
pointerType: 'touch',
|
||||||
@ -247,7 +247,7 @@ export class Harness<E extends HTMLElement = HTMLElement> {
|
|||||||
* @param init Additional event options.
|
* @param init Additional event options.
|
||||||
* @param touchInit Additional touch event options.
|
* @param touchInit Additional touch event options.
|
||||||
*/
|
*/
|
||||||
async tapCancel(init: PointerEventInit = {}, touchInit: TouchEventInit = {}) {
|
async cancelTap(init: PointerEventInit = {}, touchInit: TouchEventInit = {}) {
|
||||||
const element = await this.getInteractiveElement();
|
const element = await this.getInteractiveElement();
|
||||||
this.simulateTouchCancel(element, init, touchInit);
|
this.simulateTouchCancel(element, init, touchInit);
|
||||||
}
|
}
|
||||||
@ -255,17 +255,17 @@ export class Harness<E extends HTMLElement = HTMLElement> {
|
|||||||
/**
|
/**
|
||||||
* Hovers over the element with a simulated mouse.
|
* Hovers over the element with a simulated mouse.
|
||||||
*/
|
*/
|
||||||
async hoverEnter() {
|
async startHover() {
|
||||||
const element = await this.getInteractiveElement();
|
const element = await this.getInteractiveElement();
|
||||||
this.simulateHoverEnter(element);
|
this.simulateStartHover(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Moves the simulated mouse cursor off of the element.
|
* Moves the simulated mouse cursor off of the element.
|
||||||
*/
|
*/
|
||||||
async hoverLeave() {
|
async endHover() {
|
||||||
const element = await this.getInteractiveElement();
|
const element = await this.getInteractiveElement();
|
||||||
this.simulateHoverLeave(element);
|
this.simulateEndHover(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -283,7 +283,7 @@ export class Harness<E extends HTMLElement = HTMLElement> {
|
|||||||
*/
|
*/
|
||||||
async focusWithPointer() {
|
async focusWithPointer() {
|
||||||
const element = await this.getInteractiveElement();
|
const element = await this.getInteractiveElement();
|
||||||
await this.hoverEnter();
|
await this.startHover();
|
||||||
this.simulatePointerFocus(element);
|
this.simulatePointerFocus(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -292,7 +292,7 @@ export class Harness<E extends HTMLElement = HTMLElement> {
|
|||||||
*/
|
*/
|
||||||
async blur() {
|
async blur() {
|
||||||
const element = await this.getInteractiveElement();
|
const element = await this.getInteractiveElement();
|
||||||
await this.hoverLeave();
|
await this.endHover();
|
||||||
this.simulateBlur(element);
|
this.simulateBlur(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -418,7 +418,7 @@ export class Harness<E extends HTMLElement = HTMLElement> {
|
|||||||
* @param element The element to hover over.
|
* @param element The element to hover over.
|
||||||
* @param init Additional event options.
|
* @param init Additional event options.
|
||||||
*/
|
*/
|
||||||
protected simulateHoverEnter(
|
protected simulateStartHover(
|
||||||
element: HTMLElement, init: PointerEventInit = {}) {
|
element: HTMLElement, init: PointerEventInit = {}) {
|
||||||
this.addPseudoClass(element, ':hover');
|
this.addPseudoClass(element, ':hover');
|
||||||
const rect = element.getBoundingClientRect();
|
const rect = element.getBoundingClientRect();
|
||||||
@ -457,7 +457,7 @@ export class Harness<E extends HTMLElement = HTMLElement> {
|
|||||||
* @param element The element to stop hovering over.
|
* @param element The element to stop hovering over.
|
||||||
* @param init Additional event options.
|
* @param init Additional event options.
|
||||||
*/
|
*/
|
||||||
protected simulateHoverLeave(
|
protected simulateEndHover(
|
||||||
element: HTMLElement, init: PointerEventInit = {}) {
|
element: HTMLElement, init: PointerEventInit = {}) {
|
||||||
this.removePseudoClass(element, ':hover');
|
this.removePseudoClass(element, ':hover');
|
||||||
const rect = element.getBoundingClientRect();
|
const rect = element.getBoundingClientRect();
|
||||||
|
@ -258,10 +258,10 @@ export class TemplateBuilder<H extends Harness = never,
|
|||||||
await harness.focusWithKeyboard();
|
await harness.focusWithKeyboard();
|
||||||
break;
|
break;
|
||||||
case State.HOVER:
|
case State.HOVER:
|
||||||
await harness.hoverEnter();
|
await harness.startHover();
|
||||||
break;
|
break;
|
||||||
case State.PRESSED:
|
case State.PRESSED:
|
||||||
await harness.clickWithMouseStart();
|
await harness.startClickWithMouse();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -67,14 +67,14 @@ export class TextFieldHarness extends Harness<TextField> {
|
|||||||
await super.reset();
|
await super.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
override async hoverEnter() {
|
override async startHover() {
|
||||||
await super.hoverEnter();
|
await super.startHover();
|
||||||
await (await this.field).hoverEnter();
|
await (await this.field).startHover();
|
||||||
}
|
}
|
||||||
|
|
||||||
override async hoverLeave() {
|
override async endHover() {
|
||||||
await super.hoverLeave();
|
await super.endHover();
|
||||||
await (await this.field).hoverLeave();
|
await (await this.field).endHover();
|
||||||
}
|
}
|
||||||
|
|
||||||
override async focusWithKeyboard() {
|
override async focusWithKeyboard() {
|
||||||
|
@ -124,22 +124,22 @@ describe('TextFieldHarness', () => {
|
|||||||
// Setup.
|
// Setup.
|
||||||
const harness = setupTest();
|
const harness = setupTest();
|
||||||
const field = await harness.field;
|
const field = await harness.field;
|
||||||
spyOn(field, 'hoverEnter').and.callThrough();
|
spyOn(field, 'startHover').and.callThrough();
|
||||||
// Test case.
|
// Test case.
|
||||||
await harness.hoverEnter();
|
await harness.startHover();
|
||||||
// Assertion.
|
// Assertion.
|
||||||
expect(field.hoverEnter).toHaveBeenCalledTimes(1);
|
expect(field.startHover).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call hoverLeave() on the field harness', async () => {
|
it('should call hoverLeave() on the field harness', async () => {
|
||||||
// Setup.
|
// Setup.
|
||||||
const harness = setupTest();
|
const harness = setupTest();
|
||||||
const field = await harness.field;
|
const field = await harness.field;
|
||||||
spyOn(field, 'hoverLeave').and.callThrough();
|
spyOn(field, 'endHover').and.callThrough();
|
||||||
// Test case.
|
// Test case.
|
||||||
await harness.hoverLeave();
|
await harness.endHover();
|
||||||
// Assertion.
|
// Assertion.
|
||||||
expect(field.hoverLeave).toHaveBeenCalledTimes(1);
|
expect(field.endHover).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call focusWithKeyboard() on the field harness', async () => {
|
it('should call focusWithKeyboard() on the field harness', async () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user