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 { ContentContainerComponentHarness, HarnessPredicate, } from '@angular/cdk/testing';
|
---|
10 | import { coerceBooleanProperty, coerceNumberProperty } from '@angular/cdk/coercion';
|
---|
11 | /** Harness for interacting with a standard Angular Material tree node. */
|
---|
12 | export class MatTreeNodeHarness extends ContentContainerComponentHarness {
|
---|
13 | constructor() {
|
---|
14 | super(...arguments);
|
---|
15 | this._toggle = this.locatorForOptional('[matTreeNodeToggle]');
|
---|
16 | }
|
---|
17 | /**
|
---|
18 | * Gets a `HarnessPredicate` that can be used to search for a tree node with specific attributes.
|
---|
19 | * @param options Options for narrowing the search
|
---|
20 | * @return a `HarnessPredicate` configured with the given options.
|
---|
21 | */
|
---|
22 | static with(options = {}) {
|
---|
23 | return getNodePredicate(MatTreeNodeHarness, options);
|
---|
24 | }
|
---|
25 | /** Whether the tree node is expanded. */
|
---|
26 | isExpanded() {
|
---|
27 | return __awaiter(this, void 0, void 0, function* () {
|
---|
28 | return coerceBooleanProperty(yield (yield this.host()).getAttribute('aria-expanded'));
|
---|
29 | });
|
---|
30 | }
|
---|
31 | /** Whether the tree node is disabled. */
|
---|
32 | isDisabled() {
|
---|
33 | return __awaiter(this, void 0, void 0, function* () {
|
---|
34 | return coerceBooleanProperty(yield (yield this.host()).getProperty('aria-disabled'));
|
---|
35 | });
|
---|
36 | }
|
---|
37 | /** Gets the level of the tree node. Note that this gets the aria-level and is 1 indexed. */
|
---|
38 | getLevel() {
|
---|
39 | return __awaiter(this, void 0, void 0, function* () {
|
---|
40 | return coerceNumberProperty(yield (yield this.host()).getAttribute('aria-level'));
|
---|
41 | });
|
---|
42 | }
|
---|
43 | /** Gets the tree node's text. */
|
---|
44 | getText() {
|
---|
45 | return __awaiter(this, void 0, void 0, function* () {
|
---|
46 | return (yield this.host()).text({ exclude: '.mat-tree-node, .mat-nested-tree-node, button' });
|
---|
47 | });
|
---|
48 | }
|
---|
49 | /** Toggles node between expanded/collapsed. Only works when node is not disabled. */
|
---|
50 | toggle() {
|
---|
51 | return __awaiter(this, void 0, void 0, function* () {
|
---|
52 | const toggle = yield this._toggle();
|
---|
53 | if (toggle) {
|
---|
54 | return toggle.click();
|
---|
55 | }
|
---|
56 | });
|
---|
57 | }
|
---|
58 | /** Expands the node if it is collapsed. Only works when node is not disabled. */
|
---|
59 | expand() {
|
---|
60 | return __awaiter(this, void 0, void 0, function* () {
|
---|
61 | if (!(yield this.isExpanded())) {
|
---|
62 | yield this.toggle();
|
---|
63 | }
|
---|
64 | });
|
---|
65 | }
|
---|
66 | /** Collapses the node if it is expanded. Only works when node is not disabled. */
|
---|
67 | collapse() {
|
---|
68 | return __awaiter(this, void 0, void 0, function* () {
|
---|
69 | if (yield this.isExpanded()) {
|
---|
70 | yield this.toggle();
|
---|
71 | }
|
---|
72 | });
|
---|
73 | }
|
---|
74 | }
|
---|
75 | /** The selector of the host element of a `MatTreeNode` instance. */
|
---|
76 | MatTreeNodeHarness.hostSelector = '.mat-tree-node, .mat-nested-tree-node';
|
---|
77 | function getNodePredicate(type, options) {
|
---|
78 | return new HarnessPredicate(type, options)
|
---|
79 | .addOption('text', options.text, (harness, text) => HarnessPredicate.stringMatches(harness.getText(), text))
|
---|
80 | .addOption('disabled', options.disabled, (harness, disabled) => __awaiter(this, void 0, void 0, function* () { return (yield harness.isDisabled()) === disabled; }))
|
---|
81 | .addOption('expanded', options.expanded, (harness, expanded) => __awaiter(this, void 0, void 0, function* () { return (yield harness.isExpanded()) === expanded; }))
|
---|
82 | .addOption('level', options.level, (harness, level) => __awaiter(this, void 0, void 0, function* () { return (yield harness.getLevel()) === level; }));
|
---|
83 | }
|
---|
84 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWx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