@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
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/angular';
|
|
2
|
+
import { Injectable, signal } from '@angular/core';
|
|
3
|
+
import { provideRouter } from '@angular/router';
|
|
4
|
+
import { provideFirebaseMock } from 'src/app/core/firebase/firebase.mock.service';
|
|
5
|
+
import { GuestWarningBarComponent } from './guest-warning-bar.component';
|
|
6
|
+
import { AuthStore } from 'src/app/core/store/auth/auth.store';
|
|
7
|
+
import { AuthMockDB, AuthLoggedInMockDB } from 'src/app/core/store/auth/auth.mock';
|
|
8
|
+
|
|
9
|
+
describe('GuestWarningBarComponent', () => {
|
|
10
|
+
it('should not show warning bar when user is signed out', async () => {
|
|
11
|
+
await render(GuestWarningBarComponent, {
|
|
12
|
+
providers: [
|
|
13
|
+
provideRouter([]),
|
|
14
|
+
{ provide: AuthStore, useClass: AuthMockDB },
|
|
15
|
+
...provideFirebaseMock({ disableLatency: true }),
|
|
16
|
+
],
|
|
17
|
+
});
|
|
18
|
+
expect(screen.queryByText(/Guest Account:/i)).toBeNull();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('should not show warning bar when logged in as registered non-anonymous user', async () => {
|
|
22
|
+
await render(GuestWarningBarComponent, {
|
|
23
|
+
providers: [
|
|
24
|
+
provideRouter([]),
|
|
25
|
+
{ provide: AuthStore, useClass: AuthLoggedInMockDB },
|
|
26
|
+
...provideFirebaseMock({ disableLatency: true }),
|
|
27
|
+
],
|
|
28
|
+
});
|
|
29
|
+
expect(screen.queryByText(/Guest Account:/i)).toBeNull();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('should show persistent warning bar when logged in as an anonymous guest on an active route', async () => {
|
|
33
|
+
@Injectable()
|
|
34
|
+
class AnonymousAuthMockDB extends AuthMockDB {
|
|
35
|
+
override afUser = signal({
|
|
36
|
+
uid: 'anon-123',
|
|
37
|
+
email: null,
|
|
38
|
+
displayName: 'Guest',
|
|
39
|
+
photoURL: null,
|
|
40
|
+
isAnonymous: true,
|
|
41
|
+
emailVerified: false,
|
|
42
|
+
emailLinkEnabled: false,
|
|
43
|
+
providerIds: [],
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
await render(GuestWarningBarComponent, {
|
|
48
|
+
providers: [
|
|
49
|
+
provideRouter([]),
|
|
50
|
+
{ provide: AuthStore, useClass: AnonymousAuthMockDB },
|
|
51
|
+
...provideFirebaseMock({ disableLatency: true }),
|
|
52
|
+
],
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Warning text & Save Progress link should be visible
|
|
56
|
+
expect(screen.getByText(/Guest Account:/i)).toBeVisible();
|
|
57
|
+
expect(screen.getByRole('link', { name: /Save Progress/i })).toBeVisible();
|
|
58
|
+
});
|
|
59
|
+
});
|
package/src/ng-add/files/src/app/shared/guest-warning-bar/guest-warning-bar.component.ts.template
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Component, inject, computed, ChangeDetectionStrategy } from '@angular/core';
|
|
2
|
+
import { Router, NavigationEnd, RouterLink } from '@angular/router';
|
|
3
|
+
import { toSignal } from '@angular/core/rxjs-interop';
|
|
4
|
+
import { filter, map } from 'rxjs/operators';
|
|
5
|
+
import { AuthStore } from '../../core/store/auth/auth.store';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Top warning banner displayed when a user is signed in with an anonymous guest account.
|
|
9
|
+
* Reminds users that guest progress is only saved locally on their current device and
|
|
10
|
+
* prompts them to link Google or an Email address to save progress permanently.
|
|
11
|
+
*/
|
|
12
|
+
@Component({
|
|
13
|
+
selector: 'app-guest-warning-bar',
|
|
14
|
+
standalone: true,
|
|
15
|
+
imports: [RouterLink],
|
|
16
|
+
templateUrl: './guest-warning-bar.component.html',
|
|
17
|
+
styleUrl: './guest-warning-bar.component.scss',
|
|
18
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
19
|
+
})
|
|
20
|
+
export class GuestWarningBarComponent {
|
|
21
|
+
private readonly authStore = inject(AuthStore);
|
|
22
|
+
private readonly router = inject(Router, { optional: true });
|
|
23
|
+
|
|
24
|
+
/** Current route URL signal. */
|
|
25
|
+
private readonly currentUrl = toSignal(
|
|
26
|
+
this.router?.events ?
|
|
27
|
+
this.router.events.pipe(
|
|
28
|
+
filter((event): event is NavigationEnd => event instanceof NavigationEnd),
|
|
29
|
+
map((event) => event.urlAfterRedirects || event.url),
|
|
30
|
+
) :
|
|
31
|
+
undefined,
|
|
32
|
+
{ initialValue: this.router?.url || '' },
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
/** Whether the banner should be visible. */
|
|
36
|
+
readonly showWarning = computed(() => {
|
|
37
|
+
const afUser = this.authStore.afUser?.();
|
|
38
|
+
if (!afUser?.isAnonymous) return false;
|
|
39
|
+
const url = this.currentUrl() || '';
|
|
40
|
+
const excludedRoutes = ['/landing', '/early-access', '/consent'];
|
|
41
|
+
if (excludedRoutes.some((route) => url.startsWith(route))) return false;
|
|
42
|
+
return true;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
@@ -1,15 +1,45 @@
|
|
|
1
|
-
<
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
<nav class="navbar-container">
|
|
2
|
+
<a routerLink="/" class="brand-section">
|
|
3
|
+
<div class="brand-mark" aria-hidden="true">
|
|
4
|
+
<svg class="brand-logo-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
5
|
+
<path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5" />
|
|
6
|
+
</svg>
|
|
7
|
+
</div>
|
|
8
|
+
<span class="brand-title"><%= classify(project) %></span>
|
|
9
|
+
</a>
|
|
10
|
+
|
|
11
|
+
<div class="navbar-right">
|
|
12
|
+
@if (currentUser(); as user) {
|
|
13
|
+
<div class="user-setting-section">
|
|
14
|
+
@if (userPhotoUrl(); as photoUrl) {
|
|
15
|
+
<img
|
|
16
|
+
class="profile-pic"
|
|
17
|
+
[src]="photoUrl"
|
|
18
|
+
referrerpolicy="no-referrer"
|
|
19
|
+
alt="Profile Picture"
|
|
20
|
+
(error)="onPhotoError()"
|
|
21
|
+
[matMenuTriggerFor]="menu"
|
|
22
|
+
#menuTrigger
|
|
23
|
+
/>
|
|
24
|
+
} @else {
|
|
25
|
+
<div
|
|
26
|
+
class="profile-initial-avatar"
|
|
27
|
+
[matMenuTriggerFor]="menu"
|
|
28
|
+
#menuTrigger
|
|
29
|
+
role="button"
|
|
30
|
+
tabindex="0"
|
|
31
|
+
aria-label="User Profile Menu"
|
|
32
|
+
>
|
|
33
|
+
<span>{{ (user.name || 'G').charAt(0).toUpperCase() }}</span>
|
|
34
|
+
</div>
|
|
35
|
+
}
|
|
36
|
+
<mat-menu #menu="matMenu">
|
|
37
|
+
<a class="menu-item" routerLink="/account" mat-menu-item>Profile & Settings</a>
|
|
38
|
+
<button class="menu-item" (click)="logout()" mat-menu-item type="button">Logout</button>
|
|
39
|
+
</mat-menu>
|
|
40
|
+
</div>
|
|
41
|
+
} @else {
|
|
42
|
+
<a routerLink="/login" class="login-link">Log in</a>
|
|
43
|
+
}
|
|
44
|
+
</div>
|
|
45
|
+
</nav>
|
|
@@ -1,41 +1,125 @@
|
|
|
1
|
+
:host {
|
|
2
|
+
display: block;
|
|
3
|
+
width: 100%;
|
|
4
|
+
position: sticky;
|
|
5
|
+
top: 0;
|
|
6
|
+
z-index: 100;
|
|
7
|
+
}
|
|
8
|
+
|
|
1
9
|
.navbar-container {
|
|
2
10
|
height: 70px;
|
|
3
11
|
width: 100%;
|
|
4
|
-
background:
|
|
5
|
-
|
|
12
|
+
background: rgba(255, 255, 255, 0.85);
|
|
13
|
+
backdrop-filter: blur(12px);
|
|
14
|
+
border-bottom: 1px solid rgba(255, 255, 255, 0.5);
|
|
15
|
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
|
|
6
16
|
display: flex;
|
|
7
17
|
flex-direction: row;
|
|
8
18
|
align-items: center;
|
|
9
|
-
|
|
19
|
+
justify-content: space-between;
|
|
20
|
+
padding: 8px max(20px, calc(50vw - 460px));
|
|
21
|
+
box-sizing: border-box;
|
|
22
|
+
|
|
23
|
+
.brand-section {
|
|
24
|
+
display: flex;
|
|
25
|
+
align-items: center;
|
|
26
|
+
gap: 10px;
|
|
27
|
+
text-decoration: none;
|
|
28
|
+
|
|
29
|
+
.brand-mark {
|
|
30
|
+
display: flex;
|
|
31
|
+
align-items: center;
|
|
32
|
+
justify-content: center;
|
|
33
|
+
color: #0e7490;
|
|
34
|
+
flex-shrink: 0;
|
|
35
|
+
|
|
36
|
+
.brand-logo-icon {
|
|
37
|
+
width: 28px;
|
|
38
|
+
height: 28px;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.brand-title {
|
|
43
|
+
font-size: 1.35rem;
|
|
44
|
+
font-weight: 800;
|
|
45
|
+
color: #1e1b4b;
|
|
46
|
+
letter-spacing: -0.02em;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
&:hover {
|
|
50
|
+
opacity: 0.9;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.navbar-right {
|
|
55
|
+
display: flex;
|
|
56
|
+
align-items: center;
|
|
57
|
+
gap: 20px;
|
|
10
58
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
59
|
+
.login-link {
|
|
60
|
+
color: #0e7490;
|
|
61
|
+
font-weight: 600;
|
|
62
|
+
font-size: 0.95rem;
|
|
63
|
+
text-decoration: none;
|
|
64
|
+
padding: 8px 16px;
|
|
65
|
+
border-radius: 6px;
|
|
66
|
+
transition: background-color 0.2s, color 0.2s;
|
|
67
|
+
|
|
68
|
+
&:hover {
|
|
69
|
+
background-color: rgba(14, 116, 144, 0.08);
|
|
70
|
+
color: #155e75;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
16
73
|
}
|
|
17
74
|
|
|
18
75
|
.user-setting-section {
|
|
19
|
-
margin-left: auto;
|
|
20
76
|
display: flex;
|
|
21
77
|
align-items: center;
|
|
22
|
-
|
|
23
|
-
.profile-pic{
|
|
24
|
-
height:
|
|
25
|
-
width:
|
|
78
|
+
|
|
79
|
+
.profile-pic {
|
|
80
|
+
height: 42px;
|
|
81
|
+
width: 42px;
|
|
26
82
|
border-radius: 50%;
|
|
27
83
|
cursor: pointer;
|
|
84
|
+
border: 2px solid #ffffff;
|
|
85
|
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
|
|
86
|
+
object-fit: cover;
|
|
87
|
+
transition: transform 0.2s ease;
|
|
88
|
+
|
|
89
|
+
&:hover {
|
|
90
|
+
transform: scale(1.05);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.profile-initial-avatar {
|
|
95
|
+
height: 42px;
|
|
96
|
+
width: 42px;
|
|
97
|
+
border-radius: 50%;
|
|
98
|
+
background: linear-gradient(135deg, #0e7490 0%, #155e75 100%);
|
|
99
|
+
color: #ffffff;
|
|
100
|
+
font-size: 1.15rem;
|
|
101
|
+
font-weight: 700;
|
|
102
|
+
display: flex;
|
|
103
|
+
align-items: center;
|
|
104
|
+
justify-content: center;
|
|
105
|
+
cursor: pointer;
|
|
106
|
+
border: 2px solid #ffffff;
|
|
107
|
+
box-shadow: 0 2px 8px rgba(14, 116, 144, 0.25);
|
|
108
|
+
transition: transform 0.2s ease, box-shadow 0.2s ease;
|
|
109
|
+
user-select: none;
|
|
110
|
+
|
|
111
|
+
&:hover {
|
|
112
|
+
transform: scale(1.05);
|
|
113
|
+
box-shadow: 0 4px 12px rgba(14, 116, 144, 0.35);
|
|
114
|
+
}
|
|
28
115
|
}
|
|
29
116
|
}
|
|
30
117
|
}
|
|
31
118
|
|
|
32
|
-
|
|
33
|
-
.logout {
|
|
119
|
+
.logout, .menu-item {
|
|
34
120
|
display: flex;
|
|
35
121
|
align-items: center;
|
|
36
|
-
font-size:
|
|
37
|
-
font-weight:
|
|
122
|
+
font-size: 15px;
|
|
123
|
+
font-weight: 500;
|
|
38
124
|
cursor: pointer;
|
|
39
|
-
padding: 10px;
|
|
40
125
|
}
|
|
41
|
-
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { render, screen } from '@testing-library/angular';
|
|
2
2
|
import userEvent from '@testing-library/user-event';
|
|
3
|
-
import { Provider } from '@angular/core';
|
|
3
|
+
import { Injectable, Provider, signal } from '@angular/core';
|
|
4
|
+
import { provideRouter } from '@angular/router';
|
|
5
|
+
import { provideFirebaseMock } from 'src/app/core/firebase/firebase.mock.service';
|
|
4
6
|
|
|
5
7
|
import { NavbarComponent } from './navbar.component';
|
|
6
8
|
import { AuthStore } from 'src/app/core/store/auth/auth.store';
|
|
@@ -13,7 +15,9 @@ async function setup(providers: Provider[] = []) {
|
|
|
13
15
|
|
|
14
16
|
const view = await render(NavbarComponent, {
|
|
15
17
|
providers: [
|
|
18
|
+
provideRouter([]),
|
|
16
19
|
{ provide: AuthStore, useClass: AuthMockDB },
|
|
20
|
+
...provideFirebaseMock({ disableLatency: true }),
|
|
17
21
|
...providers,
|
|
18
22
|
],
|
|
19
23
|
});
|
|
@@ -26,19 +30,36 @@ async function setup(providers: Provider[] = []) {
|
|
|
26
30
|
}
|
|
27
31
|
|
|
28
32
|
describe('NavbarComponent', () => {
|
|
33
|
+
it('should show the application brand', async () => {
|
|
34
|
+
await setup();
|
|
35
|
+
expect(screen.getByText('<%= classify(project) %>')).toBeVisible();
|
|
36
|
+
});
|
|
37
|
+
|
|
29
38
|
it('should not show profile picture when logged out', async () => {
|
|
30
39
|
await setup();
|
|
31
|
-
expect(screen.
|
|
40
|
+
expect(screen.queryByAltText('Profile Picture')).toBeNull();
|
|
32
41
|
});
|
|
33
42
|
|
|
34
|
-
it('should show profile picture when logged in, and clicking it opens menu
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
43
|
+
it('should show profile picture when logged in with a photo URL, and clicking it opens menu', async () => {
|
|
44
|
+
@Injectable()
|
|
45
|
+
class AuthWithPhotoMockDB extends AuthLoggedInMockDB {
|
|
46
|
+
override user = signal({ ...USER_DB[0], photoURL: 'https://example.com/avatar.jpg' });
|
|
47
|
+
override afUser = signal({
|
|
48
|
+
uid: USER_DB[0].__id,
|
|
49
|
+
email: 'user@example.com',
|
|
50
|
+
displayName: 'User A',
|
|
51
|
+
photoURL: 'https://example.com/avatar.jpg',
|
|
52
|
+
isAnonymous: false,
|
|
53
|
+
emailVerified: true,
|
|
54
|
+
emailLinkEnabled: false,
|
|
55
|
+
providerIds: ['google.com'],
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
const { user, authStore } = await setup([{ provide: AuthStore, useClass: AuthWithPhotoMockDB }]);
|
|
38
59
|
|
|
39
|
-
const profilePic = screen.
|
|
60
|
+
const profilePic = screen.getByAltText('Profile Picture');
|
|
40
61
|
expect(profilePic).toBeVisible();
|
|
41
|
-
expect(profilePic).toHaveAttribute('src',
|
|
62
|
+
expect(profilePic).toHaveAttribute('src', 'https://example.com/avatar.jpg');
|
|
42
63
|
|
|
43
64
|
// Menu should not be in the document initially
|
|
44
65
|
expect(screen.queryByText(/Logout/i)).toBeNull();
|
|
@@ -46,7 +67,8 @@ describe('NavbarComponent', () => {
|
|
|
46
67
|
// Click profile pic to open menu
|
|
47
68
|
await user.click(profilePic);
|
|
48
69
|
|
|
49
|
-
// Logout should be visible now
|
|
70
|
+
// Profile & Settings link & Logout button should be visible now
|
|
71
|
+
expect(screen.getByText(/Profile & Settings/i)).toBeVisible();
|
|
50
72
|
const logoutBtn = screen.getByText(/Logout/i);
|
|
51
73
|
expect(logoutBtn).toBeVisible();
|
|
52
74
|
|
|
@@ -55,4 +77,46 @@ describe('NavbarComponent', () => {
|
|
|
55
77
|
expect(logoutSpy).toHaveBeenCalled();
|
|
56
78
|
logoutSpy.mockRestore();
|
|
57
79
|
});
|
|
80
|
+
|
|
81
|
+
it('renders initial letter avatar fallback when user has no photoURL', async () => {
|
|
82
|
+
@Injectable()
|
|
83
|
+
class AuthLoggedInNoPhotoMockDB extends AuthLoggedInMockDB {
|
|
84
|
+
override user = signal({ ...USER_DB[0], photoURL: null as string | null });
|
|
85
|
+
}
|
|
86
|
+
const { user } = await setup([{ provide: AuthStore, useClass: AuthLoggedInNoPhotoMockDB }]);
|
|
87
|
+
|
|
88
|
+
expect(screen.queryByAltText('Profile Picture')).toBeNull();
|
|
89
|
+
const avatarFallback = screen.getByRole('button', { name: /User Profile Menu/i });
|
|
90
|
+
expect(avatarFallback).toBeVisible();
|
|
91
|
+
expect(avatarFallback).toHaveTextContent(USER_DB[0].name.charAt(0).toUpperCase());
|
|
92
|
+
|
|
93
|
+
await user.click(avatarFallback);
|
|
94
|
+
expect(screen.getByText(/Profile & Settings/i)).toBeVisible();
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('falls back to initial letter avatar if photoURL triggers an error event', async () => {
|
|
98
|
+
@Injectable()
|
|
99
|
+
class AuthWithPhotoMockDB extends AuthLoggedInMockDB {
|
|
100
|
+
override user = signal({ ...USER_DB[0], photoURL: 'https://example.com/broken.jpg' });
|
|
101
|
+
override afUser = signal({
|
|
102
|
+
uid: USER_DB[0].__id,
|
|
103
|
+
email: 'user@example.com',
|
|
104
|
+
displayName: 'User A',
|
|
105
|
+
photoURL: 'https://example.com/broken.jpg',
|
|
106
|
+
isAnonymous: false,
|
|
107
|
+
emailVerified: true,
|
|
108
|
+
emailLinkEnabled: false,
|
|
109
|
+
providerIds: ['google.com'],
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
const { fixture } = await setup([{ provide: AuthStore, useClass: AuthWithPhotoMockDB }]);
|
|
113
|
+
|
|
114
|
+
const profilePic = screen.getByAltText('Profile Picture');
|
|
115
|
+
profilePic.dispatchEvent(new Event('error'));
|
|
116
|
+
fixture.detectChanges();
|
|
117
|
+
|
|
118
|
+
expect(screen.queryByAltText('Profile Picture')).toBeNull();
|
|
119
|
+
const avatarFallback = screen.getByRole('button', { name: /User Profile Menu/i });
|
|
120
|
+
expect(avatarFallback).toBeVisible();
|
|
121
|
+
});
|
|
58
122
|
});
|
|
@@ -1,39 +1,67 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Component, ChangeDetectionStrategy, computed, inject, signal } from '@angular/core';
|
|
2
|
+
import { AccessState } from 'src/app/core/store/user/user.model';
|
|
3
3
|
import { AuthStore } from 'src/app/core/store/auth/auth.store';
|
|
4
|
-
import { MatMenuTrigger, MatMenu } from '@angular/material/menu';
|
|
4
|
+
import { MatMenuTrigger, MatMenu, MatMenuItem } from '@angular/material/menu';
|
|
5
|
+
import { RouterLink } from '@angular/router';
|
|
5
6
|
|
|
7
|
+
function isValidPhotoUrl(url: string | null | undefined): boolean {
|
|
8
|
+
if (!url || typeof url !== 'string') return false;
|
|
9
|
+
const trimmed = url.trim();
|
|
10
|
+
if (trimmed === '' || trimmed === 'null' || trimmed === 'undefined') return false;
|
|
11
|
+
if (trimmed.includes('loremflickr.com')) return false;
|
|
12
|
+
return trimmed.startsWith('http://') || trimmed.startsWith('https://') || trimmed.startsWith('/');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Shared top navigation bar component across the application.
|
|
17
|
+
* Displays the application brand and provides a user account profile menu with logout.
|
|
18
|
+
*/
|
|
6
19
|
@Component({
|
|
7
20
|
selector: 'app-navbar',
|
|
8
21
|
templateUrl: './navbar.component.html',
|
|
9
22
|
styleUrl: './navbar.component.scss',
|
|
10
23
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
11
|
-
imports: [MatMenuTrigger, MatMenu],
|
|
24
|
+
imports: [MatMenuTrigger, MatMenu, MatMenuItem, RouterLink],
|
|
12
25
|
})
|
|
13
|
-
export class NavbarComponent
|
|
26
|
+
export class NavbarComponent {
|
|
14
27
|
readonly authStore = inject(AuthStore);
|
|
15
28
|
|
|
16
29
|
// --------------- INPUTS AND OUTPUTS ------------------
|
|
17
30
|
|
|
18
|
-
/**
|
|
19
|
-
|
|
31
|
+
/** Track image load errors to fallback to initial letter avatar if photoURL fails to load. */
|
|
32
|
+
readonly hasPhotoError = signal(false);
|
|
20
33
|
|
|
21
|
-
|
|
34
|
+
onPhotoError() {
|
|
35
|
+
this.hasPhotoError.set(true);
|
|
36
|
+
}
|
|
22
37
|
|
|
23
|
-
|
|
38
|
+
/** The current signed in user (with fallback to afUser session if store entity is loading). */
|
|
39
|
+
readonly currentUser = computed(() => {
|
|
40
|
+
const user = this.authStore.user();
|
|
41
|
+
if (user) return user;
|
|
42
|
+
const afUser = this.authStore.afUser?.();
|
|
43
|
+
if (!afUser) return null;
|
|
44
|
+
return {
|
|
45
|
+
__id: afUser.uid,
|
|
46
|
+
name: afUser.displayName || afUser.email || (afUser.isAnonymous ? 'Guest' : 'Learner'),
|
|
47
|
+
photoURL: afUser.photoURL,
|
|
48
|
+
isAdmin: false,
|
|
49
|
+
consented: false,
|
|
50
|
+
accessState: AccessState.SUBMIT_INTEREST,
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
/** Validated image photo URL to render (or null for letter avatar fallback). */
|
|
55
|
+
readonly userPhotoUrl = computed(() => {
|
|
56
|
+
if (this.hasPhotoError()) return null;
|
|
57
|
+
const user = this.currentUser();
|
|
58
|
+
return user && isValidPhotoUrl(user.photoURL) ? user.photoURL! : null;
|
|
59
|
+
});
|
|
24
60
|
|
|
25
61
|
// --------------- EVENT HANDLING ----------------------
|
|
26
62
|
|
|
27
|
-
/** Logout. */
|
|
63
|
+
/** Logout current user. */
|
|
28
64
|
logout() {
|
|
29
65
|
this.authStore.logout();
|
|
30
66
|
}
|
|
31
|
-
|
|
32
|
-
// --------------- OTHER -------------------------------
|
|
33
|
-
|
|
34
|
-
constructor() {
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
ngOnInit(): void {
|
|
38
|
-
}
|
|
39
67
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const schematics_1 = require("@angular-devkit/schematics");
|
|
5
|
+
const testing_1 = require("@angular-devkit/schematics/testing");
|
|
6
|
+
const path = tslib_1.__importStar(require("path"));
|
|
7
|
+
const collectionPath = path.join(__dirname, '../collection.json');
|
|
8
|
+
function createWorkspaceTree() {
|
|
9
|
+
const tree = new testing_1.UnitTestTree(schematics_1.Tree.empty());
|
|
10
|
+
tree.create('/angular.json', JSON.stringify({
|
|
11
|
+
version: 1,
|
|
12
|
+
projects: {
|
|
13
|
+
'sample-app': {
|
|
14
|
+
projectType: 'application',
|
|
15
|
+
root: '',
|
|
16
|
+
sourceRoot: 'src',
|
|
17
|
+
prefix: 'app',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
}));
|
|
21
|
+
tree.create('/src/app/app.ts', 'export class App {}');
|
|
22
|
+
tree.create('/src/app/app.html', '<router-outlet />');
|
|
23
|
+
tree.create('/src/app/app.scss', '');
|
|
24
|
+
tree.create('/src/app/app.spec.ts', '');
|
|
25
|
+
return tree;
|
|
26
|
+
}
|
|
27
|
+
describe('ng-add authentication infrastructure', () => {
|
|
28
|
+
const runner = new testing_1.SchematicTestRunner('schematics', collectionPath);
|
|
29
|
+
async function generate() {
|
|
30
|
+
return runner.runSchematic('ng-add', { project: 'sample-app', proceed: true }, createWorkspaceTree());
|
|
31
|
+
}
|
|
32
|
+
it('generates the complete passwordless, Google, and guest auth surface', async () => {
|
|
33
|
+
const tree = await generate();
|
|
34
|
+
const expectedFiles = [
|
|
35
|
+
'/src/app/first-time/auth-action/auth-action.component.ts',
|
|
36
|
+
'/src/app/first-time/email-link/email-link.component.ts',
|
|
37
|
+
'/src/app/main/account-profile/account-profile.component.ts',
|
|
38
|
+
'/src/app/main/account-profile/sign-in-methods-card/sign-in-methods-card.component.ts',
|
|
39
|
+
'/src/app/shared/guest-warning-bar/guest-warning-bar.component.ts',
|
|
40
|
+
'/src/app/core/firebase/email-link-context.service.ts',
|
|
41
|
+
'/src/app/core/store/auth/auth.store.spec.ts',
|
|
42
|
+
'/functions/src/index.ts',
|
|
43
|
+
'/docs-infra/authentication-architecture.md',
|
|
44
|
+
];
|
|
45
|
+
for (const file of expectedFiles)
|
|
46
|
+
expect(tree.files).toContain(file);
|
|
47
|
+
});
|
|
48
|
+
it('uses generic application routes and generated branding', async () => {
|
|
49
|
+
const tree = await generate();
|
|
50
|
+
const routes = tree.readContent('/src/app/app.routes.ts');
|
|
51
|
+
const login = tree.readContent('/src/app/first-time/login/login.component.html');
|
|
52
|
+
const navbar = tree.readContent('/src/app/shared/navbar/navbar.component.html');
|
|
53
|
+
const emailLink = tree.readContent('/src/app/first-time/email-link/email-link.component.ts');
|
|
54
|
+
const firebaseService = tree.readContent('/src/app/core/firebase/firebase.service.ts');
|
|
55
|
+
expect(routes).toContain("path: 'auth/action'");
|
|
56
|
+
expect(routes).toContain("path: 'email-link'");
|
|
57
|
+
expect(routes).toContain("path: 'account'");
|
|
58
|
+
expect(routes).toContain("path: 'home'");
|
|
59
|
+
expect(routes).not.toContain("path: 'practice'");
|
|
60
|
+
expect(login).toContain('Welcome to SampleApp');
|
|
61
|
+
expect(navbar).toContain('SampleApp');
|
|
62
|
+
expect(emailLink).toContain("navigate(['/home'])");
|
|
63
|
+
expect(firebaseService).toContain('const result = await signInWithPopup(this.afAuth, new GoogleAuthProvider());\n await result.user.getIdToken(true);');
|
|
64
|
+
expect(firebaseService).toContain('private getEmailLinkFlow(url: string): EmailLinkFlow');
|
|
65
|
+
});
|
|
66
|
+
it('generates callable guest deletion and provider-aware Firestore rules', async () => {
|
|
67
|
+
const tree = await generate();
|
|
68
|
+
const firebaseConfig = tree.readContent('/firebase.json');
|
|
69
|
+
const functions = tree.readContent('/functions/src/index.ts');
|
|
70
|
+
const indexes = JSON.parse(tree.readContent('/firestore.indexes.json'));
|
|
71
|
+
const rules = tree.readContent('/firestore.rules');
|
|
72
|
+
expect(firebaseConfig).toContain('"source": "functions"');
|
|
73
|
+
expect(functions).toContain('deleteAnonymousAccount');
|
|
74
|
+
expect(functions).toContain("const QUERY_COLLECTIONS = ['userContexts']");
|
|
75
|
+
expect(rules).toContain('function isVerifiedOrAnonymous()');
|
|
76
|
+
expect(rules).toContain("request.auth.token.firebase.sign_in_provider == 'anonymous'");
|
|
77
|
+
expect(rules).toContain("resource.data.accessState == '01 - submit interest' && request.resource.data.accessState == '03 - consent'");
|
|
78
|
+
expect(rules).toContain("('email_verified' in request.auth.token && request.auth.token.email_verified == true)");
|
|
79
|
+
expect(rules).toContain('allow create: if isVerifiedOrAnonymous()');
|
|
80
|
+
const userContextsIndex = indexes.indexes.find((index) => index.collectionGroup === 'userContexts');
|
|
81
|
+
expect(userContextsIndex).toEqual({
|
|
82
|
+
collectionGroup: 'userContexts',
|
|
83
|
+
queryScope: 'COLLECTION',
|
|
84
|
+
fields: [
|
|
85
|
+
{ fieldPath: '__userId', order: 'ASCENDING' },
|
|
86
|
+
{ fieldPath: '_deleted', order: 'ASCENDING' },
|
|
87
|
+
{ fieldPath: '_updatedAt', order: 'ASCENDING' },
|
|
88
|
+
{ fieldPath: '__name__', order: 'ASCENDING' },
|
|
89
|
+
],
|
|
90
|
+
density: 'SPARSE_ALL',
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
it('does not leak source-application branding or role-specific auth behavior', async () => {
|
|
94
|
+
const tree = await generate();
|
|
95
|
+
const authFiles = tree.files.filter((file) => file.includes('/core/firebase/') ||
|
|
96
|
+
file.includes('/core/store/auth/') ||
|
|
97
|
+
file.includes('/first-time/login/') ||
|
|
98
|
+
file.includes('/main/account-profile/') ||
|
|
99
|
+
file.includes('/shared/guest-warning-bar/'));
|
|
100
|
+
const contents = authFiles.map((file) => tree.readContent(file)).join('\n');
|
|
101
|
+
expect(contents).not.toContain('Math Pets');
|
|
102
|
+
expect(contents).not.toContain('Mentor');
|
|
103
|
+
expect(contents).not.toContain('pendingGoogleLink');
|
|
104
|
+
expect(contents).not.toContain('isMentor');
|
|
105
|
+
expect(contents).not.toContain('/practice');
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
//# sourceMappingURL=index_spec.js.map
|