-
Notifications
You must be signed in to change notification settings - Fork 6
/
tractor-control.component.spec.ts
50 lines (39 loc) · 1.67 KB
/
tractor-control.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
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { TractorControlComponent } from './tractor-control.component';
describe('TractorControlComponent', () => {
let component: TractorControlComponent;
let fixture: ComponentFixture<TractorControlComponent>;
beforeEach(async(async() => {
await TestBed.configureTestingModule({
declarations: [ TractorControlComponent ]
}).compileComponents();
fixture = TestBed.createComponent(TractorControlComponent);
component = fixture.componentInstance;
fixture.detectChanges();
}));
it('should create the component', () => {
expect(component).toBeTruthy();
});
it('should click on the image and increment the frame', () => {
let leverImage = fixture.debugElement.nativeElement
.querySelector('img.lever');
let frameState = fixture.debugElement.nativeElement
.querySelector('span.frame-state');
for (let i = 1; i < 4; i++) {
// Check the existing state then in the view.
expect(frameState.textContent).toContain(i);
// Click the image and update the view.
leverImage.click();
// After clicking the component, the component's frameState property
// incremented by 1 but the view is the same.
expect(component.frameState).toEqual(i + 1);
expect(frameState.textContent).toContain(i);
fixture.detectChanges();
// After detecting the change, the view has been updated.
expect(frameState.textContent).toContain(i + 1);
}
// After clicking on the element, the frame state will not increment.
expect(component.frameState).toEqual(4);
expect(frameState.textContent).toContain(4);
});
});