Front end of the Slack clone application.

testing.js 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. /**
  2. * @license Angular v5.2.11
  3. * (c) 2010-2018 Google, Inc. https://angular.io/
  4. * License: MIT
  5. */
  6. import { Injectable } from '@angular/core';
  7. import { ReadyState, Request } from '@angular/http';
  8. import { ReplaySubject } from 'rxjs/ReplaySubject';
  9. import { Subject } from 'rxjs/Subject';
  10. import { take } from 'rxjs/operator/take';
  11. /**
  12. * @fileoverview added by tsickle
  13. * @suppress {checkTypes} checked by tsc
  14. */
  15. /**
  16. * @license
  17. * Copyright Google Inc. All Rights Reserved.
  18. *
  19. * Use of this source code is governed by an MIT-style license that can be
  20. * found in the LICENSE file at https://angular.io/license
  21. */
  22. /**
  23. *
  24. * Mock Connection to represent a {\@link Connection} for tests.
  25. *
  26. * @deprecated use \@angular/common/http instead
  27. */
  28. var MockConnection = /** @class */ (function () {
  29. function MockConnection(req) {
  30. this.response = /** @type {?} */ (take.call(new ReplaySubject(1), 1));
  31. this.readyState = ReadyState.Open;
  32. this.request = req;
  33. }
  34. /**
  35. * Sends a mock response to the connection. This response is the value that is emitted to the
  36. * {@link EventEmitter} returned by {@link Http}.
  37. *
  38. * ### Example
  39. *
  40. * ```
  41. * var connection;
  42. * backend.connections.subscribe(c => connection = c);
  43. * http.request('data.json').subscribe(res => console.log(res.text()));
  44. * connection.mockRespond(new Response(new ResponseOptions({ body: 'fake response' }))); //logs
  45. * 'fake response'
  46. * ```
  47. *
  48. */
  49. /**
  50. * Sends a mock response to the connection. This response is the value that is emitted to the
  51. * {\@link EventEmitter} returned by {\@link Http}.
  52. *
  53. * ### Example
  54. *
  55. * ```
  56. * var connection;
  57. * backend.connections.subscribe(c => connection = c);
  58. * http.request('data.json').subscribe(res => console.log(res.text()));
  59. * connection.mockRespond(new Response(new ResponseOptions({ body: 'fake response' }))); //logs
  60. * 'fake response'
  61. * ```
  62. *
  63. * @param {?} res
  64. * @return {?}
  65. */
  66. MockConnection.prototype.mockRespond = /**
  67. * Sends a mock response to the connection. This response is the value that is emitted to the
  68. * {\@link EventEmitter} returned by {\@link Http}.
  69. *
  70. * ### Example
  71. *
  72. * ```
  73. * var connection;
  74. * backend.connections.subscribe(c => connection = c);
  75. * http.request('data.json').subscribe(res => console.log(res.text()));
  76. * connection.mockRespond(new Response(new ResponseOptions({ body: 'fake response' }))); //logs
  77. * 'fake response'
  78. * ```
  79. *
  80. * @param {?} res
  81. * @return {?}
  82. */
  83. function (res) {
  84. if (this.readyState === ReadyState.Done || this.readyState === ReadyState.Cancelled) {
  85. throw new Error('Connection has already been resolved');
  86. }
  87. this.readyState = ReadyState.Done;
  88. this.response.next(res);
  89. this.response.complete();
  90. };
  91. /**
  92. * Not yet implemented!
  93. *
  94. * Sends the provided {@link Response} to the `downloadObserver` of the `Request`
  95. * associated with this connection.
  96. */
  97. /**
  98. * Not yet implemented!
  99. *
  100. * Sends the provided {\@link Response} to the `downloadObserver` of the `Request`
  101. * associated with this connection.
  102. * @param {?} res
  103. * @return {?}
  104. */
  105. MockConnection.prototype.mockDownload = /**
  106. * Not yet implemented!
  107. *
  108. * Sends the provided {\@link Response} to the `downloadObserver` of the `Request`
  109. * associated with this connection.
  110. * @param {?} res
  111. * @return {?}
  112. */
  113. function (res) {
  114. // this.request.downloadObserver.onNext(res);
  115. // if (res.bytesLoaded === res.totalBytes) {
  116. // this.request.downloadObserver.onCompleted();
  117. // }
  118. };
  119. // TODO(jeffbcross): consider using Response type
  120. /**
  121. * Emits the provided error object as an error to the {@link Response} {@link EventEmitter}
  122. * returned
  123. * from {@link Http}.
  124. *
  125. * ### Example
  126. *
  127. * ```
  128. * var connection;
  129. * backend.connections.subscribe(c => connection = c);
  130. * http.request('data.json').subscribe(res => res, err => console.log(err)));
  131. * connection.mockError(new Error('error'));
  132. * ```
  133. *
  134. */
  135. /**
  136. * Emits the provided error object as an error to the {\@link Response} {\@link EventEmitter}
  137. * returned
  138. * from {\@link Http}.
  139. *
  140. * ### Example
  141. *
  142. * ```
  143. * var connection;
  144. * backend.connections.subscribe(c => connection = c);
  145. * http.request('data.json').subscribe(res => res, err => console.log(err)));
  146. * connection.mockError(new Error('error'));
  147. * ```
  148. *
  149. * @param {?=} err
  150. * @return {?}
  151. */
  152. MockConnection.prototype.mockError = /**
  153. * Emits the provided error object as an error to the {\@link Response} {\@link EventEmitter}
  154. * returned
  155. * from {\@link Http}.
  156. *
  157. * ### Example
  158. *
  159. * ```
  160. * var connection;
  161. * backend.connections.subscribe(c => connection = c);
  162. * http.request('data.json').subscribe(res => res, err => console.log(err)));
  163. * connection.mockError(new Error('error'));
  164. * ```
  165. *
  166. * @param {?=} err
  167. * @return {?}
  168. */
  169. function (err) {
  170. // Matches ResourceLoader semantics
  171. this.readyState = ReadyState.Done;
  172. this.response.error(err);
  173. };
  174. return MockConnection;
  175. }());
  176. /**
  177. * A mock backend for testing the {\@link Http} service.
  178. *
  179. * This class can be injected in tests, and should be used to override providers
  180. * to other backends, such as {\@link XHRBackend}.
  181. *
  182. * ### Example
  183. *
  184. * ```
  185. * import {Injectable, Injector} from '\@angular/core';
  186. * import {async, fakeAsync, tick} from '\@angular/core/testing';
  187. * import {BaseRequestOptions, ConnectionBackend, Http, RequestOptions} from '\@angular/http';
  188. * import {Response, ResponseOptions} from '\@angular/http';
  189. * import {MockBackend, MockConnection} from '\@angular/http/testing';
  190. *
  191. * const HERO_ONE = 'HeroNrOne';
  192. * const HERO_TWO = 'WillBeAlwaysTheSecond';
  193. *
  194. * \@Injectable()
  195. * class HeroService {
  196. * constructor(private http: Http) {}
  197. *
  198. * getHeroes(): Promise<String[]> {
  199. * return this.http.get('myservices.de/api/heroes')
  200. * .toPromise()
  201. * .then(response => response.json().data)
  202. * .catch(e => this.handleError(e));
  203. * }
  204. *
  205. * private handleError(error: any): Promise<any> {
  206. * console.error('An error occurred', error);
  207. * return Promise.reject(error.message || error);
  208. * }
  209. * }
  210. *
  211. * describe('MockBackend HeroService Example', () => {
  212. * beforeEach(() => {
  213. * this.injector = Injector.create([
  214. * {provide: ConnectionBackend, useClass: MockBackend},
  215. * {provide: RequestOptions, useClass: BaseRequestOptions},
  216. * Http,
  217. * HeroService,
  218. * ]);
  219. * this.heroService = this.injector.get(HeroService);
  220. * this.backend = this.injector.get(ConnectionBackend) as MockBackend;
  221. * this.backend.connections.subscribe((connection: any) => this.lastConnection = connection);
  222. * });
  223. *
  224. * it('getHeroes() should query current service url', () => {
  225. * this.heroService.getHeroes();
  226. * expect(this.lastConnection).toBeDefined('no http service connection at all?');
  227. * expect(this.lastConnection.request.url).toMatch(/api\/heroes$/, 'url invalid');
  228. * });
  229. *
  230. * it('getHeroes() should return some heroes', fakeAsync(() => {
  231. * let result: String[];
  232. * this.heroService.getHeroes().then((heroes: String[]) => result = heroes);
  233. * this.lastConnection.mockRespond(new Response(new ResponseOptions({
  234. * body: JSON.stringify({data: [HERO_ONE, HERO_TWO]}),
  235. * })));
  236. * tick();
  237. * expect(result.length).toEqual(2, 'should contain given amount of heroes');
  238. * expect(result[0]).toEqual(HERO_ONE, ' HERO_ONE should be the first hero');
  239. * expect(result[1]).toEqual(HERO_TWO, ' HERO_TWO should be the second hero');
  240. * }));
  241. *
  242. * it('getHeroes() while server is down', fakeAsync(() => {
  243. * let result: String[];
  244. * let catchedError: any;
  245. * this.heroService.getHeroes()
  246. * .then((heroes: String[]) => result = heroes)
  247. * .catch((error: any) => catchedError = error);
  248. * this.lastConnection.mockRespond(new Response(new ResponseOptions({
  249. * status: 404,
  250. * statusText: 'URL not Found',
  251. * })));
  252. * tick();
  253. * expect(result).toBeUndefined();
  254. * expect(catchedError).toBeDefined();
  255. * }));
  256. * });
  257. * ```
  258. *
  259. * This method only exists in the mock implementation, not in real Backends.
  260. *
  261. * @deprecated use \@angular/common/http instead
  262. */
  263. var MockBackend = /** @class */ (function () {
  264. function MockBackend() {
  265. var _this = this;
  266. this.connectionsArray = [];
  267. this.connections = new Subject();
  268. this.connections.subscribe(function (connection) { return _this.connectionsArray.push(connection); });
  269. this.pendingConnections = new Subject();
  270. }
  271. /**
  272. * Checks all connections, and raises an exception if any connection has not received a response.
  273. *
  274. * This method only exists in the mock implementation, not in real Backends.
  275. */
  276. /**
  277. * Checks all connections, and raises an exception if any connection has not received a response.
  278. *
  279. * This method only exists in the mock implementation, not in real Backends.
  280. * @return {?}
  281. */
  282. MockBackend.prototype.verifyNoPendingRequests = /**
  283. * Checks all connections, and raises an exception if any connection has not received a response.
  284. *
  285. * This method only exists in the mock implementation, not in real Backends.
  286. * @return {?}
  287. */
  288. function () {
  289. var /** @type {?} */ pending = 0;
  290. this.pendingConnections.subscribe(function (c) { return pending++; });
  291. if (pending > 0)
  292. throw new Error(pending + " pending connections to be resolved");
  293. };
  294. /**
  295. * Can be used in conjunction with `verifyNoPendingRequests` to resolve any not-yet-resolve
  296. * connections, if it's expected that there are connections that have not yet received a response.
  297. *
  298. * This method only exists in the mock implementation, not in real Backends.
  299. */
  300. /**
  301. * Can be used in conjunction with `verifyNoPendingRequests` to resolve any not-yet-resolve
  302. * connections, if it's expected that there are connections that have not yet received a response.
  303. *
  304. * This method only exists in the mock implementation, not in real Backends.
  305. * @return {?}
  306. */
  307. MockBackend.prototype.resolveAllConnections = /**
  308. * Can be used in conjunction with `verifyNoPendingRequests` to resolve any not-yet-resolve
  309. * connections, if it's expected that there are connections that have not yet received a response.
  310. *
  311. * This method only exists in the mock implementation, not in real Backends.
  312. * @return {?}
  313. */
  314. function () { this.connections.subscribe(function (c) { return c.readyState = 4; }); };
  315. /**
  316. * Creates a new {@link MockConnection}. This is equivalent to calling `new
  317. * MockConnection()`, except that it also will emit the new `Connection` to the `connections`
  318. * emitter of this `MockBackend` instance. This method will usually only be used by tests
  319. * against the framework itself, not by end-users.
  320. */
  321. /**
  322. * Creates a new {\@link MockConnection}. This is equivalent to calling `new
  323. * MockConnection()`, except that it also will emit the new `Connection` to the `connections`
  324. * emitter of this `MockBackend` instance. This method will usually only be used by tests
  325. * against the framework itself, not by end-users.
  326. * @param {?} req
  327. * @return {?}
  328. */
  329. MockBackend.prototype.createConnection = /**
  330. * Creates a new {\@link MockConnection}. This is equivalent to calling `new
  331. * MockConnection()`, except that it also will emit the new `Connection` to the `connections`
  332. * emitter of this `MockBackend` instance. This method will usually only be used by tests
  333. * against the framework itself, not by end-users.
  334. * @param {?} req
  335. * @return {?}
  336. */
  337. function (req) {
  338. if (!req || !(req instanceof Request)) {
  339. throw new Error("createConnection requires an instance of Request, got " + req);
  340. }
  341. var /** @type {?} */ connection = new MockConnection(req);
  342. this.connections.next(connection);
  343. return connection;
  344. };
  345. MockBackend.decorators = [
  346. { type: Injectable },
  347. ];
  348. /** @nocollapse */
  349. MockBackend.ctorParameters = function () { return []; };
  350. return MockBackend;
  351. }());
  352. /**
  353. * @fileoverview added by tsickle
  354. * @suppress {checkTypes} checked by tsc
  355. */
  356. /**
  357. * @license
  358. * Copyright Google Inc. All Rights Reserved.
  359. *
  360. * Use of this source code is governed by an MIT-style license that can be
  361. * found in the LICENSE file at https://angular.io/license
  362. */
  363. /**
  364. * @module
  365. * @description
  366. * Entry point for all public APIs of the platform-server/testing package.
  367. */
  368. /**
  369. * @fileoverview added by tsickle
  370. * @suppress {checkTypes} checked by tsc
  371. */
  372. /**
  373. * @license
  374. * Copyright Google Inc. All Rights Reserved.
  375. *
  376. * Use of this source code is governed by an MIT-style license that can be
  377. * found in the LICENSE file at https://angular.io/license
  378. */
  379. /**
  380. * @module
  381. * @description
  382. * Entry point for all public APIs of this package.
  383. */
  384. /**
  385. * @fileoverview added by tsickle
  386. * @suppress {checkTypes} checked by tsc
  387. */
  388. /**
  389. * Generated bundle index. Do not edit.
  390. */
  391. export { MockConnection, MockBackend };
  392. //# sourceMappingURL=testing.js.map