Skip to content

Commit 369d09d

Browse files
committed
chore: format code
1 parent e85b757 commit 369d09d

File tree

4 files changed

+32
-29
lines changed

4 files changed

+32
-29
lines changed

Sandbox.AngularWorkspace/projects/sandbox-app/src/app/app.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ import Header from './core/header/header';
99
styleUrl: './app.css',
1010
changeDetection: ChangeDetectionStrategy.OnPush,
1111
})
12+
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
1213
export class App {}

Sandbox.AngularWorkspace/projects/sandbox-app/src/app/core/header/header.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ <h3>👋 Hello, {{ user()?.name }}</h3>
1212
<a routerLink="/customers">Customers</a> | <a routerLink="/user">Current User</a> |
1313
<a href="/bff/logout">Logout</a>
1414
</nav>
15-
</header>
15+
</header>

Sandbox.AngularWorkspace/projects/sandbox-app/src/app/core/header/header.spec.ts

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,52 +5,54 @@ import { signal } from '@angular/core';
55
import Header from './header';
66
import { Authentication } from '@sandbox-app/authentication/authentication';
77

8-
const mockUser = signal<{ isAuthenticated: boolean; name: string | null }>({
9-
isAuthenticated: true,
10-
name: 'Test User',
11-
});
12-
const mockAuthService = {
13-
user: mockUser,
14-
};
15-
16-
it('renders anonymous header when user is not authenticated', async () => {
17-
mockUser.set({ isAuthenticated: false, name: null });
8+
function setupWithRoutes(user: { isAuthenticated: boolean; name: string | null }) {
9+
const mockUser = signal(user);
10+
const mockAuthService = {
11+
user: mockUser,
12+
};
1813

19-
await render(Header, {
20-
providers: [provideRouter([]), { provide: Authentication, useValue: mockAuthService }],
14+
return render(Header, {
15+
providers: [
16+
provideRouter([
17+
{ path: 'customers', component: Header },
18+
{ path: 'user', component: Header },
19+
]),
20+
{ provide: Authentication, useValue: mockAuthService },
21+
],
2122
});
23+
}
24+
25+
it('renders anonymous header when user is not authenticated', async () => {
26+
await setup({ isAuthenticated: false, name: null });
2227

2328
expect(screen.getByText('Login')).toBeInTheDocument();
2429
expect(screen.getByText('Customers')).toBeInTheDocument();
2530
});
2631

2732
it('renders authenticated header when user is authenticated', async () => {
28-
mockUser.set({ isAuthenticated: true, name: 'John Doe' });
29-
30-
await render(Header, {
31-
providers: [provideRouter([]), { provide: Authentication, useValue: mockAuthService }],
32-
});
33+
await setup({ isAuthenticated: true, name: 'John Doe' });
3334

3435
expect(screen.getByText('👋 Hello, John Doe')).toBeInTheDocument();
3536
expect(screen.getByText('Logout')).toBeInTheDocument();
3637
expect(screen.getByText('Customers')).toBeInTheDocument();
3738
});
3839

3940
it('has working navigation links', async () => {
40-
mockUser.set({ isAuthenticated: true, name: 'John Doe' });
41-
42-
await render(Header, {
43-
providers: [
44-
provideRouter([
45-
{ path: 'customers', component: Header },
46-
{ path: 'user', component: Header },
47-
]),
48-
],
49-
});
41+
await setupWithRoutes({ isAuthenticated: true, name: 'John Doe' });
5042

5143
const customersLink = screen.getByRole('link', { name: 'Customers' });
5244
const userLink = screen.getByRole('link', { name: 'Current User' });
5345

5446
expect(customersLink).toHaveAttribute('href', '/customers');
5547
expect(userLink).toHaveAttribute('href', '/user');
5648
});
49+
50+
function setup(user: { isAuthenticated: boolean; name: string | null }) {
51+
const mockAuthService = {
52+
user: signal(user),
53+
};
54+
55+
return render(Header, {
56+
providers: [provideRouter([]), { provide: Authentication, useValue: mockAuthService }],
57+
});
58+
}

Sandbox.AngularWorkspace/projects/sandbox-app/src/app/core/header/header.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ import { Anonymous } from '@sandbox-app/authentication/anonymous';
1414
export default class Header {
1515
private readonly authenticationService = inject(Authentication);
1616
protected readonly user = this.authenticationService.user;
17-
}
17+
}

0 commit comments

Comments
 (0)