source: trip-planner-front/node_modules/@angular/material/esm2015/badge/testing/badge-harness.js@ 59329aa

Last change on this file since 59329aa was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 9.1 KB
Line 
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 */
8import { __awaiter } from "tslib";
9import { ComponentHarness, HarnessPredicate } from '@angular/cdk/testing';
10/** Harness for interacting with a standard Material badge in tests. */
11export class MatBadgeHarness extends ComponentHarness {
12 constructor() {
13 super(...arguments);
14 this._badgeElement = this.locatorFor('.mat-badge-content');
15 }
16 /**
17 * Gets a `HarnessPredicate` that can be used to search for a badge with specific attributes.
18 * @param options Options for narrowing the search:
19 * - `text` finds a badge host with a particular text.
20 * @return a `HarnessPredicate` configured with the given options.
21 */
22 static with(options = {}) {
23 return new HarnessPredicate(MatBadgeHarness, options)
24 .addOption('text', options.text, (harness, text) => HarnessPredicate.stringMatches(harness.getText(), text));
25 }
26 /** Gets a promise for the badge text. */
27 getText() {
28 return __awaiter(this, void 0, void 0, function* () {
29 return (yield this._badgeElement()).text();
30 });
31 }
32 /** Gets whether the badge is overlapping the content. */
33 isOverlapping() {
34 return __awaiter(this, void 0, void 0, function* () {
35 return (yield this.host()).hasClass('mat-badge-overlap');
36 });
37 }
38 /** Gets the position of the badge. */
39 getPosition() {
40 return __awaiter(this, void 0, void 0, function* () {
41 const host = yield this.host();
42 let result = '';
43 if (yield host.hasClass('mat-badge-above')) {
44 result += 'above';
45 }
46 else if (yield host.hasClass('mat-badge-below')) {
47 result += 'below';
48 }
49 if (yield host.hasClass('mat-badge-before')) {
50 result += ' before';
51 }
52 else if (yield host.hasClass('mat-badge-after')) {
53 result += ' after';
54 }
55 return result.trim();
56 });
57 }
58 /** Gets the size of the badge. */
59 getSize() {
60 return __awaiter(this, void 0, void 0, function* () {
61 const host = yield this.host();
62 if (yield host.hasClass('mat-badge-small')) {
63 return 'small';
64 }
65 else if (yield host.hasClass('mat-badge-large')) {
66 return 'large';
67 }
68 return 'medium';
69 });
70 }
71 /** Gets whether the badge is hidden. */
72 isHidden() {
73 return __awaiter(this, void 0, void 0, function* () {
74 return (yield this.host()).hasClass('mat-badge-hidden');
75 });
76 }
77 /** Gets whether the badge is disabled. */
78 isDisabled() {
79 return __awaiter(this, void 0, void 0, function* () {
80 return (yield this.host()).hasClass('mat-badge-disabled');
81 });
82 }
83}
84MatBadgeHarness.hostSelector = '.mat-badge';
85//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmFkZ2UtaGFybmVzcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uL3NyYy9tYXRlcmlhbC9iYWRnZS90ZXN0aW5nL2JhZGdlLWhhcm5lc3MudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HOztBQUVILE9BQU8sRUFBQyxnQkFBZ0IsRUFBRSxnQkFBZ0IsRUFBQyxNQUFNLHNCQUFzQixDQUFDO0FBS3hFLHVFQUF1RTtBQUN2RSxNQUFNLE9BQU8sZUFBZ0IsU0FBUSxnQkFBZ0I7SUFBckQ7O1FBZVUsa0JBQWEsR0FBRyxJQUFJLENBQUMsVUFBVSxDQUFDLG9CQUFvQixDQUFDLENBQUM7SUFzRGhFLENBQUM7SUFsRUM7Ozs7O09BS0c7SUFDSCxNQUFNLENBQUMsSUFBSSxDQUFDLFVBQStCLEVBQUU7UUFDM0MsT0FBTyxJQUFJLGdCQUFnQixDQUFDLGVBQWUsRUFBRSxPQUFPLENBQUM7YUFDaEQsU0FBUyxDQUFDLE1BQU0sRUFBRSxPQUFPLENBQUMsSUFBSSxFQUMzQixDQUFDLE9BQU8sRUFBRSxJQUFJLEVBQUUsRUFBRSxDQUFDLGdCQUFnQixDQUFDLGFBQWEsQ0FBQ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