@tech4good/angular-schematics 21.4.0 → 21.6.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 +33 -0
- package/package.json +1 -1
- package/src/entity/files/__name@dasherize__/__name@dasherize__.mock.ts.template +2 -1
- package/src/entity/files/__name@dasherize__/__name@dasherize__.model.ts.template +2 -1
- package/src/entity/index.js +57 -0
- package/src/entity/index.js.map +1 -1
- package/src/entity/schema.json +4 -0
- package/src/ng-add/files/.firebaserc.template +2 -1
- package/src/ng-add/files/.gitignore.template +2 -0
- package/src/ng-add/files/bigquery/queries/active_time_by_route.sql.template +34 -0
- package/src/ng-add/files/bigquery/scripts/export_entities.py.template +143 -0
- package/src/ng-add/files/bigquery/scripts/run_query.py.template +167 -0
- package/src/ng-add/files/bigquery/views/events_flat.sql.template +60 -0
- package/src/ng-add/files/bigquery/views/logs_latest.sql.template +34 -0
- package/src/ng-add/files/docs-infra/analytics-guide.md.template +170 -0
- package/src/ng-add/files/docs-infra/authentication-architecture.md.template +270 -0
- package/src/ng-add/files/docs-infra/infrastructure-guide.md.template +16 -10
- package/src/ng-add/files/firebase.json.template +6 -0
- package/src/ng-add/files/firebase.logs.json.template +5 -0
- package/src/ng-add/files/firestore.indexes.json.template +112 -0
- package/src/ng-add/files/firestore.logs.rules.spec.ts.template +100 -0
- package/src/ng-add/files/firestore.logs.rules.template +8 -0
- package/src/ng-add/files/firestore.rules.spec.ts.template +84 -15
- package/src/ng-add/files/firestore.rules.template +29 -17
- package/src/ng-add/files/functions/.gitignore.template +3 -0
- package/src/ng-add/files/functions/package.json.template +12 -0
- package/src/ng-add/files/functions/src/index.ts.template +44 -0
- package/src/ng-add/files/functions/tsconfig.json.template +13 -0
- package/src/ng-add/files/jest.config.ts.template +1 -1
- package/src/ng-add/files/package.json.template +7 -4
- package/src/ng-add/files/src/app/admin/admin-panel/admin-panel.component.html.template +3 -1
- package/src/ng-add/files/src/app/admin/admin-panel/admin-panel.component.spec.ts.template +6 -8
- package/src/ng-add/files/src/app/admin/admin-panel/admin-panel.component.ts.template +2 -0
- package/src/ng-add/files/src/app/app.component.html.template +2 -2
- package/src/ng-add/files/src/app/app.component.ts.template +2 -0
- package/src/ng-add/files/src/app/app.routes.ts.template +6 -0
- package/src/ng-add/files/src/app/auth-routing.spec.ts.template +9 -4
- package/src/ng-add/files/src/app/core/analytics/log.service.ts.template +26 -4
- package/src/ng-add/files/src/app/core/analytics/time-analytics.service.spec.ts.template +145 -2
- package/src/ng-add/files/src/app/core/analytics/time-analytics.service.ts.template +355 -149
- package/src/ng-add/files/src/app/core/auth/auth.service.ts.template +6 -1
- package/src/ng-add/files/src/app/core/auth/guards/require-admin.guard.spec.ts.template +38 -0
- package/src/ng-add/files/src/app/core/auth/guards/require-admin.guard.ts.template +3 -2
- package/src/ng-add/files/src/app/core/auth/guards/require-auth-and-consent.guard.ts.template +10 -3
- package/src/ng-add/files/src/app/core/firebase/cached-listeners.service.ts.template +11 -5
- package/src/ng-add/files/src/app/core/firebase/database.service.ts.template +34 -17
- package/src/ng-add/files/src/app/core/firebase/email-link-context.service.spec.ts.template +59 -0
- package/src/ng-add/files/src/app/core/firebase/email-link-context.service.ts.template +147 -0
- package/src/ng-add/files/src/app/core/firebase/firebase.mock.service.ts.template +104 -17
- package/src/ng-add/files/src/app/core/firebase/firebase.service.spec.ts.template +116 -0
- package/src/ng-add/files/src/app/core/firebase/firebase.service.ts.template +367 -70
- package/src/ng-add/files/src/app/core/store/app.store.ts.template +4 -1
- package/src/ng-add/files/src/app/core/store/auth/auth.mock.ts.template +52 -66
- package/src/ng-add/files/src/app/core/store/auth/auth.store.spec.ts.template +127 -0
- package/src/ng-add/files/src/app/core/store/auth/auth.store.ts.template +216 -147
- package/src/ng-add/files/src/app/core/store/user/user.mock.ts.template +2 -4
- package/src/ng-add/files/src/app/core/store/user/user.model.ts.template +1 -1
- package/src/ng-add/files/src/app/core/store/user-private/user-private.model.ts.template +1 -0
- package/src/ng-add/files/src/app/first-time/auth-action/auth-action.component.html.template +4 -0
- package/src/ng-add/files/src/app/first-time/auth-action/auth-action.component.scss.template +1 -0
- package/src/ng-add/files/src/app/first-time/auth-action/auth-action.component.ts.template +38 -0
- package/src/ng-add/files/src/app/first-time/consent/consent.component.html.template +172 -48
- package/src/ng-add/files/src/app/first-time/consent/consent.component.scss.template +31 -0
- package/src/ng-add/files/src/app/first-time/consent/consent.component.spec.ts.template +31 -3
- package/src/ng-add/files/src/app/first-time/consent/consent.component.ts.template +12 -11
- package/src/ng-add/files/src/app/first-time/consent/consent.guard.ts.template +5 -7
- package/src/ng-add/files/src/app/first-time/early-access/early-access.component.spec.ts.template +12 -1
- package/src/ng-add/files/src/app/first-time/early-access/early-access.component.ts.template +93 -48
- package/src/ng-add/files/src/app/first-time/early-access/early-access.guard.ts.template +12 -2
- package/src/ng-add/files/src/app/first-time/email-link/email-link.component.html.template +18 -0
- package/src/ng-add/files/src/app/first-time/email-link/email-link.component.scss.template +2 -0
- package/src/ng-add/files/src/app/first-time/email-link/email-link.component.spec.ts.template +40 -0
- package/src/ng-add/files/src/app/first-time/email-link/email-link.component.ts.template +76 -0
- package/src/ng-add/files/src/app/first-time/first-time-routing.spec.ts.template +14 -8
- package/src/ng-add/files/src/app/first-time/landing/hero/hero.component.html.template +19 -7
- package/src/ng-add/files/src/app/first-time/landing/hero/hero.component.scss.template +51 -0
- package/src/ng-add/files/src/app/first-time/landing/hero/hero.component.ts.template +29 -5
- package/src/ng-add/files/src/app/first-time/landing/landing.component.html.template +2 -1
- package/src/ng-add/files/src/app/first-time/landing/landing.component.scss.template +12 -8
- package/src/ng-add/files/src/app/first-time/landing/landing.component.spec.ts.template +31 -10
- package/src/ng-add/files/src/app/first-time/landing/landing.component.ts.template +6 -19
- package/src/ng-add/files/src/app/first-time/login/login.component.html.template +58 -6
- package/src/ng-add/files/src/app/first-time/login/login.component.scss.template +151 -22
- package/src/ng-add/files/src/app/first-time/login/login.component.spec.ts.template +18 -38
- package/src/ng-add/files/src/app/first-time/login/login.component.ts.template +59 -31
- package/src/ng-add/files/src/app/main/account-profile/account-profile.component.html.template +12 -0
- package/src/ng-add/files/src/app/main/account-profile/account-profile.component.scss.template +39 -0
- package/src/ng-add/files/src/app/main/account-profile/account-profile.component.spec.ts.template +68 -0
- package/src/ng-add/files/src/app/main/account-profile/account-profile.component.ts.template +20 -0
- package/src/ng-add/files/src/app/main/account-profile/delete-guest-card/delete-guest-card.component.html.template +24 -0
- package/src/ng-add/files/src/app/main/account-profile/delete-guest-card/delete-guest-card.component.scss.template +50 -0
- package/src/ng-add/files/src/app/main/account-profile/delete-guest-card/delete-guest-card.component.spec.ts.template +65 -0
- package/src/ng-add/files/src/app/main/account-profile/delete-guest-card/delete-guest-card.component.ts.template +59 -0
- package/src/ng-add/files/src/app/main/account-profile/guest-deletion-dialog.component.ts.template +51 -0
- package/src/ng-add/files/src/app/main/account-profile/profile-details-card/profile-details-card.component.html.template +50 -0
- package/src/ng-add/files/src/app/main/account-profile/profile-details-card/profile-details-card.component.scss.template +137 -0
- package/src/ng-add/files/src/app/main/account-profile/profile-details-card/profile-details-card.component.spec.ts.template +57 -0
- package/src/ng-add/files/src/app/main/account-profile/profile-details-card/profile-details-card.component.ts.template +59 -0
- package/src/ng-add/files/src/app/main/account-profile/sign-in-methods-card/sign-in-methods-card.component.html.template +133 -0
- package/src/ng-add/files/src/app/main/account-profile/sign-in-methods-card/sign-in-methods-card.component.scss.template +207 -0
- package/src/ng-add/files/src/app/main/account-profile/sign-in-methods-card/sign-in-methods-card.component.spec.ts.template +74 -0
- package/src/ng-add/files/src/app/main/account-profile/sign-in-methods-card/sign-in-methods-card.component.ts.template +130 -0
- package/src/ng-add/files/src/app/main/home/home.component.ts.template +0 -5
- package/src/ng-add/files/src/app/shared/guest-warning-bar/guest-warning-bar.component.html.template +15 -0
- package/src/ng-add/files/src/app/shared/guest-warning-bar/guest-warning-bar.component.scss.template +79 -0
- package/src/ng-add/files/src/app/shared/guest-warning-bar/guest-warning-bar.component.spec.ts.template +59 -0
- package/src/ng-add/files/src/app/shared/guest-warning-bar/guest-warning-bar.component.ts.template +44 -0
- package/src/ng-add/files/src/app/shared/navbar/navbar.component.html.template +45 -15
- package/src/ng-add/files/src/app/shared/navbar/navbar.component.scss.template +103 -19
- package/src/ng-add/files/src/app/shared/navbar/navbar.component.spec.ts.template +73 -9
- package/src/ng-add/files/src/app/shared/navbar/navbar.component.ts.template +46 -18
- package/src/ng-add/files/src/environments/environment.prod.ts.template +1 -0
- package/src/ng-add/files/src/environments/environment.test.ts.template +1 -0
- package/src/ng-add/files/src/environments/environment.ts.template +1 -1
- package/src/ng-add/index_spec.d.ts +1 -0
- package/src/ng-add/index_spec.js +108 -0
- package/src/ng-add/index_spec.js.map +1 -0
- package/tsconfig.json +2 -2
|
@@ -18,12 +18,13 @@ import { createMockUser } from './core/store/user/user.mock';
|
|
|
18
18
|
describe('Core Auth Routing', () => {
|
|
19
19
|
let harness: RouterTestingHarness;
|
|
20
20
|
let router: Router;
|
|
21
|
-
let mockAuthService: { resolveUser: jest.Mock };
|
|
21
|
+
let mockAuthService: { resolveUser: jest.Mock; resolveSession: jest.Mock };
|
|
22
22
|
let mockUserSignal: any;
|
|
23
23
|
|
|
24
24
|
beforeEach(async () => {
|
|
25
25
|
mockAuthService = {
|
|
26
26
|
resolveUser: jest.fn().mockReturnValue(of(null)),
|
|
27
|
+
resolveSession: jest.fn().mockReturnValue(of(null)),
|
|
27
28
|
};
|
|
28
29
|
mockUserSignal = signal(null);
|
|
29
30
|
|
|
@@ -53,7 +54,7 @@ describe('Core Auth Routing', () => {
|
|
|
53
54
|
expect(router.url).toEqual('/landing');
|
|
54
55
|
});
|
|
55
56
|
|
|
56
|
-
it('should intercept navigation to /admin and redirect to /
|
|
57
|
+
it('should intercept navigation to /admin and redirect through /landing to /home', async () => {
|
|
57
58
|
await harness.navigateByUrl('/admin');
|
|
58
59
|
// Wait for async routing to settle
|
|
59
60
|
await harness.fixture.whenStable();
|
|
@@ -64,6 +65,7 @@ describe('Core Auth Routing', () => {
|
|
|
64
65
|
describe('Authenticated User (Standard)', () => {
|
|
65
66
|
beforeEach(() => {
|
|
66
67
|
mockAuthService.resolveUser.mockReturnValue(of(createMockUser()));
|
|
68
|
+
mockAuthService.resolveSession.mockReturnValue(of({ isAnonymous: false, emailVerified: true }));
|
|
67
69
|
mockUserSignal.set(createMockUser());
|
|
68
70
|
});
|
|
69
71
|
|
|
@@ -73,7 +75,7 @@ describe('Core Auth Routing', () => {
|
|
|
73
75
|
expect(router.url).toEqual('/home');
|
|
74
76
|
});
|
|
75
77
|
|
|
76
|
-
it('should intercept navigation to /admin and redirect to /
|
|
78
|
+
it('should intercept navigation to /admin and redirect to /landing', async () => {
|
|
77
79
|
await harness.navigateByUrl('/admin');
|
|
78
80
|
await harness.fixture.whenStable();
|
|
79
81
|
expect(router.url).toEqual('/home');
|
|
@@ -82,7 +84,10 @@ describe('Core Auth Routing', () => {
|
|
|
82
84
|
|
|
83
85
|
describe('Admin User', () => {
|
|
84
86
|
beforeEach(() => {
|
|
85
|
-
mockAuthService.resolveUser.mockReturnValue(
|
|
87
|
+
mockAuthService.resolveUser.mockReturnValue(
|
|
88
|
+
of(createMockUser({ isAdmin: true, __id: 'admin1' })),
|
|
89
|
+
);
|
|
90
|
+
mockAuthService.resolveSession.mockReturnValue(of({ isAnonymous: false, emailVerified: true }));
|
|
86
91
|
mockUserSignal.set(createMockUser({ isAdmin: true, __id: 'admin1' }));
|
|
87
92
|
});
|
|
88
93
|
|
|
@@ -6,6 +6,8 @@ import { TimeAtRoute } from './time-analytics.service';
|
|
|
6
6
|
|
|
7
7
|
interface LogData extends TimeAtRoute {
|
|
8
8
|
interactions?: Array<{ 0: number; 1: string; 2: string; 3: string; }>;
|
|
9
|
+
_createdAt?: number;
|
|
10
|
+
_updatedAt?: number;
|
|
9
11
|
}
|
|
10
12
|
|
|
11
13
|
/**
|
|
@@ -37,7 +39,12 @@ export class LogInDevService {
|
|
|
37
39
|
rawLog(data: LogData) {
|
|
38
40
|
if (this.LOG_IN_DEV) {
|
|
39
41
|
const logId = getLogId(data);
|
|
40
|
-
|
|
42
|
+
const updatedData = {
|
|
43
|
+
...data,
|
|
44
|
+
_createdAt: data._createdAt || data.startTime,
|
|
45
|
+
_updatedAt: Date.now(),
|
|
46
|
+
};
|
|
47
|
+
console.log('LOGGING', logId, updatedData);
|
|
41
48
|
}
|
|
42
49
|
}
|
|
43
50
|
|
|
@@ -45,7 +52,12 @@ export class LogInDevService {
|
|
|
45
52
|
if (this.LOG_IN_DEV) {
|
|
46
53
|
const logId = getLogId(data);
|
|
47
54
|
if (data !== null) {
|
|
48
|
-
|
|
55
|
+
const updatedData = {
|
|
56
|
+
...data,
|
|
57
|
+
_createdAt: data._createdAt || data.startTime,
|
|
58
|
+
_updatedAt: Date.now(),
|
|
59
|
+
};
|
|
60
|
+
console.log('BEACON LOGGING', logId, updatedData);
|
|
49
61
|
}
|
|
50
62
|
}
|
|
51
63
|
}
|
|
@@ -130,7 +142,12 @@ export class LogDBService {
|
|
|
130
142
|
// e.g. for storing things in localStorage and saving next time we load
|
|
131
143
|
// the browser
|
|
132
144
|
const docRef = doc(this.log, logType, logId);
|
|
133
|
-
|
|
145
|
+
const updatedData = {
|
|
146
|
+
...data,
|
|
147
|
+
_createdAt: data._createdAt || data.startTime,
|
|
148
|
+
_updatedAt: Date.now(),
|
|
149
|
+
};
|
|
150
|
+
setDoc(docRef, updatedData);
|
|
134
151
|
}
|
|
135
152
|
}
|
|
136
153
|
|
|
@@ -140,9 +157,14 @@ export class LogDBService {
|
|
|
140
157
|
|
|
141
158
|
if (data !== null) {
|
|
142
159
|
if (!isDevMode() && environment['firebaseLogs'] && environment['firebaseLogs']['projectId']) {
|
|
160
|
+
const updatedData = {
|
|
161
|
+
...data,
|
|
162
|
+
_createdAt: data._createdAt || data.startTime,
|
|
163
|
+
_updatedAt: Date.now(),
|
|
164
|
+
};
|
|
143
165
|
navigator.sendBeacon(
|
|
144
166
|
`https://firestore.googleapis.com/v1/projects/${environment['firebaseLogs']['projectId']}/databases/(default)/documents:commit`,
|
|
145
|
-
reformatLogForBeacon(
|
|
167
|
+
reformatLogForBeacon(updatedData, logType, logId),
|
|
146
168
|
);
|
|
147
169
|
}
|
|
148
170
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { TestBed } from '@angular/core/testing';
|
|
2
|
+
import { signal, Injector } from '@angular/core';
|
|
2
3
|
import { Router, NavigationEnd, Event as RouterEvent } from '@angular/router';
|
|
3
|
-
import { Subject, of } from 'rxjs';
|
|
4
|
+
import { Subject, BehaviorSubject, of } from 'rxjs';
|
|
4
5
|
import { TimeAnalyticsService } from './time-analytics.service';
|
|
5
6
|
import { DATABASE_SERVICE } from '../firebase/database.service';
|
|
6
7
|
import { LOG_SERVICE } from './log.service';
|
|
@@ -136,5 +137,147 @@ describe('TimeAnalyticsService', () => {
|
|
|
136
137
|
// Cleanup
|
|
137
138
|
dateSpy.mockRestore();
|
|
138
139
|
});
|
|
139
|
-
});
|
|
140
140
|
|
|
141
|
+
it('should serialize objects as JSON strings when tracking interactions', () => {
|
|
142
|
+
let currentTime = 1000;
|
|
143
|
+
const dateSpy = jest.spyOn(Date, 'now').mockImplementation(() => currentTime);
|
|
144
|
+
const logService = TestBed.inject(LOG_SERVICE) as any;
|
|
145
|
+
|
|
146
|
+
// Start logging
|
|
147
|
+
service.startTimeLogging();
|
|
148
|
+
|
|
149
|
+
// 1. User routes to /home
|
|
150
|
+
currentTime = 1000;
|
|
151
|
+
routerEvents$.next(new NavigationEnd(1, '/home', '/home'));
|
|
152
|
+
document.dispatchEvent(new Event('click'));
|
|
153
|
+
|
|
154
|
+
// 2. User interacts again on /home at T=2000 to accumulate active time
|
|
155
|
+
currentTime = 2000;
|
|
156
|
+
document.dispatchEvent(new Event('click'));
|
|
157
|
+
|
|
158
|
+
// 3. User tracks interaction with object payload
|
|
159
|
+
currentTime = 2500;
|
|
160
|
+
const payload = { key: 'value', count: 123 };
|
|
161
|
+
service.trackInteraction('category', 'action', payload);
|
|
162
|
+
|
|
163
|
+
// 4. User interacts again on /home at T=3000
|
|
164
|
+
currentTime = 3000;
|
|
165
|
+
document.dispatchEvent(new Event('click'));
|
|
166
|
+
|
|
167
|
+
// 5. User routes away to save the log
|
|
168
|
+
currentTime = 4000;
|
|
169
|
+
routerEvents$.next(new NavigationEnd(2, '/profile', '/profile'));
|
|
170
|
+
document.dispatchEvent(new Event('click'));
|
|
171
|
+
|
|
172
|
+
// Verify interaction was serialized
|
|
173
|
+
expect(logService.rawLog).toHaveBeenCalledTimes(1);
|
|
174
|
+
const savedLog = logService.rawLog.mock.calls[0][0];
|
|
175
|
+
|
|
176
|
+
expect(savedLog.interactions).toBeDefined();
|
|
177
|
+
expect(savedLog.interactions.length).toEqual(1);
|
|
178
|
+
expect(savedLog.interactions[0]).toEqual({
|
|
179
|
+
0: 2500,
|
|
180
|
+
1: 'category',
|
|
181
|
+
2: 'action',
|
|
182
|
+
3: JSON.stringify(payload),
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
dateSpy.mockRestore();
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('should track active time per registered state signal and flush log to DB when state changes', () => {
|
|
189
|
+
let currentTime = 1000;
|
|
190
|
+
const dateSpy = jest.spyOn(Date, 'now').mockImplementation(() => currentTime);
|
|
191
|
+
const logService = TestBed.inject(LOG_SERVICE) as any;
|
|
192
|
+
|
|
193
|
+
service.startTimeLogging();
|
|
194
|
+
|
|
195
|
+
// 1. User routes to /practice at T=1000
|
|
196
|
+
currentTime = 1000;
|
|
197
|
+
routerEvents$.next(new NavigationEnd(1, '/practice', '/practice'));
|
|
198
|
+
|
|
199
|
+
const problemSignal = signal<string | null>('prob-1');
|
|
200
|
+
service.registerState('problemId', problemSignal, TestBed.inject(Injector));
|
|
201
|
+
TestBed.flushEffects();
|
|
202
|
+
|
|
203
|
+
// Initial click at T=1000
|
|
204
|
+
document.dispatchEvent(new Event('click'));
|
|
205
|
+
|
|
206
|
+
// 2. User interacts again on prob-1 at T=2000
|
|
207
|
+
currentTime = 2000;
|
|
208
|
+
document.dispatchEvent(new Event('click'));
|
|
209
|
+
|
|
210
|
+
// 3. User changes state to prob-2 at T=3000
|
|
211
|
+
currentTime = 3000;
|
|
212
|
+
problemSignal.set('prob-2');
|
|
213
|
+
TestBed.flushEffects();
|
|
214
|
+
document.dispatchEvent(new Event('click'));
|
|
215
|
+
|
|
216
|
+
// rawLog should be called for prob-1
|
|
217
|
+
expect(logService.rawLog).toHaveBeenCalledTimes(1);
|
|
218
|
+
const prob1Log = logService.rawLog.mock.calls[0][0];
|
|
219
|
+
expect(prob1Log.route).toEqual('/practice');
|
|
220
|
+
expect(prob1Log.state).toEqual({ problemId: 'prob-1' });
|
|
221
|
+
expect(prob1Log.time.find((t: any) => t.type === 'active').total).toEqual(1000);
|
|
222
|
+
|
|
223
|
+
// 4. User interacts again on prob-2 at T=4000
|
|
224
|
+
currentTime = 4000;
|
|
225
|
+
document.dispatchEvent(new Event('click'));
|
|
226
|
+
|
|
227
|
+
// 5. User routes away to /profile at T=5000
|
|
228
|
+
currentTime = 5000;
|
|
229
|
+
routerEvents$.next(new NavigationEnd(2, '/profile', '/profile'));
|
|
230
|
+
document.dispatchEvent(new Event('click'));
|
|
231
|
+
|
|
232
|
+
// rawLog should be called for prob-2
|
|
233
|
+
expect(logService.rawLog).toHaveBeenCalledTimes(2);
|
|
234
|
+
const prob2Log = logService.rawLog.mock.calls[1][0];
|
|
235
|
+
expect(prob2Log.route).toEqual('/practice');
|
|
236
|
+
expect(prob2Log.state).toEqual({ problemId: 'prob-2' });
|
|
237
|
+
expect(prob2Log.time.find((t: any) => t.type === 'active').total).toEqual(2000);
|
|
238
|
+
|
|
239
|
+
dateSpy.mockRestore();
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it('should support registering Angular signals via registerState', () => {
|
|
243
|
+
let currentTime = 1000;
|
|
244
|
+
const dateSpy = jest.spyOn(Date, 'now').mockImplementation(() => currentTime);
|
|
245
|
+
const logService = TestBed.inject(LOG_SERVICE) as any;
|
|
246
|
+
|
|
247
|
+
service.startTimeLogging();
|
|
248
|
+
|
|
249
|
+
currentTime = 1000;
|
|
250
|
+
routerEvents$.next(new NavigationEnd(1, '/practice', '/practice'));
|
|
251
|
+
|
|
252
|
+
const problemSignal = signal<string | null>('prob-100');
|
|
253
|
+
service.registerState('problemId', problemSignal, TestBed.inject(Injector));
|
|
254
|
+
TestBed.flushEffects();
|
|
255
|
+
|
|
256
|
+
document.dispatchEvent(new Event('click'));
|
|
257
|
+
|
|
258
|
+
currentTime = 2000;
|
|
259
|
+
document.dispatchEvent(new Event('click'));
|
|
260
|
+
|
|
261
|
+
// Update signal value and flush Angular signal effects
|
|
262
|
+
currentTime = 3000;
|
|
263
|
+
problemSignal.set('prob-200');
|
|
264
|
+
TestBed.flushEffects();
|
|
265
|
+
document.dispatchEvent(new Event('click'));
|
|
266
|
+
|
|
267
|
+
// Should flush log for prob-100
|
|
268
|
+
expect(logService.rawLog).toHaveBeenCalledTimes(1);
|
|
269
|
+
const log1 = logService.rawLog.mock.calls[0][0];
|
|
270
|
+
expect(log1.state).toEqual({ problemId: 'prob-100' });
|
|
271
|
+
|
|
272
|
+
currentTime = 4000;
|
|
273
|
+
routerEvents$.next(new NavigationEnd(2, '/profile', '/profile'));
|
|
274
|
+
document.dispatchEvent(new Event('click'));
|
|
275
|
+
|
|
276
|
+
// Should flush log for prob-200
|
|
277
|
+
expect(logService.rawLog).toHaveBeenCalledTimes(2);
|
|
278
|
+
const log2 = logService.rawLog.mock.calls[1][0];
|
|
279
|
+
expect(log2.state).toEqual({ problemId: 'prob-200' });
|
|
280
|
+
|
|
281
|
+
dateSpy.mockRestore();
|
|
282
|
+
});
|
|
283
|
+
});
|