Skip to content

Commit

Permalink
Fixed redundancies component in imperial
Browse files Browse the repository at this point in the history
  • Loading branch information
jirkapok committed Mar 7, 2024
1 parent 7082eab commit f6fb907
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { ViewSwitchService } from '../shared/viewSwitchService';
import { DiveSchedules } from '../shared/dive.schedules';
import { ReloadDispatcher } from '../shared/reloadDispatcher';

fdescribe('GasBlenderComponent', () => {
describe('GasBlenderComponent', () => {
let component: GasBlenderComponent;
let fixture: ComponentFixture<GasBlenderComponent>;
let calculateSpy: jasmine.Spy<() => void>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
</div>
<div>
<label for="finalPressure" class="form-label" mdbLabel>Final pressure [{{units.pressure}}]:</label>
<input class="form-control readonly" name="finalPressure" id="finalPressure" type="number"
[readonly]="true" [value]="calc.finalPressure | number: '1.0-0'" readonly />
<input class="form-control readonly" name="finalPressure" id="finalPressure"
[readonly]="true" [value]="calc.finalPressure | number: '1.0-1'" readonly />
</div>
</form>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,19 @@ describe('RedundanciesComponent', () => {
ReloadDispatcher, DiveSchedules
]
});

const units = TestBed.inject(UnitConversion);
units.imperialUnits = true;
// no need to reset view states, they are empty
fixture = TestBed.createComponent(RedundanciesComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
it('Creates default tank dimensions in imperial units', () => {
expect(component.firstTank.size).toBeCloseTo(124.1 , 1);
expect(component.firstTank.workingPressure).toBeCloseTo(3442);
expect(component.secondTank.size).toBeCloseTo(124.1 , 1);
expect(component.secondTank.workingPressure).toBeCloseTo(3442);
});
});
11 changes: 8 additions & 3 deletions projects/planner/src/app/redundancies/redundancies.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export class RedundanciesComponent implements OnInit {
private loadTank(target: ITankSize, state: TankFillState): void {
target.startPressure = this.units.fromBar(state.startPressure);
target.workingPressure = this.units.fromBar(state.workingPressure);
target.size = this.units.fromLiter(state.size);
target.size = this.units.fromTankLiters(state.size, state.workingPressure);
}

private saveState(): void {
Expand All @@ -158,7 +158,12 @@ export class RedundanciesComponent implements OnInit {
}

private createDefaultState(): RedundanciesViewState {
return this.createState(this.createTankState(), this.createTankState());
const defaultTank = this.units.defaults.tanks.primary;
const workingPressure = this.units.toBar(defaultTank.workingPressure);
const size = this.units.toTankLiters(defaultTank.size, workingPressure);
const firstTank = this.createTankState(200, workingPressure, size);
const secondTank = this.createTankState(200, workingPressure, size);
return this.createState(firstTank, secondTank);
}

private createState(first: TankFillState, second: TankFillState): RedundanciesViewState {
Expand All @@ -172,7 +177,7 @@ export class RedundanciesComponent implements OnInit {
private createTankStateFrom(tank: ITankSize): TankFillState {
const startPressure = this.units.toBar(tank.startPressure);
const workingPressure = this.units.toBar(tank.workingPressure);
const size = this.units.toLiter(tank.size);
const size = this.units.toTankLiters(tank.size, workingPressure);
return this.createTankState(startPressure, workingPressure, size);
}

Expand Down

0 comments on commit f6fb907

Please sign in to comment.