testing.mjs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { ComponentHarness, HarnessPredicate } from '@angular/cdk/testing';
  2. /** Harness for interacting with a standard Material badge in tests. */
  3. class MatBadgeHarness extends ComponentHarness {
  4. static hostSelector = '.mat-badge';
  5. /**
  6. * Gets a `HarnessPredicate` that can be used to search for a badge with specific attributes.
  7. * @param options Options for narrowing the search:
  8. * - `text` finds a badge host with a particular text.
  9. * @return a `HarnessPredicate` configured with the given options.
  10. */
  11. static with(options = {}) {
  12. return new HarnessPredicate(MatBadgeHarness, options).addOption('text', options.text, (harness, text) => HarnessPredicate.stringMatches(harness.getText(), text));
  13. }
  14. _badgeElement = this.locatorFor('.mat-badge-content');
  15. /** Gets a promise for the badge text. */
  16. async getText() {
  17. return (await this._badgeElement()).text();
  18. }
  19. /** Gets whether the badge is overlapping the content. */
  20. async isOverlapping() {
  21. return (await this.host()).hasClass('mat-badge-overlap');
  22. }
  23. /** Gets the position of the badge. */
  24. async getPosition() {
  25. const host = await this.host();
  26. let result = '';
  27. if (await host.hasClass('mat-badge-above')) {
  28. result += 'above';
  29. }
  30. else if (await host.hasClass('mat-badge-below')) {
  31. result += 'below';
  32. }
  33. if (await host.hasClass('mat-badge-before')) {
  34. result += ' before';
  35. }
  36. else if (await host.hasClass('mat-badge-after')) {
  37. result += ' after';
  38. }
  39. return result.trim();
  40. }
  41. /** Gets the size of the badge. */
  42. async getSize() {
  43. const host = await this.host();
  44. if (await host.hasClass('mat-badge-small')) {
  45. return 'small';
  46. }
  47. else if (await host.hasClass('mat-badge-large')) {
  48. return 'large';
  49. }
  50. return 'medium';
  51. }
  52. /** Gets whether the badge is hidden. */
  53. async isHidden() {
  54. return (await this.host()).hasClass('mat-badge-hidden');
  55. }
  56. /** Gets whether the badge is disabled. */
  57. async isDisabled() {
  58. return (await this.host()).hasClass('mat-badge-disabled');
  59. }
  60. }
  61. export { MatBadgeHarness };
  62. //# sourceMappingURL=testing.mjs.map