@tech4good/angular-schematics 21.5.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.
Files changed (100) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/package.json +1 -1
  3. package/src/entity/files/__name@dasherize__/__name@dasherize__.mock.ts.template +2 -1
  4. package/src/entity/files/__name@dasherize__/__name@dasherize__.model.ts.template +2 -1
  5. package/src/entity/index.js +57 -0
  6. package/src/entity/index.js.map +1 -1
  7. package/src/entity/schema.json +4 -0
  8. package/src/ng-add/files/.gitignore.template +2 -0
  9. package/src/ng-add/files/docs-infra/authentication-architecture.md.template +270 -0
  10. package/src/ng-add/files/docs-infra/infrastructure-guide.md.template +16 -10
  11. package/src/ng-add/files/firebase.json.template +6 -0
  12. package/src/ng-add/files/firestore.indexes.json.template +23 -0
  13. package/src/ng-add/files/firestore.rules.spec.ts.template +84 -15
  14. package/src/ng-add/files/firestore.rules.template +29 -17
  15. package/src/ng-add/files/functions/.gitignore.template +3 -0
  16. package/src/ng-add/files/functions/package.json.template +12 -0
  17. package/src/ng-add/files/functions/src/index.ts.template +44 -0
  18. package/src/ng-add/files/functions/tsconfig.json.template +13 -0
  19. package/src/ng-add/files/package.json.template +5 -3
  20. package/src/ng-add/files/src/app/admin/admin-panel/admin-panel.component.html.template +3 -1
  21. package/src/ng-add/files/src/app/admin/admin-panel/admin-panel.component.spec.ts.template +6 -8
  22. package/src/ng-add/files/src/app/admin/admin-panel/admin-panel.component.ts.template +2 -0
  23. package/src/ng-add/files/src/app/app.component.html.template +2 -2
  24. package/src/ng-add/files/src/app/app.component.ts.template +2 -0
  25. package/src/ng-add/files/src/app/app.routes.ts.template +6 -0
  26. package/src/ng-add/files/src/app/auth-routing.spec.ts.template +9 -4
  27. package/src/ng-add/files/src/app/core/auth/auth.service.ts.template +6 -1
  28. package/src/ng-add/files/src/app/core/auth/guards/require-admin.guard.spec.ts.template +38 -0
  29. package/src/ng-add/files/src/app/core/auth/guards/require-admin.guard.ts.template +3 -2
  30. package/src/ng-add/files/src/app/core/auth/guards/require-auth-and-consent.guard.ts.template +7 -2
  31. package/src/ng-add/files/src/app/core/firebase/cached-listeners.service.ts.template +11 -5
  32. package/src/ng-add/files/src/app/core/firebase/database.service.ts.template +34 -17
  33. package/src/ng-add/files/src/app/core/firebase/email-link-context.service.spec.ts.template +59 -0
  34. package/src/ng-add/files/src/app/core/firebase/email-link-context.service.ts.template +147 -0
  35. package/src/ng-add/files/src/app/core/firebase/firebase.mock.service.ts.template +104 -17
  36. package/src/ng-add/files/src/app/core/firebase/firebase.service.spec.ts.template +116 -0
  37. package/src/ng-add/files/src/app/core/firebase/firebase.service.ts.template +367 -70
  38. package/src/ng-add/files/src/app/core/store/app.store.ts.template +4 -1
  39. package/src/ng-add/files/src/app/core/store/auth/auth.mock.ts.template +52 -66
  40. package/src/ng-add/files/src/app/core/store/auth/auth.store.spec.ts.template +127 -0
  41. package/src/ng-add/files/src/app/core/store/auth/auth.store.ts.template +216 -147
  42. package/src/ng-add/files/src/app/core/store/user/user.mock.ts.template +2 -4
  43. package/src/ng-add/files/src/app/core/store/user/user.model.ts.template +1 -1
  44. package/src/ng-add/files/src/app/core/store/user-private/user-private.model.ts.template +1 -0
  45. package/src/ng-add/files/src/app/first-time/auth-action/auth-action.component.html.template +4 -0
  46. package/src/ng-add/files/src/app/first-time/auth-action/auth-action.component.scss.template +1 -0
  47. package/src/ng-add/files/src/app/first-time/auth-action/auth-action.component.ts.template +38 -0
  48. package/src/ng-add/files/src/app/first-time/consent/consent.guard.ts.template +5 -1
  49. package/src/ng-add/files/src/app/first-time/early-access/early-access.component.spec.ts.template +12 -1
  50. package/src/ng-add/files/src/app/first-time/early-access/early-access.component.ts.template +93 -48
  51. package/src/ng-add/files/src/app/first-time/early-access/early-access.guard.ts.template +5 -1
  52. package/src/ng-add/files/src/app/first-time/email-link/email-link.component.html.template +18 -0
  53. package/src/ng-add/files/src/app/first-time/email-link/email-link.component.scss.template +2 -0
  54. package/src/ng-add/files/src/app/first-time/email-link/email-link.component.spec.ts.template +40 -0
  55. package/src/ng-add/files/src/app/first-time/email-link/email-link.component.ts.template +76 -0
  56. package/src/ng-add/files/src/app/first-time/first-time-routing.spec.ts.template +7 -2
  57. package/src/ng-add/files/src/app/first-time/landing/hero/hero.component.html.template +19 -7
  58. package/src/ng-add/files/src/app/first-time/landing/hero/hero.component.scss.template +51 -0
  59. package/src/ng-add/files/src/app/first-time/landing/hero/hero.component.ts.template +29 -5
  60. package/src/ng-add/files/src/app/first-time/landing/landing.component.html.template +2 -1
  61. package/src/ng-add/files/src/app/first-time/landing/landing.component.scss.template +12 -8
  62. package/src/ng-add/files/src/app/first-time/landing/landing.component.spec.ts.template +31 -10
  63. package/src/ng-add/files/src/app/first-time/landing/landing.component.ts.template +6 -19
  64. package/src/ng-add/files/src/app/first-time/login/login.component.html.template +58 -6
  65. package/src/ng-add/files/src/app/first-time/login/login.component.scss.template +151 -22
  66. package/src/ng-add/files/src/app/first-time/login/login.component.spec.ts.template +18 -38
  67. package/src/ng-add/files/src/app/first-time/login/login.component.ts.template +59 -31
  68. package/src/ng-add/files/src/app/main/account-profile/account-profile.component.html.template +12 -0
  69. package/src/ng-add/files/src/app/main/account-profile/account-profile.component.scss.template +39 -0
  70. package/src/ng-add/files/src/app/main/account-profile/account-profile.component.spec.ts.template +68 -0
  71. package/src/ng-add/files/src/app/main/account-profile/account-profile.component.ts.template +20 -0
  72. package/src/ng-add/files/src/app/main/account-profile/delete-guest-card/delete-guest-card.component.html.template +24 -0
  73. package/src/ng-add/files/src/app/main/account-profile/delete-guest-card/delete-guest-card.component.scss.template +50 -0
  74. package/src/ng-add/files/src/app/main/account-profile/delete-guest-card/delete-guest-card.component.spec.ts.template +65 -0
  75. package/src/ng-add/files/src/app/main/account-profile/delete-guest-card/delete-guest-card.component.ts.template +59 -0
  76. package/src/ng-add/files/src/app/main/account-profile/guest-deletion-dialog.component.ts.template +51 -0
  77. package/src/ng-add/files/src/app/main/account-profile/profile-details-card/profile-details-card.component.html.template +50 -0
  78. package/src/ng-add/files/src/app/main/account-profile/profile-details-card/profile-details-card.component.scss.template +137 -0
  79. package/src/ng-add/files/src/app/main/account-profile/profile-details-card/profile-details-card.component.spec.ts.template +57 -0
  80. package/src/ng-add/files/src/app/main/account-profile/profile-details-card/profile-details-card.component.ts.template +59 -0
  81. package/src/ng-add/files/src/app/main/account-profile/sign-in-methods-card/sign-in-methods-card.component.html.template +133 -0
  82. package/src/ng-add/files/src/app/main/account-profile/sign-in-methods-card/sign-in-methods-card.component.scss.template +207 -0
  83. package/src/ng-add/files/src/app/main/account-profile/sign-in-methods-card/sign-in-methods-card.component.spec.ts.template +74 -0
  84. package/src/ng-add/files/src/app/main/account-profile/sign-in-methods-card/sign-in-methods-card.component.ts.template +130 -0
  85. package/src/ng-add/files/src/app/main/home/home.component.ts.template +0 -5
  86. package/src/ng-add/files/src/app/shared/guest-warning-bar/guest-warning-bar.component.html.template +15 -0
  87. package/src/ng-add/files/src/app/shared/guest-warning-bar/guest-warning-bar.component.scss.template +79 -0
  88. package/src/ng-add/files/src/app/shared/guest-warning-bar/guest-warning-bar.component.spec.ts.template +59 -0
  89. package/src/ng-add/files/src/app/shared/guest-warning-bar/guest-warning-bar.component.ts.template +44 -0
  90. package/src/ng-add/files/src/app/shared/navbar/navbar.component.html.template +45 -15
  91. package/src/ng-add/files/src/app/shared/navbar/navbar.component.scss.template +103 -19
  92. package/src/ng-add/files/src/app/shared/navbar/navbar.component.spec.ts.template +73 -9
  93. package/src/ng-add/files/src/app/shared/navbar/navbar.component.ts.template +46 -18
  94. package/src/ng-add/files/src/environments/environment.prod.ts.template +1 -0
  95. package/src/ng-add/files/src/environments/environment.test.ts.template +1 -0
  96. package/src/ng-add/files/src/environments/environment.ts.template +1 -1
  97. package/src/ng-add/index_spec.d.ts +1 -0
  98. package/src/ng-add/index_spec.js +108 -0
  99. package/src/ng-add/index_spec.js.map +1 -0
  100. package/tsconfig.json +2 -2
@@ -37,6 +37,18 @@
37
37
  margin-bottom: 40px;
38
38
  }
39
39
 
40
+ .cta-actions {
41
+ display: flex;
42
+ align-items: center;
43
+ justify-content: center;
44
+ gap: 16px;
45
+ flex-wrap: wrap;
46
+
47
+ @media (min-width: 900px) {
48
+ justify-content: flex-start;
49
+ }
50
+ }
51
+
40
52
  .cta-button {
41
53
  background-color: #0E7490;
42
54
  color: #FFFFFF;
@@ -51,6 +63,7 @@
51
63
  display: inline-flex;
52
64
  align-items: center;
53
65
  gap: 8px;
66
+ text-decoration: none;
54
67
 
55
68
  &:hover:not(:disabled) {
56
69
  background-color: #155E75;
@@ -73,6 +86,35 @@
73
86
  stroke: #FFFFFF !important;
74
87
  }
75
88
  }
89
+
90
+ .try-guest {
91
+ display: inline-flex;
92
+ align-items: center;
93
+ gap: 8px;
94
+ margin: 0;
95
+ padding: 12px 16px;
96
+ border: 1px solid transparent;
97
+ border-radius: 8px;
98
+ background: transparent;
99
+ color: #0e7490;
100
+ cursor: pointer;
101
+ font: inherit;
102
+ font-weight: 600;
103
+
104
+ &:hover:not(:disabled) {
105
+ background-color: rgba(14, 116, 144, 0.08);
106
+ color: #155e75;
107
+ }
108
+
109
+ &:disabled {
110
+ opacity: 0.65;
111
+ cursor: wait;
112
+ }
113
+
114
+ .spinner-icon {
115
+ animation: spin 0.8s linear infinite;
116
+ }
117
+ }
76
118
  }
77
119
 
78
120
  .hero-visual {
@@ -90,3 +132,12 @@
90
132
  }
91
133
  }
92
134
  }
135
+
136
+ @keyframes spin {
137
+ from {
138
+ transform: rotate(0deg);
139
+ }
140
+ to {
141
+ transform: rotate(360deg);
142
+ }
143
+ }
@@ -1,20 +1,44 @@
1
- import { Component, ChangeDetectionStrategy, output, input } from '@angular/core';
2
- import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
1
+ import { Component, ChangeDetectionStrategy, inject, input, signal } from '@angular/core';
2
+ import { Router } from '@angular/router';
3
3
  import { RotatingQuotesComponent } from '../rotating-quotes/rotating-quotes.component';
4
+ import { AuthStore } from 'src/app/core/store/auth/auth.store';
4
5
 
5
6
  @Component({
6
7
  selector: 'app-hero',
7
8
  templateUrl: './hero.component.html',
8
9
  styleUrl: './hero.component.scss',
9
10
  changeDetection: ChangeDetectionStrategy.OnPush,
10
- imports: [RotatingQuotesComponent, MatProgressSpinnerModule],
11
+ imports: [RotatingQuotesComponent],
11
12
  })
12
13
  export class HeroComponent {
14
+ private readonly authStore = inject(AuthStore);
15
+ private readonly router = inject(Router);
16
+
13
17
  readonly sentences = [
14
18
  'First generic placeholder quote.',
15
19
  'Second generic placeholder quote.',
16
20
  'Third generic placeholder quote.',
17
21
  ];
18
- isLoading = input<boolean>(false);
19
- login = output<void>();
22
+ showGuestLogin = input<boolean>(true);
23
+
24
+ readonly isGuestLoading = signal(false);
25
+
26
+ onGetStarted(event: Event) {
27
+ event.preventDefault();
28
+ setTimeout(() => {
29
+ this.router.navigate(['/login']);
30
+ }, 0);
31
+ }
32
+
33
+ async tryWithoutLoggingIn() {
34
+ if (this.isGuestLoading()) return;
35
+ this.isGuestLoading.set(true);
36
+ try {
37
+ await this.authStore.loginAnonymously();
38
+ await this.router.navigate(['/home']);
39
+ } catch (error) {
40
+ console.error('[HeroComponent] Guest login failed:', error);
41
+ this.isGuestLoading.set(false);
42
+ }
43
+ }
20
44
  }
@@ -1,3 +1,4 @@
1
+ <app-navbar />
1
2
  <div class="landing-container">
2
- <app-hero [isLoading]="authStore.isLoadingLogin()" (login)="login()"></app-hero>
3
+ <app-hero [showGuestLogin]="showGuestLogin()"></app-hero>
3
4
  </div>
@@ -1,15 +1,19 @@
1
+ @use 'variables' as *;
2
+
1
3
  :host {
2
4
  display: block;
3
5
  font-family: 'Inter', sans-serif;
4
6
  color: #303030;
5
7
  line-height: 1.6;
8
+ min-height: 100vh;
9
+ background: $bg-primary;
10
+ }
6
11
 
7
- .landing-container {
8
- display: flex;
9
- flex-direction: column;
10
- align-items: center;
11
- justify-content: center;
12
- min-height: 100%;
13
- width: 100%;
14
- }
12
+ .landing-container {
13
+ display: flex;
14
+ flex-direction: column;
15
+ align-items: center;
16
+ justify-content: center;
17
+ min-height: calc(100vh - 70px);
18
+ width: 100%;
15
19
  }
@@ -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 the landing title and call authStore login when CTA is clicked', async () => {
29
- const { user, authStore } = await setup();
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
- // Spy on the authStore login method
35
- const loginSpy = jest.spyOn(authStore, 'login');
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(loginSpy).toHaveBeenCalledWith('google.com');
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
- loginSpy.mockRestore();
63
+ await user.click(guestBtn);
64
+ expect(guestSpy).toHaveBeenCalled();
44
65
  });
45
66
  });
@@ -1,37 +1,24 @@
1
- import { Component, ChangeDetectionStrategy, inject, Signal, Injector } from '@angular/core';
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
- // --------------- COMPUTED DATA -----------------------
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 (currentUser()) {
3
- <img class="profile" [src]="currentUser().photoURL" referrerpolicy="no-referrer"/>
4
- <h2>Hello {{currentUser().name}}!</h2>
5
- <input type="submit" value="Logout" (click)="logout()">
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
- <h2>Hello!</h2>
8
- <input type="submit" value="Login" (click)="login()">
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
- border: 1px solid #E7E7E7;
9
- box-shadow: 0px 5px 9px rgba(0, 0, 0, 0.02);
10
- border-radius: 12px;
11
- margin: 40px auto;
12
-
13
- .profile {
14
- width: 95px;
15
- height: 95px;
16
- border-radius: 50%;
17
- background: #D8D8D8;
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
- input {
21
- margin-top: 30px;
22
- width: 115px;
23
- height: 42px;
24
- background: #FAFAFA;
25
- border: 1px solid #E1E1E1;
26
- box-sizing: border-box;
27
- border-radius: 4px;
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, AuthLoggedInMockDB } from 'src/app/core/store/auth/auth.mock';
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
- imports: [],
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('should render login state when user is logged out', async () => {
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
- expect(screen.getByText(/Hello!/i)).toBeVisible();
34
- const loginBtn = screen.getByRole('button', { name: /Login/i });
35
- expect(loginBtn).toBeVisible();
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('should render logout state when user is logged in', async () => {
44
- const { user, authStore } = await setup([
45
- { provide: AuthStore, useClass: AuthLoggedInMockDB },
46
- ]);
47
-
48
- expect(screen.getByText(`Hello ${USER_DB[0].name}!`)).toBeVisible();
49
- const logoutBtn = screen.getByRole('button', { name: /Logout/i });
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
  });