1
1
import { ComponentFixture , TestBed } from '@angular/core/testing' ;
2
+ import { ReactiveFormsModule } from '@angular/forms' ;
2
3
import { DecimalPipe } from '@angular/common' ;
3
4
import { GasBlenderComponent } from './gas-blender.component' ;
4
5
import { UnitConversion } from '../shared/UnitConversion' ;
@@ -14,15 +15,40 @@ import { DiveSchedules } from '../shared/dive.schedules';
14
15
import { ReloadDispatcher } from '../shared/reloadDispatcher' ;
15
16
import { ApplicationSettingsService } from '../shared/ApplicationSettings' ;
16
17
import { BlendPricingService } from '../shared/blend-pricing.service' ;
18
+ import { By } from '@angular/platform-browser' ;
17
19
20
+ class GasBlenderPage {
21
+ constructor ( private fixture : ComponentFixture < GasBlenderComponent > ) { }
22
+
23
+ public get pricingToggleBtn ( ) : HTMLInputElement {
24
+ return this . fixture . debugElement . query ( By . css ( '#pricingToggle' ) ) . nativeElement as HTMLInputElement ;
25
+ }
26
+
27
+ public get o2unitPriceInput ( ) : HTMLInputElement {
28
+ return this . fixture . debugElement . query ( By . css ( '#o2UnitPrice' ) ) . nativeElement as HTMLInputElement ;
29
+ }
30
+
31
+ public get heUnitPriceInput ( ) : HTMLInputElement {
32
+ return this . fixture . debugElement . query ( By . css ( '#heUnitPrice' ) ) . nativeElement as HTMLInputElement ;
33
+ }
34
+
35
+ public get topMixUnitPriceInput ( ) : HTMLInputElement {
36
+ return this . fixture . debugElement . query ( By . css ( '#topMixUnitPrice' ) ) . nativeElement as HTMLInputElement ;
37
+ }
38
+
39
+ public get totalPriceDisplay ( ) : HTMLElement {
40
+ return this . fixture . debugElement . query ( By . css ( '#totalPrice' ) ) . nativeElement as HTMLElement ;
41
+ }
42
+ }
18
43
describe ( 'GasBlenderComponent' , ( ) => {
19
44
let component : GasBlenderComponent ;
20
45
let fixture : ComponentFixture < GasBlenderComponent > ;
21
46
let calculateSpy : jasmine . Spy < ( ) => void > ;
22
-
23
- beforeEach ( ( ) => {
24
- TestBed . configureTestingModule ( {
47
+ let simplePage : GasBlenderPage ;
48
+ beforeEach ( async ( ) => {
49
+ await TestBed . configureTestingModule ( {
25
50
declarations : [ GasBlenderComponent ] ,
51
+ imports : [ ReactiveFormsModule ] ,
26
52
providers : [
27
53
UnitConversion ,
28
54
GasBlenderService , BlendPricingService ,
@@ -31,12 +57,39 @@ describe('GasBlenderComponent', () => {
31
57
Preferences , ViewSwitchService , DiveSchedules ,
32
58
ReloadDispatcher , ApplicationSettingsService
33
59
]
34
- } ) ;
60
+ } ) . compileComponents ( ) ;
61
+ } ) ;
62
+
63
+ beforeEach ( ( ) => {
35
64
fixture = TestBed . createComponent ( GasBlenderComponent ) ;
36
65
component = fixture . componentInstance ;
37
66
fixture . detectChanges ( ) ;
38
67
const calc = TestBed . inject ( GasBlenderService ) ;
39
68
calculateSpy = spyOn ( calc , 'calculate' ) ;
69
+ simplePage = new GasBlenderPage ( fixture ) ;
70
+ } ) ;
71
+
72
+ it ( 'should toggle pricing and display total price' , ( ) => {
73
+
74
+ expect ( simplePage . pricingToggleBtn . checked ) . toBeFalsy ( ) ;
75
+
76
+ simplePage . pricingToggleBtn . click ( ) ;
77
+ fixture . detectChanges ( ) ;
78
+
79
+ const pricingElement = simplePage . totalPriceDisplay ;
80
+ expect ( pricingElement ) . toBeTruthy ( ) ;
81
+
82
+ simplePage . o2unitPriceInput . value = '50' ;
83
+ simplePage . o2unitPriceInput . dispatchEvent ( new Event ( 'input' ) ) ;
84
+
85
+ simplePage . heUnitPriceInput . value = '75' ;
86
+ simplePage . heUnitPriceInput . dispatchEvent ( new Event ( 'input' ) ) ;
87
+
88
+ simplePage . topMixUnitPriceInput . value = '100' ;
89
+ simplePage . topMixUnitPriceInput . dispatchEvent ( new Event ( 'input' ) ) ;
90
+
91
+ fixture . detectChanges ( ) ;
92
+ expect ( simplePage . totalPriceDisplay . textContent ) . toBe ( '20,000' ) ;
40
93
} ) ;
41
94
42
95
it ( 'Apply change calls calculate' , ( ) => {
0 commit comments