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 { HarnessPredicate, ContentContainerComponentHarness } from '@angular/cdk/testing';
|
---|
10 | /** Harness for interacting with a standard mat-card in tests. */
|
---|
11 | export class MatCardHarness extends ContentContainerComponentHarness {
|
---|
12 | constructor() {
|
---|
13 | super(...arguments);
|
---|
14 | this._title = this.locatorForOptional('.mat-card-title');
|
---|
15 | this._subtitle = this.locatorForOptional('.mat-card-subtitle');
|
---|
16 | }
|
---|
17 | /**
|
---|
18 | * Gets a `HarnessPredicate` that can be used to search for a `MatCardHarness` that meets
|
---|
19 | * certain criteria.
|
---|
20 | * @param options Options for filtering which card instances are considered a match.
|
---|
21 | * @return a `HarnessPredicate` configured with the given options.
|
---|
22 | */
|
---|
23 | static with(options = {}) {
|
---|
24 | return new HarnessPredicate(MatCardHarness, options)
|
---|
25 | .addOption('text', options.text, (harness, text) => HarnessPredicate.stringMatches(harness.getText(), text))
|
---|
26 | .addOption('title', options.title, (harness, title) => HarnessPredicate.stringMatches(harness.getTitleText(), title))
|
---|
27 | .addOption('subtitle', options.subtitle, (harness, subtitle) => HarnessPredicate.stringMatches(harness.getSubtitleText(), subtitle));
|
---|
28 | }
|
---|
29 | /** Gets all of the card's content as text. */
|
---|
30 | getText() {
|
---|
31 | return __awaiter(this, void 0, void 0, function* () {
|
---|
32 | return (yield this.host()).text();
|
---|
33 | });
|
---|
34 | }
|
---|
35 | /** Gets the cards's title text. */
|
---|
36 | getTitleText() {
|
---|
37 | var _a, _b;
|
---|
38 | return __awaiter(this, void 0, void 0, function* () {
|
---|
39 | return (_b = (_a = (yield this._title())) === null || _a === void 0 ? void 0 : _a.text()) !== null && _b !== void 0 ? _b : '';
|
---|
40 | });
|
---|
41 | }
|
---|
42 | /** Gets the cards's subtitle text. */
|
---|
43 | getSubtitleText() {
|
---|
44 | var _a, _b;
|
---|
45 | return __awaiter(this, void 0, void 0, function* () {
|
---|
46 | return (_b = (_a = (yield this._subtitle())) === null || _a === void 0 ? void 0 : _a.text()) !== null && _b !== void 0 ? _b : '';
|
---|
47 | });
|
---|
48 | }
|
---|
49 | }
|
---|
50 | /** The selector for the host element of a `MatCard` instance. */
|
---|
51 | MatCardHarness.hostSelector = '.mat-card';
|
---|
52 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2FyZC1oYXJuZXNzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vLi4vc3JjL21hdGVyaWFsL2NhcmQvdGVzdGluZy9jYXJkLWhhcm5lc3MudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HOztBQUVILE9BQU8sRUFBQyxnQkFBZ0IsRUFBRSxnQ0FBZ0MsRUFBQyxNQUFNLHNCQUFzQixDQUFDO0FBV3hGLGlFQUFpRTtBQUNqRSxNQUFNLE9BQU8sY0FBZSxTQUFRLGdDQUFnRDtJQUFwRjs7UUFxQlUsV0FBTSxHQUFHLElBQUksQ0FBQyxrQkFBa0IsQ0FBQyxpQkFBaUIsQ0FBQyxDQUFDO1FBQ3BELGNBQVMsR0FBRyxJQUFJLENBQUMsa0JBQWtCLENBQUMsb0JBQW9CLENBQUMsQ0FBQztJQWdCcEUsQ0FBQztJQWxDQzs7Ozs7T0FLRztJQUNILE1BQU0sQ0FBQyxJQUFJLENBQUMsVUFBOEIsRUFBRTtRQUMxQyxPQUFPLElBQUksZ0JBQWdCLENBQUMsY0FBYyxFQUFFLE9BQU8sQ0FBQzthQUMvQyxTQUFTLENBQUMsTUFBTSxFQUFFLE9BQU8sQ0FBQyxJQUFJLEVBQzNCLENBQUMsT0FBTyxFQUFFLElBQUksRUFBRSxFQUFFLENB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