source: trip-planner-front/node_modules/@angular/material/fesm2015/snack-bar/testing.js@ 84d0fbb

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

initial commit

  • Property mode set to 100644
File size: 6.3 KB
Line 
1import { __awaiter } from 'tslib';
2import { ContentContainerComponentHarness, HarnessPredicate, parallel } from '@angular/cdk/testing';
3
4/**
5 * @license
6 * Copyright Google LLC All Rights Reserved.
7 *
8 * Use of this source code is governed by an MIT-style license that can be
9 * found in the LICENSE file at https://angular.io/license
10 */
11/** Harness for interacting with a standard mat-snack-bar in tests. */
12class MatSnackBarHarness extends ContentContainerComponentHarness {
13 constructor() {
14 super(...arguments);
15 this._messageSelector = '.mat-simple-snackbar > span';
16 this._actionButtonSelector = '.mat-simple-snackbar-action > button';
17 this._snackBarLiveRegion = this.locatorFor('[aria-live]');
18 }
19 /**
20 * Gets a `HarnessPredicate` that can be used to search for a `MatSnackBarHarness` that meets
21 * certain criteria.
22 * @param options Options for filtering which snack bar instances are considered a match.
23 * @return a `HarnessPredicate` configured with the given options.
24 */
25 static with(options = {}) {
26 return new HarnessPredicate(MatSnackBarHarness, options);
27 }
28 /**
29 * Gets the role of the snack-bar. The role of a snack-bar is determined based
30 * on the ARIA politeness specified in the snack-bar config.
31 * @deprecated Use `getAriaLive` instead.
32 * @breaking-change 13.0.0
33 */
34 getRole() {
35 return __awaiter(this, void 0, void 0, function* () {
36 return (yield this.host()).getAttribute('role');
37 });
38 }
39 /**
40 * Gets the aria-live of the snack-bar's live region. The aria-live of a snack-bar is
41 * determined based on the ARIA politeness specified in the snack-bar config.
42 */
43 getAriaLive() {
44 return __awaiter(this, void 0, void 0, function* () {
45 return (yield this._snackBarLiveRegion())
46 .getAttribute('aria-live');
47 });
48 }
49 /**
50 * Whether the snack-bar has an action. Method cannot be used for snack-bar's with custom content.
51 */
52 hasAction() {
53 return __awaiter(this, void 0, void 0, function* () {
54 yield this._assertContentAnnotated();
55 return (yield this._getActionButton()) !== null;
56 });
57 }
58 /**
59 * Gets the description of the snack-bar. Method cannot be used for snack-bar's without action or
60 * with custom content.
61 */
62 getActionDescription() {
63 return __awaiter(this, void 0, void 0, function* () {
64 yield this._assertHasAction();
65 return (yield this._getActionButton()).text();
66 });
67 }
68 /**
69 * Dismisses the snack-bar by clicking the action button. Method cannot be used for snack-bar's
70 * without action or with custom content.
71 */
72 dismissWithAction() {
73 return __awaiter(this, void 0, void 0, function* () {
74 yield this._assertHasAction();
75 yield (yield this._getActionButton()).click();
76 });
77 }
78 /**
79 * Gets the message of the snack-bar. Method cannot be used for snack-bar's with custom content.
80 */
81 getMessage() {
82 return __awaiter(this, void 0, void 0, function* () {
83 yield this._assertContentAnnotated();
84 return (yield this.locatorFor(this._messageSelector)()).text();
85 });
86 }
87 /** Gets whether the snack-bar has been dismissed. */
88 isDismissed() {
89 return __awaiter(this, void 0, void 0, function* () {
90 // We consider the snackbar dismissed if it's not in the DOM. We can assert that the
91 // element isn't in the DOM by seeing that its width and height are zero.
92 const host = yield this.host();
93 const [exit, dimensions] = yield parallel(() => [
94 // The snackbar container is marked with the "exit" attribute after it has been dismissed
95 // but before the animation has finished (after which it's removed from the DOM).
96 host.getAttribute('mat-exit'),
97 host.getDimensions(),
98 ]);
99 return exit != null || (!!dimensions && dimensions.height === 0 && dimensions.width === 0);
100 });
101 }
102 /**
103 * Asserts that the current snack-bar has annotated content. Promise reject
104 * if content is not annotated.
105 */
106 _assertContentAnnotated() {
107 return __awaiter(this, void 0, void 0, function* () {
108 if (!(yield this._isSimpleSnackBar())) {
109 throw Error('Method cannot be used for snack-bar with custom content.');
110 }
111 });
112 }
113 /**
114 * Asserts that the current snack-bar has an action defined. Otherwise the
115 * promise will reject.
116 */
117 _assertHasAction() {
118 return __awaiter(this, void 0, void 0, function* () {
119 yield this._assertContentAnnotated();
120 if (!(yield this.hasAction())) {
121 throw Error('Method cannot be used for a snack-bar without an action.');
122 }
123 });
124 }
125 /** Whether the snack-bar is using the default content template. */
126 _isSimpleSnackBar() {
127 return __awaiter(this, void 0, void 0, function* () {
128 return (yield this.locatorForOptional('.mat-simple-snackbar')()) !== null;
129 });
130 }
131 /** Gets the simple snack bar action button. */
132 _getActionButton() {
133 return __awaiter(this, void 0, void 0, function* () {
134 return this.locatorForOptional(this._actionButtonSelector)();
135 });
136 }
137}
138// Developers can provide a custom component or template for the
139// snackbar. The canonical snack-bar parent is the "MatSnackBarContainer".
140/** The selector for the host element of a `MatSnackBar` instance. */
141MatSnackBarHarness.hostSelector = '.mat-snack-bar-container';
142
143/**
144 * @license
145 * Copyright Google LLC All Rights Reserved.
146 *
147 * Use of this source code is governed by an MIT-style license that can be
148 * found in the LICENSE file at https://angular.io/license
149 */
150
151/**
152 * @license
153 * Copyright Google LLC All Rights Reserved.
154 *
155 * Use of this source code is governed by an MIT-style license that can be
156 * found in the LICENSE file at https://angular.io/license
157 */
158
159/**
160 * @license
161 * Copyright Google LLC All Rights Reserved.
162 *
163 * Use of this source code is governed by an MIT-style license that can be
164 * found in the LICENSE file at https://angular.io/license
165 */
166
167export { MatSnackBarHarness };
168//# sourceMappingURL=testing.js.map
Note: See TracBrowser for help on using the repository browser.