@tech4good/angular-schematics 21.1.0 → 21.2.0

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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## [21.2.0](https://github.com/tech4good-lab/angular-schematics/compare/v21.1.0...v21.2.0) (2026-07-02)
2
+
3
+ ### Features
4
+
5
+ * **ng-add:** support simulating read errors and loading states in firebase mock ([7f3ad7e](https://github.com/tech4good-lab/angular-schematics/commit/7f3ad7e665ec129fb7151c6ea4a02712068a1d0e))
6
+
7
+ ### Build System
8
+
9
+ * **ng-add:** bump template dependency for release ([f717736](https://github.com/tech4good-lab/angular-schematics/commit/f717736d4f349d9c09ed408055a36501a0b729cb))
1
10
  ## [21.1.0](https://github.com/tech4good-lab/angular-schematics/compare/v21.0.0...v21.1.0) (2026-07-01)
2
11
 
3
12
  ### Features
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tech4good/angular-schematics",
3
- "version": "21.1.0",
3
+ "version": "21.2.0",
4
4
  "description": "A set of schematics for generating modules, containers, components, and entities",
5
5
  "scripts": {
6
6
  "build": "tsc -p tsconfig.json",
@@ -53,7 +53,7 @@
53
53
  "@firebase/rules-unit-testing": "^5.0.1",
54
54
  "firebase-tools": "^14.27.0",
55
55
  "@ngx-env/builder": "^21.0.1",
56
- "@tech4good/angular-schematics": "^21.1.0",
56
+ "@tech4good/angular-schematics": "^21.2.0",
57
57
  "@types/estree": "^1.0.0",
58
58
  "@types/jest": "^30.0.0",
59
59
  "@types/node": "^18.19.47",
@@ -1,6 +1,6 @@
1
1
  import { Injectable, inject, Injector, computed, Provider } from '@angular/core';
2
2
  import { toObservable } from '@angular/core/rxjs-interop';
3
- import { Observable, combineLatest, merge, of, from, pipe, BehaviorSubject } from 'rxjs';
3
+ import { Observable, combineLatest, merge, of, from, pipe, BehaviorSubject, throwError, NEVER } from 'rxjs';
4
4
  import { tap, pluck, mergeMap, pairwise, delay, startWith, filter, takeUntil, skip, switchMap, map, take } from 'rxjs/operators';
5
5
  import { environment } from '../../../environments/environment';
6
6
  import { DocumentSnapshot, serverTimestamp, Timestamp, getDoc, getDocs, doc, setDoc, updateDoc, deleteDoc, docData, collection, collectionData, collectionChanges, query, where, orderBy, OrderByDirection, limit, startAt, startAfter, endAt, endBefore, DocumentChange, increment, AggregateQuerySnapshot, AggregateField, AggregateSpec, getAggregateFromServer, getCountFromServer } from '@angular/fire/firestore';
@@ -30,6 +30,20 @@ export class FirebaseMockService implements DatabaseService {
30
30
  GET_LATENCY_SIMULATION_DELAY = 100;
31
31
  PUT_LATENCY_SIMULATION_DELAY = 300;
32
32
 
33
+ /**
34
+ * Collections that throw/reject on any read operation.
35
+ * Set via `provideFirebaseMock({ failCollections: [...] })` or mutate mid-test
36
+ * via `db.failCollections = [...]` to simulate error → recovery flows.
37
+ */
38
+ failCollections: string[] = [];
39
+
40
+ /**
41
+ * Collections where reads never emit/resolve (simulates perpetual loading).
42
+ * Set via `provideFirebaseMock({ stallCollections: [...] })` or mutate mid-test
43
+ * via `db.stallCollections = [...]`.
44
+ */
45
+ stallCollections: string[] = [];
46
+
33
47
  constructor(
34
48
  private injector: Injector,
35
49
  ) {
@@ -77,6 +91,10 @@ export class FirebaseMockService implements DatabaseService {
77
91
  }
78
92
 
79
93
  streamEntity<T>(collectionName: string, id: string) {
94
+ if (this.stallCollections.includes(collectionName)) return NEVER;
95
+ if (this.failCollections.includes(collectionName)) {
96
+ return throwError(() => new Error(`Simulated read error for collection: ${collectionName}`));
97
+ }
80
98
  const store = this.DB[collectionName];
81
99
  const entity = computed(() => {
82
100
  return store.selectEntity(id);
@@ -87,6 +105,10 @@ export class FirebaseMockService implements DatabaseService {
87
105
  }
88
106
 
89
107
  streamEntities<T>(collectionName, queryParams, queryOptions) {
108
+ if (this.stallCollections.includes(collectionName)) return NEVER;
109
+ if (this.failCollections.includes(collectionName)) {
110
+ return throwError(() => new Error(`Simulated read error for collection: ${collectionName}`));
111
+ }
90
112
  const store = this.DB[collectionName];
91
113
  const entities = computed(() => {
92
114
  return store.selectEntities(queryParams, queryOptions);
@@ -98,6 +120,10 @@ export class FirebaseMockService implements DatabaseService {
98
120
  }
99
121
 
100
122
  streamEntitiesChanges<T>(collectionName, queryParams, queryOptions) {
123
+ if (this.stallCollections.includes(collectionName)) return NEVER;
124
+ if (this.failCollections.includes(collectionName)) {
125
+ return throwError(() => new Error(`Simulated read error for collection: ${collectionName}`));
126
+ }
101
127
  const store = this.DB[collectionName];
102
128
  const streamEntities = computed(() => {
103
129
  return store.selectEntities(queryParams, queryOptions);
@@ -148,6 +174,10 @@ export class FirebaseMockService implements DatabaseService {
148
174
  }
149
175
 
150
176
  async getEntity<T>(collectionName: string, id: string) {
177
+ if (this.stallCollections.includes(collectionName)) return new Promise(() => {});
178
+ if (this.failCollections.includes(collectionName)) {
179
+ throw new Error(`Simulated read error for collection: ${collectionName}`);
180
+ }
151
181
  const store = this.DB[collectionName];
152
182
  await new Promise((resolve) => setTimeout(resolve, this.GET_LATENCY_SIMULATION_DELAY));
153
183
  return store.selectEntity(id);
@@ -158,6 +188,10 @@ export class FirebaseMockService implements DatabaseService {
158
188
  queryParams: [string, string, any][],
159
189
  queryOptions?: { [index: string]: any },
160
190
  ): Promise<S[]> {
191
+ if (this.stallCollections.includes(collectionName)) return new Promise(() => {}) as Promise<S[]>;
192
+ if (this.failCollections.includes(collectionName)) {
193
+ throw new Error(`Simulated read error for collection: ${collectionName}`);
194
+ }
161
195
  const db = this.DB[collectionName];
162
196
  await new Promise((resolve) => setTimeout(resolve, this.GET_LATENCY_SIMULATION_DELAY));
163
197
  return db.selectEntities(queryParams, queryOptions);
@@ -278,19 +312,43 @@ export class FirebaseMockService implements DatabaseService {
278
312
 
279
313
  /**
280
314
  * Creates provider configuration for FirebaseMockService with custom DB collection seeding.
315
+ *
316
+ * @param options.disableLatency - When true, sets GET and PUT latency simulation delays to 0ms.
317
+ * Use this in spec files to avoid the `APP_INITIALIZER` boilerplate for zeroing latency.
318
+ * See TEST-AP-005 in testing-guide.md.
319
+ * @param options.failCollections - Collections that throw/reject on any read operation.
320
+ * The property is mutable mid-test via `db.failCollections = [...]` to simulate
321
+ * error → recovery flows (e.g., set failCollections, verify error banner,
322
+ * clear failCollections, click Retry, verify recovery).
323
+ * @param options.stallCollections - Collections where reads never emit/resolve, simulating
324
+ * perpetual loading. Mutable mid-test via `db.stallCollections = [...]`.
281
325
  */
282
326
  export function provideFirebaseMock({
283
327
  users,
284
328
  userContexts,
329
+ disableLatency,
330
+ failCollections,
331
+ stallCollections,
285
332
  }: {
286
333
  users?: any[];
287
334
  userContexts?: any[];
335
+ disableLatency?: boolean;
336
+ /** Collections that throw/reject on any read. Mutable mid-test via `db.failCollections`. */
337
+ failCollections?: string[];
338
+ /** Collections where reads never emit/resolve. Mutable mid-test via `db.stallCollections`. */
339
+ stallCollections?: string[];
288
340
  } = {}): Provider[] {
289
341
  return [
290
342
  {
291
343
  provide: FirebaseMockService,
292
344
  useFactory: (injector: Injector) => {
293
345
  const service = new FirebaseMockService(injector);
346
+ if (disableLatency) {
347
+ service.GET_LATENCY_SIMULATION_DELAY = 0;
348
+ service.PUT_LATENCY_SIMULATION_DELAY = 0;
349
+ }
350
+ if (failCollections) service.failCollections = failCollections;
351
+ if (stallCollections) service.stallCollections = stallCollections;
294
352
  if (users) service.DB['users'].init(users);
295
353
  if (userContexts) service.DB['userContexts'].init(userContexts);
296
354
  return service;