/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ import { __awaiter } from "tslib"; import { HarnessPredicate, ComponentHarness } from '@angular/cdk/testing'; import { MatCalendarCellHarness } from './calendar-cell-harness'; /** Harness for interacting with a standard Material calendar in tests. */ export class MatCalendarHarness extends ComponentHarness { constructor() { super(...arguments); /** Queries for the calendar's period toggle button. */ this._periodButton = this.locatorFor('.mat-calendar-period-button'); } /** * Gets a `HarnessPredicate` that can be used to search for a `MatCalendarHarness` * that meets certain criteria. * @param options Options for filtering which calendar instances are considered a match. * @return a `HarnessPredicate` configured with the given options. */ static with(options = {}) { return new HarnessPredicate(MatCalendarHarness, options); } /** * Gets a list of cells inside the calendar. * @param filter Optionally filters which cells are included. */ getCells(filter = {}) { return __awaiter(this, void 0, void 0, function* () { return this.locatorForAll(MatCalendarCellHarness.with(filter))(); }); } /** Gets the current view that is being shown inside the calendar. */ getCurrentView() { return __awaiter(this, void 0, void 0, function* () { if (yield this.locatorForOptional('mat-multi-year-view')()) { return 2 /* MULTI_YEAR */; } if (yield this.locatorForOptional('mat-year-view')()) { return 1 /* YEAR */; } return 0 /* MONTH */; }); } /** Gets the label of the current calendar view. */ getCurrentViewLabel() { return __awaiter(this, void 0, void 0, function* () { return (yield this._periodButton()).text(); }); } /** Changes the calendar view by clicking on the view toggle button. */ changeView() { return __awaiter(this, void 0, void 0, function* () { return (yield this._periodButton()).click(); }); } /** Goes to the next page of the current view (e.g. next month when inside the month view). */ next() { return __awaiter(this, void 0, void 0, function* () { return (yield this.locatorFor('.mat-calendar-next-button')()).click(); }); } /** * Goes to the previous page of the current view * (e.g. previous month when inside the month view). */ previous() { return __awaiter(this, void 0, void 0, function* () { return (yield this.locatorFor('.mat-calendar-previous-button')()).click(); }); } /** * Selects a cell in the current calendar view. * @param filter An optional filter to apply to the cells. The first cell matching the filter * will be selected. */ selectCell(filter = {}) { return __awaiter(this, void 0, void 0, function* () { const cells = yield this.getCells(filter); if (!cells.length) { throw Error(`Cannot find calendar cell matching filter ${JSON.stringify(filter)}`); } yield cells[0].select(); }); } } MatCalendarHarness.hostSelector = '.mat-calendar'; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2FsZW5kYXItaGFybmVzcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uL3NyYy9tYXRlcmlhbC9kYXRlcGlja2VyL3Rlc3RpbmcvY2FsZW5kYXItaGFybmVzcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7O0dBTUc7O0FBRUgsT0FBTyxFQUFDLGdCQUFnQixFQUFFLGdCQUFnQixFQUFDLE1BQU0sc0JBQXNCLENBQUM7QUFFeEUsT0FBTyxFQUFDLHNCQUFzQixFQUFDLE1BQU0seUJBQXlCLENBQUM7QUFLL0QsMEVBQTBFO0FBQzFFLE1BQU0sT0FBTyxrQkFBbUIsU0FBUSxnQkFBZ0I7SUFBeEQ7O1FBR0UsdURBQXVEO1FBQy9DLGtCQUFhLEdBQUcsSUFBSSxDQUFDLFVBQVUsQ0FBQyw2QkFBNkIsQ0FBQyxDQUFDO0lBb0V6RSxDQUFDO0lBbEVDOzs7OztPQUtHO0lBQ0gsTUFBTSxDQUFDLElBQUksQ0FBQyxVQUFrQyxFQUFFO1FBQzlDLE9BQU8sSUFBSSxnQkFBZ0IsQ0FBQyxrQkFBa0IsRUFBRSxPQUFPLENBQUMsQ0FBQztJQUMzRCxDQUFDO0lBRUQ7OztPQUdHO0lBQ0csUUFBUSxDQUFDLFNBQXFDLEVBQUU7O1lBQ3BELE9BQU8sSUFBSSxDQUFDLGFBQWEsQ0FBQyxzQkFBc0IsQ0FBQyxJQUFJLENBQUMsTUFBTSxDQUFDLENBQUMsRUFBRSxDQUFDO1FBQ25FLENBQUM7S0FBQTtJQUVELHFFQUFxRTtJQUMvRCxjQUFj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