/
login.component.spec.ts
80 lines (70 loc) · 2.46 KB
/
login.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { Component } from '@angular/core';
import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { RouterTestingModule } from '@angular/router/testing';
import { KnoraApiConnection } from '@dasch-swiss/dsp-js';
import { DspActionModule } from '@dasch-swiss/dsp-ui';
import { AppInitService } from 'src/app/app-init.service';
import { TestConfig } from 'test.config';
import { DspApiConfigToken, DspApiConnectionToken } from '../declarations/dsp-api-tokens';
import { LoginComponent } from './login.component';
/**
* test host component to simulate parent component.
*/
@Component({
template: '<app-login></app-login>'
})
class TestHostLoginComponent { }
/**
* test component to simulate child component.
*/
@Component({
selector: 'app-login-form',
template: ''
})
class TestLoginFormComponent { }
describe('LoginComponent', () => {
let testHostComponent: TestHostLoginComponent;
let testHostFixture: ComponentFixture<TestHostLoginComponent>;
let hostCompDe;
let loginComponentDe;
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [
LoginComponent,
TestHostLoginComponent,
TestLoginFormComponent
],
imports: [
DspActionModule,
RouterTestingModule
],
providers: [
AppInitService,
{
provide: DspApiConfigToken,
useValue: TestConfig.ApiConfig
},
{
provide: DspApiConnectionToken,
useValue: new KnoraApiConnection(TestConfig.ApiConfig)
}
]
}).compileComponents();
}));
beforeEach(() => {
testHostFixture = TestBed.createComponent(TestHostLoginComponent);
testHostComponent = testHostFixture.componentInstance;
testHostFixture.detectChanges();
hostCompDe = testHostFixture.debugElement;
loginComponentDe = hostCompDe.query(By.directive(LoginComponent));
expect(testHostComponent).toBeTruthy();
});
it('should create', () => {
expect(testHostComponent).toBeTruthy();
});
it('should define the login form', () => {
const loginForm = testHostFixture.debugElement.query(By.css('app-login app-login-form'));
expect(loginForm).toBeTruthy();
});
});