-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathquote-page.component.spec.ts
65 lines (55 loc) · 1.89 KB
/
quote-page.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
import {ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing';
import {PageObject} from '@utils/test/pageObject';
import {quotesMock} from '@mocks/qoutes.mock';
import {RouterTestingModule} from '@angular/router/testing';
import {QuotePageComponent} from '@modules/quote-page/quote-page.component';
import {QuotePageModule} from '@modules/quote-page/quote-page.module';
import {ActivatedRoute} from '@angular/router';
import {of} from 'rxjs';
import {Location} from '@angular/common';
describe('QuotePageComponent - quote page component', () => {
const [firstQuote] = quotesMock;
let fixture: ComponentFixture<QuotePageComponent>;
let component: QuotePageComponent;
let pageObject: PageObject<QuotePageComponent>;
let location: Location;
beforeEach( () => {
TestBed.configureTestingModule({
imports: [
QuotePageModule,
RouterTestingModule
],
providers: [
{
provide: ActivatedRoute,
useValue: {data: of({quote: firstQuote})}
}
]
}).compileComponents();
fixture = TestBed.createComponent(QuotePageComponent);
component = fixture.componentInstance;
pageObject = new PageObject<QuotePageComponent>(fixture);
location = TestBed.get(Location);
fixture.detectChanges();
});
it('Displayed text of quote is correct', () => {
expect(pageObject.getElementText('.text')).toBe(
firstQuote.text,
'Quotes text is not expected'
);
});
it('Displayed author of quote is correct', () => {
expect(pageObject.getElementText('.author')).toBe(
firstQuote.author,
'Authors text is not expected'
);
});
it('Page should be changed to main on click to "To quotes list"', fakeAsync(() => {
pageObject.triggerClick('.back');
tick();
expect(location.path()).toBe(
'/',
'The current path is not math to the main page path'
);
}));
});