Skip to content

Commit

Permalink
chore(dialog): adds screenshot tests
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 511353583
  • Loading branch information
material-web-copybara authored and copybara-github committed Feb 22, 2023
1 parent 0d862c3 commit 1f7e538
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ FAB | 🟢 | 🔴 | 🔴
Icon button | 🟢 | 🔴 | 🔴
Checkbox | 🟢 | 🟢 | 🔴
Chips | 🔴 | 🔴 | 🔴
Dialog | 🟢 | 🔴 | 🔴
Dialog | 🟢 | 🟢 | 🔴
Divider | 🟢 | 🟢 | 🟡
Elevation | 🟢 | 🔴 | 🔴
Focus ring | 🟢 | 🔴 | 🔴
Expand Down
19 changes: 11 additions & 8 deletions dialog/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,29 @@ export class DialogHarness extends Harness<Dialog> {
HTMLDialogElement;
}

async isOpening() {
await this.element.updateComplete;
return Boolean(this.element.open && this.element.hasAttribute('opening'));
isOpening() {
// Test access to state
// tslint:disable-next-line:no-dict-access-on-struct-type
return Boolean(this.element.open && this.element['opening']);
}

async isClosing() {
await this.element.updateComplete;
return Boolean(!this.element.open && this.element.hasAttribute('closing'));
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 (await this.isOpening()) {
if (this.isOpening()) {
this.element.addEventListener('opened', resolve, {once: true});
} else if (await this.isClosing()) {
} else if (this.isClosing()) {
this.element.addEventListener('closed', resolve, {once: true});
} else {
resolve();
Expand Down
10 changes: 7 additions & 3 deletions dialog/lib/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,13 @@ export class Dialog extends LitElement {
// Compute desired transition duration.
const duration = msFromTimeCSSValue(getComputedStyle(this).getPropertyValue(
this.open ? OPENING_TRANSITION_PROP : CLOSING_TRANSITION_PROP));
await new Promise(r => {
setTimeout(r, duration);
});
let promise = this.updateComplete;
if (duration > 0) {
promise = new Promise((r) => {
setTimeout(r, duration);
});
}
await promise;
this.opening = false;
this.closing = false;
if (!this.open && this.dialogElement.open) {
Expand Down
13 changes: 13 additions & 0 deletions dialog/test/window_size.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"capabilities": {
"goog:chromeOptions": {
"args": ["--window-position=0,0", "--window-size=599,800"]
},
"moz:firefoxOptions": {
"args": ["-width=599","-height=800"]
}
},
"extension": {
"xvfbResolution": "599x800x24"
}
}

0 comments on commit 1f7e538

Please sign in to comment.