-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests for AppDatePickerInputSurface
- Loading branch information
Showing
3 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const promiseTimeout = 3e3 as const; |
59 changes: 59 additions & 0 deletions
59
src/__tests__/date-picker-input-surface/app-date-picker-input-surface.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import '../../date-picker-input-surface/app-date-picker-input-surface'; | ||
|
||
import { expect, fixture, html } from '@open-wc/testing'; | ||
|
||
import { appDatePickerInputSurfaceName } from '../../date-picker-input-surface/constants'; | ||
import type { DatePickerInputSurface } from '../../date-picker-input-surface/date-picker-input-surface'; | ||
import { promiseTimeout } from '../constants'; | ||
|
||
describe(appDatePickerInputSurfaceName, () => { | ||
const elementSelectors = { | ||
mdcMenuSurface: '.mdc-menu-surface', | ||
} as const; | ||
|
||
it('renders', async () => { | ||
|
||
|
||
const el = await new Promise<DatePickerInputSurface>(async (resolve) => { | ||
const element = await fixture<DatePickerInputSurface>( | ||
html`<app-date-picker-input-surface .open=${true} @opened=${() => resolve(element)}> | ||
<h1 class=test>Test</h1> | ||
</app-date-picker-input-surface>` | ||
); | ||
}); | ||
|
||
const mdcMenuSurface = el.query(elementSelectors.mdcMenuSurface); | ||
|
||
expect(mdcMenuSurface).exist; | ||
}); | ||
|
||
it('closes when clicking outside of surface', async () => { | ||
const el = await new Promise<DatePickerInputSurface>(async (resolve) => { | ||
const element = await fixture<DatePickerInputSurface>( | ||
html`<app-date-picker-input-surface .open=${true} @opened=${() => resolve(element)}> | ||
<h1 class=test>Test</h1> | ||
</app-date-picker-input-surface>` | ||
); | ||
}); | ||
|
||
const mdcMenuSurface = el.query(elementSelectors.mdcMenuSurface); | ||
|
||
expect(mdcMenuSurface).exist; | ||
|
||
const closedTask = new Promise<boolean>((resolve) => { | ||
el.addEventListener('closed', () => { | ||
resolve(true); | ||
|
||
globalThis.setTimeout(() => resolve(false), promiseTimeout); | ||
}, { once: true }); | ||
}); | ||
|
||
document.body.click(); | ||
|
||
const closed = await closedTask; | ||
|
||
expect(closed).true; | ||
expect(el.open).false; | ||
expect(mdcMenuSurface).exist; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters