option-harness-BFcc-M_4.mjs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { ContentContainerComponentHarness, HarnessPredicate } from '@angular/cdk/testing';
  2. /** Harness for interacting with a `mat-option` in tests. */
  3. class MatOptionHarness extends ContentContainerComponentHarness {
  4. /** Selector used to locate option instances. */
  5. static hostSelector = '.mat-mdc-option';
  6. /** Element containing the option's text. */
  7. _text = this.locatorFor('.mdc-list-item__primary-text');
  8. /**
  9. * Gets a `HarnessPredicate` that can be used to search for an option with specific attributes.
  10. * @param options Options for filtering which option instances are considered a match.
  11. * @return a `HarnessPredicate` configured with the given options.
  12. */
  13. static with(options = {}) {
  14. return new HarnessPredicate(this, options)
  15. .addOption('text', options.text, async (harness, title) => HarnessPredicate.stringMatches(await harness.getText(), title))
  16. .addOption('isSelected', options.isSelected, async (harness, isSelected) => (await harness.isSelected()) === isSelected);
  17. }
  18. /** Clicks the option. */
  19. async click() {
  20. return (await this.host()).click();
  21. }
  22. /** Gets the option's label text. */
  23. async getText() {
  24. return (await this._text()).text();
  25. }
  26. /** Gets whether the option is disabled. */
  27. async isDisabled() {
  28. return (await this.host()).hasClass('mdc-list-item--disabled');
  29. }
  30. /** Gets whether the option is selected. */
  31. async isSelected() {
  32. return (await this.host()).hasClass('mdc-list-item--selected');
  33. }
  34. /** Gets whether the option is active. */
  35. async isActive() {
  36. return (await this.host()).hasClass('mat-mdc-option-active');
  37. }
  38. /** Gets whether the option is in multiple selection mode. */
  39. async isMultiple() {
  40. return (await this.host()).hasClass('mat-mdc-option-multiple');
  41. }
  42. }
  43. export { MatOptionHarness as M };
  44. //# sourceMappingURL=option-harness-BFcc-M_4.mjs.map