@dugararchit/cdk 0.0.0-dugararchit

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. package/_index.scss +8 -0
  2. package/a11y/_index.import.scss +2 -0
  3. package/a11y/_index.scss +102 -0
  4. package/a11y/a11y-prebuilt.scss +3 -0
  5. package/fesm2022/stagefright5-cdk-a11y.mjs +2381 -0
  6. package/fesm2022/stagefright5-cdk-a11y.mjs.map +1 -0
  7. package/fesm2022/stagefright5-cdk-accordion.mjs +267 -0
  8. package/fesm2022/stagefright5-cdk-accordion.mjs.map +1 -0
  9. package/fesm2022/stagefright5-cdk-bidi.mjs +185 -0
  10. package/fesm2022/stagefright5-cdk-bidi.mjs.map +1 -0
  11. package/fesm2022/stagefright5-cdk-clipboard.mjs +250 -0
  12. package/fesm2022/stagefright5-cdk-clipboard.mjs.map +1 -0
  13. package/fesm2022/stagefright5-cdk-coercion.mjs +128 -0
  14. package/fesm2022/stagefright5-cdk-coercion.mjs.map +1 -0
  15. package/fesm2022/stagefright5-cdk-collections.mjs +472 -0
  16. package/fesm2022/stagefright5-cdk-collections.mjs.map +1 -0
  17. package/fesm2022/stagefright5-cdk-drag-drop.mjs +3690 -0
  18. package/fesm2022/stagefright5-cdk-drag-drop.mjs.map +1 -0
  19. package/fesm2022/stagefright5-cdk-keycodes.mjs +159 -0
  20. package/fesm2022/stagefright5-cdk-keycodes.mjs.map +1 -0
  21. package/fesm2022/stagefright5-cdk-layout.mjs +246 -0
  22. package/fesm2022/stagefright5-cdk-layout.mjs.map +1 -0
  23. package/fesm2022/stagefright5-cdk-observers.mjs +203 -0
  24. package/fesm2022/stagefright5-cdk-observers.mjs.map +1 -0
  25. package/fesm2022/stagefright5-cdk-overlay.mjs +3033 -0
  26. package/fesm2022/stagefright5-cdk-overlay.mjs.map +1 -0
  27. package/fesm2022/stagefright5-cdk-platform.mjs +375 -0
  28. package/fesm2022/stagefright5-cdk-platform.mjs.map +1 -0
  29. package/fesm2022/stagefright5-cdk-portal.mjs +672 -0
  30. package/fesm2022/stagefright5-cdk-portal.mjs.map +1 -0
  31. package/fesm2022/stagefright5-cdk-scrolling.mjs +1399 -0
  32. package/fesm2022/stagefright5-cdk-scrolling.mjs.map +1 -0
  33. package/fesm2022/stagefright5-cdk-stepper.mjs +624 -0
  34. package/fesm2022/stagefright5-cdk-stepper.mjs.map +1 -0
  35. package/fesm2022/stagefright5-cdk-table.mjs +2346 -0
  36. package/fesm2022/stagefright5-cdk-table.mjs.map +1 -0
  37. package/fesm2022/stagefright5-cdk-testing-protractor.mjs +324 -0
  38. package/fesm2022/stagefright5-cdk-testing-protractor.mjs.map +1 -0
  39. package/fesm2022/stagefright5-cdk-testing-selenium-webdriver.mjs +364 -0
  40. package/fesm2022/stagefright5-cdk-testing-selenium-webdriver.mjs.map +1 -0
  41. package/fesm2022/stagefright5-cdk-testing-testbed.mjs +806 -0
  42. package/fesm2022/stagefright5-cdk-testing-testbed.mjs.map +1 -0
  43. package/fesm2022/stagefright5-cdk-testing.mjs +740 -0
  44. package/fesm2022/stagefright5-cdk-testing.mjs.map +1 -0
  45. package/fesm2022/stagefright5-cdk-text-field.mjs +453 -0
  46. package/fesm2022/stagefright5-cdk-text-field.mjs.map +1 -0
  47. package/fesm2022/stagefright5-cdk-tree.mjs +945 -0
  48. package/fesm2022/stagefright5-cdk-tree.mjs.map +1 -0
  49. package/fesm2022/stagefright5-cdk.mjs +26 -0
  50. package/fesm2022/stagefright5-cdk.mjs.map +1 -0
  51. package/overlay/_index-deprecated.scss +13 -0
  52. package/overlay/_index.import.scss +13 -0
  53. package/overlay/_index.scss +148 -0
  54. package/overlay/overlay-prebuilt.scss +3 -0
  55. package/package.json +159 -0
  56. package/schematics/ng-update/test-cases/misc/global-stylesheets-test.scss +3 -0
  57. package/schematics/schematics/BUILD.bazel +104 -0
  58. package/schematics/schematics/README.md +4 -0
  59. package/schematics/schematics/collection.json +18 -0
  60. package/schematics/schematics/index.ts +22 -0
  61. package/schematics/schematics/migration.json +50 -0
  62. package/schematics/schematics/ng-add/index.spec.ts +50 -0
  63. package/schematics/schematics/ng-add/index.ts +39 -0
  64. package/schematics/schematics/ng-add/package-config.ts +62 -0
  65. package/schematics/schematics/ng-add/schema.json +16 -0
  66. package/schematics/schematics/ng-add/schema.ts +12 -0
  67. package/schematics/schematics/ng-generate/drag-drop/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.__style__.template +53 -0
  68. package/schematics/schematics/ng-generate/drag-drop/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.html.template +17 -0
  69. package/schematics/schematics/ng-generate/drag-drop/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.spec.ts.template +29 -0
  70. package/schematics/schematics/ng-generate/drag-drop/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.ts.template +43 -0
  71. package/schematics/schematics/ng-generate/drag-drop/index.spec.ts +205 -0
  72. package/schematics/schematics/ng-generate/drag-drop/index.ts +35 -0
  73. package/schematics/schematics/ng-generate/drag-drop/schema.json +93 -0
  74. package/schematics/schematics/ng-generate/drag-drop/schema.ts +11 -0
  75. package/schematics/schematics/ng-update/data/attribute-selectors.ts +29 -0
  76. package/schematics/schematics/ng-update/data/class-names.ts +50 -0
  77. package/schematics/schematics/ng-update/data/constructor-checks.ts +75 -0
  78. package/schematics/schematics/ng-update/data/css-selectors.ts +33 -0
  79. package/schematics/schematics/ng-update/data/element-selectors.ts +21 -0
  80. package/schematics/schematics/ng-update/data/index.ts +18 -0
  81. package/schematics/schematics/ng-update/data/input-names.ts +118 -0
  82. package/schematics/schematics/ng-update/data/method-call-checks.ts +63 -0
  83. package/schematics/schematics/ng-update/data/output-names.ts +42 -0
  84. package/schematics/schematics/ng-update/data/property-names.ts +151 -0
  85. package/schematics/schematics/ng-update/data/symbol-removal.ts +22 -0
  86. package/schematics/schematics/ng-update/devkit-file-system.ts +87 -0
  87. package/schematics/schematics/ng-update/devkit-migration-rule.ts +185 -0
  88. package/schematics/schematics/ng-update/devkit-migration.ts +47 -0
  89. package/schematics/schematics/ng-update/find-stylesheets.ts +43 -0
  90. package/schematics/schematics/ng-update/html-parsing/angular.ts +49 -0
  91. package/schematics/schematics/ng-update/html-parsing/elements.ts +66 -0
  92. package/schematics/schematics/ng-update/index.ts +113 -0
  93. package/schematics/schematics/ng-update/migrations/attribute-selectors.ts +83 -0
  94. package/schematics/schematics/ng-update/migrations/class-inheritance.ts +63 -0
  95. package/schematics/schematics/ng-update/migrations/class-names.ts +107 -0
  96. package/schematics/schematics/ng-update/migrations/constructor-signature.ts +170 -0
  97. package/schematics/schematics/ng-update/migrations/css-selectors.ts +83 -0
  98. package/schematics/schematics/ng-update/migrations/element-selectors.ts +75 -0
  99. package/schematics/schematics/ng-update/migrations/input-names.ts +83 -0
  100. package/schematics/schematics/ng-update/migrations/method-call-arguments.ts +70 -0
  101. package/schematics/schematics/ng-update/migrations/misc-template.ts +36 -0
  102. package/schematics/schematics/ng-update/migrations/output-names.ts +61 -0
  103. package/schematics/schematics/ng-update/migrations/property-names.ts +61 -0
  104. package/schematics/schematics/ng-update/migrations/symbol-removal.ts +51 -0
  105. package/schematics/schematics/ng-update/migrations/tilde-import-v13/tilde-import-migration.ts +40 -0
  106. package/schematics/schematics/ng-update/public-api.ts +18 -0
  107. package/schematics/schematics/ng-update/test-cases/index.spec.ts +18 -0
  108. package/schematics/schematics/ng-update/test-cases/misc/external-resource-resolution.spec.ts +32 -0
  109. package/schematics/schematics/ng-update/test-cases/misc/external-resource-resolution_input.ts +22 -0
  110. package/schematics/schematics/ng-update/test-cases/misc/global-stylesheets-test.scss +3 -0
  111. package/schematics/schematics/ng-update/test-cases/misc/global-stylesheets.spec.ts +50 -0
  112. package/schematics/schematics/ng-update/test-cases/misc/global-stylesheets_input.ts +8 -0
  113. package/schematics/schematics/ng-update/test-cases/misc/method-call-checks.spec.ts +20 -0
  114. package/schematics/schematics/ng-update/test-cases/misc/method-call-checks_input.ts +18 -0
  115. package/schematics/schematics/ng-update/test-cases/misc/module-resolution.spec.ts +27 -0
  116. package/schematics/schematics/ng-update/test-cases/v13/misc/tilde-import-v13.spec.ts +149 -0
  117. package/schematics/schematics/ng-update/test-cases/v6/attribute-selectors_expected_output.ts +36 -0
  118. package/schematics/schematics/ng-update/test-cases/v6/attribute-selectors_input.ts +36 -0
  119. package/schematics/schematics/ng-update/test-cases/v6/class-names_expected_output.ts +8 -0
  120. package/schematics/schematics/ng-update/test-cases/v6/class-names_input.ts +8 -0
  121. package/schematics/schematics/ng-update/test-cases/v6/input-names_expected_output.ts +22 -0
  122. package/schematics/schematics/ng-update/test-cases/v6/input-names_input.ts +22 -0
  123. package/schematics/schematics/ng-update/test-cases/v6/property-names_expected_output.ts +64 -0
  124. package/schematics/schematics/ng-update/test-cases/v6/property-names_input.ts +64 -0
  125. package/schematics/schematics/ng-update/test-cases/v7/property-names_expected_output.ts +28 -0
  126. package/schematics/schematics/ng-update/test-cases/v7/property-names_input.ts +28 -0
  127. package/schematics/schematics/ng-update/typescript/base-types.ts +22 -0
  128. package/schematics/schematics/ng-update/typescript/imports.ts +54 -0
  129. package/schematics/schematics/ng-update/typescript/literal.ts +32 -0
  130. package/schematics/schematics/ng-update/typescript/module-specifiers.ts +39 -0
  131. package/schematics/schematics/ng-update/update-schematic.md +209 -0
  132. package/schematics/schematics/ng-update/upgrade-data.ts +79 -0
  133. package/schematics/schematics/paths.ts +15 -0
  134. package/schematics/schematics/testing/BUILD.bazel +27 -0
  135. package/schematics/schematics/testing/file-content.ts +20 -0
  136. package/schematics/schematics/testing/index.ts +14 -0
  137. package/schematics/schematics/testing/post-scheduled-tasks.ts +45 -0
  138. package/schematics/schematics/testing/resolve-bazel-path.ts +46 -0
  139. package/schematics/schematics/testing/test-app.ts +21 -0
  140. package/schematics/schematics/testing/test-case-setup.ts +236 -0
  141. package/schematics/schematics/testing/test-library.ts +21 -0
  142. package/schematics/schematics/testing/test-project.ts +40 -0
  143. package/schematics/schematics/testing/tsconfig.json +7 -0
  144. package/schematics/schematics/tsconfig.json +28 -0
  145. package/schematics/schematics/update-tool/BUILD.bazel +19 -0
  146. package/schematics/schematics/update-tool/component-resource-collector.ts +195 -0
  147. package/schematics/schematics/update-tool/file-system.ts +78 -0
  148. package/schematics/schematics/update-tool/index.ts +191 -0
  149. package/schematics/schematics/update-tool/logger.ts +23 -0
  150. package/schematics/schematics/update-tool/migration.ts +88 -0
  151. package/schematics/schematics/update-tool/public-api.ts +16 -0
  152. package/schematics/schematics/update-tool/target-version.ts +31 -0
  153. package/schematics/schematics/update-tool/tsconfig.json +7 -0
  154. package/schematics/schematics/update-tool/update-recorder.ts +14 -0
  155. package/schematics/schematics/update-tool/utils/decorators.ts +54 -0
  156. package/schematics/schematics/update-tool/utils/functions.ts +18 -0
  157. package/schematics/schematics/update-tool/utils/imports.ts +128 -0
  158. package/schematics/schematics/update-tool/utils/line-mappings.ts +84 -0
  159. package/schematics/schematics/update-tool/utils/parse-tsconfig.ts +25 -0
  160. package/schematics/schematics/update-tool/utils/property-name.ts +28 -0
  161. package/schematics/schematics/update-tool/utils/virtual-host.ts +116 -0
  162. package/schematics/schematics/update-tool/version-changes.ts +49 -0
  163. package/schematics/schematics/utils/ast/ng-module-imports.spec.ts +43 -0
  164. package/schematics/schematics/utils/ast/ng-module-imports.ts +102 -0
  165. package/schematics/schematics/utils/ast.ts +88 -0
  166. package/schematics/schematics/utils/build-component.ts +252 -0
  167. package/schematics/schematics/utils/get-project.ts +27 -0
  168. package/schematics/schematics/utils/html-manipulation.ts +105 -0
  169. package/schematics/schematics/utils/index.ts +19 -0
  170. package/schematics/schematics/utils/parse5-element.ts +34 -0
  171. package/schematics/schematics/utils/project-index-file.ts +21 -0
  172. package/schematics/schematics/utils/project-main-file.ts +26 -0
  173. package/schematics/schematics/utils/project-style-file.ts +53 -0
  174. package/schematics/schematics/utils/project-targets.ts +43 -0
  175. package/schematics/schematics/utils/project-tsconfig-paths.spec.ts +91 -0
  176. package/schematics/schematics/utils/project-tsconfig-paths.ts +49 -0
  177. package/schematics/schematics/utils/schematic-options.ts +65 -0
  178. package/schematics/schematics/utils/vendored-ast-utils/index.ts +599 -0
  179. package/scrolling/virtual-scroll-viewport.scss +87 -0
  180. package/table/table.scss +3 -0
  181. package/text-field/_index.import.scss +2 -0
  182. package/text-field/_index.scss +89 -0
  183. package/text-field/text-field-prebuilt.scss +4 -0
  184. package/types/stagefright5-cdk-a11y.d.ts +1160 -0
  185. package/types/stagefright5-cdk-accordion.d.ts +95 -0
  186. package/types/stagefright5-cdk-bidi.d.ts +95 -0
  187. package/types/stagefright5-cdk-clipboard.d.ts +116 -0
  188. package/types/stagefright5-cdk-coercion.d.ts +101 -0
  189. package/types/stagefright5-cdk-collections.d.ts +405 -0
  190. package/types/stagefright5-cdk-drag-drop.d.ts +1471 -0
  191. package/types/stagefright5-cdk-keycodes.d.ts +142 -0
  192. package/types/stagefright5-cdk-layout.d.ts +96 -0
  193. package/types/stagefright5-cdk-observers.d.ts +91 -0
  194. package/types/stagefright5-cdk-overlay.d.ts +1258 -0
  195. package/types/stagefright5-cdk-platform.d.ts +130 -0
  196. package/types/stagefright5-cdk-portal.d.ts +327 -0
  197. package/types/stagefright5-cdk-scrolling.d.ts +631 -0
  198. package/types/stagefright5-cdk-stepper.d.ts +302 -0
  199. package/types/stagefright5-cdk-table.d.ts +1128 -0
  200. package/types/stagefright5-cdk-testing-protractor.d.ts +146 -0
  201. package/types/stagefright5-cdk-testing-selenium-webdriver.d.ts +161 -0
  202. package/types/stagefright5-cdk-testing-testbed.d.ts +168 -0
  203. package/types/stagefright5-cdk-testing.d.ts +735 -0
  204. package/types/stagefright5-cdk-text-field.d.ts +171 -0
  205. package/types/stagefright5-cdk-tree.d.ts +522 -0
  206. package/types/stagefright5-cdk.d.ts +14 -0
@@ -0,0 +1,806 @@
1
+ import { getNoKeysSpecifiedError, TestKey, _getTextWithExcludedElements, handleAutoChangeDetectionStatus, stopHandlingAutoChangeDetectionStatus, HarnessEnvironment } from '@dugararchit/cdk/testing';
2
+ import { flush } from '@angular/core/testing';
3
+ import { takeWhile } from 'rxjs/operators';
4
+ import { BehaviorSubject } from 'rxjs';
5
+ import * as keyCodes from '@dugararchit/cdk/keycodes';
6
+ import { PERIOD } from '@dugararchit/cdk/keycodes';
7
+
8
+ /**
9
+ * @license
10
+ * Copyright Google LLC All Rights Reserved.
11
+ *
12
+ * Use of this source code is governed by an MIT-style license that can be
13
+ * found in the LICENSE file at https://angular.io/license
14
+ */
15
+ /** Unique symbol that is used to patch a property to a proxy zone. */
16
+ const stateObservableSymbol = Symbol('ProxyZone_PATCHED#stateObservable');
17
+ /**
18
+ * Interceptor that can be set up in a `ProxyZone` instance. The interceptor
19
+ * will keep track of the task state and emit whenever the state changes.
20
+ *
21
+ * This serves as a workaround for https://github.com/angular/angular/issues/32896.
22
+ */
23
+ class TaskStateZoneInterceptor {
24
+ constructor(_lastState) {
25
+ this._lastState = _lastState;
26
+ /** Subject that can be used to emit a new state change. */
27
+ this._stateSubject = new BehaviorSubject(this._lastState ? this._getTaskStateFromInternalZoneState(this._lastState) : { stable: true });
28
+ /** Public observable that emits whenever the task state changes. */
29
+ this.state = this._stateSubject;
30
+ }
31
+ /** This will be called whenever the task state changes in the intercepted zone. */
32
+ onHasTask(delegate, current, target, hasTaskState) {
33
+ if (current === target) {
34
+ this._stateSubject.next(this._getTaskStateFromInternalZoneState(hasTaskState));
35
+ }
36
+ }
37
+ /** Gets the task state from the internal ZoneJS task state. */
38
+ _getTaskStateFromInternalZoneState(state) {
39
+ return { stable: !state.macroTask && !state.microTask };
40
+ }
41
+ /**
42
+ * Sets up the custom task state Zone interceptor in the `ProxyZone`. Throws if
43
+ * no `ProxyZone` could be found.
44
+ * @returns an observable that emits whenever the task state changes.
45
+ */
46
+ static setup() {
47
+ if (Zone === undefined) {
48
+ throw Error('Could not find ZoneJS. For test harnesses running in TestBed, ' +
49
+ 'ZoneJS needs to be installed.');
50
+ }
51
+ // tslint:disable-next-line:variable-name
52
+ const ProxyZoneSpec = Zone['ProxyZoneSpec'];
53
+ // If there is no "ProxyZoneSpec" installed, we throw an error and recommend
54
+ // setting up the proxy zone by pulling in the testing bundle.
55
+ if (!ProxyZoneSpec) {
56
+ throw Error('ProxyZoneSpec is needed for the test harnesses but could not be found. ' +
57
+ 'Please make sure that your environment includes zone.js/dist/zone-testing.js');
58
+ }
59
+ // Ensure that there is a proxy zone instance set up, and get
60
+ // a reference to the instance if present.
61
+ const zoneSpec = ProxyZoneSpec.assertPresent();
62
+ // If there already is a delegate registered in the proxy zone, and it
63
+ // is type of the custom task state interceptor, we just use that state
64
+ // observable. This allows us to only intercept Zone once per test
65
+ // (similar to how `fakeAsync` or `async` work).
66
+ if (zoneSpec[stateObservableSymbol]) {
67
+ return zoneSpec[stateObservableSymbol];
68
+ }
69
+ // Since we intercept on environment creation and the fixture has been
70
+ // created before, we might have missed tasks scheduled before. Fortunately
71
+ // the proxy zone keeps track of the previous task state, so we can just pass
72
+ // this as initial state to the task zone interceptor.
73
+ const interceptor = new TaskStateZoneInterceptor(zoneSpec.lastTaskState);
74
+ const zoneSpecOnHasTask = zoneSpec.onHasTask.bind(zoneSpec);
75
+ // We setup the task state interceptor in the `ProxyZone`. Note that we cannot register
76
+ // the interceptor as a new proxy zone delegate because it would mean that other zone
77
+ // delegates (e.g. `FakeAsyncTestZone` or `AsyncTestZone`) can accidentally overwrite/disable
78
+ // our interceptor. Since we just intend to monitor the task state of the proxy zone, it is
79
+ // sufficient to just patch the proxy zone. This also avoids that we interfere with the task
80
+ // queue scheduling logic.
81
+ zoneSpec.onHasTask = function (...args) {
82
+ zoneSpecOnHasTask(...args);
83
+ interceptor.onHasTask(...args);
84
+ };
85
+ return (zoneSpec[stateObservableSymbol] = interceptor.state);
86
+ }
87
+ }
88
+
89
+ /**
90
+ * @license
91
+ * Copyright Google LLC All Rights Reserved.
92
+ *
93
+ * Use of this source code is governed by an MIT-style license that can be
94
+ * found in the LICENSE file at https://angular.io/license
95
+ */
96
+ /** Used to generate unique IDs for events. */
97
+ let uniqueIds = 0;
98
+ /**
99
+ * Creates a browser MouseEvent with the specified options.
100
+ * @docs-private
101
+ */
102
+ function createMouseEvent(type, clientX = 0, clientY = 0, button = 0, modifiers = {}) {
103
+ // Note: We cannot determine the position of the mouse event based on the screen
104
+ // because the dimensions and position of the browser window are not available
105
+ // To provide reasonable `screenX` and `screenY` coordinates, we simply use the
106
+ // client coordinates as if the browser is opened in fullscreen.
107
+ const screenX = clientX;
108
+ const screenY = clientY;
109
+ const event = new MouseEvent(type, {
110
+ bubbles: true,
111
+ cancelable: true,
112
+ composed: true, // Required for shadow DOM events.
113
+ view: window,
114
+ detail: 0,
115
+ relatedTarget: null,
116
+ screenX,
117
+ screenY,
118
+ clientX,
119
+ clientY,
120
+ ctrlKey: modifiers.control,
121
+ altKey: modifiers.alt,
122
+ shiftKey: modifiers.shift,
123
+ metaKey: modifiers.meta,
124
+ button: button,
125
+ buttons: 1,
126
+ });
127
+ // The `MouseEvent` constructor doesn't allow us to pass these properties into the constructor.
128
+ // Override them to `1`, because they're used for fake screen reader event detection.
129
+ defineReadonlyEventProperty(event, 'offsetX', 1);
130
+ defineReadonlyEventProperty(event, 'offsetY', 1);
131
+ return event;
132
+ }
133
+ /**
134
+ * Creates a browser `PointerEvent` with the specified options. Pointer events
135
+ * by default will appear as if they are the primary pointer of their type.
136
+ * https://www.w3.org/TR/pointerevents2/#dom-pointerevent-isprimary.
137
+ *
138
+ * For example, if pointer events for a multi-touch interaction are created, the non-primary
139
+ * pointer touches would need to be represented by non-primary pointer events.
140
+ *
141
+ * @docs-private
142
+ */
143
+ function createPointerEvent(type, clientX = 0, clientY = 0, options = { isPrimary: true }) {
144
+ return new PointerEvent(type, {
145
+ bubbles: true,
146
+ cancelable: true,
147
+ composed: true, // Required for shadow DOM events.
148
+ view: window,
149
+ clientX,
150
+ clientY,
151
+ ...options,
152
+ });
153
+ }
154
+ /**
155
+ * Creates a browser TouchEvent with the specified pointer coordinates.
156
+ * @docs-private
157
+ */
158
+ function createTouchEvent(type, pageX = 0, pageY = 0, clientX = 0, clientY = 0) {
159
+ // We cannot use the `TouchEvent` or `Touch` because Firefox and Safari lack support.
160
+ // TODO: Switch to the constructor API when it is available for Firefox and Safari.
161
+ const event = document.createEvent('UIEvent');
162
+ const touchDetails = { pageX, pageY, clientX, clientY, identifier: uniqueIds++ };
163
+ // TS3.6 removes the initUIEvent method and suggests porting to "new UIEvent()".
164
+ event.initUIEvent(type, true, true, window, 0);
165
+ // Most of the browsers don't have a "initTouchEvent" method that can be used to define
166
+ // the touch details.
167
+ defineReadonlyEventProperty(event, 'touches', [touchDetails]);
168
+ defineReadonlyEventProperty(event, 'targetTouches', [touchDetails]);
169
+ defineReadonlyEventProperty(event, 'changedTouches', [touchDetails]);
170
+ return event;
171
+ }
172
+ /**
173
+ * Creates a keyboard event with the specified key and modifiers.
174
+ * @docs-private
175
+ */
176
+ function createKeyboardEvent(type, keyCode = 0, key = '', modifiers = {}) {
177
+ return new KeyboardEvent(type, {
178
+ bubbles: true,
179
+ cancelable: true,
180
+ composed: true, // Required for shadow DOM events.
181
+ view: window,
182
+ keyCode: keyCode,
183
+ key: key,
184
+ shiftKey: modifiers.shift,
185
+ metaKey: modifiers.meta,
186
+ altKey: modifiers.alt,
187
+ ctrlKey: modifiers.control,
188
+ });
189
+ }
190
+ /**
191
+ * Creates a fake event object with any desired event type.
192
+ * @docs-private
193
+ */
194
+ function createFakeEvent(type, bubbles = false, cancelable = true, composed = true) {
195
+ return new Event(type, { bubbles, cancelable, composed });
196
+ }
197
+ /**
198
+ * Defines a readonly property on the given event object. Readonly properties on an event object
199
+ * are always set as configurable as that matches default readonly properties for DOM event objects.
200
+ */
201
+ function defineReadonlyEventProperty(event, propertyName, value) {
202
+ Object.defineProperty(event, propertyName, { get: () => value, configurable: true });
203
+ }
204
+
205
+ /**
206
+ * @license
207
+ * Copyright Google LLC All Rights Reserved.
208
+ *
209
+ * Use of this source code is governed by an MIT-style license that can be
210
+ * found in the LICENSE file at https://angular.io/license
211
+ */
212
+ /**
213
+ * Utility to dispatch any event on a Node.
214
+ * @docs-private
215
+ */
216
+ function dispatchEvent(node, event) {
217
+ node.dispatchEvent(event);
218
+ return event;
219
+ }
220
+ /**
221
+ * Shorthand to dispatch a fake event on a specified node.
222
+ * @docs-private
223
+ */
224
+ function dispatchFakeEvent(node, type, bubbles) {
225
+ return dispatchEvent(node, createFakeEvent(type, bubbles));
226
+ }
227
+ /**
228
+ * Shorthand to dispatch a keyboard event with a specified key code and
229
+ * optional modifiers.
230
+ * @docs-private
231
+ */
232
+ function dispatchKeyboardEvent(node, type, keyCode, key, modifiers) {
233
+ return dispatchEvent(node, createKeyboardEvent(type, keyCode, key, modifiers));
234
+ }
235
+ /**
236
+ * Shorthand to dispatch a mouse event on the specified coordinates.
237
+ * @docs-private
238
+ */
239
+ function dispatchMouseEvent(node, type, clientX = 0, clientY = 0, button, modifiers) {
240
+ return dispatchEvent(node, createMouseEvent(type, clientX, clientY, button, modifiers));
241
+ }
242
+ /**
243
+ * Shorthand to dispatch a pointer event on the specified coordinates.
244
+ * @docs-private
245
+ */
246
+ function dispatchPointerEvent(node, type, clientX = 0, clientY = 0, options) {
247
+ return dispatchEvent(node, createPointerEvent(type, clientX, clientY, options));
248
+ }
249
+ /**
250
+ * Shorthand to dispatch a touch event on the specified coordinates.
251
+ * @docs-private
252
+ */
253
+ function dispatchTouchEvent(node, type, pageX = 0, pageY = 0, clientX = 0, clientY = 0) {
254
+ return dispatchEvent(node, createTouchEvent(type, pageX, pageY, clientX, clientY));
255
+ }
256
+
257
+ /**
258
+ * @license
259
+ * Copyright Google LLC All Rights Reserved.
260
+ *
261
+ * Use of this source code is governed by an MIT-style license that can be
262
+ * found in the LICENSE file at https://angular.io/license
263
+ */
264
+ function triggerFocusChange(element, event) {
265
+ let eventFired = false;
266
+ const handler = () => (eventFired = true);
267
+ element.addEventListener(event, handler);
268
+ element[event]();
269
+ element.removeEventListener(event, handler);
270
+ if (!eventFired) {
271
+ dispatchFakeEvent(element, event);
272
+ }
273
+ }
274
+ /**
275
+ * Patches an elements focus and blur methods to emit events consistently and predictably.
276
+ * This is necessary, because some browsers can call the focus handlers asynchronously,
277
+ * while others won't fire them at all if the browser window is not focused.
278
+ * @docs-private
279
+ */
280
+ // TODO: Check if this element focus patching is still needed for local testing,
281
+ // where browser is not necessarily focused.
282
+ function patchElementFocus(element) {
283
+ element.focus = () => dispatchFakeEvent(element, 'focus');
284
+ element.blur = () => dispatchFakeEvent(element, 'blur');
285
+ }
286
+ /** @docs-private */
287
+ function triggerFocus(element) {
288
+ triggerFocusChange(element, 'focus');
289
+ }
290
+ /** @docs-private */
291
+ function triggerBlur(element) {
292
+ triggerFocusChange(element, 'blur');
293
+ }
294
+
295
+ /**
296
+ * @license
297
+ * Copyright Google LLC All Rights Reserved.
298
+ *
299
+ * Use of this source code is governed by an MIT-style license that can be
300
+ * found in the LICENSE file at https://angular.io/license
301
+ */
302
+ /** Input types for which the value can be entered incrementally. */
303
+ const incrementalInputTypes = new Set([
304
+ 'text',
305
+ 'email',
306
+ 'hidden',
307
+ 'password',
308
+ 'search',
309
+ 'tel',
310
+ 'url',
311
+ ]);
312
+ /**
313
+ * Checks whether the given Element is a text input element.
314
+ * @docs-private
315
+ */
316
+ function isTextInput(element) {
317
+ const nodeName = element.nodeName.toLowerCase();
318
+ return nodeName === 'input' || nodeName === 'textarea';
319
+ }
320
+ function typeInElement(element, ...modifiersAndKeys) {
321
+ const first = modifiersAndKeys[0];
322
+ let modifiers;
323
+ let rest;
324
+ if (first !== undefined &&
325
+ typeof first !== 'string' &&
326
+ first.keyCode === undefined &&
327
+ first.key === undefined) {
328
+ modifiers = first;
329
+ rest = modifiersAndKeys.slice(1);
330
+ }
331
+ else {
332
+ modifiers = {};
333
+ rest = modifiersAndKeys;
334
+ }
335
+ const isInput = isTextInput(element);
336
+ const inputType = element.getAttribute('type') || 'text';
337
+ const keys = rest
338
+ .map(k => typeof k === 'string'
339
+ ? k.split('').map(c => ({ keyCode: c.toUpperCase().charCodeAt(0), key: c }))
340
+ : [k])
341
+ .reduce((arr, k) => arr.concat(k), []);
342
+ // Throw an error if no keys have been specified. Calling this function with no
343
+ // keys should not result in a focus event being dispatched unexpectedly.
344
+ if (keys.length === 0) {
345
+ throw getNoKeysSpecifiedError();
346
+ }
347
+ // We simulate the user typing in a value by incrementally assigning the value below. The problem
348
+ // is that for some input types, the browser won't allow for an invalid value to be set via the
349
+ // `value` property which will always be the case when going character-by-character. If we detect
350
+ // such an input, we have to set the value all at once or listeners to the `input` event (e.g.
351
+ // the `ReactiveFormsModule` uses such an approach) won't receive the correct value.
352
+ const enterValueIncrementally = inputType === 'number'
353
+ ? // The value can be set character by character in number inputs if it doesn't have any decimals.
354
+ keys.every(key => key.key !== '.' && key.key !== '-' && key.keyCode !== PERIOD)
355
+ : incrementalInputTypes.has(inputType);
356
+ triggerFocus(element);
357
+ // When we aren't entering the value incrementally, assign it all at once ahead
358
+ // of time so that any listeners to the key events below will have access to it.
359
+ if (!enterValueIncrementally) {
360
+ element.value = keys.reduce((value, key) => value + (key.key || ''), '');
361
+ }
362
+ for (const key of keys) {
363
+ dispatchKeyboardEvent(element, 'keydown', key.keyCode, key.key, modifiers);
364
+ dispatchKeyboardEvent(element, 'keypress', key.keyCode, key.key, modifiers);
365
+ if (isInput && key.key && key.key.length === 1) {
366
+ if (enterValueIncrementally) {
367
+ element.value += key.key;
368
+ dispatchFakeEvent(element, 'input');
369
+ }
370
+ }
371
+ dispatchKeyboardEvent(element, 'keyup', key.keyCode, key.key, modifiers);
372
+ }
373
+ // Since we weren't dispatching `input` events while sending the keys, we have to do it now.
374
+ if (!enterValueIncrementally) {
375
+ dispatchFakeEvent(element, 'input');
376
+ }
377
+ }
378
+ /**
379
+ * Clears the text in an input or textarea element.
380
+ * @docs-private
381
+ */
382
+ function clearElement(element) {
383
+ triggerFocus(element);
384
+ element.value = '';
385
+ dispatchFakeEvent(element, 'input');
386
+ }
387
+
388
+ /**
389
+ * @license
390
+ * Copyright Google LLC All Rights Reserved.
391
+ *
392
+ * Use of this source code is governed by an MIT-style license that can be
393
+ * found in the LICENSE file at https://angular.io/license
394
+ */
395
+ // These are private APIs that are used both by the public APIs inside of this package, as well
396
+ // as in unit tests of other entry-points, hence why we need to re-export them through here.
397
+
398
+ /**
399
+ * @license
400
+ * Copyright Google LLC All Rights Reserved.
401
+ *
402
+ * Use of this source code is governed by an MIT-style license that can be
403
+ * found in the LICENSE file at https://angular.io/license
404
+ */
405
+ /** Maps `TestKey` constants to the `keyCode` and `key` values used by native browser events. */
406
+ const keyMap = {
407
+ [TestKey.BACKSPACE]: { keyCode: keyCodes.BACKSPACE, key: 'Backspace' },
408
+ [TestKey.TAB]: { keyCode: keyCodes.TAB, key: 'Tab' },
409
+ [TestKey.ENTER]: { keyCode: keyCodes.ENTER, key: 'Enter' },
410
+ [TestKey.SHIFT]: { keyCode: keyCodes.SHIFT, key: 'Shift' },
411
+ [TestKey.CONTROL]: { keyCode: keyCodes.CONTROL, key: 'Control' },
412
+ [TestKey.ALT]: { keyCode: keyCodes.ALT, key: 'Alt' },
413
+ [TestKey.ESCAPE]: { keyCode: keyCodes.ESCAPE, key: 'Escape' },
414
+ [TestKey.PAGE_UP]: { keyCode: keyCodes.PAGE_UP, key: 'PageUp' },
415
+ [TestKey.PAGE_DOWN]: { keyCode: keyCodes.PAGE_DOWN, key: 'PageDown' },
416
+ [TestKey.END]: { keyCode: keyCodes.END, key: 'End' },
417
+ [TestKey.HOME]: { keyCode: keyCodes.HOME, key: 'Home' },
418
+ [TestKey.LEFT_ARROW]: { keyCode: keyCodes.LEFT_ARROW, key: 'ArrowLeft' },
419
+ [TestKey.UP_ARROW]: { keyCode: keyCodes.UP_ARROW, key: 'ArrowUp' },
420
+ [TestKey.RIGHT_ARROW]: { keyCode: keyCodes.RIGHT_ARROW, key: 'ArrowRight' },
421
+ [TestKey.DOWN_ARROW]: { keyCode: keyCodes.DOWN_ARROW, key: 'ArrowDown' },
422
+ [TestKey.INSERT]: { keyCode: keyCodes.INSERT, key: 'Insert' },
423
+ [TestKey.DELETE]: { keyCode: keyCodes.DELETE, key: 'Delete' },
424
+ [TestKey.F1]: { keyCode: keyCodes.F1, key: 'F1' },
425
+ [TestKey.F2]: { keyCode: keyCodes.F2, key: 'F2' },
426
+ [TestKey.F3]: { keyCode: keyCodes.F3, key: 'F3' },
427
+ [TestKey.F4]: { keyCode: keyCodes.F4, key: 'F4' },
428
+ [TestKey.F5]: { keyCode: keyCodes.F5, key: 'F5' },
429
+ [TestKey.F6]: { keyCode: keyCodes.F6, key: 'F6' },
430
+ [TestKey.F7]: { keyCode: keyCodes.F7, key: 'F7' },
431
+ [TestKey.F8]: { keyCode: keyCodes.F8, key: 'F8' },
432
+ [TestKey.F9]: { keyCode: keyCodes.F9, key: 'F9' },
433
+ [TestKey.F10]: { keyCode: keyCodes.F10, key: 'F10' },
434
+ [TestKey.F11]: { keyCode: keyCodes.F11, key: 'F11' },
435
+ [TestKey.F12]: { keyCode: keyCodes.F12, key: 'F12' },
436
+ [TestKey.META]: { keyCode: keyCodes.META, key: 'Meta' },
437
+ };
438
+ /** A `TestElement` implementation for unit tests. */
439
+ class UnitTestElement {
440
+ constructor(element, _stabilize) {
441
+ this.element = element;
442
+ this._stabilize = _stabilize;
443
+ }
444
+ /** Blur the element. */
445
+ async blur() {
446
+ triggerBlur(this.element);
447
+ await this._stabilize();
448
+ }
449
+ /** Clear the element's input (for input and textarea elements only). */
450
+ async clear() {
451
+ if (!isTextInput(this.element)) {
452
+ throw Error('Attempting to clear an invalid element');
453
+ }
454
+ clearElement(this.element);
455
+ await this._stabilize();
456
+ }
457
+ async click(...args) {
458
+ const isDisabled = this.element.disabled === true;
459
+ // If the element is `disabled` and has a `disabled` property, we emit the mouse event
460
+ // sequence but not dispatch the `click` event. This is necessary to keep the behavior
461
+ // consistent with an actual user interaction. The click event is not necessarily
462
+ // automatically prevented by the browser. There is mismatch between Firefox and Chromium:
463
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=329509.
464
+ // https://bugs.chromium.org/p/chromium/issues/detail?id=1115661.
465
+ await this._dispatchMouseEventSequence(isDisabled ? null : 'click', args, 0);
466
+ await this._stabilize();
467
+ }
468
+ async rightClick(...args) {
469
+ await this._dispatchMouseEventSequence('contextmenu', args, 2);
470
+ await this._stabilize();
471
+ }
472
+ /** Focus the element. */
473
+ async focus() {
474
+ triggerFocus(this.element);
475
+ await this._stabilize();
476
+ }
477
+ /** Get the computed value of the given CSS property for the element. */
478
+ async getCssValue(property) {
479
+ await this._stabilize();
480
+ // TODO(mmalerba): Consider adding value normalization if we run into common cases where its
481
+ // needed.
482
+ return getComputedStyle(this.element).getPropertyValue(property);
483
+ }
484
+ /** Hovers the mouse over the element. */
485
+ async hover() {
486
+ this._dispatchPointerEventIfSupported('pointerenter');
487
+ dispatchMouseEvent(this.element, 'mouseover');
488
+ dispatchMouseEvent(this.element, 'mouseenter');
489
+ await this._stabilize();
490
+ }
491
+ /** Moves the mouse away from the element. */
492
+ async mouseAway() {
493
+ this._dispatchPointerEventIfSupported('pointerleave');
494
+ dispatchMouseEvent(this.element, 'mouseout');
495
+ dispatchMouseEvent(this.element, 'mouseleave');
496
+ await this._stabilize();
497
+ }
498
+ async sendKeys(...modifiersAndKeys) {
499
+ const args = modifiersAndKeys.map(k => (typeof k === 'number' ? keyMap[k] : k));
500
+ typeInElement(this.element, ...args);
501
+ await this._stabilize();
502
+ }
503
+ /**
504
+ * Gets the text from the element.
505
+ * @param options Options that affect what text is included.
506
+ */
507
+ async text(options) {
508
+ await this._stabilize();
509
+ if (options?.exclude) {
510
+ return _getTextWithExcludedElements(this.element, options.exclude);
511
+ }
512
+ return (this.element.textContent || '').trim();
513
+ }
514
+ /** Gets the value for the given attribute from the element. */
515
+ async getAttribute(name) {
516
+ await this._stabilize();
517
+ return this.element.getAttribute(name);
518
+ }
519
+ /** Checks whether the element has the given class. */
520
+ async hasClass(name) {
521
+ await this._stabilize();
522
+ return this.element.classList.contains(name);
523
+ }
524
+ /** Gets the dimensions of the element. */
525
+ async getDimensions() {
526
+ await this._stabilize();
527
+ return this.element.getBoundingClientRect();
528
+ }
529
+ /** Gets the value of a property of an element. */
530
+ async getProperty(name) {
531
+ await this._stabilize();
532
+ return this.element[name];
533
+ }
534
+ /** Sets the value of a property of an input. */
535
+ async setInputValue(value) {
536
+ this.element.value = value;
537
+ await this._stabilize();
538
+ }
539
+ /** Selects the options at the specified indexes inside of a native `select` element. */
540
+ async selectOptions(...optionIndexes) {
541
+ let hasChanged = false;
542
+ const options = this.element.querySelectorAll('option');
543
+ const indexes = new Set(optionIndexes); // Convert to a set to remove duplicates.
544
+ for (let i = 0; i < options.length; i++) {
545
+ const option = options[i];
546
+ const wasSelected = option.selected;
547
+ // We have to go through `option.selected`, because `HTMLSelectElement.value` doesn't
548
+ // allow for multiple options to be selected, even in `multiple` mode.
549
+ option.selected = indexes.has(i);
550
+ if (option.selected !== wasSelected) {
551
+ hasChanged = true;
552
+ dispatchFakeEvent(this.element, 'change');
553
+ }
554
+ }
555
+ if (hasChanged) {
556
+ await this._stabilize();
557
+ }
558
+ }
559
+ /** Checks whether this element matches the given selector. */
560
+ async matchesSelector(selector) {
561
+ await this._stabilize();
562
+ const elementPrototype = Element.prototype;
563
+ return (elementPrototype['matches'] || elementPrototype['msMatchesSelector']).call(this.element, selector);
564
+ }
565
+ /** Checks whether the element is focused. */
566
+ async isFocused() {
567
+ await this._stabilize();
568
+ return document.activeElement === this.element;
569
+ }
570
+ /**
571
+ * Dispatches an event with a particular name.
572
+ * @param name Name of the event to be dispatched.
573
+ */
574
+ async dispatchEvent(name, data) {
575
+ const event = createFakeEvent(name);
576
+ if (data) {
577
+ // tslint:disable-next-line:ban Have to use `Object.assign` to preserve the original object.
578
+ Object.assign(event, data);
579
+ }
580
+ dispatchEvent(this.element, event);
581
+ await this._stabilize();
582
+ }
583
+ /**
584
+ * Dispatches a pointer event on the current element if the browser supports it.
585
+ * @param name Name of the pointer event to be dispatched.
586
+ * @param clientX Coordinate of the user's pointer along the X axis.
587
+ * @param clientY Coordinate of the user's pointer along the Y axis.
588
+ * @param button Mouse button that should be pressed when dispatching the event.
589
+ */
590
+ _dispatchPointerEventIfSupported(name, clientX, clientY, button) {
591
+ // The latest versions of all browsers we support have the new `PointerEvent` API.
592
+ // Though since we capture the two most recent versions of these browsers, we also
593
+ // need to support Safari 12 at time of writing. Safari 12 does not have support for this,
594
+ // so we need to conditionally create and dispatch these events based on feature detection.
595
+ if (typeof PointerEvent !== 'undefined' && PointerEvent) {
596
+ dispatchPointerEvent(this.element, name, clientX, clientY, { isPrimary: true, button });
597
+ }
598
+ }
599
+ /**
600
+ * Dispatches all the events that are part of a mouse event sequence
601
+ * and then emits a given primary event at the end, if speciifed.
602
+ */
603
+ async _dispatchMouseEventSequence(primaryEventName, args, button) {
604
+ let clientX = undefined;
605
+ let clientY = undefined;
606
+ let modifiers = {};
607
+ if (args.length && typeof args[args.length - 1] === 'object') {
608
+ modifiers = args.pop();
609
+ }
610
+ if (args.length) {
611
+ const { left, top, width, height } = await this.getDimensions();
612
+ const relativeX = args[0] === 'center' ? width / 2 : args[0];
613
+ const relativeY = args[0] === 'center' ? height / 2 : args[1];
614
+ // Round the computed click position as decimal pixels are not
615
+ // supported by mouse events and could lead to unexpected results.
616
+ clientX = Math.round(left + relativeX);
617
+ clientY = Math.round(top + relativeY);
618
+ }
619
+ this._dispatchPointerEventIfSupported('pointerdown', clientX, clientY, button);
620
+ dispatchMouseEvent(this.element, 'mousedown', clientX, clientY, button, modifiers);
621
+ this._dispatchPointerEventIfSupported('pointerup', clientX, clientY, button);
622
+ dispatchMouseEvent(this.element, 'mouseup', clientX, clientY, button, modifiers);
623
+ // If a primary event name is specified, emit it after the mouse event sequence.
624
+ if (primaryEventName !== null) {
625
+ dispatchMouseEvent(this.element, primaryEventName, clientX, clientY, button, modifiers);
626
+ }
627
+ // This call to _stabilize should not be needed since the callers will already do that them-
628
+ // selves. Nevertheless it breaks some tests in g3 without it. It needs to be investigated
629
+ // why removing breaks those tests.
630
+ // See: https://github.com/angular/components/pull/20758/files#r520886256.
631
+ await this._stabilize();
632
+ }
633
+ }
634
+
635
+ /**
636
+ * @license
637
+ * Copyright Google LLC All Rights Reserved.
638
+ *
639
+ * Use of this source code is governed by an MIT-style license that can be
640
+ * found in the LICENSE file at https://angular.io/license
641
+ */
642
+ /** The default environment options. */
643
+ const defaultEnvironmentOptions = {
644
+ queryFn: (selector, root) => root.querySelectorAll(selector),
645
+ };
646
+ /** Whether auto change detection is currently disabled. */
647
+ let disableAutoChangeDetection = false;
648
+ /**
649
+ * The set of non-destroyed fixtures currently being used by `TestbedHarnessEnvironment` instances.
650
+ */
651
+ const activeFixtures = new Set();
652
+ /**
653
+ * Installs a handler for change detection batching status changes for a specific fixture.
654
+ * @param fixture The fixture to handle change detection batching for.
655
+ */
656
+ function installAutoChangeDetectionStatusHandler(fixture) {
657
+ if (!activeFixtures.size) {
658
+ handleAutoChangeDetectionStatus(({ isDisabled, onDetectChangesNow }) => {
659
+ disableAutoChangeDetection = isDisabled;
660
+ if (onDetectChangesNow) {
661
+ Promise.all(Array.from(activeFixtures).map(detectChanges)).then(onDetectChangesNow);
662
+ }
663
+ });
664
+ }
665
+ activeFixtures.add(fixture);
666
+ }
667
+ /**
668
+ * Uninstalls a handler for change detection batching status changes for a specific fixture.
669
+ * @param fixture The fixture to stop handling change detection batching for.
670
+ */
671
+ function uninstallAutoChangeDetectionStatusHandler(fixture) {
672
+ activeFixtures.delete(fixture);
673
+ if (!activeFixtures.size) {
674
+ stopHandlingAutoChangeDetectionStatus();
675
+ }
676
+ }
677
+ /** Whether we are currently in the fake async zone. */
678
+ function isInFakeAsyncZone() {
679
+ return Zone.current.get('FakeAsyncTestZoneSpec') != null;
680
+ }
681
+ /**
682
+ * Triggers change detection for a specific fixture.
683
+ * @param fixture The fixture to trigger change detection for.
684
+ */
685
+ async function detectChanges(fixture) {
686
+ fixture.detectChanges();
687
+ if (isInFakeAsyncZone()) {
688
+ flush();
689
+ }
690
+ else {
691
+ await fixture.whenStable();
692
+ }
693
+ }
694
+ /** A `HarnessEnvironment` implementation for Angular's Testbed. */
695
+ class TestbedHarnessEnvironment extends HarnessEnvironment {
696
+ constructor(rawRootElement, _fixture, options) {
697
+ super(rawRootElement);
698
+ this._fixture = _fixture;
699
+ /** Whether the environment has been destroyed. */
700
+ this._destroyed = false;
701
+ this._options = { ...defaultEnvironmentOptions, ...options };
702
+ this._taskState = TaskStateZoneInterceptor.setup();
703
+ this._stabilizeCallback = () => this.forceStabilize();
704
+ installAutoChangeDetectionStatusHandler(_fixture);
705
+ _fixture.componentRef.onDestroy(() => {
706
+ uninstallAutoChangeDetectionStatusHandler(_fixture);
707
+ this._destroyed = true;
708
+ });
709
+ }
710
+ /** Creates a `HarnessLoader` rooted at the given fixture's root element. */
711
+ static loader(fixture, options) {
712
+ return new TestbedHarnessEnvironment(fixture.nativeElement, fixture, options);
713
+ }
714
+ /**
715
+ * Creates a `HarnessLoader` at the document root. This can be used if harnesses are
716
+ * located outside of a fixture (e.g. overlays appended to the document body).
717
+ */
718
+ static documentRootLoader(fixture, options) {
719
+ return new TestbedHarnessEnvironment(document.body, fixture, options);
720
+ }
721
+ /** Gets the native DOM element corresponding to the given TestElement. */
722
+ static getNativeElement(el) {
723
+ if (el instanceof UnitTestElement) {
724
+ return el.element;
725
+ }
726
+ throw Error('This TestElement was not created by the TestbedHarnessEnvironment');
727
+ }
728
+ /**
729
+ * Creates an instance of the given harness type, using the fixture's root element as the
730
+ * harness's host element. This method should be used when creating a harness for the root element
731
+ * of a fixture, as components do not have the correct selector when they are created as the root
732
+ * of the fixture.
733
+ */
734
+ static async harnessForFixture(fixture, harnessType, options) {
735
+ const environment = new TestbedHarnessEnvironment(fixture.nativeElement, fixture, options);
736
+ await environment.forceStabilize();
737
+ return environment.createComponentHarness(harnessType, fixture.nativeElement);
738
+ }
739
+ /**
740
+ * Flushes change detection and async tasks captured in the Angular zone.
741
+ * In most cases it should not be necessary to call this manually. However, there may be some edge
742
+ * cases where it is needed to fully flush animation events.
743
+ */
744
+ async forceStabilize() {
745
+ if (!disableAutoChangeDetection) {
746
+ if (this._destroyed) {
747
+ throw Error('Harness is attempting to use a fixture that has already been destroyed.');
748
+ }
749
+ await detectChanges(this._fixture);
750
+ }
751
+ }
752
+ /**
753
+ * Waits for all scheduled or running async tasks to complete. This allows harness
754
+ * authors to wait for async tasks outside of the Angular zone.
755
+ */
756
+ async waitForTasksOutsideAngular() {
757
+ // If we run in the fake async zone, we run "flush" to run any scheduled tasks. This
758
+ // ensures that the harnesses behave inside of the FakeAsyncTestZone similar to the
759
+ // "AsyncTestZone" and the root zone (i.e. neither fakeAsync or async). Note that we
760
+ // cannot just rely on the task state observable to become stable because the state will
761
+ // never change. This is because the task queue will be only drained if the fake async
762
+ // zone is being flushed.
763
+ if (isInFakeAsyncZone()) {
764
+ flush();
765
+ }
766
+ // Wait until the task queue has been drained and the zone is stable. Note that
767
+ // we cannot rely on "fixture.whenStable" since it does not catch tasks scheduled
768
+ // outside of the Angular zone. For test harnesses, we want to ensure that the
769
+ // app is fully stabilized and therefore need to use our own zone interceptor.
770
+ await this._taskState.pipe(takeWhile(state => !state.stable)).toPromise();
771
+ }
772
+ /** Gets the root element for the document. */
773
+ getDocumentRoot() {
774
+ return document.body;
775
+ }
776
+ /** Creates a `TestElement` from a raw element. */
777
+ createTestElement(element) {
778
+ return new UnitTestElement(element, this._stabilizeCallback);
779
+ }
780
+ /** Creates a `HarnessLoader` rooted at the given raw element. */
781
+ createEnvironment(element) {
782
+ return new TestbedHarnessEnvironment(element, this._fixture, this._options);
783
+ }
784
+ /**
785
+ * Gets a list of all elements matching the given selector under this environment's root element.
786
+ */
787
+ async getAllRawElements(selector) {
788
+ await this.forceStabilize();
789
+ return Array.from(this._options.queryFn(selector, this.rawRootElement));
790
+ }
791
+ }
792
+
793
+ /**
794
+ * @license
795
+ * Copyright Google LLC All Rights Reserved.
796
+ *
797
+ * Use of this source code is governed by an MIT-style license that can be
798
+ * found in the LICENSE file at https://angular.io/license
799
+ */
800
+
801
+ /**
802
+ * Generated bundle index. Do not edit.
803
+ */
804
+
805
+ export { TestbedHarnessEnvironment, UnitTestElement };
806
+ //# sourceMappingURL=stagefright5-cdk-testing-testbed.mjs.map