source: trip-planner-front/node_modules/@angular/material/esm2015/grid-list/testing/grid-list-harness.js

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

initial commit

  • Property mode set to 100644
File size: 11.7 KB
Line 
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 */
8import { __awaiter } from "tslib";
9import { ComponentHarness, HarnessPredicate, parallel } from '@angular/cdk/testing';
10import { ɵTileCoordinator as TileCoordinator } from '@angular/material/grid-list';
11import { MatGridTileHarness } from './grid-tile-harness';
12/** Harness for interacting with a standard `MatGridList` in tests. */
13export class MatGridListHarness extends ComponentHarness {
14 constructor() {
15 super(...arguments);
16 /**
17 * Tile coordinator that is used by the "MatGridList" for computing
18 * positions of tiles. We leverage the coordinator to provide an API
19 * for retrieving tiles based on visual tile positions.
20 */
21 this._tileCoordinator = new TileCoordinator();
22 }
23 /**
24 * Gets a `HarnessPredicate` that can be used to search for a `MatGridListHarness`
25 * that meets certain criteria.
26 * @param options Options for filtering which dialog instances are considered a match.
27 * @return a `HarnessPredicate` configured with the given options.
28 */
29 static with(options = {}) {
30 return new HarnessPredicate(MatGridListHarness, options);
31 }
32 /** Gets all tiles of the grid-list. */
33 getTiles(filters = {}) {
34 return __awaiter(this, void 0, void 0, function* () {
35 return yield this.locatorForAll(MatGridTileHarness.with(filters))();
36 });
37 }
38 /** Gets the amount of columns of the grid-list. */
39 getColumns() {
40 return __awaiter(this, void 0, void 0, function* () {
41 return Number(yield (yield this.host()).getAttribute('cols'));
42 });
43 }
44 /**
45 * Gets a tile of the grid-list that is located at the given location.
46 * @param row Zero-based row index.
47 * @param column Zero-based column index.
48 */
49 getTileAtPosition({ row, column }) {
50 return __awaiter(this, void 0, void 0, function* () {
51 const [tileHarnesses, columns] = yield parallel(() => [this.getTiles(), this.getColumns()]);
52 const tileSpans = tileHarnesses.map(t => parallel(() => [t.getColspan(), t.getRowspan()]));
53 const tiles = (yield parallel(() => tileSpans))
54 .map(([colspan, rowspan]) => ({ colspan, rowspan }));
55 // Update the tile coordinator to reflect the current column amount and
56 // rendered tiles. We update upon every call of this method since we do not
57 // know if tiles have been added, removed or updated (in terms of rowspan/colspan).
58 this._tileCoordinator.update(columns, tiles);
59 // The tile coordinator respects the colspan and rowspan for calculating the positions
60 // of tiles, but it does not create multiple position entries if a tile spans over multiple
61 // columns or rows. We want to provide an API where developers can retrieve a tile based on
62 // any position that lies within the visual tile boundaries. For example: If a tile spans
63 // over two columns, then the same tile should be returned for either column indices.
64 for (let i = 0; i < this._tileCoordinator.positions.length; i++) {
65 const position = this._tileCoordinator.positions[i];
66 const { rowspan, colspan } = tiles[i];
67 // Return the tile harness if the given position visually resolves to the tile.
68 if (column >= position.col && column <= position.col + colspan - 1 && row >= position.row &&
69 row <= position.row + rowspan - 1) {
70 return tileHarnesses[i];
71 }
72 }
73 throw Error('Could not find tile at given position.');
74 });
75 }
76}
77/** The selector for the host element of a `MatGridList` instance. */
78MatGridListHarness.hostSelector = '.mat-grid-list';
79//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ3JpZC1saXN0LWhhcm5lc3MuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi9zcmMvbWF0ZXJpYWwvZ3JpZC1saXN0L3Rlc3RpbmcvZ3JpZC1saXN0LWhhcm5lc3MudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HOztBQUVILE9BQU8sRUFBQyxnQkFBZ0IsRUFBRSxnQkFBZ0IsRUFBRSxRQUFRLEVBQUMsTUFBTSxzQkFBc0IsQ0FBQztBQUNsRixPQUFPLEVBQUMsZ0JBQWdCLElBQUksZUFBZSxFQUFDLE1BQU0sNkJBQTZCLENBQUM7QUFFaEYsT0FBTyxFQUFDLGtCQUFrQixFQUFDLE1BQU0scUJBQXFCLENB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4nKTtcbiAgfVxufVxuIl19
Note: See TracBrowser for help on using the repository browser.