-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlanding.component.spec.ts
58 lines (49 loc) · 2.38 KB
/
landing.component.spec.ts
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
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AuthService } from 'src/app/services/auth.service';
import { LandingAuthFormComponent } from '../../components/landing-auth-form/landing-auth-form.component';
import { LandingLoggedInComponent } from '../../components/landing-logged-in/landing-logged-in.component';
import { LandingLoggedOutComponent } from '../../components/landing-logged-out/landing-logged-out.component';
import { LandingComponent } from './landing.component';
describe('LandingComponent', () => {
let component: LandingComponent;
let fixture: ComponentFixture<LandingComponent>;
let authService: AuthService;
beforeEach(() => {
authService = new AuthService();
TestBed.configureTestingModule({
declarations: [LandingComponent, LandingLoggedOutComponent, LandingLoggedInComponent, LandingAuthFormComponent],
imports: [ReactiveFormsModule, FormsModule],
providers: [{ provide: AuthService, useValue: authService }],
});
fixture = TestBed.createComponent(LandingComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should render the logged out component if not authed', () => {
const compiled = fixture.nativeElement;
expect(compiled.querySelector('app-landing-logged-out'))
.withContext('Have you set a default auth username?')
.toBeTruthy();
expect(compiled.querySelector('app-landing-logged-in')).toBeFalsy();
});
it('should render the logged in component if authed', () => {
const compiled = fixture.nativeElement;
component.authed = true;
fixture.detectChanges();
expect(compiled.querySelector('app-landing-logged-out')).toBeFalsy();
expect(compiled.querySelector('app-landing-logged-in')).toBeTruthy();
});
it('should dynamically change the logged in component if authed', () => {
const compiled = fixture.nativeElement;
expect(compiled.querySelector('app-landing-logged-out')).toBeTruthy();
expect(compiled.querySelector('app-landing-logged-in')).toBeFalsy();
authService.authChanges.next('test');
fixture.detectChanges();
expect(compiled.querySelector('app-landing-logged-out')).toBeFalsy();
expect(compiled.querySelector('app-landing-logged-in')).toBeTruthy();
});
});