Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
<div class="row">
<div class="form-group mt-3">
<button type="button" class="btn btn-primary me-2" (click)="location.back()">Back</button>
<button type="button" class="btn btn-secondary me-2" (click)="resetToDefault()" >Reset to Default</button>
<button type="button" class="btn btn-secondary" (click)="use()" [hidden]="!settingsForm.valid">Use</button>
<button id="resetToDefault" type="button" class="btn btn-secondary me-2" (click)="resetToDefault()" >Reset to Default</button>
<button id="useButton" type="button" class="btn btn-secondary" (click)="use()" [hidden]="!settingsForm.valid">Use</button>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,48 @@ import { DiveSchedules } from '../shared/dive.schedules';
import { ApplicationSettingsService } from '../shared/ApplicationSettings';
import { MdbModalService } from 'mdb-angular-ui-kit/modal';
import { CardHeaderComponent } from '../card-header/card-header.component';
import { ImperialUnits } from 'scuba-physics';
import { values } from 'lodash';
import { AppSettings } from '../shared/models';

export class AppSettingsPage {
constructor(private fixture: ComponentFixture<AppSettingsComponent>) { }

public get imperialRadio(): HTMLInputElement {
return this.fixture.debugElement.query(By.css('#imperialRadio')).nativeElement as HTMLInputElement;
}

public get metricRadio(): HTMLInputElement {
return this.fixture.debugElement.query(By.css('#metricRadio')).nativeElement as HTMLInputElement;
}

public get useButton(): HTMLButtonElement {
return this.fixture.debugElement.query(By.css('#useButton')).nativeElement as HTMLButtonElement;
}

public get resetToDefault(): HTMLButtonElement {
return this.fixture.debugElement.query(By.css('#resetToDefault')).nativeElement as HTMLButtonElement;
}

public get maxDensityInput(): HTMLInputElement {
return this.fixture.debugElement.query(By.css('[formControlName="maxDensity"]')).nativeElement as HTMLInputElement;
}

public get primaryReserveInput(): HTMLInputElement {
return this.fixture.debugElement.query(By.css('[formControlName="primaryTankReserve"]')).nativeElement as HTMLInputElement;

}

public get stageReserveInput(): HTMLInputElement {
return this.fixture.debugElement.query(By.css('[formControlName="stageTankReserve"]')).nativeElement as HTMLInputElement;

}

public setInputValue(input: HTMLInputElement, value: number | string): void {
input.value = String(value);
input.dispatchEvent(new Event('input'));
this.fixture.detectChanges();
}
}

describe('App settings component', () => {
Expand Down Expand Up @@ -76,6 +111,64 @@ describe('App settings component', () => {
it('Applies units change', inject([UnitConversion],
(units: UnitConversion) => {
expect(units.imperialUnits).toBeTruthy();
}));

}));
});

describe('Metric units', () => {
let options: OptionsService;

beforeEach(() => {
page.metricRadio.click();
component.use();
const schedules = TestBed.inject(DiveSchedules);
options = schedules.selected.optionsService;
})

it('Should set Max Gas density after switch to metric units', () => {
expect(component.appSettings.maxGasDensity).toBeCloseTo(5.7, 1);

});

it('Should return to default values of max density after changing values', () => {

page.setInputValue(page.maxDensityInput, 4.5);
page.setInputValue(page.primaryReserveInput, 29);
page.setInputValue(page.stageReserveInput, 19);


page.useButton.click();
fixture.detectChanges();

page.resetToDefault.click();
fixture.detectChanges();

expect(page.maxDensityInput.value).toBeCloseTo(component.appSettings.defaultMaxGasDensity, 1);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default metric gas density and primary tank reserve arent 1.

expect(page.primaryReserveInput.value).toBeCloseTo(component.appSettings.defaultPrimaryTankReserve, 1);
expect(page.stageReserveInput.value).toBeCloseTo(20,1);

});

it('Should apply ICD ignored after Use', () => {

component.settingsForm.patchValue({ icdIgnored: true });

fixture.detectChanges();

component.use();
expect(component.appSettings.icdIgnored).toBeTrue();

});

it('Should not apply Use after invalid value is filled', () => {

component.settingsForm.patchValue({ maxDensity: -1});

fixture.detectChanges();

component.use();
expect(component.settingsForm.invalid).toBeTrue();
expect(component.appSettings.maxGasDensity).not.toBe(-1);
});
});
});