-
Notifications
You must be signed in to change notification settings - Fork 0
/
converter-from-hex.component.spec.ts
77 lines (66 loc) · 2.38 KB
/
converter-from-hex.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
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ConverterFromHexComponent } from './converter-from-hex.component';
import { ConverterModule } from '../converter.module';
import { ConverterFromHexPageObject } from './converter-from-hex.component.po';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
const urlToSave = 'http://localhost:4200/save-hex';
describe('ConverterFromHexComponent', () => {
let component: ConverterFromHexComponent;
let fixture: ComponentFixture<ConverterFromHexComponent>;
let page: ConverterFromHexPageObject;
let httpTestingController: HttpTestingController;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [ConverterModule, HttpClientTestingModule]
})
.compileComponents();
httpTestingController = TestBed.get(HttpTestingController);
}));
beforeEach(() => {
fixture = TestBed.createComponent(ConverterFromHexComponent);
component = fixture.componentInstance;
page = new ConverterFromHexPageObject(fixture.nativeElement);
fixture.detectChanges();
});
afterEach(() => {
httpTestingController.verify();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should clear', async () => {
page.hex('112233');
expect(page.hex()).toBe('112233');
await page.clear();
fixture.detectChanges();
expect(page.hex()).toBe('');
});
it('should convert', async () => {
page.hex('123123');
expect(page.rgb()).toBe('');
page.calc();
const req = httpTestingController.expectOne(urlToSave);
expect(req.request.method).toEqual('POST');
expect(req.request.body.hex).toEqual('123123');
req.flush({});
await fixture.detectChanges();
expect(page.rgb()).toBe('rgb(18, 49, 35)');
});
it('should convert three-digit hex', async () => {
page.hex('567');
expect(page.rgb()).toBe('');
page.calc();
const req = httpTestingController.expectOne(urlToSave);
expect(req.request.method).toEqual('POST');
req.flush({});
await fixture.detectChanges();
expect(page.rgb()).toBe('rgb(85, 102, 119)');
});
it('rgb should be empty when entered incorrectly hex', async () => {
page.hex('qw123we');
page.calc();
const req = httpTestingController.expectNone(urlToSave);
await fixture.detectChanges();
expect(page.rgb()).toBe('');
});
});