-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.spec.ts
More file actions
136 lines (116 loc) · 4.37 KB
/
Copy pathapp.spec.ts
File metadata and controls
136 lines (116 loc) · 4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { provideRouter, Router } from '@angular/router';
import { of } from 'rxjs';
import { App } from './app';
import { LoginPage } from './auth/login-page/login-page';
import { CatalogPage } from './catalog/catalog-page/catalog-page';
import { HomePage } from './home/home-page/home-page';
import { MovieDetails, PagedMovieSummaryResponse } from './movies/movie.models';
import { MovieDetailsPage } from './movies/movie-details-page/movie-details-page';
import { MoviesApi } from './movies/movies-api';
describe('App', () => {
let component: App;
let fixture: ComponentFixture<App>;
let router: Router;
const emptyResponse: PagedMovieSummaryResponse = {
items: [],
page: 1,
pageSize: 12,
totalCount: 0,
totalPages: 0,
hasPreviousPage: false,
hasNextPage: false
};
const detailsResponse: MovieDetails = {
id: 'movie-1',
title: 'Central do Brasil',
originalTitle: 'Central Station',
releaseYear: 1998,
countryCode: 'BR',
originalLanguage: 'pt-BR',
genres: ['Drama'],
director: 'Walter Salles',
synopsis: 'A retired teacher and a young boy travel through Brazil in search of his father.',
durationMinutes: 110,
ageRating: '12',
externalId: 666,
posterUrl: '/p/central.jpg',
createdAt: '2026-05-04T12:00:00Z'
};
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [App],
providers: [
provideRouter([
{ path: '', component: HomePage },
{ path: 'login', component: LoginPage },
{ path: 'catalog', component: CatalogPage },
{ path: 'movies/:id', component: MovieDetailsPage }
]),
{
provide: MoviesApi,
useValue: {
listMovies: vi.fn(() => of(emptyResponse)),
getMovieById: vi.fn(() => of(detailsResponse))
}
}
]
}).compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(App);
component = fixture.componentInstance;
router = TestBed.inject(Router);
});
it('should create the app', () => {
expect(component).toBeTruthy();
});
it('should render the app brand and primary navigation links', () => {
fixture.detectChanges();
const compiled = fixture.nativeElement as HTMLElement;
expect(compiled.querySelector('.brand-link')?.textContent).toContain('Smart Movie Catalog');
expect(compiled.querySelector('nav a[routerLink="/"]')?.textContent).toContain('Home');
expect(compiled.querySelector('a[routerLink="/catalog"]')?.textContent).toContain('Catalog');
expect(compiled.querySelector('a[routerLink="/login"]')?.textContent).toContain('Login');
});
it('should render the public home route', async () => {
fixture.detectChanges();
await router.navigateByUrl('/');
fixture.detectChanges();
await fixture.whenStable();
fixture.detectChanges();
const compiled = fixture.nativeElement as HTMLElement;
expect(compiled.querySelector('app-home-page')).toBeTruthy();
expect(compiled.textContent).toContain('Latest from the catalog');
});
it('should render the public catalog route without an auth guard', async () => {
fixture.detectChanges();
await router.navigateByUrl('/catalog');
fixture.detectChanges();
await fixture.whenStable();
fixture.detectChanges();
const compiled = fixture.nativeElement as HTMLElement;
expect(compiled.querySelector('app-catalog-page')).toBeTruthy();
expect(compiled.textContent).toContain('Catalog');
});
it('should render the movie details route', async () => {
fixture.detectChanges();
await router.navigateByUrl('/movies/movie-1');
fixture.detectChanges();
await fixture.whenStable();
fixture.detectChanges();
const compiled = fixture.nativeElement as HTMLElement;
expect(compiled.querySelector('app-movie-details-page')).toBeTruthy();
expect(compiled.textContent).toContain('Central do Brasil');
});
it('should render the login route', async () => {
fixture.detectChanges();
await router.navigateByUrl('/login');
fixture.detectChanges();
await fixture.whenStable();
fixture.detectChanges();
const compiled = fixture.nativeElement as HTMLElement;
expect(compiled.querySelector('app-login-page')).toBeTruthy();
expect(compiled.textContent).toContain('Smart Movie Catalog');
});
});