1 | import { __awaiter } from 'tslib';
|
---|
2 | import { ContentContainerComponentHarness, HarnessPredicate, ComponentHarness, parallel } from '@angular/cdk/testing';
|
---|
3 | import { ɵTileCoordinator } from '@angular/material/grid-list';
|
---|
4 |
|
---|
5 | /**
|
---|
6 | * @license
|
---|
7 | * Copyright Google LLC All Rights Reserved.
|
---|
8 | *
|
---|
9 | * Use of this source code is governed by an MIT-style license that can be
|
---|
10 | * found in the LICENSE file at https://angular.io/license
|
---|
11 | */
|
---|
12 | /** Harness for interacting with a standard `MatGridTitle` in tests. */
|
---|
13 | class MatGridTileHarness extends ContentContainerComponentHarness {
|
---|
14 | constructor() {
|
---|
15 | super(...arguments);
|
---|
16 | this._header = this.locatorForOptional(".mat-grid-tile-header" /* HEADER */);
|
---|
17 | this._footer = this.locatorForOptional(".mat-grid-tile-footer" /* FOOTER */);
|
---|
18 | this._avatar = this.locatorForOptional('.mat-grid-avatar');
|
---|
19 | }
|
---|
20 | /**
|
---|
21 | * Gets a `HarnessPredicate` that can be used to search for a `MatGridTileHarness`
|
---|
22 | * that meets certain criteria.
|
---|
23 | * @param options Options for filtering which dialog instances are considered a match.
|
---|
24 | * @return a `HarnessPredicate` configured with the given options.
|
---|
25 | */
|
---|
26 | static with(options = {}) {
|
---|
27 | return new HarnessPredicate(MatGridTileHarness, options)
|
---|
28 | .addOption('headerText', options.headerText, (harness, pattern) => HarnessPredicate.stringMatches(harness.getHeaderText(), pattern))
|
---|
29 | .addOption('footerText', options.footerText, (harness, pattern) => HarnessPredicate.stringMatches(harness.getFooterText(), pattern));
|
---|
30 | }
|
---|
31 | /** Gets the amount of rows that the grid-tile takes up. */
|
---|
32 | getRowspan() {
|
---|
33 | return __awaiter(this, void 0, void 0, function* () {
|
---|
34 | return Number(yield (yield this.host()).getAttribute('rowspan'));
|
---|
35 | });
|
---|
36 | }
|
---|
37 | /** Gets the amount of columns that the grid-tile takes up. */
|
---|
38 | getColspan() {
|
---|
39 | return __awaiter(this, void 0, void 0, function* () {
|
---|
40 | return Number(yield (yield this.host()).getAttribute('colspan'));
|
---|
41 | });
|
---|
42 | }
|
---|
43 | /** Whether the grid-tile has a header. */
|
---|
44 | hasHeader() {
|
---|
45 | return __awaiter(this, void 0, void 0, function* () {
|
---|
46 | return (yield this._header()) !== null;
|
---|
47 | });
|
---|
48 | }
|
---|
49 | /** Whether the grid-tile has a footer. */
|
---|
50 | hasFooter() {
|
---|
51 | return __awaiter(this, void 0, void 0, function* () {
|
---|
52 | return (yield this._footer()) !== null;
|
---|
53 | });
|
---|
54 | }
|
---|
55 | /** Whether the grid-tile has an avatar. */
|
---|
56 | hasAvatar() {
|
---|
57 | return __awaiter(this, void 0, void 0, function* () {
|
---|
58 | return (yield this._avatar()) !== null;
|
---|
59 | });
|
---|
60 | }
|
---|
61 | /** Gets the text of the header if present. */
|
---|
62 | getHeaderText() {
|
---|
63 | return __awaiter(this, void 0, void 0, function* () {
|
---|
64 | // For performance reasons, we do not use "hasHeader" as
|
---|
65 | // we would then need to query twice for the header.
|
---|
66 | const headerEl = yield this._header();
|
---|
67 | return headerEl ? headerEl.text() : null;
|
---|
68 | });
|
---|
69 | }
|
---|
70 | /** Gets the text of the footer if present. */
|
---|
71 | getFooterText() {
|
---|
72 | return __awaiter(this, void 0, void 0, function* () {
|
---|
73 | // For performance reasons, we do not use "hasFooter" as
|
---|
74 | // we would then need to query twice for the footer.
|
---|
75 | const headerEl = yield this._footer();
|
---|
76 | return headerEl ? headerEl.text() : null;
|
---|
77 | });
|
---|
78 | }
|
---|
79 | }
|
---|
80 | /** The selector for the host element of a `MatGridTile` instance. */
|
---|
81 | MatGridTileHarness.hostSelector = '.mat-grid-tile';
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * @license
|
---|
85 | * Copyright Google LLC All Rights Reserved.
|
---|
86 | *
|
---|
87 | * Use of this source code is governed by an MIT-style license that can be
|
---|
88 | * found in the LICENSE file at https://angular.io/license
|
---|
89 | */
|
---|
90 | /** Harness for interacting with a standard `MatGridList` in tests. */
|
---|
91 | class MatGridListHarness extends ComponentHarness {
|
---|
92 | constructor() {
|
---|
93 | super(...arguments);
|
---|
94 | /**
|
---|
95 | * Tile coordinator that is used by the "MatGridList" for computing
|
---|
96 | * positions of tiles. We leverage the coordinator to provide an API
|
---|
97 | * for retrieving tiles based on visual tile positions.
|
---|
98 | */
|
---|
99 | this._tileCoordinator = new ɵTileCoordinator();
|
---|
100 | }
|
---|
101 | /**
|
---|
102 | * Gets a `HarnessPredicate` that can be used to search for a `MatGridListHarness`
|
---|
103 | * that meets certain criteria.
|
---|
104 | * @param options Options for filtering which dialog instances are considered a match.
|
---|
105 | * @return a `HarnessPredicate` configured with the given options.
|
---|
106 | */
|
---|
107 | static with(options = {}) {
|
---|
108 | return new HarnessPredicate(MatGridListHarness, options);
|
---|
109 | }
|
---|
110 | /** Gets all tiles of the grid-list. */
|
---|
111 | getTiles(filters = {}) {
|
---|
112 | return __awaiter(this, void 0, void 0, function* () {
|
---|
113 | return yield this.locatorForAll(MatGridTileHarness.with(filters))();
|
---|
114 | });
|
---|
115 | }
|
---|
116 | /** Gets the amount of columns of the grid-list. */
|
---|
117 | getColumns() {
|
---|
118 | return __awaiter(this, void 0, void 0, function* () {
|
---|
119 | return Number(yield (yield this.host()).getAttribute('cols'));
|
---|
120 | });
|
---|
121 | }
|
---|
122 | /**
|
---|
123 | * Gets a tile of the grid-list that is located at the given location.
|
---|
124 | * @param row Zero-based row index.
|
---|
125 | * @param column Zero-based column index.
|
---|
126 | */
|
---|
127 | getTileAtPosition({ row, column }) {
|
---|
128 | return __awaiter(this, void 0, void 0, function* () {
|
---|
129 | const [tileHarnesses, columns] = yield parallel(() => [this.getTiles(), this.getColumns()]);
|
---|
130 | const tileSpans = tileHarnesses.map(t => parallel(() => [t.getColspan(), t.getRowspan()]));
|
---|
131 | const tiles = (yield parallel(() => tileSpans))
|
---|
132 | .map(([colspan, rowspan]) => ({ colspan, rowspan }));
|
---|
133 | // Update the tile coordinator to reflect the current column amount and
|
---|
134 | // rendered tiles. We update upon every call of this method since we do not
|
---|
135 | // know if tiles have been added, removed or updated (in terms of rowspan/colspan).
|
---|
136 | this._tileCoordinator.update(columns, tiles);
|
---|
137 | // The tile coordinator respects the colspan and rowspan for calculating the positions
|
---|
138 | // of tiles, but it does not create multiple position entries if a tile spans over multiple
|
---|
139 | // columns or rows. We want to provide an API where developers can retrieve a tile based on
|
---|
140 | // any position that lies within the visual tile boundaries. For example: If a tile spans
|
---|
141 | // over two columns, then the same tile should be returned for either column indices.
|
---|
142 | for (let i = 0; i < this._tileCoordinator.positions.length; i++) {
|
---|
143 | const position = this._tileCoordinator.positions[i];
|
---|
144 | const { rowspan, colspan } = tiles[i];
|
---|
145 | // Return the tile harness if the given position visually resolves to the tile.
|
---|
146 | if (column >= position.col && column <= position.col + colspan - 1 && row >= position.row &&
|
---|
147 | row <= position.row + rowspan - 1) {
|
---|
148 | return tileHarnesses[i];
|
---|
149 | }
|
---|
150 | }
|
---|
151 | throw Error('Could not find tile at given position.');
|
---|
152 | });
|
---|
153 | }
|
---|
154 | }
|
---|
155 | /** The selector for the host element of a `MatGridList` instance. */
|
---|
156 | MatGridListHarness.hostSelector = '.mat-grid-list';
|
---|
157 |
|
---|
158 | /**
|
---|
159 | * @license
|
---|
160 | * Copyright Google LLC All Rights Reserved.
|
---|
161 | *
|
---|
162 | * Use of this source code is governed by an MIT-style license that can be
|
---|
163 | * found in the LICENSE file at https://angular.io/license
|
---|
164 | */
|
---|
165 |
|
---|
166 | /**
|
---|
167 | * @license
|
---|
168 | * Copyright Google LLC All Rights Reserved.
|
---|
169 | *
|
---|
170 | * Use of this source code is governed by an MIT-style license that can be
|
---|
171 | * found in the LICENSE file at https://angular.io/license
|
---|
172 | */
|
---|
173 |
|
---|
174 | /**
|
---|
175 | * @license
|
---|
176 | * Copyright Google LLC All Rights Reserved.
|
---|
177 | *
|
---|
178 | * Use of this source code is governed by an MIT-style license that can be
|
---|
179 | * found in the LICENSE file at https://angular.io/license
|
---|
180 | */
|
---|
181 |
|
---|
182 | export { MatGridListHarness, MatGridTileHarness };
|
---|
183 | //# sourceMappingURL=testing.js.map
|
---|