UNPKG

3.21 kBJavaScriptView Raw
1import { ComponentHarness, HarnessPredicate } from '@angular/cdk/testing';
2
3/**
4 * @license
5 * Copyright Google LLC All Rights Reserved.
6 *
7 * Use of this source code is governed by an MIT-style license that can be
8 * found in the LICENSE file at https://angular.io/license
9 */
10/** Harness for interacting with a standard Material badge in tests. */
11class 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).addOption('text', options.text, (harness, text) => HarnessPredicate.stringMatches(harness.getText(), text));
24 }
25 /** Gets a promise for the badge text. */
26 async getText() {
27 return (await this._badgeElement()).text();
28 }
29 /** Gets whether the badge is overlapping the content. */
30 async isOverlapping() {
31 return (await this.host()).hasClass('mat-badge-overlap');
32 }
33 /** Gets the position of the badge. */
34 async getPosition() {
35 const host = await this.host();
36 let result = '';
37 if (await host.hasClass('mat-badge-above')) {
38 result += 'above';
39 }
40 else if (await host.hasClass('mat-badge-below')) {
41 result += 'below';
42 }
43 if (await host.hasClass('mat-badge-before')) {
44 result += ' before';
45 }
46 else if (await host.hasClass('mat-badge-after')) {
47 result += ' after';
48 }
49 return result.trim();
50 }
51 /** Gets the size of the badge. */
52 async getSize() {
53 const host = await this.host();
54 if (await host.hasClass('mat-badge-small')) {
55 return 'small';
56 }
57 else if (await host.hasClass('mat-badge-large')) {
58 return 'large';
59 }
60 return 'medium';
61 }
62 /** Gets whether the badge is hidden. */
63 async isHidden() {
64 return (await this.host()).hasClass('mat-badge-hidden');
65 }
66 /** Gets whether the badge is disabled. */
67 async isDisabled() {
68 return (await this.host()).hasClass('mat-badge-disabled');
69 }
70}
71MatBadgeHarness.hostSelector = '.mat-badge';
72
73/**
74 * @license
75 * Copyright Google LLC All Rights Reserved.
76 *
77 * Use of this source code is governed by an MIT-style license that can be
78 * found in the LICENSE file at https://angular.io/license
79 */
80
81/**
82 * @license
83 * Copyright Google LLC All Rights Reserved.
84 *
85 * Use of this source code is governed by an MIT-style license that can be
86 * found in the LICENSE file at https://angular.io/license
87 */
88
89/**
90 * @license
91 * Copyright Google LLC All Rights Reserved.
92 *
93 * Use of this source code is governed by an MIT-style license that can be
94 * found in the LICENSE file at https://angular.io/license
95 */
96
97export { MatBadgeHarness };
98//# sourceMappingURL=testing.mjs.map