@angular/material
Version:
Angular Material
1 lines • 8.26 kB
Source Map (JSON)
{"version":3,"file":"slide-toggle-testing.mjs","sources":["../../../../../darwin_arm64-fastbuild-ST-fdfa778d11ba/bin/src/material/slide-toggle/testing/slide-toggle-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 {\n ComponentHarness,\n ComponentHarnessConstructor,\n HarnessPredicate,\n} from '@angular/cdk/testing';\nimport {coerceBooleanProperty} from '@angular/cdk/coercion';\nimport {SlideToggleHarnessFilters} from './slide-toggle-harness-filters';\n\n/** Harness for interacting with a mat-slide-toggle in tests. */\nexport class MatSlideToggleHarness extends ComponentHarness {\n private _label = this.locatorFor('label');\n _nativeElement = this.locatorFor('button');\n static hostSelector = '.mat-mdc-slide-toggle';\n\n /**\n * Gets a `HarnessPredicate` that can be used to search for a slide-toggle w/ specific attributes.\n * @param options Options for narrowing the search:\n * - `selector` finds a slide-toggle whose host element matches the given selector.\n * - `label` finds a slide-toggle with specific label text.\n * @return a `HarnessPredicate` configured with the given options.\n */\n static with<T extends MatSlideToggleHarness>(\n this: ComponentHarnessConstructor<T>,\n options: SlideToggleHarnessFilters = {},\n ): HarnessPredicate<T> {\n return (\n new HarnessPredicate(this, options)\n .addOption('label', options.label, (harness, label) =>\n HarnessPredicate.stringMatches(harness.getLabelText(), label),\n )\n // We want to provide a filter option for \"name\" because the name of the slide-toggle is\n // only set on the underlying input. This means that it's not possible for developers\n // to retrieve the harness of a specific checkbox with name through a CSS selector.\n .addOption(\n 'name',\n options.name,\n async (harness, name) => (await harness.getName()) === name,\n )\n .addOption(\n 'checked',\n options.checked,\n async (harness, checked) => (await harness.isChecked()) == checked,\n )\n .addOption(\n 'disabled',\n options.disabled,\n async (harness, disabled) => (await harness.isDisabled()) == disabled,\n )\n );\n }\n\n /** Toggle the checked state of the slide-toggle. */\n async toggle(): Promise<void> {\n return (await this._nativeElement()).click();\n }\n\n /** Whether the slide-toggle is checked. */\n async isChecked(): Promise<boolean> {\n const checked = (await this._nativeElement()).getAttribute('aria-checked');\n return coerceBooleanProperty(await checked);\n }\n\n /** Whether the slide-toggle is disabled. */\n async isDisabled(): Promise<boolean> {\n const nativeElement = await this._nativeElement();\n const disabled = await nativeElement.getAttribute('disabled');\n\n if (disabled !== null) {\n return coerceBooleanProperty(disabled);\n }\n\n return (await nativeElement.getAttribute('aria-disabled')) === 'true';\n }\n\n /** Whether the slide-toggle is required. */\n async isRequired(): Promise<boolean> {\n const ariaRequired = await (await this._nativeElement()).getAttribute('aria-required');\n return ariaRequired === 'true';\n }\n\n /** Whether the slide-toggle is valid. */\n async isValid(): Promise<boolean> {\n const invalid = (await this.host()).hasClass('ng-invalid');\n return !(await invalid);\n }\n\n /** Gets the slide-toggle's name. */\n async getName(): Promise<string | null> {\n return (await this._nativeElement()).getAttribute('name');\n }\n\n /** Gets the slide-toggle's aria-label. */\n async getAriaLabel(): Promise<string | null> {\n return (await this._nativeElement()).getAttribute('aria-label');\n }\n\n /** Gets the slide-toggle's aria-labelledby. */\n async getAriaLabelledby(): Promise<string | null> {\n return (await this._nativeElement()).getAttribute('aria-labelledby');\n }\n\n /** Gets the slide-toggle's label text. */\n async getLabelText(): Promise<string> {\n return (await this._label()).text();\n }\n\n /** Focuses the slide-toggle. */\n async focus(): Promise<void> {\n return (await this._nativeElement()).focus();\n }\n\n /** Blurs the slide-toggle. */\n async blur(): Promise<void> {\n return (await this._nativeElement()).blur();\n }\n\n /** Whether the slide-toggle is focused. */\n async isFocused(): Promise<boolean> {\n return (await this._nativeElement()).isFocused();\n }\n\n /**\n * Puts the slide-toggle in a checked state by toggling it if it is currently unchecked, or doing\n * 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 slide-toggle in an unchecked state by toggling it if it is currently checked, or doing\n * nothing if it is already unchecked.\n */\n async uncheck(): Promise<void> {\n if (await this.isChecked()) {\n await this.toggle();\n }\n }\n}\n"],"names":["MatSlideToggleHarness","ComponentHarness","_label","locatorFor","_nativeElement","hostSelector","with","options","HarnessPredicate","addOption","label","harness","stringMatches","getLabelText","name","getName","checked","isChecked","disabled","isDisabled","toggle","click","getAttribute","coerceBooleanProperty","nativeElement","isRequired","ariaRequired","isValid","invalid","host","hasClass","getAriaLabel","getAriaLabelledby","text","focus","blur","isFocused","check","uncheck"],"mappings":";;;AAiBM,MAAOA,qBAAsB,SAAQC,gBAAgB,CAAA;AACjDC,EAAAA,MAAM,GAAG,IAAI,CAACC,UAAU,CAAC,OAAO,CAAC;AACzCC,EAAAA,cAAc,GAAG,IAAI,CAACD,UAAU,CAAC,QAAQ,CAAC;EAC1C,OAAOE,YAAY,GAAG,uBAAuB;AAS7C,EAAA,OAAOC,IAAIA,CAETC,OAAA,GAAqC,EAAE,EAAA;IAEvC,OACE,IAAIC,gBAAgB,CAAC,IAAI,EAAED,OAAO,CAAA,CAC/BE,SAAS,CAAC,OAAO,EAAEF,OAAO,CAACG,KAAK,EAAE,CAACC,OAAO,EAAED,KAAK,KAChDF,gBAAgB,CAACI,aAAa,CAACD,OAAO,CAACE,YAAY,EAAE,EAAEH,KAAK,CAAC,CAAA,CAK9DD,SAAS,CACR,MAAM,EACNF,OAAO,CAACO,IAAI,EACZ,OAAOH,OAAO,EAAEG,IAAI,KAAK,CAAC,MAAMH,OAAO,CAACI,OAAO,EAAE,MAAMD,IAAI,CAAA,CAE5DL,SAAS,CACR,SAAS,EACTF,OAAO,CAACS,OAAO,EACf,OAAOL,OAAO,EAAEK,OAAO,KAAK,CAAC,MAAML,OAAO,CAACM,SAAS,EAAE,KAAKD,OAAO,CAAA,CAEnEP,SAAS,CACR,UAAU,EACVF,OAAO,CAACW,QAAQ,EAChB,OAAOP,OAAO,EAAEO,QAAQ,KAAK,CAAC,MAAMP,OAAO,CAACQ,UAAU,EAAE,KAAKD,QAAQ,CACtE;AAEP;E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