Skip to content

Commit cbd1d76

Browse files
authored
add toggle pricing test (#13)
1 parent 136d94e commit cbd1d76

File tree

3 files changed

+62
-8
lines changed

3 files changed

+62
-8
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

projects/planner/src/app/gas-blender/gas-blender.component.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
</div>
1010
<div class="float-end me-1">
1111
<button class="btn btn-sm btn-secondary" [ngClass]="{ 'active': showPricing }" type="button"
12+
id="pricingToggle"
1213
data-toggle="button" [attr.aria-pressed]="showPricing" autocomplete="off" (click)="togglePricing()">
1314
<fa-icon [icon]="dollarIcon" class="fa-lg"></fa-icon>
1415
</button>
@@ -130,7 +131,7 @@
130131
<label for="o2UnitPrice" class="form-label">Unit price O2:</label>
131132
<input formControlName="o2UnitPrice" class="form-control" type="number"
132133
(input)="applyChange()" [min]="ranges.money[0]" [max]="ranges.money[1]" step="1"
133-
required [class.is-invalid]="o2UnitPriceInvalid" id="o2UnitPrice" />
134+
required [class.is-invalid]="o2UnitPriceInvalid" id="o2UnitPrice"/>
134135
<div class="text-danger" *ngIf="o2UnitPriceInvalid">Needs to be number
135136
{{ranges.moneyLabel}}</div>
136137
</div>
@@ -175,7 +176,7 @@
175176
</tr>
176177
<tr>
177178
<td><strong>Total price</strong></td>
178-
<td class="table-active"><strong>{{ pricing.totalPrice | number:'1.0-1' }}</strong></td>
179+
<td class="table-active" id="totalPrice"><strong>{{ pricing.totalPrice | number:'1.0-1' }}</strong></td>
179180
</tr>
180181
</tbody>
181182
</table>

projects/planner/src/app/gas-blender/gas-blender.component.spec.ts

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ComponentFixture, TestBed } from '@angular/core/testing';
2+
import { ReactiveFormsModule } from '@angular/forms';
23
import { DecimalPipe } from '@angular/common';
34
import { GasBlenderComponent } from './gas-blender.component';
45
import { UnitConversion } from '../shared/UnitConversion';
@@ -14,15 +15,40 @@ import { DiveSchedules } from '../shared/dive.schedules';
1415
import { ReloadDispatcher } from '../shared/reloadDispatcher';
1516
import { ApplicationSettingsService } from '../shared/ApplicationSettings';
1617
import { BlendPricingService } from '../shared/blend-pricing.service';
18+
import { By } from '@angular/platform-browser';
1719

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+
}
1843
describe('GasBlenderComponent', () => {
1944
let component: GasBlenderComponent;
2045
let fixture: ComponentFixture<GasBlenderComponent>;
2146
let calculateSpy: jasmine.Spy<() => void>;
22-
23-
beforeEach(() => {
24-
TestBed.configureTestingModule({
47+
let simplePage: GasBlenderPage;
48+
beforeEach(async() => {
49+
await TestBed.configureTestingModule({
2550
declarations: [GasBlenderComponent],
51+
imports: [ReactiveFormsModule],
2652
providers: [
2753
UnitConversion,
2854
GasBlenderService, BlendPricingService,
@@ -31,12 +57,39 @@ describe('GasBlenderComponent', () => {
3157
Preferences, ViewSwitchService, DiveSchedules,
3258
ReloadDispatcher, ApplicationSettingsService
3359
]
34-
});
60+
}).compileComponents();
61+
});
62+
63+
beforeEach(() => {
3564
fixture = TestBed.createComponent(GasBlenderComponent);
3665
component = fixture.componentInstance;
3766
fixture.detectChanges();
3867
const calc = TestBed.inject(GasBlenderService);
3968
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');
4093
});
4194

4295
it('Apply change calls calculate', () => {

0 commit comments

Comments
 (0)