UNPKG

@angular/material

Version:
1 lines 16.7 kB
{"version":3,"file":"stepper-testing.mjs","sources":["../../../../../darwin_arm64-fastbuild-ST-fdfa778d11ba/bin/src/material/stepper/testing/step-harness.ts","../../../../../darwin_arm64-fastbuild-ST-fdfa778d11ba/bin/src/material/stepper/testing/step-harness-filters.ts","../../../../../darwin_arm64-fastbuild-ST-fdfa778d11ba/bin/src/material/stepper/testing/stepper-harness.ts","../../../../../darwin_arm64-fastbuild-ST-fdfa778d11ba/bin/src/material/stepper/testing/stepper-button-harnesses.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 ContentContainerComponentHarness,\n HarnessPredicate,\n HarnessLoader,\n} from '@angular/cdk/testing';\nimport {StepHarnessFilters} from './step-harness-filters';\n\n/** Harness for interacting with a standard Angular Material step in tests. */\nexport class MatStepHarness extends ContentContainerComponentHarness<string> {\n /** The selector for the host element of a `MatStep` instance. */\n static hostSelector = '.mat-step-header';\n\n /**\n * Gets a `HarnessPredicate` that can be used to search for a `MatStepHarness` that meets\n * certain criteria.\n * @param options Options for filtering which steps are considered a match.\n * @return a `HarnessPredicate` configured with the given options.\n */\n static with(options: StepHarnessFilters = {}): HarnessPredicate<MatStepHarness> {\n return new HarnessPredicate(MatStepHarness, options)\n .addOption('label', options.label, (harness, label) =>\n HarnessPredicate.stringMatches(harness.getLabel(), label),\n )\n .addOption(\n 'selected',\n options.selected,\n async (harness, selected) => (await harness.isSelected()) === selected,\n )\n .addOption(\n 'completed',\n options.completed,\n async (harness, completed) => (await harness.isCompleted()) === completed,\n )\n .addOption(\n 'invalid',\n options.invalid,\n async (harness, invalid) => (await harness.hasErrors()) === invalid,\n );\n }\n\n /** Gets the label of the step. */\n async getLabel(): Promise<string> {\n return (await this.locatorFor('.mat-step-text-label')()).text();\n }\n\n /** Gets the `aria-label` of the step. */\n async getAriaLabel(): Promise<string | null> {\n return (await this.host()).getAttribute('aria-label');\n }\n\n /** Gets the value of the `aria-labelledby` attribute. */\n async getAriaLabelledby(): Promise<string | null> {\n return (await this.host()).getAttribute('aria-labelledby');\n }\n\n /** Whether the step is selected. */\n async isSelected(): Promise<boolean> {\n const host = await this.host();\n return (\n (await host.getAttribute('aria-selected')) === 'true' ||\n (await host.getAttribute('aria-current')) === 'step'\n );\n }\n\n /** Whether the step has been filled out. */\n async isCompleted(): Promise<boolean> {\n const state = await this._getIconState();\n return state === 'done' || (state === 'edit' && !(await this.isSelected()));\n }\n\n /**\n * Whether the step is currently showing its error state. Note that this doesn't mean that there\n * are or aren't any invalid form controls inside the step, but that the step is showing its\n * error-specific styling which depends on there being invalid controls, as well as the\n * `ErrorStateMatcher` determining that an error should be shown and that the `showErrors`\n * option was enabled through the `STEPPER_GLOBAL_OPTIONS` injection token.\n */\n async hasErrors(): Promise<boolean> {\n return (await this._getIconState()) === 'error';\n }\n\n /** Whether the step is optional. */\n async isOptional(): Promise<boolean> {\n // If the node with the optional text is present, it means that the step is optional.\n const optionalNode = await this.locatorForOptional('.mat-step-optional')();\n return !!optionalNode;\n }\n\n /**\n * Selects the given step by clicking on the label. The step may not be selected\n * if the stepper doesn't allow it (e.g. if there are validation errors).\n */\n async select(): Promise<void> {\n await (await this.host()).click();\n }\n\n protected override async getRootHarnessLoader(): Promise<HarnessLoader> {\n const contentId = await (await this.host()).getAttribute('aria-controls');\n return this.documentRootLocatorFactory().harnessLoaderFor(`#${contentId}`);\n }\n\n /**\n * Gets the state of the step. Note that we have a `StepState` which we could use to type the\n * return value, but it's basically the same as `string`, because the type has `| string`.\n */\n private async _getIconState(): Promise<string> {\n // The state is exposed on the icon with a class that looks like `mat-step-icon-state-{{state}}`\n const icon = await this.locatorFor('.mat-step-icon')();\n const classes = (await icon.getAttribute('class'))!;\n const match = classes.match(/mat-step-icon-state-([a-z]+)/);\n\n if (!match) {\n throw Error(`Could not determine step state from \"${classes}\".`);\n }\n\n return match[1];\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 */\nimport {BaseHarnessFilters} from '@angular/cdk/testing';\n\n/** Possible orientations for a stepper. */\nexport enum StepperOrientation {\n HORIZONTAL,\n VERTICAL,\n}\n\n/** A set of criteria that can be used to filter a list of `MatStepHarness` instances. */\nexport interface StepHarnessFilters extends BaseHarnessFilters {\n /** Only find instances whose label matches the given value. */\n label?: string | RegExp;\n /** Only find steps with the given selected state. */\n selected?: boolean;\n /** Only find completed steps. */\n completed?: boolean;\n /** Only find steps that have errors. */\n invalid?: boolean;\n}\n\n/** A set of criteria that can be used to filter a list of `MatStepperHarness` instances. */\nexport interface StepperHarnessFilters extends BaseHarnessFilters {\n /** Only find instances whose orientation matches the given value. */\n orientation?: StepperOrientation;\n}\n\n/**\n * A set of criteria that can be used to filter a list of\n * `MatStepperNextHarness` and `MatStepperPreviousHarness` instances.\n */\nexport interface StepperButtonHarnessFilters extends BaseHarnessFilters {\n /** Only find instances whose text matches the given value. */\n text?: 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.dev/license\n */\n\nimport {ComponentHarness, HarnessPredicate} from '@angular/cdk/testing';\nimport {MatStepHarness} from './step-harness';\nimport {\n StepperHarnessFilters,\n StepHarnessFilters,\n StepperOrientation,\n} from './step-harness-filters';\n\n/** Harness for interacting with a standard Material stepper in tests. */\nexport class MatStepperHarness extends ComponentHarness {\n /** The selector for the host element of a `MatStepper` instance. */\n static hostSelector = '.mat-stepper-horizontal, .mat-stepper-vertical';\n\n /**\n * Gets a `HarnessPredicate` that can be used to search for a `MatStepperHarness` that meets\n * certain criteria.\n * @param options Options for filtering which stepper instances are considered a match.\n * @return a `HarnessPredicate` configured with the given options.\n */\n static with(options: StepperHarnessFilters = {}): HarnessPredicate<MatStepperHarness> {\n return new HarnessPredicate(MatStepperHarness, options).addOption(\n 'orientation',\n options.orientation,\n async (harness, orientation) => (await harness.getOrientation()) === orientation,\n );\n }\n\n /**\n * Gets the list of steps in the stepper.\n * @param filter Optionally filters which steps are included.\n */\n async getSteps(filter: StepHarnessFilters = {}): Promise<MatStepHarness[]> {\n return this.locatorForAll(MatStepHarness.with(filter))();\n }\n\n /** Gets the orientation of the stepper. */\n async getOrientation(): Promise<StepperOrientation> {\n const host = await this.host();\n return (await host.hasClass('mat-stepper-horizontal'))\n ? StepperOrientation.HORIZONTAL\n : StepperOrientation.VERTICAL;\n }\n\n /**\n * Selects a step in this stepper.\n * @param filter An optional filter to apply to the child steps. The first step matching the\n * filter will be selected.\n */\n async selectStep(filter: StepHarnessFilters = {}): Promise<void> {\n const steps = await this.getSteps(filter);\n if (!steps.length) {\n throw Error(`Cannot find mat-step matching filter ${JSON.stringify(filter)}`);\n }\n await steps[0].select();\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 {StepperButtonHarnessFilters} from './step-harness-filters';\n\n/** Base class for stepper button harnesses. */\nabstract class StepperButtonHarness extends ComponentHarness {\n /** Gets the text of the button. */\n async getText(): Promise<string> {\n return (await this.host()).text();\n }\n\n /** Clicks the button. */\n async click(): Promise<void> {\n return (await this.host()).click();\n }\n}\n\n/** Harness for interacting with a standard Angular Material stepper next button in tests. */\nexport class MatStepperNextHarness extends StepperButtonHarness {\n /** The selector for the host element of a `MatStep` instance. */\n static hostSelector = '.mat-stepper-next';\n\n /**\n * Gets a `HarnessPredicate` that can be used to search for a `MatStepperNextHarness` that meets\n * certain criteria.\n * @param options Options for filtering which steps are considered a match.\n * @return a `HarnessPredicate` configured with the given options.\n */\n static with(options: StepperButtonHarnessFilters = {}): HarnessPredicate<MatStepperNextHarness> {\n return new HarnessPredicate(MatStepperNextHarness, options).addOption(\n 'text',\n options.text,\n (harness, text) => HarnessPredicate.stringMatches(harness.getText(), text),\n );\n }\n}\n\n/** Harness for interacting with a standard Angular Material stepper previous button in tests. */\nexport class MatStepperPreviousHarness extends StepperButtonHarness {\n /** The selector for the host element of a `MatStep` instance. */\n static hostSelector = '.mat-stepper-previous';\n\n /**\n * Gets a `HarnessPredicate` that can be used to search for a `MatStepperPreviousHarness`\n * that meets certain criteria.\n * @param options Options for filtering which steps are considered a match.\n * @return a `HarnessPredicate` configured with the given options.\n */\n static with(\n options: StepperButtonHarnessFilters = {},\n ): HarnessPredicate<MatStepperPreviousHarness> {\n return new HarnessPredicate(MatStepperPreviousHarness, options).addOption(\n 'text',\n options.text,\n (harness, text) => HarnessPredicate.stringMatches(harness.getText(), text),\n );\n }\n}\n"],"names":["MatStepHarness","ContentContainerComponentHarness","hostSelector","with","options","HarnessPredicate","addOption","label","harness","stringMatches","getLabel","selected","isSelected","completed","isCompleted","invalid","hasErrors","locatorFor","text","getAriaLabel","host","getAttribute","getAriaLabelledby","state","_getIconState","isOptional","optionalNode","locatorForOptional","select","click","getRootHarnessLoader","contentId","documentRootLocatorFactory","harnessLoaderFor","icon","classes","match","Error","StepperOrientation","MatStepperHarness","ComponentHarness","orientation","getOrientation","getSteps","filter","locatorForAll","hasClass","HORIZONTAL","VERTICAL","selectStep","steps","length","JSON","stringify","StepperButtonHarness","getText","MatStepperNextHarness","MatStepperPreviousHarness"],"mappings":";;AAgBM,MAAOA,cAAe,SAAQC,gCAAwC,CAAA;EAE1E,OAAOC,YAAY,GAAG,kBAAkB;AAQxC,EAAA,OAAOC,IAAIA,CAACC,OAAA,GAA8B,EAAE,EAAA;IAC1C,OAAO,IAAIC,gBAAgB,CAACL,cAAc,EAAEI,OAAO,CAAA,CAChDE,SAAS,CAAC,OAAO,EAAEF,OAAO,CAACG,KAAK,EAAE,CAACC,OAAO,EAAED,KAAK,KAChDF,gBAAgB,CAACI,aAAa,CAACD,OAA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