1 | /**
|
---|
2 | * @license
|
---|
3 | * Copyright Google LLC All Rights Reserved.
|
---|
4 | *
|
---|
5 | * Use of this source code is governed by an MIT-style license that can be
|
---|
6 | * found in the LICENSE file at https://angular.io/license
|
---|
7 | */
|
---|
8 | import { __awaiter } from "tslib";
|
---|
9 | import { ComponentHarness, parallel } from '@angular/cdk/testing';
|
---|
10 | import { MatCalendarHarness } from './calendar-harness';
|
---|
11 | /** Base class for harnesses that can trigger a calendar. */
|
---|
12 | export class DatepickerTriggerHarnessBase extends ComponentHarness {
|
---|
13 | /** Opens the calendar if the trigger is enabled and it has a calendar. */
|
---|
14 | openCalendar() {
|
---|
15 | return __awaiter(this, void 0, void 0, function* () {
|
---|
16 | const [isDisabled, hasCalendar] = yield parallel(() => [this.isDisabled(), this.hasCalendar()]);
|
---|
17 | if (!isDisabled && hasCalendar) {
|
---|
18 | return this._openCalendar();
|
---|
19 | }
|
---|
20 | });
|
---|
21 | }
|
---|
22 | /** Closes the calendar if it is open. */
|
---|
23 | closeCalendar() {
|
---|
24 | return __awaiter(this, void 0, void 0, function* () {
|
---|
25 | if (yield this.isCalendarOpen()) {
|
---|
26 | yield closeCalendar(getCalendarId(this.host()), this.documentRootLocatorFactory());
|
---|
27 | // This is necessary so that we wait for the closing animation to finish in touch UI mode.
|
---|
28 | yield this.forceStabilize();
|
---|
29 | }
|
---|
30 | });
|
---|
31 | }
|
---|
32 | /** Gets whether there is a calendar associated with the trigger. */
|
---|
33 | hasCalendar() {
|
---|
34 | return __awaiter(this, void 0, void 0, function* () {
|
---|
35 | return (yield getCalendarId(this.host())) != null;
|
---|
36 | });
|
---|
37 | }
|
---|
38 | /**
|
---|
39 | * Gets the `MatCalendarHarness` that is associated with the trigger.
|
---|
40 | * @param filter Optionally filters which calendar is included.
|
---|
41 | */
|
---|
42 | getCalendar(filter = {}) {
|
---|
43 | return __awaiter(this, void 0, void 0, function* () {
|
---|
44 | return getCalendar(filter, this.host(), this.documentRootLocatorFactory());
|
---|
45 | });
|
---|
46 | }
|
---|
47 | }
|
---|
48 | /** Gets the ID of the calendar that a particular test element can trigger. */
|
---|
49 | export function getCalendarId(host) {
|
---|
50 | return __awaiter(this, void 0, void 0, function* () {
|
---|
51 | return (yield host).getAttribute('data-mat-calendar');
|
---|
52 | });
|
---|
53 | }
|
---|
54 | /** Closes the calendar with a specific ID. */
|
---|
55 | export function closeCalendar(calendarId, documentLocator) {
|
---|
56 | return __awaiter(this, void 0, void 0, function* () {
|
---|
57 | // We close the calendar by clicking on the backdrop, even though all datepicker variants
|
---|
58 | // have the ability to close by pressing escape. The backdrop is preferrable, because the
|
---|
59 | // escape key has multiple functions inside a range picker (either cancel the current range
|
---|
60 | // or close the calendar). Since we don't have access to set the ID on the backdrop in all
|
---|
61 | // cases, we set a unique class instead which is the same as the calendar's ID and suffixed
|
---|
62 | // with `-backdrop`.
|
---|
63 | const backdropSelector = `.${yield calendarId}-backdrop`;
|
---|
64 | return (yield documentLocator.locatorFor(backdropSelector)()).click();
|
---|
65 | });
|
---|
66 | }
|
---|
67 | /** Gets the test harness for a calendar associated with a particular host. */
|
---|
68 | export function getCalendar(filter, host, documentLocator) {
|
---|
69 | return __awaiter(this, void 0, void 0, function* () {
|
---|
70 | const calendarId = yield getCalendarId(host);
|
---|
71 | if (!calendarId) {
|
---|
72 | throw Error(`Element is not associated with a calendar`);
|
---|
73 | }
|
---|
74 | return documentLocator.locatorFor(MatCalendarHarness.with(Object.assign(Object.assign({}, filter), { selector: `#${calendarId}` })))();
|
---|
75 | });
|
---|
76 | }
|
---|
77 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGF0ZXBpY2tlci10cmlnZ2VyLWhhcm5lc3MtYmFzZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uL3NyYy9tYXRlcmlhbC9kYXRlcGlja2VyL3Rlc3RpbmcvZGF0ZXBpY2tlci10cmlnZ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