source: trip-planner-front/node_modules/@angular/material/esm2015/table/testing/cell-harness.js@ fa375fe

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

initial commit

  • Property mode set to 100644
File size: 10.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 { HarnessPredicate, ContentContainerComponentHarness } from '@angular/cdk/testing';
10/** Harness for interacting with a standard Angular Material table cell. */
11export class MatCellHarness extends ContentContainerComponentHarness {
12 /**
13 * Gets a `HarnessPredicate` that can be used to search for a table cell with specific attributes.
14 * @param options Options for narrowing the search
15 * @return a `HarnessPredicate` configured with the given options.
16 */
17 static with(options = {}) {
18 return MatCellHarness._getCellPredicate(MatCellHarness, options);
19 }
20 /** Gets the cell's text. */
21 getText() {
22 return __awaiter(this, void 0, void 0, function* () {
23 return (yield this.host()).text();
24 });
25 }
26 /** Gets the name of the column that the cell belongs to. */
27 getColumnName() {
28 return __awaiter(this, void 0, void 0, function* () {
29 const host = yield this.host();
30 const classAttribute = yield host.getAttribute('class');
31 if (classAttribute) {
32 const prefix = 'mat-column-';
33 const name = classAttribute.split(' ').map(c => c.trim()).find(c => c.startsWith(prefix));
34 if (name) {
35 return name.split(prefix)[1];
36 }
37 }
38 throw Error('Could not determine column name of cell.');
39 });
40 }
41 static _getCellPredicate(type, options) {
42 return new HarnessPredicate(type, options)
43 .addOption('text', options.text, (harness, text) => HarnessPredicate.stringMatches(harness.getText(), text))
44 .addOption('columnName', options.columnName, (harness, name) => HarnessPredicate.stringMatches(harness.getColumnName(), name));
45 }
46}
47/** The selector for the host element of a `MatCellHarness` instance. */
48MatCellHarness.hostSelector = '.mat-cell';
49/** Harness for interacting with a standard Angular Material table header cell. */
50export class MatHeaderCellHarness extends MatCellHarness {
51 /**
52 * Gets a `HarnessPredicate` that can be used to search for
53 * a table header cell with specific attributes.
54 * @param options Options for narrowing the search
55 * @return a `HarnessPredicate` configured with the given options.
56 */
57 static with(options = {}) {
58 return MatHeaderCellHarness._getCellPredicate(MatHeaderCellHarness, options);
59 }
60}
61/** The selector for the host element of a `MatHeaderCellHarness` instance. */
62MatHeaderCellHarness.hostSelector = '.mat-header-cell';
63/** Harness for interacting with a standard Angular Material table footer cell. */
64export class MatFooterCellHarness extends MatCellHarness {
65 /**
66 * Gets a `HarnessPredicate` that can be used to search for
67 * a table footer cell with specific attributes.
68 * @param options Options for narrowing the search
69 * @return a `HarnessPredicate` configured with the given options.
70 */
71 static with(options = {}) {
72 return MatFooterCellHarness._getCellPredicate(MatFooterCellHarness, options);
73 }
74}
75/** The selector for the host element of a `MatFooterCellHarness` instance. */
76MatFooterCellHarness.hostSelector = '.mat-footer-cell';
77//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2VsbC1oYXJuZXNzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vLi4vc3JjL21hdGVyaWFsL3RhYmxlL3Rlc3RpbmcvY2VsbC1oYXJuZXNzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7R0FNRzs7QUFFSCxPQUFPLEVBQ0wsZ0JBQWdCLEVBRWhCLGdDQUFnQyxFQUNqQyxNQUFNLHNCQUFzQixDQUFDO0FBRzlCLDJFQUEyRTtBQUMzRSxNQUFNLE9BQU8sY0FBZSxTQUFRLGdDQUFnQztJQUlsRTs7OztPQUlHO0lBQ0gsTUFBTSxDQUFDLElBQUksQ0FBQyxVQUE4QixFQUFFO1FBQzFDLE9BQU8sY0FBYyxDQUFDLGlCQUFpQixDQUFDLGNBQWMsRUFBRSxPQUFPLENBQUMsQ0FBQztJQUNuRSxDQUFDO0lBRUQsNEJBQTRCO0lBQ3RCLE9BQU87O1lBQ1gsT0FBTyxDQUFDLE1BQU0sSUFBSSxDQUF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