blob: 6a062b2a93a37c0e132a3eb479b89a1f6bb94df0 [file] [log] [blame]
{"version":3,"file":"grid-list__testing.js","sources":["../../../../../../src/material/grid-list/testing/grid-tile-harness.ts","../../../../../../src/material/grid-list/testing/grid-list-harness.ts","../../../../../../src/material/grid-list/testing/grid-list-harness-filters.ts","../../../../../../src/material/grid-list/testing/public-api.ts","../../../../../../src/material/grid-list/testing/index.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport {ContentContainerComponentHarness, HarnessPredicate} from '@angular/cdk/testing';\nimport {GridTileHarnessFilters} from './grid-list-harness-filters';\n\n/** Selectors for the various `mat-grid-tile` sections that may contain user content. */\nexport const enum MatGridTileSection {\n HEADER = '.mat-grid-tile-header',\n FOOTER = '.mat-grid-tile-footer'\n}\n\n/** Harness for interacting with a standard `MatGridTitle` in tests. */\nexport class MatGridTileHarness extends ContentContainerComponentHarness<MatGridTileSection> {\n /** The selector for the host element of a `MatGridTile` instance. */\n static hostSelector = '.mat-grid-tile';\n\n /**\n * Gets a `HarnessPredicate` that can be used to search for a `MatGridTileHarness`\n * that meets certain criteria.\n * @param options Options for filtering which dialog instances are considered a match.\n * @return a `HarnessPredicate` configured with the given options.\n */\n static with(options: GridTileHarnessFilters = {}): HarnessPredicate<MatGridTileHarness> {\n return new HarnessPredicate(MatGridTileHarness, options)\n .addOption(\n 'headerText', options.headerText,\n (harness, pattern) => HarnessPredicate.stringMatches(harness.getHeaderText(), pattern))\n .addOption(\n 'footerText', options.footerText,\n (harness, pattern) => HarnessPredicate.stringMatches(harness.getFooterText(), pattern));\n }\n\n private _header = this.locatorForOptional(MatGridTileSection.HEADER);\n private _footer = this.locatorForOptional(MatGridTileSection.FOOTER);\n private _avatar = this.locatorForOptional('.mat-grid-avatar');\n\n /** Gets the amount of rows that the grid-tile takes up. */\n async getRowspan(): Promise<number> {\n return Number(await (await this.host()).getAttribute('rowspan'));\n }\n\n /** Gets the amount of columns that the grid-tile takes up. */\n async getColspan(): Promise<number> {\n return Number(await (await this.host()).getAttribute('colspan'));\n }\n\n /** Whether the grid-tile has a header. */\n async hasHeader(): Promise<boolean> {\n return (await this._header()) !== null;\n }\n\n /** Whether the grid-tile has a footer. */\n async hasFooter(): Promise<boolean> {\n return (await this._footer()) !== null;\n }\n\n /** Whether the grid-tile has an avatar. */\n async hasAvatar(): Promise<boolean> {\n return (await this._avatar()) !== null;\n }\n\n /** Gets the text of the header if present. */\n async getHeaderText(): Promise<string|null> {\n // For performance reasons, we do not use \"hasHeader\" as\n // we would then need to query twice for the header.\n const headerEl = await this._header();\n return headerEl ? headerEl.text() : null;\n }\n\n /** Gets the text of the footer if present. */\n async getFooterText(): Promise<string|null> {\n // For performance reasons, we do not use \"hasFooter\" as\n // we would then need to query twice for the footer.\n const headerEl = await this._footer();\n return headerEl ? headerEl.text() : null;\n }\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport {ComponentHarness, HarnessPredicate, parallel} from '@angular/cdk/testing';\nimport {ɵTileCoordinator as TileCoordinator} from '@angular/material/grid-list';\nimport {GridListHarnessFilters, GridTileHarnessFilters} from './grid-list-harness-filters';\nimport {MatGridTileHarness} from './grid-tile-harness';\n\n/** Harness for interacting with a standard `MatGridList` in tests. */\nexport class MatGridListHarness extends ComponentHarness {\n /** The selector for the host element of a `MatGridList` instance. */\n static hostSelector = '.mat-grid-list';\n\n /**\n * Gets a `HarnessPredicate` that can be used to search for a `MatGridListHarness`\n * that meets certain criteria.\n * @param options Options for filtering which dialog instances are considered a match.\n * @return a `HarnessPredicate` configured with the given options.\n */\n static with(options: GridListHarnessFilters = {}): HarnessPredicate<MatGridListHarness> {\n return new HarnessPredicate(MatGridListHarness, options);\n }\n\n /**\n * Tile coordinator that is used by the \"MatGridList\" for computing\n * positions of tiles. We leverage the coordinator to provide an API\n * for retrieving tiles based on visual tile positions.\n */\n private _tileCoordinator = new TileCoordinator();\n\n /** Gets all tiles of the grid-list. */\n async getTiles(filters: GridTileHarnessFilters = {}): Promise<MatGridTileHarness[]> {\n return await this.locatorForAll(MatGridTileHarness.with(filters))();\n }\n\n /** Gets the amount of columns of the grid-list. */\n async getColumns(): Promise<number> {\n return Number(await (await this.host()).getAttribute('cols'));\n }\n\n /**\n * Gets a tile of the grid-list that is located at the given location.\n * @param row Zero-based row index.\n * @param column Zero-based column index.\n */\n async getTileAtPosition({row, column}: {row: number, column: number}):\n Promise<MatGridTileHarness> {\n const [tileHarnesses, columns] = await parallel(() => [this.getTiles(), this.getColumns()]);\n const tileSpans = tileHarnesses.map(t => parallel(() => [t.getColspan(), t.getRowspan()]));\n const tiles = (await parallel(() => tileSpans))\n .map(([colspan, rowspan]) => ({colspan, rowspan}));\n // Update the tile coordinator to reflect the current column amount and\n // rendered tiles. We update upon every call of this method since we do not\n // know if tiles have been added, removed or updated (in terms of rowspan/colspan).\n this._tileCoordinator.update(columns, tiles);\n // The tile coordinator respects the colspan and rowspan for calculating the positions\n // of tiles, but it does not create multiple position entries if a tile spans over multiple\n // columns or rows. We want to provide an API where developers can retrieve a tile based on\n // any position that lies within the visual tile boundaries. For example: If a tile spans\n // over two columns, then the same tile should be returned for either column indices.\n for (let i = 0; i < this._tileCoordinator.positions.length; i++) {\n const position = this._tileCoordinator.positions[i];\n const {rowspan, colspan} = tiles[i];\n // Return the tile harness if the given position visually resolves to the tile.\n if (column >= position.col && column <= position.col + colspan - 1 && row >= position.row &&\n row <= position.row + rowspan - 1) {\n return tileHarnesses[i];\n }\n }\n throw Error('Could not find tile at given position.');\n }\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport {BaseHarnessFilters} from '@angular/cdk/testing';\n\n/** A set of criteria that can be used to filter a list of `MatGridListHarness` instances. */\nexport interface GridListHarnessFilters extends BaseHarnessFilters {}\n\n/** A set of criteria that can be used to filter a list of `MatTileHarness` instances. */\nexport interface GridTileHarnessFilters extends BaseHarnessFilters {\n /** Text the grid-tile header should match. */\n headerText?: string|RegExp;\n /** Text the grid-tile footer should match. */\n footerText?: string|RegExp;\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nexport * from './grid-tile-harness';\nexport * from './grid-list-harness';\nexport * from './grid-list-harness-filters';\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nexport * from './public-api';\n"],"names":["TileCoordinator"],"mappings":";;;;AAAA;;;;;;;AAiBA;AACA,MAAa,kBAAmB,SAAQ,gCAAoD;IAA5F;;QAoBU,YAAO,GAAG,IAAI,CAAC,kBAAkB,sCAA2B,CAAC;QAC7D,YAAO,GAAG,IAAI,CAAC,kBAAkB,sCAA2B,CAAC;QAC7D,YAAO,GAAG,IAAI,CAAC,kBAAkB,CAAC,kBAAkB,CAAC,CAAC;KA0C/D;;;;;;;IAtDC,OAAO,IAAI,CAAC,UAAkC,EAAE;QAC9C,OAAO,IAAI,gBAAgB,CAAC,kBAAkB,EAAE,OAAO,CAAC;aACnD,SAAS,CACN,YAAY,EAAE,OAAO,CAAC,UAAU,EAChC,CAAC,OAAO,EAAE,OAAO,KAAK,gBAAgB,CAAC,aAAa,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,OAAO,CAAC,CAAC;aAC1F,SAAS,CACN,YAAY,EAAE,OAAO,CAAC,UAAU,EAChC,CAAC,OAAO,EAAE,OAAO,KAAK,gBAAgB,CAAC,aAAa,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC;KACjG;;IAOK,UAAU;;YACd,OAAO,MAAM,CAAC,MAAM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