Front end of the Slack clone application.

testing.js 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. /**
  2. * @license Angular v5.2.11
  3. * (c) 2010-2018 Google, Inc. https://angular.io/
  4. * License: MIT
  5. */
  6. import { COMPILER_OPTIONS, CompilerFactory, Component, Directive, Inject, Injectable, Injector, NgModule, Pipe, createPlatformFactory, ɵstringify } from '@angular/core';
  7. import { TestComponentRenderer, ɵTestingCompilerFactory } from '@angular/core/testing';
  8. import { ɵINTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS, ɵplatformCoreDynamic } from '@angular/platform-browser-dynamic';
  9. import { BrowserTestingModule } from '@angular/platform-browser/testing';
  10. import { DOCUMENT, ɵgetDOM } from '@angular/platform-browser';
  11. import { CompileReflector, DirectiveResolver, ERROR_COMPONENT_TYPE, NgModuleResolver, PipeResolver } from '@angular/compiler';
  12. import { MockDirectiveResolver, MockNgModuleResolver, MockPipeResolver } from '@angular/compiler/testing';
  13. /**
  14. * @fileoverview added by tsickle
  15. * @suppress {checkTypes} checked by tsc
  16. */
  17. /**
  18. * @license
  19. * Copyright Google Inc. All Rights Reserved.
  20. *
  21. * Use of this source code is governed by an MIT-style license that can be
  22. * found in the LICENSE file at https://angular.io/license
  23. */
  24. /**
  25. * A DOM based implementation of the TestComponentRenderer.
  26. */
  27. class DOMTestComponentRenderer extends TestComponentRenderer {
  28. /**
  29. * @param {?} _doc
  30. */
  31. constructor(_doc /** TODO #9100 */) {
  32. super();
  33. this._doc = _doc;
  34. }
  35. /**
  36. * @param {?} rootElId
  37. * @return {?}
  38. */
  39. insertRootElement(rootElId) {
  40. const /** @type {?} */ rootEl = /** @type {?} */ (ɵgetDOM().firstChild(ɵgetDOM().content(ɵgetDOM().createTemplate(`<div id="${rootElId}"></div>`))));
  41. // TODO(juliemr): can/should this be optional?
  42. const /** @type {?} */ oldRoots = ɵgetDOM().querySelectorAll(this._doc, '[id^=root]');
  43. for (let /** @type {?} */ i = 0; i < oldRoots.length; i++) {
  44. ɵgetDOM().remove(oldRoots[i]);
  45. }
  46. ɵgetDOM().appendChild(this._doc.body, rootEl);
  47. }
  48. }
  49. DOMTestComponentRenderer.decorators = [
  50. { type: Injectable },
  51. ];
  52. /** @nocollapse */
  53. DOMTestComponentRenderer.ctorParameters = () => [
  54. { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] },] },
  55. ];
  56. /**
  57. * @fileoverview added by tsickle
  58. * @suppress {checkTypes} checked by tsc
  59. */
  60. /**
  61. * @license
  62. * Copyright Google Inc. All Rights Reserved.
  63. *
  64. * Use of this source code is governed by an MIT-style license that can be
  65. * found in the LICENSE file at https://angular.io/license
  66. */
  67. let _nextReferenceId = 0;
  68. class MetadataOverrider {
  69. constructor() {
  70. this._references = new Map();
  71. }
  72. /**
  73. * Creates a new instance for the given metadata class
  74. * based on an old instance and overrides.
  75. * @template C, T
  76. * @param {?} metadataClass
  77. * @param {?} oldMetadata
  78. * @param {?} override
  79. * @return {?}
  80. */
  81. overrideMetadata(metadataClass, oldMetadata, override) {
  82. const /** @type {?} */ props = {};
  83. if (oldMetadata) {
  84. _valueProps(oldMetadata).forEach((prop) => props[prop] = (/** @type {?} */ (oldMetadata))[prop]);
  85. }
  86. if (override.set) {
  87. if (override.remove || override.add) {
  88. throw new Error(`Cannot set and add/remove ${ɵstringify(metadataClass)} at the same time!`);
  89. }
  90. setMetadata(props, override.set);
  91. }
  92. if (override.remove) {
  93. removeMetadata(props, override.remove, this._references);
  94. }
  95. if (override.add) {
  96. addMetadata(props, override.add);
  97. }
  98. return new metadataClass(/** @type {?} */ (props));
  99. }
  100. }
  101. /**
  102. * @param {?} metadata
  103. * @param {?} remove
  104. * @param {?} references
  105. * @return {?}
  106. */
  107. function removeMetadata(metadata, remove, references) {
  108. const /** @type {?} */ removeObjects = new Set();
  109. for (const /** @type {?} */ prop in remove) {
  110. const /** @type {?} */ removeValue = remove[prop];
  111. if (removeValue instanceof Array) {
  112. removeValue.forEach((value) => { removeObjects.add(_propHashKey(prop, value, references)); });
  113. }
  114. else {
  115. removeObjects.add(_propHashKey(prop, removeValue, references));
  116. }
  117. }
  118. for (const /** @type {?} */ prop in metadata) {
  119. const /** @type {?} */ propValue = metadata[prop];
  120. if (propValue instanceof Array) {
  121. metadata[prop] = propValue.filter((value) => !removeObjects.has(_propHashKey(prop, value, references)));
  122. }
  123. else {
  124. if (removeObjects.has(_propHashKey(prop, propValue, references))) {
  125. metadata[prop] = undefined;
  126. }
  127. }
  128. }
  129. }
  130. /**
  131. * @param {?} metadata
  132. * @param {?} add
  133. * @return {?}
  134. */
  135. function addMetadata(metadata, add) {
  136. for (const /** @type {?} */ prop in add) {
  137. const /** @type {?} */ addValue = add[prop];
  138. const /** @type {?} */ propValue = metadata[prop];
  139. if (propValue != null && propValue instanceof Array) {
  140. metadata[prop] = propValue.concat(addValue);
  141. }
  142. else {
  143. metadata[prop] = addValue;
  144. }
  145. }
  146. }
  147. /**
  148. * @param {?} metadata
  149. * @param {?} set
  150. * @return {?}
  151. */
  152. function setMetadata(metadata, set) {
  153. for (const /** @type {?} */ prop in set) {
  154. metadata[prop] = set[prop];
  155. }
  156. }
  157. /**
  158. * @param {?} propName
  159. * @param {?} propValue
  160. * @param {?} references
  161. * @return {?}
  162. */
  163. function _propHashKey(propName, propValue, references) {
  164. const /** @type {?} */ replacer = (key, value) => {
  165. if (typeof value === 'function') {
  166. value = _serializeReference(value, references);
  167. }
  168. return value;
  169. };
  170. return `${propName}:${JSON.stringify(propValue, replacer)}`;
  171. }
  172. /**
  173. * @param {?} ref
  174. * @param {?} references
  175. * @return {?}
  176. */
  177. function _serializeReference(ref, references) {
  178. let /** @type {?} */ id = references.get(ref);
  179. if (!id) {
  180. id = `${ɵstringify(ref)}${_nextReferenceId++}`;
  181. references.set(ref, id);
  182. }
  183. return id;
  184. }
  185. /**
  186. * @param {?} obj
  187. * @return {?}
  188. */
  189. function _valueProps(obj) {
  190. const /** @type {?} */ props = [];
  191. // regular public props
  192. Object.keys(obj).forEach((prop) => {
  193. if (!prop.startsWith('_')) {
  194. props.push(prop);
  195. }
  196. });
  197. // getters
  198. let /** @type {?} */ proto = obj;
  199. while (proto = Object.getPrototypeOf(proto)) {
  200. Object.keys(proto).forEach((protoProp) => {
  201. const /** @type {?} */ desc = Object.getOwnPropertyDescriptor(proto, protoProp);
  202. if (!protoProp.startsWith('_') && desc && 'get' in desc) {
  203. props.push(protoProp);
  204. }
  205. });
  206. }
  207. return props;
  208. }
  209. /**
  210. * @fileoverview added by tsickle
  211. * @suppress {checkTypes} checked by tsc
  212. */
  213. /**
  214. * @license
  215. * Copyright Google Inc. All Rights Reserved.
  216. *
  217. * Use of this source code is governed by an MIT-style license that can be
  218. * found in the LICENSE file at https://angular.io/license
  219. */
  220. const COMPILER_PROVIDERS = [
  221. { provide: MockPipeResolver, deps: [CompileReflector] },
  222. { provide: PipeResolver, useExisting: MockPipeResolver },
  223. { provide: MockDirectiveResolver, deps: [CompileReflector] },
  224. { provide: DirectiveResolver, useExisting: MockDirectiveResolver },
  225. { provide: MockNgModuleResolver, deps: [CompileReflector] },
  226. { provide: NgModuleResolver, useExisting: MockNgModuleResolver },
  227. ];
  228. class TestingCompilerFactoryImpl {
  229. /**
  230. * @param {?} _injector
  231. * @param {?} _compilerFactory
  232. */
  233. constructor(_injector, _compilerFactory) {
  234. this._injector = _injector;
  235. this._compilerFactory = _compilerFactory;
  236. }
  237. /**
  238. * @param {?} options
  239. * @return {?}
  240. */
  241. createTestingCompiler(options) {
  242. const /** @type {?} */ compiler = /** @type {?} */ (this._compilerFactory.createCompiler(options));
  243. return new TestingCompilerImpl(compiler, compiler.injector.get(MockDirectiveResolver), compiler.injector.get(MockPipeResolver), compiler.injector.get(MockNgModuleResolver));
  244. }
  245. }
  246. class TestingCompilerImpl {
  247. /**
  248. * @param {?} _compiler
  249. * @param {?} _directiveResolver
  250. * @param {?} _pipeResolver
  251. * @param {?} _moduleResolver
  252. */
  253. constructor(_compiler, _directiveResolver, _pipeResolver, _moduleResolver) {
  254. this._compiler = _compiler;
  255. this._directiveResolver = _directiveResolver;
  256. this._pipeResolver = _pipeResolver;
  257. this._moduleResolver = _moduleResolver;
  258. this._overrider = new MetadataOverrider();
  259. }
  260. /**
  261. * @return {?}
  262. */
  263. get injector() { return this._compiler.injector; }
  264. /**
  265. * @template T
  266. * @param {?} moduleType
  267. * @return {?}
  268. */
  269. compileModuleSync(moduleType) {
  270. return this._compiler.compileModuleSync(moduleType);
  271. }
  272. /**
  273. * @template T
  274. * @param {?} moduleType
  275. * @return {?}
  276. */
  277. compileModuleAsync(moduleType) {
  278. return this._compiler.compileModuleAsync(moduleType);
  279. }
  280. /**
  281. * @template T
  282. * @param {?} moduleType
  283. * @return {?}
  284. */
  285. compileModuleAndAllComponentsSync(moduleType) {
  286. return this._compiler.compileModuleAndAllComponentsSync(moduleType);
  287. }
  288. /**
  289. * @template T
  290. * @param {?} moduleType
  291. * @return {?}
  292. */
  293. compileModuleAndAllComponentsAsync(moduleType) {
  294. return this._compiler.compileModuleAndAllComponentsAsync(moduleType);
  295. }
  296. /**
  297. * @template T
  298. * @param {?} component
  299. * @return {?}
  300. */
  301. getComponentFactory(component) {
  302. return this._compiler.getComponentFactory(component);
  303. }
  304. /**
  305. * @param {?} type
  306. * @return {?}
  307. */
  308. checkOverrideAllowed(type) {
  309. if (this._compiler.hasAotSummary(type)) {
  310. throw new Error(`${ɵstringify(type)} was AOT compiled, so its metadata cannot be changed.`);
  311. }
  312. }
  313. /**
  314. * @param {?} ngModule
  315. * @param {?} override
  316. * @return {?}
  317. */
  318. overrideModule(ngModule, override) {
  319. this.checkOverrideAllowed(ngModule);
  320. const /** @type {?} */ oldMetadata = this._moduleResolver.resolve(ngModule, false);
  321. this._moduleResolver.setNgModule(ngModule, this._overrider.overrideMetadata(NgModule, oldMetadata, override));
  322. this.clearCacheFor(ngModule);
  323. }
  324. /**
  325. * @param {?} directive
  326. * @param {?} override
  327. * @return {?}
  328. */
  329. overrideDirective(directive, override) {
  330. this.checkOverrideAllowed(directive);
  331. const /** @type {?} */ oldMetadata = this._directiveResolver.resolve(directive, false);
  332. this._directiveResolver.setDirective(directive, this._overrider.overrideMetadata(Directive, /** @type {?} */ ((oldMetadata)), override));
  333. this.clearCacheFor(directive);
  334. }
  335. /**
  336. * @param {?} component
  337. * @param {?} override
  338. * @return {?}
  339. */
  340. overrideComponent(component, override) {
  341. this.checkOverrideAllowed(component);
  342. const /** @type {?} */ oldMetadata = this._directiveResolver.resolve(component, false);
  343. this._directiveResolver.setDirective(component, this._overrider.overrideMetadata(Component, /** @type {?} */ ((oldMetadata)), override));
  344. this.clearCacheFor(component);
  345. }
  346. /**
  347. * @param {?} pipe
  348. * @param {?} override
  349. * @return {?}
  350. */
  351. overridePipe(pipe, override) {
  352. this.checkOverrideAllowed(pipe);
  353. const /** @type {?} */ oldMetadata = this._pipeResolver.resolve(pipe, false);
  354. this._pipeResolver.setPipe(pipe, this._overrider.overrideMetadata(Pipe, oldMetadata, override));
  355. this.clearCacheFor(pipe);
  356. }
  357. /**
  358. * @param {?} summaries
  359. * @return {?}
  360. */
  361. loadAotSummaries(summaries) { this._compiler.loadAotSummaries(summaries); }
  362. /**
  363. * @return {?}
  364. */
  365. clearCache() { this._compiler.clearCache(); }
  366. /**
  367. * @param {?} type
  368. * @return {?}
  369. */
  370. clearCacheFor(type) { this._compiler.clearCacheFor(type); }
  371. /**
  372. * @param {?} error
  373. * @return {?}
  374. */
  375. getComponentFromError(error) { return (/** @type {?} */ (error))[ERROR_COMPONENT_TYPE] || null; }
  376. }
  377. /**
  378. * @fileoverview added by tsickle
  379. * @suppress {checkTypes} checked by tsc
  380. */
  381. /**
  382. * @license
  383. * Copyright Google Inc. All Rights Reserved.
  384. *
  385. * Use of this source code is governed by an MIT-style license that can be
  386. * found in the LICENSE file at https://angular.io/license
  387. */
  388. /**
  389. * Platform for dynamic tests
  390. *
  391. * \@experimental
  392. */
  393. const platformCoreDynamicTesting = createPlatformFactory(ɵplatformCoreDynamic, 'coreDynamicTesting', [
  394. { provide: COMPILER_OPTIONS, useValue: { providers: COMPILER_PROVIDERS }, multi: true }, {
  395. provide: ɵTestingCompilerFactory,
  396. useClass: TestingCompilerFactoryImpl,
  397. deps: [Injector, CompilerFactory]
  398. }
  399. ]);
  400. /**
  401. * @fileoverview added by tsickle
  402. * @suppress {checkTypes} checked by tsc
  403. */
  404. /**
  405. * @license
  406. * Copyright Google Inc. All Rights Reserved.
  407. *
  408. * Use of this source code is governed by an MIT-style license that can be
  409. * found in the LICENSE file at https://angular.io/license
  410. */
  411. /**
  412. * @fileoverview added by tsickle
  413. * @suppress {checkTypes} checked by tsc
  414. */
  415. /**
  416. * @license
  417. * Copyright Google Inc. All Rights Reserved.
  418. *
  419. * Use of this source code is governed by an MIT-style license that can be
  420. * found in the LICENSE file at https://angular.io/license
  421. */
  422. /**
  423. * \@stable
  424. */
  425. const platformBrowserDynamicTesting = createPlatformFactory(platformCoreDynamicTesting, 'browserDynamicTesting', ɵINTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS);
  426. /**
  427. * NgModule for testing.
  428. *
  429. * \@stable
  430. */
  431. class BrowserDynamicTestingModule {
  432. }
  433. BrowserDynamicTestingModule.decorators = [
  434. { type: NgModule, args: [{
  435. exports: [BrowserTestingModule],
  436. providers: [
  437. { provide: TestComponentRenderer, useClass: DOMTestComponentRenderer },
  438. ]
  439. },] },
  440. ];
  441. /** @nocollapse */
  442. BrowserDynamicTestingModule.ctorParameters = () => [];
  443. /**
  444. * @fileoverview added by tsickle
  445. * @suppress {checkTypes} checked by tsc
  446. */
  447. /**
  448. * @license
  449. * Copyright Google Inc. All Rights Reserved.
  450. *
  451. * Use of this source code is governed by an MIT-style license that can be
  452. * found in the LICENSE file at https://angular.io/license
  453. */
  454. /**
  455. * @module
  456. * @description
  457. * Entry point for all public APIs of this package.
  458. */
  459. /**
  460. * @fileoverview added by tsickle
  461. * @suppress {checkTypes} checked by tsc
  462. */
  463. /**
  464. * Generated bundle index. Do not edit.
  465. */
  466. export { platformBrowserDynamicTesting, BrowserDynamicTestingModule, DOMTestComponentRenderer as ɵDOMTestComponentRenderer, platformCoreDynamicTesting as ɵplatformCoreDynamicTesting, COMPILER_PROVIDERS as ɵa, TestingCompilerFactoryImpl as ɵb };
  467. //# sourceMappingURL=testing.js.map