1 | import { __awaiter } from 'tslib';
|
---|
2 | import { ContentContainerComponentHarness, HarnessPredicate, ComponentHarness } 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-expansion-panel in tests. */
|
---|
12 | class MatExpansionPanelHarness extends ContentContainerComponentHarness {
|
---|
13 | constructor() {
|
---|
14 | super(...arguments);
|
---|
15 | this._header = this.locatorFor(".mat-expansion-panel-header" /* HEADER */);
|
---|
16 | this._title = this.locatorForOptional(".mat-expansion-panel-header-title" /* TITLE */);
|
---|
17 | this._description = this.locatorForOptional(".mat-expansion-panel-header-description" /* DESCRIPTION */);
|
---|
18 | this._expansionIndicator = this.locatorForOptional('.mat-expansion-indicator');
|
---|
19 | this._content = this.locatorFor(".mat-expansion-panel-content" /* CONTENT */);
|
---|
20 | }
|
---|
21 | /**
|
---|
22 | * Gets a `HarnessPredicate` that can be used to search for an expansion-panel
|
---|
23 | * with specific attributes.
|
---|
24 | * @param options Options for narrowing the search:
|
---|
25 | * - `title` finds an expansion-panel with a specific title text.
|
---|
26 | * - `description` finds an expansion-panel with a specific description text.
|
---|
27 | * - `expanded` finds an expansion-panel that is currently expanded.
|
---|
28 | * - `disabled` finds an expansion-panel that is disabled.
|
---|
29 | * @return a `HarnessPredicate` configured with the given options.
|
---|
30 | */
|
---|
31 | static with(options = {}) {
|
---|
32 | return new HarnessPredicate(MatExpansionPanelHarness, options)
|
---|
33 | .addOption('title', options.title, (harness, title) => HarnessPredicate.stringMatches(harness.getTitle(), title))
|
---|
34 | .addOption('description', options.description, (harness, description) => HarnessPredicate.stringMatches(harness.getDescription(), description))
|
---|
35 | .addOption('content', options.content, (harness, content) => HarnessPredicate.stringMatches(harness.getTextContent(), content))
|
---|
36 | .addOption('expanded', options.expanded, (harness, expanded) => __awaiter(this, void 0, void 0, function* () { return (yield harness.isExpanded()) === expanded; }))
|
---|
37 | .addOption('disabled', options.disabled, (harness, disabled) => __awaiter(this, void 0, void 0, function* () { return (yield harness.isDisabled()) === disabled; }));
|
---|
38 | }
|
---|
39 | /** Whether the panel is expanded. */
|
---|
40 | isExpanded() {
|
---|
41 | return __awaiter(this, void 0, void 0, function* () {
|
---|
42 | return (yield this.host()).hasClass('mat-expanded');
|
---|
43 | });
|
---|
44 | }
|
---|
45 | /**
|
---|
46 | * Gets the title text of the panel.
|
---|
47 | * @returns Title text or `null` if no title is set up.
|
---|
48 | */
|
---|
49 | getTitle() {
|
---|
50 | return __awaiter(this, void 0, void 0, function* () {
|
---|
51 | const titleEl = yield this._title();
|
---|
52 | return titleEl ? titleEl.text() : null;
|
---|
53 | });
|
---|
54 | }
|
---|
55 | /**
|
---|
56 | * Gets the description text of the panel.
|
---|
57 | * @returns Description text or `null` if no description is set up.
|
---|
58 | */
|
---|
59 | getDescription() {
|
---|
60 | return __awaiter(this, void 0, void 0, function* () {
|
---|
61 | const descriptionEl = yield this._description();
|
---|
62 | return descriptionEl ? descriptionEl.text() : null;
|
---|
63 | });
|
---|
64 | }
|
---|
65 | /** Whether the panel is disabled. */
|
---|
66 | isDisabled() {
|
---|
67 | return __awaiter(this, void 0, void 0, function* () {
|
---|
68 | return (yield (yield this._header()).getAttribute('aria-disabled')) === 'true';
|
---|
69 | });
|
---|
70 | }
|
---|
71 | /**
|
---|
72 | * Toggles the expanded state of the panel by clicking on the panel
|
---|
73 | * header. This method will not work if the panel is disabled.
|
---|
74 | */
|
---|
75 | toggle() {
|
---|
76 | return __awaiter(this, void 0, void 0, function* () {
|
---|
77 | yield (yield this._header()).click();
|
---|
78 | });
|
---|
79 | }
|
---|
80 | /** Expands the expansion panel if collapsed. */
|
---|
81 | expand() {
|
---|
82 | return __awaiter(this, void 0, void 0, function* () {
|
---|
83 | if (!(yield this.isExpanded())) {
|
---|
84 | yield this.toggle();
|
---|
85 | }
|
---|
86 | });
|
---|
87 | }
|
---|
88 | /** Collapses the expansion panel if expanded. */
|
---|
89 | collapse() {
|
---|
90 | return __awaiter(this, void 0, void 0, function* () {
|
---|
91 | if (yield this.isExpanded()) {
|
---|
92 | yield this.toggle();
|
---|
93 | }
|
---|
94 | });
|
---|
95 | }
|
---|
96 | /** Gets the text content of the panel. */
|
---|
97 | getTextContent() {
|
---|
98 | return __awaiter(this, void 0, void 0, function* () {
|
---|
99 | return (yield this._content()).text();
|
---|
100 | });
|
---|
101 | }
|
---|
102 | /**
|
---|
103 | * Gets a `HarnessLoader` that can be used to load harnesses for
|
---|
104 | * components within the panel's content area.
|
---|
105 | * @deprecated Use either `getChildLoader(MatExpansionPanelSection.CONTENT)`, `getHarness` or
|
---|
106 | * `getAllHarnesses` instead.
|
---|
107 | * @breaking-change 12.0.0
|
---|
108 | */
|
---|
109 | getHarnessLoaderForContent() {
|
---|
110 | return __awaiter(this, void 0, void 0, function* () {
|
---|
111 | return this.getChildLoader(".mat-expansion-panel-content" /* CONTENT */);
|
---|
112 | });
|
---|
113 | }
|
---|
114 | /** Focuses the panel. */
|
---|
115 | focus() {
|
---|
116 | return __awaiter(this, void 0, void 0, function* () {
|
---|
117 | return (yield this._header()).focus();
|
---|
118 | });
|
---|
119 | }
|
---|
120 | /** Blurs the panel. */
|
---|
121 | blur() {
|
---|
122 | return __awaiter(this, void 0, void 0, function* () {
|
---|
123 | return (yield this._header()).blur();
|
---|
124 | });
|
---|
125 | }
|
---|
126 | /** Whether the panel is focused. */
|
---|
127 | isFocused() {
|
---|
128 | return __awaiter(this, void 0, void 0, function* () {
|
---|
129 | return (yield this._header()).isFocused();
|
---|
130 | });
|
---|
131 | }
|
---|
132 | /** Whether the panel has a toggle indicator displayed. */
|
---|
133 | hasToggleIndicator() {
|
---|
134 | return __awaiter(this, void 0, void 0, function* () {
|
---|
135 | return (yield this._expansionIndicator()) !== null;
|
---|
136 | });
|
---|
137 | }
|
---|
138 | /** Gets the position of the toggle indicator. */
|
---|
139 | getToggleIndicatorPosition() {
|
---|
140 | return __awaiter(this, void 0, void 0, function* () {
|
---|
141 | // By default the expansion indicator will show "after" the panel header content.
|
---|
142 | if (yield (yield this._header()).hasClass('mat-expansion-toggle-indicator-before')) {
|
---|
143 | return 'before';
|
---|
144 | }
|
---|
145 | return 'after';
|
---|
146 | });
|
---|
147 | }
|
---|
148 | }
|
---|
149 | MatExpansionPanelHarness.hostSelector = '.mat-expansion-panel';
|
---|
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 | /** Harness for interacting with a standard mat-accordion in tests. */
|
---|
159 | class MatAccordionHarness extends ComponentHarness {
|
---|
160 | /**
|
---|
161 | * Gets a `HarnessPredicate` that can be used to search for an accordion
|
---|
162 | * with specific attributes.
|
---|
163 | * @param options Options for narrowing the search.
|
---|
164 | * @return a `HarnessPredicate` configured with the given options.
|
---|
165 | */
|
---|
166 | static with(options = {}) {
|
---|
167 | return new HarnessPredicate(MatAccordionHarness, options);
|
---|
168 | }
|
---|
169 | /** Gets all expansion panels which are part of the accordion. */
|
---|
170 | getExpansionPanels(filter = {}) {
|
---|
171 | return __awaiter(this, void 0, void 0, function* () {
|
---|
172 | return this.locatorForAll(MatExpansionPanelHarness.with(filter))();
|
---|
173 | });
|
---|
174 | }
|
---|
175 | /** Whether the accordion allows multiple expanded panels simultaneously. */
|
---|
176 | isMulti() {
|
---|
177 | return __awaiter(this, void 0, void 0, function* () {
|
---|
178 | return (yield this.host()).hasClass('mat-accordion-multi');
|
---|
179 | });
|
---|
180 | }
|
---|
181 | }
|
---|
182 | MatAccordionHarness.hostSelector = '.mat-accordion';
|
---|
183 |
|
---|
184 | /**
|
---|
185 | * @license
|
---|
186 | * Copyright Google LLC All Rights Reserved.
|
---|
187 | *
|
---|
188 | * Use of this source code is governed by an MIT-style license that can be
|
---|
189 | * found in the LICENSE file at https://angular.io/license
|
---|
190 | */
|
---|
191 |
|
---|
192 | /**
|
---|
193 | * @license
|
---|
194 | * Copyright Google LLC All Rights Reserved.
|
---|
195 | *
|
---|
196 | * Use of this source code is governed by an MIT-style license that can be
|
---|
197 | * found in the LICENSE file at https://angular.io/license
|
---|
198 | */
|
---|
199 |
|
---|
200 | /**
|
---|
201 | * @license
|
---|
202 | * Copyright Google LLC All Rights Reserved.
|
---|
203 | *
|
---|
204 | * Use of this source code is governed by an MIT-style license that can be
|
---|
205 | * found in the LICENSE file at https://angular.io/license
|
---|
206 | */
|
---|
207 |
|
---|
208 | export { MatAccordionHarness, MatExpansionPanelHarness };
|
---|
209 | //# sourceMappingURL=testing.js.map
|
---|