1 | import { __awaiter } from 'tslib';
|
2 | import { coerceBooleanProperty } from '@angular/cdk/coercion';
|
3 | import { ComponentHarness, HarnessPredicate } from '@angular/cdk/testing';
|
4 |
|
5 | class _MatCheckboxHarnessBase extends ComponentHarness {
|
6 |
|
7 | isChecked() {
|
8 | return __awaiter(this, void 0, void 0, function* () {
|
9 | const checked = (yield this._input()).getProperty('checked');
|
10 | return coerceBooleanProperty(yield checked);
|
11 | });
|
12 | }
|
13 |
|
14 | isIndeterminate() {
|
15 | return __awaiter(this, void 0, void 0, function* () {
|
16 | const indeterminate = (yield this._input()).getProperty('indeterminate');
|
17 | return coerceBooleanProperty(yield indeterminate);
|
18 | });
|
19 | }
|
20 |
|
21 | isDisabled() {
|
22 | return __awaiter(this, void 0, void 0, function* () {
|
23 | const disabled = (yield this._input()).getAttribute('disabled');
|
24 | return coerceBooleanProperty(yield disabled);
|
25 | });
|
26 | }
|
27 |
|
28 | isRequired() {
|
29 | return __awaiter(this, void 0, void 0, function* () {
|
30 | const required = (yield this._input()).getProperty('required');
|
31 | return coerceBooleanProperty(yield required);
|
32 | });
|
33 | }
|
34 |
|
35 | isValid() {
|
36 | return __awaiter(this, void 0, void 0, function* () {
|
37 | const invalid = (yield this.host()).hasClass('ng-invalid');
|
38 | return !(yield invalid);
|
39 | });
|
40 | }
|
41 |
|
42 | getName() {
|
43 | return __awaiter(this, void 0, void 0, function* () {
|
44 | return (yield this._input()).getAttribute('name');
|
45 | });
|
46 | }
|
47 |
|
48 | getValue() {
|
49 | return __awaiter(this, void 0, void 0, function* () {
|
50 | return (yield this._input()).getProperty('value');
|
51 | });
|
52 | }
|
53 |
|
54 | getAriaLabel() {
|
55 | return __awaiter(this, void 0, void 0, function* () {
|
56 | return (yield this._input()).getAttribute('aria-label');
|
57 | });
|
58 | }
|
59 |
|
60 | getAriaLabelledby() {
|
61 | return __awaiter(this, void 0, void 0, function* () {
|
62 | return (yield this._input()).getAttribute('aria-labelledby');
|
63 | });
|
64 | }
|
65 |
|
66 | getLabelText() {
|
67 | return __awaiter(this, void 0, void 0, function* () {
|
68 | return (yield this._label()).text();
|
69 | });
|
70 | }
|
71 |
|
72 | focus() {
|
73 | return __awaiter(this, void 0, void 0, function* () {
|
74 | return (yield this._input()).focus();
|
75 | });
|
76 | }
|
77 |
|
78 | blur() {
|
79 | return __awaiter(this, void 0, void 0, function* () {
|
80 | return (yield this._input()).blur();
|
81 | });
|
82 | }
|
83 |
|
84 | isFocused() {
|
85 | return __awaiter(this, void 0, void 0, function* () {
|
86 | return (yield this._input()).isFocused();
|
87 | });
|
88 | }
|
89 | |
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 | check() {
|
98 | return __awaiter(this, void 0, void 0, function* () {
|
99 | if (!(yield this.isChecked())) {
|
100 | yield this.toggle();
|
101 | }
|
102 | });
|
103 | }
|
104 | |
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 | uncheck() {
|
113 | return __awaiter(this, void 0, void 0, function* () {
|
114 | if (yield this.isChecked()) {
|
115 | yield this.toggle();
|
116 | }
|
117 | });
|
118 | }
|
119 | }
|
120 |
|
121 | class MatCheckboxHarness extends _MatCheckboxHarnessBase {
|
122 | constructor() {
|
123 | super(...arguments);
|
124 | this._input = this.locatorFor('input');
|
125 | this._label = this.locatorFor('.mat-checkbox-label');
|
126 | this._inputContainer = this.locatorFor('.mat-checkbox-inner-container');
|
127 | }
|
128 | |
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 | static with(options = {}) {
|
135 | return (new HarnessPredicate(MatCheckboxHarness, options)
|
136 | .addOption('label', options.label, (harness, label) => HarnessPredicate.stringMatches(harness.getLabelText(), label))
|
137 |
|
138 |
|
139 |
|
140 | .addOption('name', options.name, (harness, name) => __awaiter(this, void 0, void 0, function* () { return (yield harness.getName()) === name; }))
|
141 | .addOption('checked', options.checked, (harness, checked) => __awaiter(this, void 0, void 0, function* () { return (yield harness.isChecked()) == checked; })));
|
142 | }
|
143 | toggle() {
|
144 | return __awaiter(this, void 0, void 0, function* () {
|
145 | return (yield this._inputContainer()).click();
|
146 | });
|
147 | }
|
148 | }
|
149 |
|
150 | MatCheckboxHarness.hostSelector = '.mat-checkbox';
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 | export { MatCheckboxHarness, _MatCheckboxHarnessBase };
|
169 |
|