chore(testing): rename harness methods

PiperOrigin-RevId: 449506213
This commit is contained in:
Liz Mitchell 2022-05-18 09:50:43 -07:00 committed by Copybara-Service
parent 16e0cf7098
commit 5d469720c7
6 changed files with 75 additions and 75 deletions

View File

@ -17,8 +17,8 @@ export class ButtonHarness extends Harness<Button> {
return this.element.renderRoot.querySelector('.md3-button') as HTMLElement;
}
override async clickWithMouseStart(init: PointerEventInit = {}) {
await super.clickWithMouseStart(init);
override async startClickWithMouse(init: PointerEventInit = {}) {
await super.startClickWithMouse(init);
// The ripple adapter unconditionally returns true for
// `containsEventTarget`, which effectively blocks simultaneous ripple
// activations. We need simulatenous activations for testing though, so

View File

@ -105,7 +105,7 @@ describe('ActionController', () => {
});
it('calls beginPress on down', async () => {
await harness.clickWithMouseStart();
await harness.startClickWithMouse();
expect(el.lastBegin).toBeDefined();
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 () => {
await harness.clickWithMouseStart();
await harness.startClickWithMouse();
const ac = el.actionController as unknown as ActionControllerInternals;
expect(ac.phase).toEqual('WAITING_FOR_MOUSE_CLICK');
await harness.clickWithMouseEnd();
await harness.endClickWithMouse();
expect(ac.phase).toEqual('INACTIVE');
});
it('cancels press if cursor leaves element during press', async () => {
await harness.clickWithMouseStart();
await harness.hoverLeave();
await harness.startClickWithMouse();
await harness.endHover();
expect(el.lastEnd).toEqual({cancelled: true});
});
@ -156,7 +156,7 @@ describe('ActionController', () => {
});
it('cancels when removed from dom', async () => {
await harness.clickWithMouseStart();
await harness.startClickWithMouse();
expect(el.lastBegin).toBeDefined();
expect(el.lastBegin!.positionEvent).toBeInstanceOf(PointerEvent);
el.remove();
@ -203,7 +203,7 @@ describe('ActionController', () => {
});
it('calls beginPress on down after hysteresis', async () => {
await harness.tapStart();
await harness.startTap();
await new Promise((resolve) => {
setTimeout(resolve, TOUCH_DELAY_MS);
});
@ -222,7 +222,7 @@ describe('ActionController', () => {
it('goes through the expected phases during a long press', async () => {
const ac = el.actionController as unknown as ActionControllerInternals;
expect(ac.phase).toEqual('INACTIVE');
await harness.tapStart();
await harness.startTap();
expect(ac.phase).toEqual('TOUCH_DELAY');
await new Promise((resolve) => {
setTimeout(resolve, TOUCH_DELAY_MS);
@ -230,9 +230,9 @@ describe('ActionController', () => {
expect(ac.phase).toEqual('HOLDING');
expect(el.lastBegin).toBeDefined();
expect(el.lastBegin!.positionEvent).toBeInstanceOf(PointerEvent);
await harness.tapEnd();
await harness.endTap();
expect(ac.phase).toEqual('WAITING_FOR_MOUSE_CLICK');
await harness.tapEndClick();
await harness.endTapClick();
expect(ac.phase).toEqual('INACTIVE');
expect(el.lastEnd).toEqual({cancelled: false});
});
@ -240,21 +240,21 @@ describe('ActionController', () => {
it('goes through the expected phases during a short press', async () => {
const ac = el.actionController as unknown as ActionControllerInternals;
expect(ac.phase).toEqual('INACTIVE');
await harness.tapStart();
await harness.startTap();
expect(ac.phase).toEqual('TOUCH_DELAY');
expect(el.lastBegin).not.toBeDefined();
await harness.tapEnd();
await harness.endTap();
expect(el.lastBegin).toBeDefined();
expect(el.lastBegin!.positionEvent).toBeInstanceOf(PointerEvent);
expect(ac.phase).toEqual('WAITING_FOR_MOUSE_CLICK');
await harness.tapEndClick();
await harness.endTapClick();
expect(ac.phase).toEqual('INACTIVE');
expect(el.lastEnd).toEqual({cancelled: false});
});
it('cancels press if a held press is very long', async () => {
await harness.tapStart();
await harness.tapEnd();
await harness.startTap();
await harness.endTap();
expect(el.lastBegin).toBeDefined();
expect(el.lastBegin!.positionEvent).toBeInstanceOf(PointerEvent);
await new Promise((resolve) => {
@ -272,19 +272,19 @@ describe('ActionController', () => {
describe('contextmenu', () => {
it('ignores the interaction if the context menu opens during a short press',
async () => {
await harness.tapStart();
await harness.tapStartContextMenu();
await harness.startTap();
await harness.startTapContextMenu();
expect(el.lastBegin).not.toBeDefined();
expect(el.lastEnd).not.toBeDefined();
});
it('cancels press if the context menu opens during a longer press',
async () => {
await harness.tapStart();
await harness.startTap();
await new Promise((resolve) => {
setTimeout(resolve, TOUCH_DELAY_MS);
});
await harness.tapStartContextMenu();
await harness.startTapContextMenu();
expect(el.lastBegin).toBeDefined();
expect(el.lastBegin!.positionEvent).toBeInstanceOf(PointerEvent);
expect(el.lastEnd).toEqual({cancelled: true});
@ -292,11 +292,11 @@ describe('ActionController', () => {
it('ignores out of bounds downs after the contextmenu opens',
async () => {
await harness.tapStart();
await harness.tapStartContextMenu();
await harness.startTap();
await harness.startTapContextMenu();
// set a _way out of bounds_ position, which would indicate pressing
// on a different element
await harness.tapStart({clientX: 9000, clientY: 9000});
await harness.startTap({clientX: 9000, clientY: 9000});
await new Promise((resolve) => {
setTimeout(resolve, TOUCH_DELAY_MS);
});
@ -307,21 +307,21 @@ describe('ActionController', () => {
describe('cancel', () => {
it('ignores the interaction if `pointercancel` happens during a short press',
async () => {
await harness.tapStart();
await harness.tapCancel();
await harness.startTap();
await harness.cancelTap();
expect(el.lastBegin).not.toBeDefined();
expect(el.lastEnd).not.toBeDefined();
});
it('cancels press if a `pointercancel` event fires during a longer press',
async () => {
await harness.tapStart();
await harness.startTap();
await new Promise((resolve) => {
setTimeout(resolve, TOUCH_DELAY_MS);
});
expect(el.lastBegin).toBeDefined();
expect(el.lastBegin!.positionEvent).toBeInstanceOf(PointerEvent);
await harness.tapCancel();
await harness.cancelTap();
expect(el.lastEnd).toEqual({cancelled: true});
});
});
@ -344,7 +344,7 @@ describe('ActionController', () => {
});
it('cancels press when disabled', async () => {
await harness.clickWithMouseStart();
await harness.startClickWithMouse();
expect(ac.pressed).toEqual(true);
expect(el.lastBegin).toBeDefined();
el.disabled = true;

View File

@ -91,30 +91,30 @@ export class Harness<E extends HTMLElement = HTMLElement> {
* @param init Additional event options.
*/
async clickWithMouse(init: PointerEventInit = {}) {
await this.clickWithMouseStart(init);
await this.clickWithMouseEnd(init);
await this.startClickWithMouse(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.
*
* @param init Additional event options.
*/
async clickWithMouseStart(init: PointerEventInit = {}) {
async startClickWithMouse(init: PointerEventInit = {}) {
const element = await this.getInteractiveElement();
await this.hoverEnter();
await this.startHover();
this.simulateMousePress(element, init);
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.
*
* @param init Additional event options.
*/
async clickWithMouseEnd(init: PointerEventInit = {}) {
async endClickWithMouse(init: PointerEventInit = {}) {
const element = await this.getInteractiveElement();
this.simulateMouseRelease(element, init);
if ((init?.button ?? 0) === 0) {
@ -131,18 +131,18 @@ export class Harness<E extends HTMLElement = HTMLElement> {
*/
async clickWithKeyboard(init: KeyboardEventInit = {}) {
const element = await this.getInteractiveElement();
await this.clickWithKeyboardStart(init);
await this.clickWithKeyboardEnd(init);
await this.startClickWithKeyboard(init);
await this.endClickWithKeyboard(init);
this.simulateClick(element, init);
}
/**
* 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.
*/
async clickWithKeyboardStart(init: KeyboardEventInit = {}) {
async startClickWithKeyboard(init: KeyboardEventInit = {}) {
const element = await this.getInteractiveElement();
await this.focusWithKeyboard(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
* with `clickWithKeyboardStart()` to customize the length of the click.
* with `startClickWithKeyboard()` to customize the length of the click.
*
* @param init Additional event options.
*/
async clickWithKeyboardEnd(init: KeyboardEventInit = {}) {
async endClickWithKeyboard(init: KeyboardEventInit = {}) {
const element = await this.getInteractiveElement();
this.simulateKeyup(element, init.key ?? ' ', init);
this.simulateClick(element, init);
@ -168,7 +168,7 @@ export class Harness<E extends HTMLElement = HTMLElement> {
async rightClickWithMouse() {
const element = await this.getInteractiveElement();
const rightMouseButton = {button: 2, buttons: 2};
await this.clickWithMouseStart(rightMouseButton);
await this.startClickWithMouse(rightMouseButton);
// Note: contextmenu right clicks do not generate the up events
this.simulateContextmenu(element, rightMouseButton);
}
@ -186,35 +186,35 @@ export class Harness<E extends HTMLElement = HTMLElement> {
this.simulateTouchRelease(element, init, touchInit);
if ((init?.isPrimary ?? true) === true) {
// 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.
*
* @param init Additional 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();
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.
*
* @param init Additional event options.
*/
async tapStartContextMenu(init: MouseEventInit = {}) {
async startTapContextMenu(init: MouseEventInit = {}) {
const element = await this.getInteractiveElement();
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.
*
* This will NOT generate a `click` event.
@ -222,18 +222,18 @@ export class Harness<E extends HTMLElement = HTMLElement> {
* @param init Additional 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();
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.
*
* @param init Additional event options.
*/
async tapEndClick(init: PointerEventInit = {}) {
async endTapClick(init: PointerEventInit = {}) {
const element = await this.getInteractiveElement();
this.simulateClick(element, {
pointerType: 'touch',
@ -247,7 +247,7 @@ export class Harness<E extends HTMLElement = HTMLElement> {
* @param init Additional 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();
this.simulateTouchCancel(element, init, touchInit);
}
@ -255,17 +255,17 @@ export class Harness<E extends HTMLElement = HTMLElement> {
/**
* Hovers over the element with a simulated mouse.
*/
async hoverEnter() {
async startHover() {
const element = await this.getInteractiveElement();
this.simulateHoverEnter(element);
this.simulateStartHover(element);
}
/**
* Moves the simulated mouse cursor off of the element.
*/
async hoverLeave() {
async endHover() {
const element = await this.getInteractiveElement();
this.simulateHoverLeave(element);
this.simulateEndHover(element);
}
/**
@ -283,7 +283,7 @@ export class Harness<E extends HTMLElement = HTMLElement> {
*/
async focusWithPointer() {
const element = await this.getInteractiveElement();
await this.hoverEnter();
await this.startHover();
this.simulatePointerFocus(element);
}
@ -292,7 +292,7 @@ export class Harness<E extends HTMLElement = HTMLElement> {
*/
async blur() {
const element = await this.getInteractiveElement();
await this.hoverLeave();
await this.endHover();
this.simulateBlur(element);
}
@ -418,7 +418,7 @@ export class Harness<E extends HTMLElement = HTMLElement> {
* @param element The element to hover over.
* @param init Additional event options.
*/
protected simulateHoverEnter(
protected simulateStartHover(
element: HTMLElement, init: PointerEventInit = {}) {
this.addPseudoClass(element, ':hover');
const rect = element.getBoundingClientRect();
@ -457,7 +457,7 @@ export class Harness<E extends HTMLElement = HTMLElement> {
* @param element The element to stop hovering over.
* @param init Additional event options.
*/
protected simulateHoverLeave(
protected simulateEndHover(
element: HTMLElement, init: PointerEventInit = {}) {
this.removePseudoClass(element, ':hover');
const rect = element.getBoundingClientRect();

View File

@ -258,10 +258,10 @@ export class TemplateBuilder<H extends Harness = never,
await harness.focusWithKeyboard();
break;
case State.HOVER:
await harness.hoverEnter();
await harness.startHover();
break;
case State.PRESSED:
await harness.clickWithMouseStart();
await harness.startClickWithMouse();
break;
default:
break;

View File

@ -67,14 +67,14 @@ export class TextFieldHarness extends Harness<TextField> {
await super.reset();
}
override async hoverEnter() {
await super.hoverEnter();
await (await this.field).hoverEnter();
override async startHover() {
await super.startHover();
await (await this.field).startHover();
}
override async hoverLeave() {
await super.hoverLeave();
await (await this.field).hoverLeave();
override async endHover() {
await super.endHover();
await (await this.field).endHover();
}
override async focusWithKeyboard() {

View File

@ -124,22 +124,22 @@ describe('TextFieldHarness', () => {
// Setup.
const harness = setupTest();
const field = await harness.field;
spyOn(field, 'hoverEnter').and.callThrough();
spyOn(field, 'startHover').and.callThrough();
// Test case.
await harness.hoverEnter();
await harness.startHover();
// Assertion.
expect(field.hoverEnter).toHaveBeenCalledTimes(1);
expect(field.startHover).toHaveBeenCalledTimes(1);
});
it('should call hoverLeave() on the field harness', async () => {
// Setup.
const harness = setupTest();
const field = await harness.field;
spyOn(field, 'hoverLeave').and.callThrough();
spyOn(field, 'endHover').and.callThrough();
// Test case.
await harness.hoverLeave();
await harness.endHover();
// Assertion.
expect(field.hoverLeave).toHaveBeenCalledTimes(1);
expect(field.endHover).toHaveBeenCalledTimes(1);
});
it('should call focusWithKeyboard() on the field harness', async () => {