|
1 | | -import { TestBed } from '@angular/core/testing'; |
| 1 | +import { ComponentFixture, TestBed } from '@angular/core/testing'; |
2 | 2 | import { AppComponent } from './app.component'; |
| 3 | +import { BombTimerState } from './types'; |
| 4 | +import { ConfigurationComponent } from './configuration/configuration.component'; |
| 5 | +import { BombTimerComponent } from './bomb-timer/bomb-timer.component'; |
| 6 | +import { TimerExpiredComponent } from './timer-expired/timer-expired.component'; |
| 7 | +import { ConfigurationStore } from './configuration.store'; |
3 | 8 |
|
4 | 9 | describe('AppComponent', () => { |
5 | | - beforeEach(() => |
| 10 | + let fixture: ComponentFixture<AppComponent>; |
| 11 | + let app: AppComponent; |
| 12 | + |
| 13 | + beforeEach(() => { |
6 | 14 | TestBed.configureTestingModule({ |
7 | | - declarations: [AppComponent], |
8 | | - }) |
9 | | - ); |
| 15 | + imports: [ |
| 16 | + AppComponent, |
| 17 | + ConfigurationComponent, |
| 18 | + BombTimerComponent, |
| 19 | + TimerExpiredComponent, |
| 20 | + ], |
| 21 | + providers: [ |
| 22 | + { |
| 23 | + provide: ConfigurationStore, |
| 24 | + useValue: { |
| 25 | + configuration: () => ({ |
| 26 | + hours: '00', |
| 27 | + minutes: '01', |
| 28 | + color: '#FF0000', |
| 29 | + showMilliseconds: false, |
| 30 | + }), |
| 31 | + setConfiguration: jasmine.createSpy('setConfiguration'), |
| 32 | + reset: jasmine.createSpy('reset'), |
| 33 | + }, |
| 34 | + }, |
| 35 | + ], |
| 36 | + }); |
| 37 | + fixture = TestBed.createComponent(AppComponent); |
| 38 | + app = fixture.componentInstance; |
| 39 | + fixture.detectChanges(); |
| 40 | + }); |
10 | 41 |
|
11 | 42 | it('should create the app', () => { |
12 | | - const fixture = TestBed.createComponent(AppComponent); |
13 | | - const app = fixture.componentInstance; |
14 | 43 | expect(app).toBeTruthy(); |
15 | 44 | }); |
| 45 | + |
| 46 | + it('should start in CONFIGURATION state', () => { |
| 47 | + expect(app.state).toBe(BombTimerState.CONFIGURATION); |
| 48 | + }); |
| 49 | + |
| 50 | + it('should move to TIMER_RUNNING after configuration completed', () => { |
| 51 | + app.onConfigurationCompleted({ |
| 52 | + hours: '00', |
| 53 | + minutes: '01', |
| 54 | + color: '#FF0000', |
| 55 | + showMilliseconds: false, |
| 56 | + }); |
| 57 | + expect(app.state).toBe(BombTimerState.TIMER_RUNNING); |
| 58 | + }); |
| 59 | + |
| 60 | + it('should move to TIMER_EXPIRED after countdown completed', () => { |
| 61 | + app.onCountdownCompleted(); |
| 62 | + expect(app.state).toBe(BombTimerState.TIMER_EXPIRED); |
| 63 | + }); |
| 64 | + |
| 65 | + it('should return to CONFIGURATION after moveToConfiguration', () => { |
| 66 | + app.state = BombTimerState.TIMER_EXPIRED; |
| 67 | + app.onMoveToConfiguration(); |
| 68 | + expect(app.state).toBe(BombTimerState.CONFIGURATION); |
| 69 | + }); |
16 | 70 | }); |
0 commit comments