testing.mjs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import { ContentContainerComponentHarness, HarnessPredicate, TestKey } from '@angular/cdk/testing';
  2. import { __decorate, __metadata } from 'tslib';
  3. import { inject, NgZone, Component, ChangeDetectionStrategy, ViewEncapsulation, NgModule } from '@angular/core';
  4. import { NoopAnimationsModule } from '@angular/platform-browser/animations';
  5. import { j as MatDialog, n as MatDialogModule } from '../module-BnDTus5c.mjs';
  6. import '@angular/cdk/dialog';
  7. import '@angular/cdk/overlay';
  8. import '@angular/cdk/portal';
  9. import '@angular/cdk/coercion';
  10. import 'rxjs';
  11. import 'rxjs/operators';
  12. import '@angular/cdk/keycodes';
  13. import '@angular/cdk/a11y';
  14. import '@angular/cdk/scrolling';
  15. import '../common-module-WayjW0Pb.mjs';
  16. import '@angular/cdk/bidi';
  17. /** Selectors for different sections of the mat-dialog that can contain user content. */
  18. var MatDialogSection;
  19. (function (MatDialogSection) {
  20. MatDialogSection["TITLE"] = ".mat-mdc-dialog-title";
  21. MatDialogSection["CONTENT"] = ".mat-mdc-dialog-content";
  22. MatDialogSection["ACTIONS"] = ".mat-mdc-dialog-actions";
  23. })(MatDialogSection || (MatDialogSection = {}));
  24. /** Harness for interacting with a standard `MatDialog` in tests. */
  25. class MatDialogHarness
  26. // @breaking-change 14.0.0 change generic type to MatDialogSection.
  27. extends ContentContainerComponentHarness {
  28. /** The selector for the host element of a `MatDialog` instance. */
  29. static hostSelector = '.mat-mdc-dialog-container';
  30. /**
  31. * Gets a `HarnessPredicate` that can be used to search for a dialog with specific attributes.
  32. * @param options Options for filtering which dialog instances are considered a match.
  33. * @return a `HarnessPredicate` configured with the given options.
  34. */
  35. static with(options = {}) {
  36. return new HarnessPredicate(this, options);
  37. }
  38. _title = this.locatorForOptional(MatDialogSection.TITLE);
  39. _content = this.locatorForOptional(MatDialogSection.CONTENT);
  40. _actions = this.locatorForOptional(MatDialogSection.ACTIONS);
  41. /** Gets the id of the dialog. */
  42. async getId() {
  43. const id = await (await this.host()).getAttribute('id');
  44. // In case no id has been specified, the "id" property always returns
  45. // an empty string. To make this method more explicit, we return null.
  46. return id !== '' ? id : null;
  47. }
  48. /** Gets the role of the dialog. */
  49. async getRole() {
  50. return (await this.host()).getAttribute('role');
  51. }
  52. /** Gets the value of the dialog's "aria-label" attribute. */
  53. async getAriaLabel() {
  54. return (await this.host()).getAttribute('aria-label');
  55. }
  56. /** Gets the value of the dialog's "aria-labelledby" attribute. */
  57. async getAriaLabelledby() {
  58. return (await this.host()).getAttribute('aria-labelledby');
  59. }
  60. /** Gets the value of the dialog's "aria-describedby" attribute. */
  61. async getAriaDescribedby() {
  62. return (await this.host()).getAttribute('aria-describedby');
  63. }
  64. /**
  65. * Closes the dialog by pressing escape.
  66. *
  67. * Note: this method does nothing if `disableClose` has been set to `true` for the dialog.
  68. */
  69. async close() {
  70. await (await this.host()).sendKeys(TestKey.ESCAPE);
  71. }
  72. /** Gets the dialog's text. */
  73. async getText() {
  74. return (await this.host()).text();
  75. }
  76. /** Gets the dialog's title text. This only works if the dialog is using mat-dialog-title. */
  77. async getTitleText() {
  78. return (await this._title())?.text() ?? '';
  79. }
  80. /** Gets the dialog's content text. This only works if the dialog is using mat-dialog-content. */
  81. async getContentText() {
  82. return (await this._content())?.text() ?? '';
  83. }
  84. /** Gets the dialog's actions text. This only works if the dialog is using mat-dialog-actions. */
  85. async getActionsText() {
  86. return (await this._actions())?.text() ?? '';
  87. }
  88. }
  89. var MatTestDialogOpener_1;
  90. /** Test component that immediately opens a dialog when bootstrapped. */
  91. let MatTestDialogOpener = class MatTestDialogOpener {
  92. static { MatTestDialogOpener_1 = this; }
  93. dialog = inject(MatDialog);
  94. /** Component that should be opened with the MatDialog `open` method. */
  95. static component;
  96. /** Config that should be provided to the MatDialog `open` method. */
  97. static config;
  98. /** MatDialogRef returned from the MatDialog `open` method. */
  99. dialogRef;
  100. /** Data passed to the `MatDialog` close method. */
  101. closedResult;
  102. _afterClosedSubscription;
  103. _ngZone = inject(NgZone);
  104. /** Static method that prepares this class to open the provided component. */
  105. static withComponent(component, config) {
  106. MatTestDialogOpener_1.component = component;
  107. MatTestDialogOpener_1.config = config;
  108. return MatTestDialogOpener_1;
  109. }
  110. constructor() {
  111. if (!MatTestDialogOpener_1.component) {
  112. throw new Error(`MatTestDialogOpener does not have a component provided.`);
  113. }
  114. this.dialogRef = this._ngZone.run(() => this.dialog.open(MatTestDialogOpener_1.component, MatTestDialogOpener_1.config || {}));
  115. this._afterClosedSubscription = this.dialogRef.afterClosed().subscribe(result => {
  116. this.closedResult = result;
  117. });
  118. }
  119. ngOnDestroy() {
  120. this._afterClosedSubscription.unsubscribe();
  121. MatTestDialogOpener_1.component = undefined;
  122. MatTestDialogOpener_1.config = undefined;
  123. }
  124. };
  125. MatTestDialogOpener = MatTestDialogOpener_1 = __decorate([
  126. Component({
  127. selector: 'mat-test-dialog-opener',
  128. template: '',
  129. changeDetection: ChangeDetectionStrategy.OnPush,
  130. encapsulation: ViewEncapsulation.None,
  131. }),
  132. __metadata("design:paramtypes", [])
  133. ], MatTestDialogOpener);
  134. let MatTestDialogOpenerModule = class MatTestDialogOpenerModule {
  135. };
  136. MatTestDialogOpenerModule = __decorate([
  137. NgModule({
  138. imports: [MatDialogModule, NoopAnimationsModule, MatTestDialogOpener],
  139. })
  140. ], MatTestDialogOpenerModule);
  141. export { MatDialogHarness, MatDialogSection, MatTestDialogOpener, MatTestDialogOpenerModule };
  142. //# sourceMappingURL=testing.mjs.map