UNPKG

@angular/material

Version:
1 lines 11.3 kB
{"version":3,"file":"button-toggle-testing.mjs","sources":["../../../../../darwin_arm64-fastbuild-ST-fdfa778d11ba/bin/src/material/button-toggle/testing/button-toggle-harness.ts","../../../../../darwin_arm64-fastbuild-ST-fdfa778d11ba/bin/src/material/button-toggle/testing/button-toggle-group-harness.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.dev/license\n */\n\nimport {ComponentHarness, HarnessPredicate, parallel} from '@angular/cdk/testing';\nimport {coerceBooleanProperty} from '@angular/cdk/coercion';\nimport {MatButtonToggleAppearance} from '../button-toggle';\nimport {ButtonToggleHarnessFilters} from './button-toggle-harness-filters';\n\n/** Harness for interacting with a standard mat-button-toggle in tests. */\nexport class MatButtonToggleHarness extends ComponentHarness {\n /** The selector for the host element of a `MatButton` instance. */\n static hostSelector = '.mat-button-toggle';\n\n private _label = this.locatorFor('.mat-button-toggle-label-content');\n private _button = this.locatorFor('.mat-button-toggle-button');\n\n /**\n * Gets a `HarnessPredicate` that can be used to search for a `MatButtonToggleHarness` that meets\n * certain criteria.\n * @param options Options for filtering which button toggle instances are considered a match.\n * @return a `HarnessPredicate` configured with the given options.\n */\n static with(options: ButtonToggleHarnessFilters = {}): HarnessPredicate<MatButtonToggleHarness> {\n return new HarnessPredicate(MatButtonToggleHarness, options)\n .addOption('text', options.text, (harness, text) =>\n HarnessPredicate.stringMatches(harness.getText(), text),\n )\n .addOption('name', options.name, (harness, name) =>\n HarnessPredicate.stringMatches(harness.getName(), name),\n )\n .addOption(\n 'checked',\n options.checked,\n async (harness, checked) => (await harness.isChecked()) === checked,\n )\n .addOption('disabled', options.disabled, async (harness, disabled) => {\n return (await harness.isDisabled()) === disabled;\n });\n }\n\n /** Gets a boolean promise indicating if the button toggle is checked. */\n async isChecked(): Promise<boolean> {\n const button = await this._button();\n const [checked, pressed] = await parallel(() => [\n button.getAttribute('aria-checked'),\n button.getAttribute('aria-pressed'),\n ]);\n return coerceBooleanProperty(checked) || coerceBooleanProperty(pressed);\n }\n\n /** Gets a boolean promise indicating if the button toggle is disabled. */\n async isDisabled(): Promise<boolean> {\n const host = await this.host();\n return host.hasClass('mat-button-toggle-disabled');\n }\n\n /** Gets a promise for the button toggle's name. */\n async getName(): Promise<string | null> {\n return (await this._button()).getAttribute('name');\n }\n\n /** Gets a promise for the button toggle's aria-label. */\n async getAriaLabel(): Promise<string | null> {\n return (await this._button()).getAttribute('aria-label');\n }\n\n /** Gets a promise for the button toggles's aria-labelledby. */\n async getAriaLabelledby(): Promise<string | null> {\n return (await this._button()).getAttribute('aria-labelledby');\n }\n\n /** Gets a promise for the button toggle's text. */\n async getText(): Promise<string> {\n return (await this._label()).text();\n }\n\n /** Gets the appearance that the button toggle is using. */\n async getAppearance(): Promise<MatButtonToggleAppearance> {\n const host = await this.host();\n const className = 'mat-button-toggle-appearance-standard';\n return (await host.hasClass(className)) ? 'standard' : 'legacy';\n }\n\n /** Focuses the toggle. */\n async focus(): Promise<void> {\n return (await this._button()).focus();\n }\n\n /** Blurs the toggle. */\n async blur(): Promise<void> {\n return (await this._button()).blur();\n }\n\n /** Whether the toggle is focused. */\n async isFocused(): Promise<boolean> {\n return (await this._button()).isFocused();\n }\n\n /** Toggle the checked state of the buttons toggle. */\n async toggle(): Promise<void> {\n return (await this._button()).click();\n }\n\n /**\n * Puts the button toggle in a checked state by toggling it if it's\n * currently unchecked, or doing nothing if it is already checked.\n */\n async check(): Promise<void> {\n if (!(await this.isChecked())) {\n await this.toggle();\n }\n }\n\n /**\n * Puts the button toggle in an unchecked state by toggling it if it's\n * currently checked, or doing nothing if it's already unchecked.\n */\n async uncheck(): Promise<void> {\n if (await this.isChecked()) {\n await this.toggle();\n }\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.dev/license\n */\n\nimport {ComponentHarness, HarnessPredicate} from '@angular/cdk/testing';\nimport {MatButtonToggleAppearance} from '../button-toggle';\nimport {ButtonToggleGroupHarnessFilters} from './button-toggle-group-harness-filters';\nimport {ButtonToggleHarnessFilters} from './button-toggle-harness-filters';\nimport {MatButtonToggleHarness} from './button-toggle-harness';\n\n/** Harness for interacting with a standard mat-button-toggle in tests. */\nexport class MatButtonToggleGroupHarness extends ComponentHarness {\n /** The selector for the host element of a `MatButton` instance. */\n static hostSelector = '.mat-button-toggle-group';\n\n /**\n * Gets a `HarnessPredicate` that can be used to search for a `MatButtonToggleGroupHarness`\n * that meets certain criteria.\n * @param options Options for filtering which button toggle instances are considered a match.\n * @return a `HarnessPredicate` configured with the given options.\n */\n static with(\n options: ButtonToggleGroupHarnessFilters = {},\n ): HarnessPredicate<MatButtonToggleGroupHarness> {\n return new HarnessPredicate(MatButtonToggleGroupHarness, options).addOption(\n 'disabled',\n options.disabled,\n async (harness, disabled) => {\n return (await harness.isDisabled()) === disabled;\n },\n );\n }\n\n /**\n * Gets the button toggles that are inside the group.\n * @param filter Optionally filters which toggles are included.\n */\n async getToggles(filter: ButtonToggleHarnessFilters = {}): Promise<MatButtonToggleHarness[]> {\n return this.locatorForAll(MatButtonToggleHarness.with(filter))();\n }\n\n /** Gets whether the button toggle group is disabled. */\n async isDisabled(): Promise<boolean> {\n return (await (await this.host()).getAttribute('aria-disabled')) === 'true';\n }\n\n /** Gets whether the button toggle group is laid out vertically. */\n async isVertical(): Promise<boolean> {\n return (await this.host()).hasClass('mat-button-toggle-vertical');\n }\n\n /** Gets the appearance that the group is using. */\n async getAppearance(): Promise<MatButtonToggleAppearance> {\n const host = await this.host();\n const className = 'mat-button-toggle-group-appearance-standard';\n return (await host.hasClass(className)) ? 'standard' : 'legacy';\n }\n}\n"],"names":["MatButtonToggleHarness","ComponentHarness","hostSelector","_label","locatorFor","_button","with","options","HarnessPredicate","addOption","text","harness","stringMatches","getText","name","getName","checked","isChecked","disabled","isDisabled","button","pressed","parallel","getAttribute","coerceBooleanProperty","host","hasClass","getAriaLabel","getAriaLabelledby","getAppearance","className","focus","blur","isFocused","toggle","click","check","uncheck","MatButtonToggleGroupHarness","getToggles","filter","locatorForAll","isVertical"],"mappings":";;;AAcM,MAAOA,sBAAuB,SAAQC,gBAAgB,CAAA;EAE1D,OAAOC,YAAY,GAAG,oBAAoB;AAElCC,EAAAA,MAAM,GAAG,IAAI,CAACC,UAAU,CAAC,kCAAkC,CAAC;AAC5DC,EAAAA,OAAO,GAAG,IAAI,CAACD,UAAU,CAAC,2BAA2B,CAAC;AAQ9D,EAAA,OAAOE,IAAIA,CAACC,OAAA,GAAsC,EAAE,EAAA;IAClD,OAAO,IAAIC,gBAAgB,CAACR,sBAAsB,EAAEO,OAAO,CAAA,CACxDE,SAAS,CAAC,MAAM,EAAEF,OAAO,CAACG,IAAI,EAAE,CAACC,OAAO,EAAED,IAAI,KAC7CF,gBAAgB,CAACI,aAAa,CAACD,OAAO,CAACE,OAAO,EAAE,EAAEH,IAAI,CAAC,CAAA,CAExDD,SAAS,CAAC,MAAM,EAAEF,OAAO,CAACO,IAAI,EAAE,CAACH,OAAO,EAAEG,IAAI,KAC7CN,gBAAgB,CAACI,aAAa,CAACD,OAAO,CAACI,OAAO,EAAE,EAAED,IAAI,CAAC,CAAA,CAExDL,SAAS,CACR,SAAS,EACTF,OAAO,CAACS,OAAO,EACf,OAAOL,OAAO,EAAEK,OAAO,KAAK,CAAC,MAAML,OAAO,CAACM,SAAS,EAAE,MAAMD,OAAO,CAAA,CAEpEP,SAAS,CAAC,UAAU,EAAEF,OAAO,CAACW,QAAQ,EAAE,OAAOP,OAAO,EAAEO,QAAQ,KAAI;MACnE,OAAO,CAAC,MAAMP,OAAO,CAACQ,UAAU,EAAE,MAAMD,QAAQ;AAClD,KAAC,CAAC;AACN;EAGA,MAAMD,SAASA,GAAA;AACb,IAAA,MAAMG,MAAM,GAAG,MAAM,IAAI,CAACf,OAAO,EAAE;IACnC,MAAM,CAACW,OA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