forked from material-components/material-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathharness.ts
67 lines (58 loc) · 1.8 KB
/
harness.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* @license
* Copyright 2023 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import {Harness} from '../testing/harness.js';
import {Dialog} from './lib/dialog.js';
/**
* Test harness for dialog.
*/
export class DialogHarness extends Harness<Dialog> {
override async getInteractiveElement() {
await this.element.updateComplete;
return this.element.renderRoot.querySelector('.dialog') as
HTMLDialogElement;
}
isOpening() {
// Test access to state
// tslint:disable-next-line:no-dict-access-on-struct-type
return Boolean(this.element.open && this.element['opening']);
}
isClosing() {
// Test access to state
// tslint:disable-next-line:no-dict-access-on-struct-type
return Boolean(!this.element.open && this.element['closing']);
}
async transitionComplete() {
await this.element.updateComplete;
let resolve = () => {};
const doneTransitioning = new Promise<void>(resolver => {
resolve = () => {
resolver();
};
});
if (this.isOpening()) {
this.element.addEventListener('opened', resolve, {once: true});
} else if (this.isClosing()) {
this.element.addEventListener('closed', resolve, {once: true});
} else {
resolve();
}
await doneTransitioning;
}
async isDialogVisible() {
await this.transitionComplete();
const dialogElement = await this.getInteractiveElement();
const {display} = getComputedStyle(dialogElement);
return display !== 'none';
}
async isScrimVisible() {
await this.transitionComplete();
const dialogElement = await this.getInteractiveElement();
const {backgroundColor, display} =
getComputedStyle(dialogElement, '::before');
const hiddenBg = `rgba(0, 0, 0, 0)`;
return backgroundColor !== hiddenBg && display !== 'none';
}
}