@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
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { render, screen } from '@testing-library/angular';
|
|
2
2
|
import userEvent from '@testing-library/user-event';
|
|
3
3
|
import { Provider } from '@angular/core';
|
|
4
|
+
import { provideRouter, Router } from '@angular/router';
|
|
4
5
|
|
|
5
6
|
import { LandingComponent } from './landing.component';
|
|
6
7
|
import { AuthStore } from 'src/app/core/store/auth/auth.store';
|
|
@@ -12,6 +13,10 @@ async function setup(providers: Provider[] = []) {
|
|
|
12
13
|
|
|
13
14
|
const view = await render(LandingComponent, {
|
|
14
15
|
providers: [
|
|
16
|
+
provideRouter([
|
|
17
|
+
{ path: 'login', component: LandingComponent },
|
|
18
|
+
{ path: 'home', component: LandingComponent },
|
|
19
|
+
]),
|
|
15
20
|
{ provide: AuthStore, useClass: AuthMockDB },
|
|
16
21
|
...providers,
|
|
17
22
|
],
|
|
@@ -20,26 +25,42 @@ async function setup(providers: Provider[] = []) {
|
|
|
20
25
|
return {
|
|
21
26
|
user,
|
|
22
27
|
fixture: view.fixture,
|
|
28
|
+
component: view.fixture.componentInstance,
|
|
23
29
|
authStore: view.fixture.debugElement.injector.get(AuthStore),
|
|
24
30
|
};
|
|
25
31
|
}
|
|
26
32
|
|
|
27
33
|
describe('LandingComponent', () => {
|
|
28
|
-
it('should render
|
|
29
|
-
const { user,
|
|
34
|
+
it('should render landing title and navigate to /login when Get Started is clicked', async () => {
|
|
35
|
+
const { user, fixture } = await setup();
|
|
30
36
|
|
|
31
|
-
// Verify title is rendered
|
|
32
37
|
expect(screen.getByRole('heading', { name: /Your Value Proposition Here/i })).toBeVisible();
|
|
33
38
|
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
// Click the Sign Up CTA button
|
|
38
|
-
const ctaBtn = screen.getByRole('button', { name: /Sign Up to Join/i });
|
|
39
|
+
const navigateSpy = jest.spyOn(fixture.debugElement.injector.get(Router), 'navigate');
|
|
40
|
+
const ctaBtn = screen.getByRole('link', { name: /Get started/i });
|
|
39
41
|
await user.click(ctaBtn);
|
|
40
42
|
|
|
41
|
-
expect(
|
|
43
|
+
expect(navigateSpy).toHaveBeenCalledWith(['/login']);
|
|
44
|
+
navigateSpy.mockRestore();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('should hide guest login button when showGuestLogin is false (hasWaitlist = true)', async () => {
|
|
48
|
+
const { component, fixture } = await setup();
|
|
49
|
+
component.showGuestLogin.set(false);
|
|
50
|
+
fixture.detectChanges();
|
|
51
|
+
expect(screen.queryByRole('button', { name: /try without logging in/i })).toBeNull();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('should show guest login button and sign in anonymously when showGuestLogin is true (hasWaitlist = false)', async () => {
|
|
55
|
+
const { user, fixture, component, authStore } = await setup();
|
|
56
|
+
component.showGuestLogin.set(true);
|
|
57
|
+
fixture.detectChanges();
|
|
58
|
+
|
|
59
|
+
const guestSpy = jest.spyOn(authStore, 'loginAnonymously');
|
|
60
|
+
const guestBtn = screen.getByRole('button', { name: /try without logging in/i });
|
|
61
|
+
expect(guestBtn).toBeVisible();
|
|
42
62
|
|
|
43
|
-
|
|
63
|
+
await user.click(guestBtn);
|
|
64
|
+
expect(guestSpy).toHaveBeenCalled();
|
|
44
65
|
});
|
|
45
66
|
});
|
|
@@ -1,37 +1,24 @@
|
|
|
1
|
-
import { Component, ChangeDetectionStrategy, inject, Signal,
|
|
1
|
+
import { Component, ChangeDetectionStrategy, inject, Signal, signal } from '@angular/core';
|
|
2
2
|
|
|
3
3
|
import { User } from 'src/app/core/store/user/user.model';
|
|
4
4
|
import { AuthStore } from 'src/app/core/store/auth/auth.store';
|
|
5
|
+
import { NavbarComponent } from 'src/app/shared/navbar/navbar.component';
|
|
5
6
|
import { HeroComponent } from './hero/hero.component';
|
|
7
|
+
import { environment } from 'src/environments/environment';
|
|
6
8
|
|
|
7
9
|
@Component({
|
|
8
10
|
selector: 'app-landing',
|
|
9
11
|
templateUrl: './landing.component.html',
|
|
10
12
|
styleUrl: './landing.component.scss',
|
|
11
13
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
12
|
-
imports: [HeroComponent],
|
|
14
|
+
imports: [NavbarComponent, HeroComponent],
|
|
13
15
|
})
|
|
14
16
|
export class LandingComponent {
|
|
15
17
|
readonly authStore = inject(AuthStore);
|
|
16
18
|
|
|
17
|
-
// --------------- INPUTS AND OUTPUTS ------------------
|
|
18
|
-
|
|
19
19
|
/** The current signed in user. */
|
|
20
20
|
currentUser: Signal<User> = this.authStore.user;
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
// --------------- EVENT HANDLING ----------------------
|
|
25
|
-
|
|
26
|
-
/** Login the user. */
|
|
27
|
-
login() {
|
|
28
|
-
this.authStore.login('google.com');
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// --------------- OTHER -------------------------------
|
|
32
|
-
|
|
33
|
-
constructor(
|
|
34
|
-
private injector: Injector,
|
|
35
|
-
) {
|
|
36
|
-
}
|
|
22
|
+
/** Whether guest login link is shown (only when environment.hasWaitlist is false). */
|
|
23
|
+
readonly showGuestLogin = signal(!environment.hasWaitlist);
|
|
37
24
|
}
|
|
@@ -1,10 +1,62 @@
|
|
|
1
1
|
<div class="login-container">
|
|
2
|
-
@if (
|
|
3
|
-
<
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
@if (!sentEmail()) {
|
|
3
|
+
<div class="login-card">
|
|
4
|
+
<h1>Welcome to <%= classify(project) %></h1>
|
|
5
|
+
<p>Sign in or create your account with a secure magic link.</p>
|
|
6
|
+
|
|
7
|
+
<form (submit)="sendMagicLink(); $event.preventDefault()">
|
|
8
|
+
<mat-form-field appearance="outline" class="full-width">
|
|
9
|
+
<mat-label>Email</mat-label>
|
|
10
|
+
<input matInput type="email" placeholder="Email*" [formField]="form.email" autocomplete="email" />
|
|
11
|
+
@if (form.email().touched() && form.email().invalid()) {
|
|
12
|
+
<mat-error>Please enter a valid email address</mat-error>
|
|
13
|
+
}
|
|
14
|
+
</mat-form-field>
|
|
15
|
+
|
|
16
|
+
<button mat-raised-button color="primary" class="btn-continue" type="submit" [disabled]="isLoading()">
|
|
17
|
+
@if (isSendingMagicLink()) {
|
|
18
|
+
<mat-spinner diameter="20" />
|
|
19
|
+
} @else {
|
|
20
|
+
<span>Send me a magic link</span>
|
|
21
|
+
}
|
|
22
|
+
</button>
|
|
23
|
+
</form>
|
|
24
|
+
|
|
25
|
+
<div class="divider"><span>or</span></div>
|
|
26
|
+
|
|
27
|
+
<button mat-stroked-button type="button" class="btn-google" (click)="signInWithGoogle()" [disabled]="isLoading()">
|
|
28
|
+
@if (isSigningInGoogle()) {
|
|
29
|
+
<mat-spinner diameter="18" class="google-spinner" />
|
|
30
|
+
<span>Signing in...</span>
|
|
31
|
+
} @else {
|
|
32
|
+
<svg viewBox="0 0 24 24" width="18" height="18" aria-hidden="true">
|
|
33
|
+
<path fill="#4285F4" d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z"/>
|
|
34
|
+
<path fill="#34A853" d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"/>
|
|
35
|
+
<path fill="#FBBC05" d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.06H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.94l2.85-2.22.81-.63z"/>
|
|
36
|
+
<path fill="#EA4335" d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.06l3.66 2.84c.87-2.6 3.3-4.52 6.16-4.52z"/>
|
|
37
|
+
</svg>
|
|
38
|
+
<span>Continue with Google</span>
|
|
39
|
+
}
|
|
40
|
+
</button>
|
|
41
|
+
|
|
42
|
+
@if (message()) {
|
|
43
|
+
<div class="invalid" role="alert">{{ message() }}</div>
|
|
44
|
+
}
|
|
45
|
+
</div>
|
|
6
46
|
} @else {
|
|
7
|
-
<
|
|
8
|
-
|
|
47
|
+
<div class="message-container">
|
|
48
|
+
<div class="image-wrapper">
|
|
49
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 24 24" fill="none" stroke="#22c55e" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
|
50
|
+
<path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"></path>
|
|
51
|
+
<polyline points="22 4 12 14.01 9 11.01"></polyline>
|
|
52
|
+
</svg>
|
|
53
|
+
</div>
|
|
54
|
+
<h2 class="title">Magic Link Sent</h2>
|
|
55
|
+
<p class="description">
|
|
56
|
+
An email has been sent to <strong>{{ loginModel().email }}</strong>. Please click the link in the email to sign in.
|
|
57
|
+
<br/><br/>
|
|
58
|
+
Don't see the email? Check your spam or junk folder.
|
|
59
|
+
</p>
|
|
60
|
+
</div>
|
|
9
61
|
}
|
|
10
62
|
</div>
|
|
@@ -1,29 +1,158 @@
|
|
|
1
|
+
@use 'variables' as *;
|
|
2
|
+
|
|
1
3
|
.login-container {
|
|
2
|
-
max-width: 430px;
|
|
3
|
-
padding: 40px 0;
|
|
4
4
|
display: flex;
|
|
5
|
-
flex-direction: column;
|
|
6
|
-
align-items: center;
|
|
7
5
|
justify-content: center;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
background: #
|
|
6
|
+
align-items: center;
|
|
7
|
+
min-height: 100vh;
|
|
8
|
+
padding: 0 20px;
|
|
9
|
+
background: $bg-primary;
|
|
10
|
+
|
|
11
|
+
.login-card {
|
|
12
|
+
padding: 36px 32px;
|
|
13
|
+
width: 100%;
|
|
14
|
+
max-width: 400px;
|
|
15
|
+
background-color: #fff;
|
|
16
|
+
border-radius: 8px;
|
|
17
|
+
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
|
|
18
|
+
text-align: center;
|
|
19
|
+
|
|
20
|
+
h1 {
|
|
21
|
+
margin: 0 0 8px;
|
|
22
|
+
color: #1e1b4b;
|
|
23
|
+
font-size: 22px;
|
|
24
|
+
font-weight: 600;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
p {
|
|
28
|
+
margin: 0 0 28px;
|
|
29
|
+
color: #757575;
|
|
30
|
+
font-size: 15px;
|
|
31
|
+
line-height: 1.4;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
mat-form-field.full-width {
|
|
35
|
+
width: 100%;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.invalid {
|
|
39
|
+
display: block;
|
|
40
|
+
width: 100%;
|
|
41
|
+
margin-top: 12px;
|
|
42
|
+
color: rgb(235, 87, 87);
|
|
43
|
+
font-size: 0.95rem;
|
|
44
|
+
text-align: center;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.btn-continue {
|
|
48
|
+
display: flex;
|
|
49
|
+
align-items: center;
|
|
50
|
+
justify-content: center;
|
|
51
|
+
width: 100%;
|
|
52
|
+
height: 44px;
|
|
53
|
+
margin-top: 18px;
|
|
54
|
+
padding: 12px;
|
|
55
|
+
border: 0;
|
|
56
|
+
border-radius: 20px;
|
|
57
|
+
background-color: #0062d2;
|
|
58
|
+
color: #fff;
|
|
59
|
+
cursor: pointer;
|
|
60
|
+
font-size: 1rem;
|
|
61
|
+
|
|
62
|
+
&:disabled {
|
|
63
|
+
background-color: #e0e0e0;
|
|
64
|
+
color: #9e9e9e;
|
|
65
|
+
cursor: not-allowed;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
::ng-deep mat-spinner circle {
|
|
69
|
+
stroke: #fff !important;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.divider {
|
|
74
|
+
display: flex;
|
|
75
|
+
align-items: center;
|
|
76
|
+
gap: 12px;
|
|
77
|
+
margin: 20px 0;
|
|
78
|
+
color: #757575;
|
|
79
|
+
font-size: 14px;
|
|
80
|
+
|
|
81
|
+
&::before,
|
|
82
|
+
&::after {
|
|
83
|
+
flex: 1;
|
|
84
|
+
border-top: 1px solid #ddd;
|
|
85
|
+
content: '';
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.btn-google {
|
|
90
|
+
display: flex;
|
|
91
|
+
align-items: center;
|
|
92
|
+
justify-content: center;
|
|
93
|
+
width: 100%;
|
|
94
|
+
height: 44px;
|
|
95
|
+
border: 1px solid #757575;
|
|
96
|
+
border-radius: 20px;
|
|
97
|
+
background-color: #fff;
|
|
98
|
+
color: #0062d2;
|
|
99
|
+
cursor: pointer;
|
|
100
|
+
font-size: 14px;
|
|
101
|
+
font-weight: 500;
|
|
102
|
+
|
|
103
|
+
::ng-deep .mdc-button__label {
|
|
104
|
+
display: inline-flex !important;
|
|
105
|
+
align-items: center !important;
|
|
106
|
+
justify-content: center !important;
|
|
107
|
+
gap: 10px !important;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
svg {
|
|
111
|
+
display: block;
|
|
112
|
+
flex-shrink: 0;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
::ng-deep mat-spinner.google-spinner circle {
|
|
116
|
+
stroke: #0062d2 !important;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
&:disabled {
|
|
120
|
+
opacity: 0.6;
|
|
121
|
+
cursor: not-allowed;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
&:hover:not(:disabled) {
|
|
125
|
+
background-color: rgba(0, 98, 210, 0.04);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
18
128
|
}
|
|
19
129
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
background: #
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
130
|
+
.message-container {
|
|
131
|
+
max-width: 380px;
|
|
132
|
+
padding: 32px 24px;
|
|
133
|
+
border-radius: 8px;
|
|
134
|
+
background-color: #fff;
|
|
135
|
+
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
|
|
136
|
+
text-align: center;
|
|
137
|
+
|
|
138
|
+
.image-wrapper {
|
|
139
|
+
display: flex;
|
|
140
|
+
justify-content: center;
|
|
141
|
+
margin-bottom: 15px;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.title {
|
|
145
|
+
margin: 0 0 8px;
|
|
146
|
+
color: rgb(55, 53, 47);
|
|
147
|
+
font-size: 22px;
|
|
148
|
+
font-weight: 500;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.description {
|
|
152
|
+
margin-bottom: 20px;
|
|
153
|
+
color: rgba(55, 53, 47, 0.65);
|
|
154
|
+
font-size: 15px;
|
|
155
|
+
line-height: 1.4;
|
|
156
|
+
}
|
|
28
157
|
}
|
|
29
158
|
}
|
|
@@ -1,57 +1,37 @@
|
|
|
1
|
+
import { provideRouter } from '@angular/router';
|
|
1
2
|
import { render, screen } from '@testing-library/angular';
|
|
2
3
|
import userEvent from '@testing-library/user-event';
|
|
3
4
|
import { Provider } from '@angular/core';
|
|
4
|
-
|
|
5
5
|
import { LoginComponent } from './login.component';
|
|
6
6
|
import { AuthStore } from 'src/app/core/store/auth/auth.store';
|
|
7
|
-
import { AuthMockDB
|
|
8
|
-
import { USER_DB } from 'src/app/core/store/user/user.mock';
|
|
7
|
+
import { AuthMockDB } from 'src/app/core/store/auth/auth.mock';
|
|
9
8
|
|
|
10
|
-
/** Sets up the testing environment for LoginComponent using render. */
|
|
11
9
|
async function setup(providers: Provider[] = []) {
|
|
12
10
|
const user = userEvent.setup();
|
|
13
|
-
|
|
14
11
|
const view = await render(LoginComponent, {
|
|
15
|
-
|
|
16
|
-
providers: [
|
|
17
|
-
{ provide: AuthStore, useClass: AuthMockDB },
|
|
18
|
-
...providers,
|
|
19
|
-
],
|
|
12
|
+
providers: [provideRouter([]), { provide: AuthStore, useClass: AuthMockDB }, ...providers],
|
|
20
13
|
});
|
|
21
|
-
|
|
22
|
-
return {
|
|
23
|
-
user,
|
|
24
|
-
fixture: view.fixture,
|
|
25
|
-
authStore: view.fixture.debugElement.injector.get(AuthStore),
|
|
26
|
-
};
|
|
14
|
+
return { user, authStore: view.fixture.debugElement.injector.get(AuthStore) };
|
|
27
15
|
}
|
|
28
16
|
|
|
29
17
|
describe('LoginComponent', () => {
|
|
30
|
-
it('
|
|
18
|
+
it('offers an email magic link first and Google beneath it', async () => {
|
|
31
19
|
const { user, authStore } = await setup();
|
|
20
|
+
expect(screen.getByRole('button', { name: /send me a magic link/i })).toBeVisible();
|
|
21
|
+
expect(screen.getByRole('button', { name: /continue with google/i })).toBeVisible();
|
|
22
|
+
expect(screen.queryByLabelText('Password')).not.toBeInTheDocument();
|
|
32
23
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
expect(
|
|
36
|
-
|
|
37
|
-
const loginSpy = jest.spyOn(authStore, 'login');
|
|
38
|
-
await user.click(loginBtn);
|
|
39
|
-
expect(loginSpy).toHaveBeenCalledWith('google.com', { doNotRoute: true });
|
|
40
|
-
loginSpy.mockRestore();
|
|
24
|
+
const googleSpy = jest.spyOn(authStore, 'signInWithGoogle');
|
|
25
|
+
await user.click(screen.getByRole('button', { name: /continue with google/i }));
|
|
26
|
+
expect(googleSpy).toHaveBeenCalled();
|
|
41
27
|
});
|
|
42
28
|
|
|
43
|
-
it('
|
|
44
|
-
const { user, authStore } = await setup(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
expect(
|
|
49
|
-
|
|
50
|
-
expect(logoutBtn).toBeVisible();
|
|
51
|
-
|
|
52
|
-
const logoutSpy = jest.spyOn(authStore, 'logout');
|
|
53
|
-
await user.click(logoutBtn);
|
|
54
|
-
expect(logoutSpy).toHaveBeenCalledWith({ doNotRoute: true });
|
|
55
|
-
logoutSpy.mockRestore();
|
|
29
|
+
it('sends a magic link and confirms the destination email', async () => {
|
|
30
|
+
const { user, authStore } = await setup();
|
|
31
|
+
const emailLinkSpy = jest.spyOn(authStore, 'sendEmailSignInLink');
|
|
32
|
+
await user.type(screen.getByLabelText('Email'), 'learner@example.com');
|
|
33
|
+
await user.click(screen.getByRole('button', { name: /send me a magic link/i }));
|
|
34
|
+
expect(emailLinkSpy).toHaveBeenCalledWith('learner@example.com');
|
|
35
|
+
expect(screen.getByRole('heading', { name: /magic link sent/i })).toBeVisible();
|
|
56
36
|
});
|
|
57
37
|
});
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ChangeDetectionStrategy, Component, computed, inject, signal } from '@angular/core';
|
|
2
|
+
import { email, form, FormField, required, submit } from '@angular/forms/signals';
|
|
3
|
+
import { MatButtonModule } from '@angular/material/button';
|
|
4
|
+
import { MatFormFieldModule } from '@angular/material/form-field';
|
|
5
|
+
import { MatInputModule } from '@angular/material/input';
|
|
6
|
+
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
|
7
|
+
import { Router } from '@angular/router';
|
|
3
8
|
import { AuthStore } from 'src/app/core/store/auth/auth.store';
|
|
4
9
|
|
|
5
10
|
@Component({
|
|
@@ -7,38 +12,61 @@ import { AuthStore } from 'src/app/core/store/auth/auth.store';
|
|
|
7
12
|
templateUrl: './login.component.html',
|
|
8
13
|
styleUrl: './login.component.scss',
|
|
9
14
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
15
|
+
imports: [FormField, MatButtonModule, MatFormFieldModule, MatInputModule, MatProgressSpinnerModule],
|
|
10
16
|
})
|
|
11
|
-
export class LoginComponent
|
|
12
|
-
authStore = inject(AuthStore);
|
|
17
|
+
export class LoginComponent {
|
|
18
|
+
readonly authStore = inject(AuthStore);
|
|
19
|
+
private readonly router = inject(Router);
|
|
20
|
+
readonly message = signal<string | null>(null);
|
|
21
|
+
readonly sentEmail = signal(false);
|
|
22
|
+
readonly isSendingMagicLink = signal(false);
|
|
23
|
+
readonly isSigningInGoogle = signal(false);
|
|
24
|
+
readonly isLoading = computed(
|
|
25
|
+
() =>
|
|
26
|
+
this.isSendingMagicLink() ||
|
|
27
|
+
this.isSigningInGoogle() ||
|
|
28
|
+
this.authStore.isLoadingLogin(),
|
|
29
|
+
);
|
|
30
|
+
readonly loginModel = signal({ email: '' });
|
|
31
|
+
readonly form = form(this.loginModel, (schema) => {
|
|
32
|
+
required(schema.email, { message: 'Email is required' });
|
|
33
|
+
email(schema.email, { message: 'Please enter a valid email address' });
|
|
34
|
+
});
|
|
13
35
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
36
|
+
async sendMagicLink(): Promise<void> {
|
|
37
|
+
if (this.isLoading()) return;
|
|
38
|
+
await submit(this.form, async () => {
|
|
39
|
+
this.message.set(null);
|
|
40
|
+
this.isSendingMagicLink.set(true);
|
|
41
|
+
try {
|
|
42
|
+
await this.authStore.sendEmailSignInLink(this.loginModel().email);
|
|
43
|
+
this.sentEmail.set(true);
|
|
44
|
+
} catch {
|
|
45
|
+
this.message.set('We could not send a sign-in link. Please try again.');
|
|
46
|
+
} finally {
|
|
47
|
+
this.isSendingMagicLink.set(false);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
28
50
|
}
|
|
29
51
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
this.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
52
|
+
async signInWithGoogle(): Promise<void> {
|
|
53
|
+
if (this.isLoading()) return;
|
|
54
|
+
this.message.set(null);
|
|
55
|
+
this.isSigningInGoogle.set(true);
|
|
56
|
+
try {
|
|
57
|
+
await this.authStore.signInWithGoogle();
|
|
58
|
+
await this.router.navigate(['/home']);
|
|
59
|
+
} catch (error) {
|
|
60
|
+
const code = (error as { code?: string }).code;
|
|
61
|
+
if (code === 'auth/account-exists-with-different-credential') {
|
|
62
|
+
this.message.set(
|
|
63
|
+
'Sign in with an email link first, then use Link Google from your account page.',
|
|
64
|
+
);
|
|
65
|
+
} else if (code !== 'auth/popup-closed-by-user') {
|
|
66
|
+
this.message.set('Google sign-in did not complete. Please try again.');
|
|
67
|
+
}
|
|
68
|
+
} finally {
|
|
69
|
+
this.isSigningInGoogle.set(false);
|
|
70
|
+
}
|
|
43
71
|
}
|
|
44
72
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<app-navbar />
|
|
2
|
+
|
|
3
|
+
<main class="profile-container animate-fade-in">
|
|
4
|
+
<header class="profile-header">
|
|
5
|
+
<h1>Profile & Account Settings</h1>
|
|
6
|
+
<p>Manage your profile details, display name, and connected sign-in methods.</p>
|
|
7
|
+
</header>
|
|
8
|
+
|
|
9
|
+
<app-profile-details-card />
|
|
10
|
+
<app-sign-in-methods-card #signInMethodsCard />
|
|
11
|
+
<app-delete-guest-card (saveProgressRequested)="signInMethodsCard.focusGuestEmail()" />
|
|
12
|
+
</main>
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
@use 'variables' as *;
|
|
2
|
+
|
|
3
|
+
:host {
|
|
4
|
+
display: block;
|
|
5
|
+
min-height: 100vh;
|
|
6
|
+
background: $bg-primary;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.profile-container {
|
|
10
|
+
max-width: 680px;
|
|
11
|
+
margin: 0 auto;
|
|
12
|
+
padding: 40px 24px 60px;
|
|
13
|
+
box-sizing: border-box;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.profile-header {
|
|
17
|
+
margin-bottom: 28px;
|
|
18
|
+
|
|
19
|
+
h1 {
|
|
20
|
+
margin: 0 0 8px;
|
|
21
|
+
color: #1e1b4b;
|
|
22
|
+
font-size: 2.2rem;
|
|
23
|
+
font-weight: 800;
|
|
24
|
+
letter-spacing: -0.025em;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
p {
|
|
28
|
+
margin: 0;
|
|
29
|
+
color: #475569;
|
|
30
|
+
font-size: 1rem;
|
|
31
|
+
line-height: 1.5;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@media (max-width: 640px) {
|
|
36
|
+
.profile-container {
|
|
37
|
+
padding: 24px 16px 40px;
|
|
38
|
+
}
|
|
39
|
+
}
|
package/src/ng-add/files/src/app/main/account-profile/account-profile.component.spec.ts.template
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Injectable, signal } from '@angular/core';
|
|
2
|
+
import { MatDialog } from '@angular/material/dialog';
|
|
3
|
+
import { provideRouter } from '@angular/router';
|
|
4
|
+
import { render, screen } from '@testing-library/angular';
|
|
5
|
+
import userEvent from '@testing-library/user-event';
|
|
6
|
+
import { of } from 'rxjs';
|
|
7
|
+
import { provideFirebaseMock } from 'src/app/core/firebase/firebase.mock.service';
|
|
8
|
+
import { AuthLoggedInMockDB } from 'src/app/core/store/auth/auth.mock';
|
|
9
|
+
import { AuthStore } from 'src/app/core/store/auth/auth.store';
|
|
10
|
+
import { USER_DB } from 'src/app/core/store/user/user.mock';
|
|
11
|
+
import { AccountProfileComponent } from './account-profile.component';
|
|
12
|
+
|
|
13
|
+
@Injectable()
|
|
14
|
+
class GuestAuthMockDB extends AuthLoggedInMockDB {
|
|
15
|
+
override afUser = signal({
|
|
16
|
+
uid: USER_DB[0].__id,
|
|
17
|
+
email: null,
|
|
18
|
+
displayName: 'Guest',
|
|
19
|
+
photoURL: null,
|
|
20
|
+
isAnonymous: true,
|
|
21
|
+
emailVerified: false,
|
|
22
|
+
emailLinkEnabled: false,
|
|
23
|
+
providerIds: [],
|
|
24
|
+
});
|
|
25
|
+
override user = signal({ ...USER_DB[0], name: 'Guest' });
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function setup(options: { guest?: boolean; dialogResult?: unknown } = {}) {
|
|
29
|
+
const user = userEvent.setup();
|
|
30
|
+
const dialog = {
|
|
31
|
+
open: jest.fn().mockReturnValue({ afterClosed: () => of(options.dialogResult) }),
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
await render(AccountProfileComponent, {
|
|
35
|
+
providers: [
|
|
36
|
+
provideRouter([]),
|
|
37
|
+
{
|
|
38
|
+
provide: AuthStore,
|
|
39
|
+
useClass: options.guest ? GuestAuthMockDB : AuthLoggedInMockDB,
|
|
40
|
+
},
|
|
41
|
+
{ provide: MatDialog, useValue: dialog },
|
|
42
|
+
...provideFirebaseMock({ disableLatency: true }),
|
|
43
|
+
],
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
return { user, dialog };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
describe('AccountProfileComponent', () => {
|
|
50
|
+
it('renders the page shell and all applicable account cards', async () => {
|
|
51
|
+
await setup();
|
|
52
|
+
|
|
53
|
+
expect(screen.getByText('<%= classify(project) %>')).toBeVisible();
|
|
54
|
+
expect(screen.getByRole('heading', { name: /Profile & Account Settings/i })).toBeVisible();
|
|
55
|
+
expect(screen.getByRole('heading', { name: /Profile Details/i })).toBeVisible();
|
|
56
|
+
expect(screen.getByRole('heading', { name: /Sign-In Methods/i })).toBeVisible();
|
|
57
|
+
expect(screen.queryByRole('heading', { name: /Delete Guest Account/i })).not.toBeInTheDocument();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('coordinates Save progress by focusing the sign-in card email field', async () => {
|
|
61
|
+
const { user } = await setup({ guest: true, dialogResult: 'save' });
|
|
62
|
+
const emailInput = screen.getByRole('textbox', { name: /Email Address/i });
|
|
63
|
+
|
|
64
|
+
await user.click(screen.getByRole('button', { name: /Delete guest account/i }));
|
|
65
|
+
|
|
66
|
+
expect(emailInput).toHaveFocus();
|
|
67
|
+
});
|
|
68
|
+
});
|