Skip to content

Commit 1caae0b

Browse files
committed
ds
1 parent 4837e85 commit 1caae0b

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/cdk/testing/testbed/unit-test-element.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,15 @@ export class UnitTestElement implements TestElement {
100100
async click(
101101
...args: [ModifierKeys?] | ['center', ModifierKeys?] | [number, number, ModifierKeys?]
102102
): Promise<void> {
103-
await this._dispatchMouseEventSequence('click', args, 0);
103+
const isDisabled = (this.element as Partial<{disabled?: boolean}>).disabled === true;
104+
105+
// If the element is `disabled` and has a `disabled` property, we emit the mouse event
106+
// sequence but not dispatch the `click` event. This is necessary to keep the behavior
107+
// consistent with an actual user interaction. The click event is not necessarily
108+
// automatically prevented by the browser. There is mismatch between Firefox and Chromium:
109+
// https://bugzilla.mozilla.org/show_bug.cgi?id=329509.
110+
// https://bugs.chromium.org/p/chromium/issues/detail?id=1115661.
111+
await this._dispatchMouseEventSequence(isDisabled ? null : 'click', args, 0);
104112
await this._stabilize();
105113
}
106114

@@ -284,9 +292,12 @@ export class UnitTestElement implements TestElement {
284292
}
285293
}
286294

287-
/** Dispatches all the events that are part of a mouse event sequence. */
295+
/**
296+
* Dispatches all the events that are part of a mouse event sequence
297+
* and then emits a given primary event at the end, if speciifed.
298+
*/
288299
private async _dispatchMouseEventSequence(
289-
name: string,
300+
primaryEventName: string | null,
290301
args: [ModifierKeys?] | ['center', ModifierKeys?] | [number, number, ModifierKeys?],
291302
button?: number,
292303
) {
@@ -313,11 +324,16 @@ export class UnitTestElement implements TestElement {
313324
dispatchMouseEvent(this.element, 'mousedown', clientX, clientY, button, modifiers);
314325
this._dispatchPointerEventIfSupported('pointerup', clientX, clientY, button);
315326
dispatchMouseEvent(this.element, 'mouseup', clientX, clientY, button, modifiers);
316-
dispatchMouseEvent(this.element, name, clientX, clientY, button, modifiers);
327+
328+
// If a primary event name is specified, emit it after the mouse event sequence.
329+
if (primaryEventName !== null) {
330+
dispatchMouseEvent(this.element, primaryEventName, clientX, clientY, button, modifiers);
331+
}
317332

318333
// This call to _stabilize should not be needed since the callers will already do that them-
319334
// selves. Nevertheless it breaks some tests in g3 without it. It needs to be investigated
320335
// why removing breaks those tests.
336+
// See: https://github.com/angular/components/pull/20758/files#r520886256.
321337
await this._stabilize();
322338
}
323339
}

0 commit comments

Comments
 (0)