testing.mjs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { ContentContainerComponentHarness, HarnessPredicate } from '@angular/cdk/testing';
  2. /** Selectors for different sections of the mat-card that can container user content. */
  3. var MatCardSection;
  4. (function (MatCardSection) {
  5. MatCardSection["HEADER"] = ".mat-mdc-card-header";
  6. MatCardSection["CONTENT"] = ".mat-mdc-card-content";
  7. MatCardSection["ACTIONS"] = ".mat-mdc-card-actions";
  8. MatCardSection["FOOTER"] = ".mat-mdc-card-footer";
  9. })(MatCardSection || (MatCardSection = {}));
  10. /** Harness for interacting with a mat-card in tests. */
  11. class MatCardHarness extends ContentContainerComponentHarness {
  12. /** The selector for the host element of a `MatCard` instance. */
  13. static hostSelector = '.mat-mdc-card';
  14. /**
  15. * Gets a `HarnessPredicate` that can be used to search for a card with specific attributes.
  16. * @param options Options for filtering which card instances are considered a match.
  17. * @return a `HarnessPredicate` configured with the given options.
  18. */
  19. static with(options = {}) {
  20. return new HarnessPredicate(this, options)
  21. .addOption('text', options.text, (harness, text) => HarnessPredicate.stringMatches(harness.getText(), text))
  22. .addOption('title', options.title, (harness, title) => HarnessPredicate.stringMatches(harness.getTitleText(), title))
  23. .addOption('subtitle', options.subtitle, (harness, subtitle) => HarnessPredicate.stringMatches(harness.getSubtitleText(), subtitle));
  24. }
  25. _title = this.locatorForOptional('.mat-mdc-card-title');
  26. _subtitle = this.locatorForOptional('.mat-mdc-card-subtitle');
  27. /** Gets all of the card's content as text. */
  28. async getText() {
  29. return (await this.host()).text();
  30. }
  31. /** Gets the cards's title text. */
  32. async getTitleText() {
  33. return (await this._title())?.text() ?? '';
  34. }
  35. /** Gets the cards's subtitle text. */
  36. async getSubtitleText() {
  37. return (await this._subtitle())?.text() ?? '';
  38. }
  39. }
  40. export { MatCardHarness, MatCardSection };
  41. //# sourceMappingURL=testing.mjs.map