Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add diver component tests #14

Merged
merged 18 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion projects/planner/src/app/diver/diver.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<label for="stressRmv" class="form-label" mdbLabel>Stress RMV [{{units.rmv}}]:</label>
<input class="form-control" id="stressRmv" formControlName="stressRmv" type="number" (input)="inputChanged()"
[min]="ranges.diverRmv[0]" [max]="ranges.diverRmv[1]" [step]="rmvStep"
[class.is-invalid]="stressRmvInvalid" />
[class.is-invalid]="stressRmvInvalid" id="stressRmv" />
<div class="invalid-feedback position-absolute">Needs to be number {{ranges.diverRmvLabel}}</div>
</div>
<div class="pt-2 mt-2 mb-4 col col-12 col-md-6">
Expand Down
84 changes: 84 additions & 0 deletions projects/planner/src/app/diver/diver.component.spec.ts
jirkapok marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ReactiveFormsModule } from '@angular/forms';
import { DecimalPipe } from '@angular/common';
import { DiverComponent } from './diver.component';
import { UnitConversion } from '../shared/UnitConversion';
import { ValidatorGroups } from '../shared/ValidatorGroups';
import { InputControls } from '../shared/inputcontrols';
import { DiverOptions } from '../shared/models';

describe('DiverComponent', () => {
let component: DiverComponent;
let fixture: ComponentFixture<DiverComponent>;
let unitConversion: UnitConversion;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [DiverComponent],
imports: [ReactiveFormsModule],
providers: [
UnitConversion,
ValidatorGroups,
InputControls,
DecimalPipe
]
}).compileComponents();

fixture = TestBed.createComponent(DiverComponent);
component = fixture.componentInstance;
unitConversion = TestBed.inject(UnitConversion);
component.diver = new DiverOptions();
fixture.detectChanges();
});

describe('inputChanged', () => {
it('should change rmv and stressRmv values and emit', () => {
expect(component.diver.rmv).toBe(20);
expect(component.diver.stressRmv).toBe(30);

const newRmv = 15;
const newStressRmv = 25;

component.diverForm.setValue({ rmv: newRmv, stressRmv: newStressRmv });
jirkapok marked this conversation as resolved.
Show resolved Hide resolved

let wasEmitted = false;
component.changed.subscribe(() => wasEmitted = true);

component.inputChanged();

expect(component.diver.rmv).toBe(unitConversion.toLiter(newRmv));
expect(component.diver.stressRmv).toBe(unitConversion.toLiter(newStressRmv));
expect(wasEmitted).toBeTrue();
});
});

describe('maxPpO2Changed', () => {
jirkapok marked this conversation as resolved.
Show resolved Hide resolved
it('should change new value of maxPpO2 and emit', () => {
expect(component.diver.maxPpO2).toBe(1.4);

const newPpO2 = 1.2;
let wasEmitted = false;
component.changed.subscribe(() => wasEmitted = true);

component.maxPpO2Changed(newPpO2);

expect(component.diver.maxPpO2).toBe(newPpO2);
expect(wasEmitted).toBeTrue();
});
});

describe('maxDecoPpO2Changed', () => {
it('should change new value of maxDecoPpO2 and emit', () => {
expect(component.diver.maxDecoPpO2).toBe(1.6);

const newDecoPpO2 = 1.4;
let wasEmitted = false;
component.changed.subscribe(() => wasEmitted = true);

component.maxDecoPpO2Changed(newDecoPpO2);

expect(component.diver.maxDecoPpO2).toBe(newDecoPpO2);
expect(wasEmitted).toBeTrue();
});
});
});