From 966127c8356fe0fc8157515bca098b97f6dfdd02 Mon Sep 17 00:00:00 2001
From: josefbogar <161020900+josefbogar@users.noreply.github.com>
Date: Tue, 29 Oct 2024 23:26:18 +0100
Subject: [PATCH 01/14] first diver.component test
---
.../src/app/diver/diver.component.html | 2 +-
.../src/app/diver/diver.component.spec.ts | 47 +++++++++++++++++++
2 files changed, 48 insertions(+), 1 deletion(-)
create mode 100644 projects/planner/src/app/diver/diver.component.spec.ts
diff --git a/projects/planner/src/app/diver/diver.component.html b/projects/planner/src/app/diver/diver.component.html
index ad73c96b..a4bff866 100644
--- a/projects/planner/src/app/diver/diver.component.html
+++ b/projects/planner/src/app/diver/diver.component.html
@@ -11,7 +11,7 @@
+ [class.is-invalid]="stressRmvInvalid" id="stressRmv" />
Needs to be number {{ranges.diverRmvLabel}}
diff --git a/projects/planner/src/app/diver/diver.component.spec.ts b/projects/planner/src/app/diver/diver.component.spec.ts
new file mode 100644
index 00000000..c44f163e
--- /dev/null
+++ b/projects/planner/src/app/diver/diver.component.spec.ts
@@ -0,0 +1,47 @@
+import { ComponentFixture, TestBed } from '@angular/core/testing';
+import { ReactiveFormsModule } from '@angular/forms';
+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';
+import { By } from '@angular/platform-browser';
+import { DecimalPipe } from '@angular/common';
+
+class DiverPage {
+ constructor(private fixture: ComponentFixture
) {}
+
+ public get stressRmvInput(): HTMLInputElement {
+ return this.fixture.debugElement.query(By.css('#stressRmv')).nativeElement as HTMLInputElement;
+ }
+}
+
+describe('DiverComponent', () => {
+ let component: DiverComponent;
+ let fixture: ComponentFixture;
+ let diverPage: DiverPage;
+
+ beforeEach(async () => {
+ await TestBed.configureTestingModule({
+ declarations: [DiverComponent],
+ imports: [ReactiveFormsModule],
+ providers: [UnitConversion, ValidatorGroups, InputControls, DecimalPipe]
+ }).compileComponents();
+ });
+
+ beforeEach(() => {
+ fixture = TestBed.createComponent(DiverComponent);
+ component = fixture.componentInstance;
+ component.diver = new DiverOptions();
+ fixture.detectChanges();
+ diverPage = new DiverPage(fixture);
+ });
+
+ // eslint-disable-next-line jasmine/no-focused-tests
+ fit('should display stress RMV value in the input field', () => {
+ component.diver.stressRmv = 30;
+ fixture.detectChanges();
+
+ expect(diverPage.stressRmvInput.value).toBe('30');
+ });
+});
From bb9a867376acb338c585f285df629af2b04a162f Mon Sep 17 00:00:00 2001
From: josefbogar <161020900+josefbogar@users.noreply.github.com>
Date: Tue, 5 Nov 2024 22:54:37 +0100
Subject: [PATCH 02/14] add diver.component tests
---
.../src/app/diver/diver.component.spec.ts | 93 ++++++++++++-------
1 file changed, 62 insertions(+), 31 deletions(-)
diff --git a/projects/planner/src/app/diver/diver.component.spec.ts b/projects/planner/src/app/diver/diver.component.spec.ts
index c44f163e..84adb0c7 100644
--- a/projects/planner/src/app/diver/diver.component.spec.ts
+++ b/projects/planner/src/app/diver/diver.component.spec.ts
@@ -1,47 +1,78 @@
-import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ReactiveFormsModule } from '@angular/forms';
-import { DiverComponent } from './diver.component';
+import {NonNullableFormBuilder, FormGroup}
+import {DiverComponent} from'./diver.component';
+import { DecimalPipe } from '@angular/common';
import { UnitConversion } from '../shared/UnitConversion';
import { ValidatorGroups } from '../shared/ValidatorGroups';
import { InputControls } from '../shared/inputcontrols';
import { DiverOptions } from '../shared/models';
-import { By } from '@angular/platform-browser';
-import { DecimalPipe } from '@angular/common';
-
-class DiverPage {
- constructor(private fixture: ComponentFixture) {}
-
- public get stressRmvInput(): HTMLInputElement {
- return this.fixture.debugElement.query(By.css('#stressRmv')).nativeElement as HTMLInputElement;
- }
-}
describe('DiverComponent', () => {
let component: DiverComponent;
- let fixture: ComponentFixture;
- let diverPage: DiverPage;
-
- beforeEach(async () => {
- await TestBed.configureTestingModule({
- declarations: [DiverComponent],
- imports: [ReactiveFormsModule],
- providers: [UnitConversion, ValidatorGroups, InputControls, DecimalPipe]
- }).compileComponents();
- });
+ let unitConversion: UnitConversion;
beforeEach(() => {
- fixture = TestBed.createComponent(DiverComponent);
- component = fixture.componentInstance;
+ const formBuilder = new NonNullableFormBuilder();
+ const decimalPipe = new DecimalPipe('en-US');
+ const inputControls = new InputControls(decimalPipe);
+ unitConversion = new UnitConversion();
+ const validatorGroups = new ValidatorGroups(unitConversion);
+
+
+ component = new DiverComponent(
+ formBuilder,
+ inputControls,
+ validatorGroups,
+ unitConversion
+ );
+
+ component.diverForm = formBuilder.group({
+ rmv: ['20'],
+ stressRmv: ['25']
+ });
+
component.diver = new DiverOptions();
- fixture.detectChanges();
- diverPage = new DiverPage(fixture);
});
- // eslint-disable-next-line jasmine/no-focused-tests
- fit('should display stress RMV value in the input field', () => {
- component.diver.stressRmv = 30;
- fixture.detectChanges();
+ describe('inputChanged', () => {
+ it('should update rmv and stressRmv values in liters and emit changes', () => {
+ const rmv = 15;
+ const stressRmv = 20;
+ component.diverForm.setValue({ rmv: rmv, stressRmv: stressRmv });
+ let wasEmitted = false;
+ component.changed.subscribe(() => wasEmitted = true);
- expect(diverPage.stressRmvInput.value).toBe('30');
+ component.inputChanged();
+
+ expect(component.diver.rmv).toBe(unitConversion.toLiter(rmv));
+ expect(component.diver.stressRmv).toBe(unitConversion.toLiter(stressRmv));
+ expect(wasEmitted).toBeTrue();
+ });
+ });
+
+
+ describe('maxPpO2Changed', () => {
+ it('should change new value of maxPpO2 and emit change', () => {
+ 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 change', () => {
+ const newDecoPpO2 = 1.4;
+ let wasEmitted = false;
+ component.changed.subscribe(() => wasEmitted = true);
+
+ component.maxDecoPpO2Changed(newDecoPpO2);
+ expect(component.diver.maxDecoPpO2).toBe(newDecoPpO2);
+ expect(wasEmitted).toBeTrue();
+ })
+ })
});
From 88c78350546ea5cdef1e73f96a688d5442b9a4eb Mon Sep 17 00:00:00 2001
From: josefbogar <161020900+josefbogar@users.noreply.github.com>
Date: Thu, 14 Nov 2024 21:11:24 +0100
Subject: [PATCH 03/14] diver.component tests corrected
---
.../src/app/diver/diver.component.spec.ts | 32 ++++++++++++-------
1 file changed, 20 insertions(+), 12 deletions(-)
diff --git a/projects/planner/src/app/diver/diver.component.spec.ts b/projects/planner/src/app/diver/diver.component.spec.ts
index 84adb0c7..efc644ac 100644
--- a/projects/planner/src/app/diver/diver.component.spec.ts
+++ b/projects/planner/src/app/diver/diver.component.spec.ts
@@ -35,44 +35,52 @@ describe('DiverComponent', () => {
});
describe('inputChanged', () => {
- it('should update rmv and stressRmv values in liters and emit changes', () => {
- const rmv = 15;
- const stressRmv = 20;
- component.diverForm.setValue({ rmv: rmv, stressRmv: stressRmv });
+ it('should change rmv and stressRmv values and emit results', () => {
+ 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 });
+
let wasEmitted = false;
component.changed.subscribe(() => wasEmitted = true);
component.inputChanged();
- expect(component.diver.rmv).toBe(unitConversion.toLiter(rmv));
- expect(component.diver.stressRmv).toBe(unitConversion.toLiter(stressRmv));
+ expect(component.diver.rmv).toBe(unitConversion.toLiter(newRmv));
+ expect(component.diver.stressRmv).toBe(unitConversion.toLiter(newStressRmv));
expect(wasEmitted).toBeTrue();
});
});
-
describe('maxPpO2Changed', () => {
- it('should change new value of maxPpO2 and emit change', () => {
+ 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 change', () => {
+ 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();
- })
- })
+ });
+ });
});
From ee9ff43b4ad3be632e7749ba745299f6885c9170 Mon Sep 17 00:00:00 2001
From: josefbogar <161020900+josefbogar@users.noreply.github.com>
Date: Fri, 15 Nov 2024 18:02:27 +0100
Subject: [PATCH 04/14] Add TestBed to diver.component tests
---
.../src/app/diver/diver.component.spec.ts | 44 +++++++++----------
1 file changed, 21 insertions(+), 23 deletions(-)
diff --git a/projects/planner/src/app/diver/diver.component.spec.ts b/projects/planner/src/app/diver/diver.component.spec.ts
index efc644ac..a25597ef 100644
--- a/projects/planner/src/app/diver/diver.component.spec.ts
+++ b/projects/planner/src/app/diver/diver.component.spec.ts
@@ -1,7 +1,7 @@
+import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ReactiveFormsModule } from '@angular/forms';
-import {NonNullableFormBuilder, FormGroup}
-import {DiverComponent} from'./diver.component';
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';
@@ -9,38 +9,36 @@ import { DiverOptions } from '../shared/models';
describe('DiverComponent', () => {
let component: DiverComponent;
+ let fixture: ComponentFixture;
let unitConversion: UnitConversion;
- beforeEach(() => {
- const formBuilder = new NonNullableFormBuilder();
- const decimalPipe = new DecimalPipe('en-US');
- const inputControls = new InputControls(decimalPipe);
- unitConversion = new UnitConversion();
- const validatorGroups = new ValidatorGroups(unitConversion);
-
-
- component = new DiverComponent(
- formBuilder,
- inputControls,
- validatorGroups,
- unitConversion
- );
-
- component.diverForm = formBuilder.group({
- rmv: ['20'],
- stressRmv: ['25']
- });
-
+ 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 results', () => {
+ 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 });
let wasEmitted = false;
From f21127e55e832ef13f888f621b1fc367862b962d Mon Sep 17 00:00:00 2001
From: josefbogar <161020900+josefbogar@users.noreply.github.com>
Date: Tue, 19 Nov 2024 14:31:50 +0100
Subject: [PATCH 05/14] add change rmvStep test
---
.../src/app/diver/diver.component.spec.ts | 72 ++++++++++---------
1 file changed, 38 insertions(+), 34 deletions(-)
diff --git a/projects/planner/src/app/diver/diver.component.spec.ts b/projects/planner/src/app/diver/diver.component.spec.ts
index a25597ef..8c1a3424 100644
--- a/projects/planner/src/app/diver/diver.component.spec.ts
+++ b/projects/planner/src/app/diver/diver.component.spec.ts
@@ -31,54 +31,58 @@ describe('DiverComponent', () => {
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);
+ 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;
+ const newRmv = 15;
+ const newStressRmv = 25;
- component.diverForm.setValue({ rmv: newRmv, stressRmv: newStressRmv });
+ component.diverForm.setValue({ rmv: newRmv, stressRmv: newStressRmv });
- let wasEmitted = false;
- component.changed.subscribe(() => wasEmitted = true);
+ let wasEmitted = false;
+ component.changed.subscribe(() => wasEmitted = true);
- component.inputChanged();
+ component.inputChanged();
- expect(component.diver.rmv).toBe(unitConversion.toLiter(newRmv));
- expect(component.diver.stressRmv).toBe(unitConversion.toLiter(newStressRmv));
- expect(wasEmitted).toBeTrue();
- });
+ expect(component.diver.rmv).toBe(unitConversion.toLiter(newRmv));
+ expect(component.diver.stressRmv).toBe(unitConversion.toLiter(newStressRmv));
+ expect(wasEmitted).toBeTrue();
});
- describe('maxPpO2Changed', () => {
- it('should change new value of maxPpO2 and emit', () => {
- expect(component.diver.maxPpO2).toBe(1.4);
+ 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);
+ const newPpO2 = 1.2;
+ let wasEmitted = false;
+ component.changed.subscribe(() => wasEmitted = true);
- component.maxPpO2Changed(newPpO2);
+ component.maxPpO2Changed(newPpO2);
- expect(component.diver.maxPpO2).toBe(newPpO2);
- expect(wasEmitted).toBeTrue();
- });
+ 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);
+ 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);
+ const newDecoPpO2 = 1.4;
+ let wasEmitted = false;
+ component.changed.subscribe(() => wasEmitted = true);
- component.maxDecoPpO2Changed(newDecoPpO2);
+ component.maxDecoPpO2Changed(newDecoPpO2);
- expect(component.diver.maxDecoPpO2).toBe(newDecoPpO2);
- expect(wasEmitted).toBeTrue();
- });
+ expect(component.diver.maxDecoPpO2).toBe(newDecoPpO2);
+ expect(wasEmitted).toBeTrue();
+ });
+
+ it('should change rmvStep when switching to imperial units', () => {
+ expect(component.rmvStep).toBe(2);
+
+ unitConversion.imperialUnits = true;
+
+ fixture.detectChanges();
+
+ expect(component.rmvStep).toBe(0.1);
});
});
From 8ea8db26dc007ae2bb892df6346592886573ae6d Mon Sep 17 00:00:00 2001
From: josefbogar <161020900+josefbogar@users.noreply.github.com>
Date: Thu, 21 Nov 2024 01:35:34 +0100
Subject: [PATCH 06/14] add change rmvStep test
---
.../src/app/diver/diver.component.spec.ts | 53 +++++++++++--------
1 file changed, 32 insertions(+), 21 deletions(-)
diff --git a/projects/planner/src/app/diver/diver.component.spec.ts b/projects/planner/src/app/diver/diver.component.spec.ts
index 8c1a3424..017a5b1b 100644
--- a/projects/planner/src/app/diver/diver.component.spec.ts
+++ b/projects/planner/src/app/diver/diver.component.spec.ts
@@ -11,6 +11,7 @@ describe('DiverComponent', () => {
let component: DiverComponent;
let fixture: ComponentFixture;
let unitConversion: UnitConversion;
+ let pageObject: DiverComponentPageObject;
beforeEach(async () => {
await TestBed.configureTestingModule({
@@ -29,60 +30,70 @@ describe('DiverComponent', () => {
unitConversion = TestBed.inject(UnitConversion);
component.diver = new DiverOptions();
fixture.detectChanges();
+ pageObject = new DiverComponentPageObject(fixture);
});
it('should change rmv and stressRmv values and emit', () => {
- expect(component.diver.rmv).toBe(20);
- expect(component.diver.stressRmv).toBe(30);
+ expect(pageObject.rmv).toBe(20);
+ expect(pageObject.stressRmv).toBe(30);
const newRmv = 15;
const newStressRmv = 25;
+ pageObject.setRmvAndStressRmv(newRmv, newStressRmv);
- component.diverForm.setValue({ rmv: newRmv, stressRmv: newStressRmv });
+ expect(pageObject.rmv).toBe(newRmv);
+ expect(pageObject.stressRmv).toBe(newStressRmv);
+ expect(pageObject.changed).toBeTrue();
+ });
- let wasEmitted = false;
- component.changed.subscribe(() => wasEmitted = true);
+ class DiverComponentPageObject {
+ constructor(private componentFixture: ComponentFixture) {}
- component.inputChanged();
- expect(component.diver.rmv).toBe(unitConversion.toLiter(newRmv));
- expect(component.diver.stressRmv).toBe(unitConversion.toLiter(newStressRmv));
- expect(wasEmitted).toBeTrue();
- });
+ get changed(): boolean {
+ let wasEmitted = false;
+ this.componentFixture.componentInstance.changed.subscribe(() => wasEmitted = true);
+ return wasEmitted;
+ }
+
+ get rmv(): number {
+ return this.componentFixture.componentInstance.diver.rmv;
+ }
+
+ get stressRmv(): number {
+ return this.componentFixture.componentInstance.diver.stressRmv;
+ }
+ setRmvAndStressRmv(rmv: number, stressRmv: number) {
+ this.componentFixture.componentInstance.diver.rmv = rmv;
+ this.componentFixture.componentInstance.diver.stressRmv = stressRmv;
+ this.componentFixture.componentInstance.inputChanged();
+ }
+ }
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();
});
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();
});
- it('should change rmvStep when switching to imperial units', () => {
- expect(component.rmvStep).toBe(2);
-
+ xit('should change rmvStep when switching to imperial units', () => {
+ expect(component.rmvStep).toBe(1);
unitConversion.imperialUnits = true;
-
fixture.detectChanges();
-
expect(component.rmvStep).toBe(0.1);
});
});
From dbf457d0ca69401cf399e66f0797518b2f463d90 Mon Sep 17 00:00:00 2001
From: josefbogar <161020900+josefbogar@users.noreply.github.com>
Date: Thu, 21 Nov 2024 18:29:25 +0100
Subject: [PATCH 07/14] correcting rmvStep change step test
---
projects/planner/src/app/diver/diver.component.spec.ts | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/projects/planner/src/app/diver/diver.component.spec.ts b/projects/planner/src/app/diver/diver.component.spec.ts
index 017a5b1b..3b26bac9 100644
--- a/projects/planner/src/app/diver/diver.component.spec.ts
+++ b/projects/planner/src/app/diver/diver.component.spec.ts
@@ -91,9 +91,9 @@ describe('DiverComponent', () => {
});
xit('should change rmvStep when switching to imperial units', () => {
- expect(component.rmvStep).toBe(1);
+ expect(component.rmvStep).toBe(0.1);
unitConversion.imperialUnits = true;
fixture.detectChanges();
- expect(component.rmvStep).toBe(0.1);
+ expect(component.rmvStep).toBe(0.001);
});
});
From 332b29af2ea38a45ba29e5db6f61185f6774f302 Mon Sep 17 00:00:00 2001
From: josefbogar <161020900+josefbogar@users.noreply.github.com>
Date: Fri, 22 Nov 2024 00:37:22 +0100
Subject: [PATCH 08/14] correction test by adding page input elements
---
.../src/app/diver/diver.component.html | 4 +-
.../src/app/diver/diver.component.spec.ts | 103 +++++++++---------
2 files changed, 53 insertions(+), 54 deletions(-)
diff --git a/projects/planner/src/app/diver/diver.component.html b/projects/planner/src/app/diver/diver.component.html
index a4bff866..0455dd73 100644
--- a/projects/planner/src/app/diver/diver.component.html
+++ b/projects/planner/src/app/diver/diver.component.html
@@ -15,11 +15,11 @@
Needs to be number {{ranges.diverRmvLabel}}
diff --git a/projects/planner/src/app/diver/diver.component.spec.ts b/projects/planner/src/app/diver/diver.component.spec.ts
index 3b26bac9..32448294 100644
--- a/projects/planner/src/app/diver/diver.component.spec.ts
+++ b/projects/planner/src/app/diver/diver.component.spec.ts
@@ -1,17 +1,39 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ReactiveFormsModule } from '@angular/forms';
-import { DecimalPipe } from '@angular/common';
+import { By } from '@angular/platform-browser';
import { DiverComponent } from './diver.component';
import { UnitConversion } from '../shared/UnitConversion';
import { ValidatorGroups } from '../shared/ValidatorGroups';
import { InputControls } from '../shared/inputcontrols';
+import { DecimalPipe } from '@angular/common';
import { DiverOptions } from '../shared/models';
-describe('DiverComponent', () => {
+class DiverPage {
+ constructor(private componentFixture: ComponentFixture) {}
+
+ public get rmvInput(): HTMLInputElement {
+ return this.componentFixture.debugElement.query(By.css('#rmv')).nativeElement as HTMLInputElement;
+ }
+
+ public get stressRmvInput(): HTMLInputElement {
+ return this.componentFixture.debugElement.query(By.css('#stressRmv')).nativeElement as HTMLInputElement;
+ }
+
+ public get maxPpO2Input(): HTMLInputElement {
+ return this.componentFixture.debugElement.query(By.css('#maxPpO2')).nativeElement as HTMLInputElement;
+ }
+
+ public get maxDecoPpO2Input(): HTMLInputElement {
+ return this.componentFixture.debugElement.query(By.css('#maxDecoPpO2')).nativeElement as HTMLInputElement;
+ }
+}
+
+// eslint-disable-next-line jasmine/no-focused-tests
+fdescribe('DiverComponent', () => {
let component: DiverComponent;
let fixture: ComponentFixture;
let unitConversion: UnitConversion;
- let pageObject: DiverComponentPageObject;
+ let simplePage: DiverPage;
beforeEach(async () => {
await TestBed.configureTestingModule({
@@ -24,76 +46,53 @@ describe('DiverComponent', () => {
DecimalPipe
]
}).compileComponents();
+ });
+ beforeEach(() => {
fixture = TestBed.createComponent(DiverComponent);
component = fixture.componentInstance;
unitConversion = TestBed.inject(UnitConversion);
component.diver = new DiverOptions();
fixture.detectChanges();
- pageObject = new DiverComponentPageObject(fixture);
+ simplePage = new DiverPage(fixture);
});
it('should change rmv and stressRmv values and emit', () => {
- expect(pageObject.rmv).toBe(20);
- expect(pageObject.stressRmv).toBe(30);
-
- const newRmv = 15;
- const newStressRmv = 25;
- pageObject.setRmvAndStressRmv(newRmv, newStressRmv);
+ simplePage.rmvInput.value = '15';
+ simplePage.rmvInput.dispatchEvent(new Event('input'));
- expect(pageObject.rmv).toBe(newRmv);
- expect(pageObject.stressRmv).toBe(newStressRmv);
- expect(pageObject.changed).toBeTrue();
- });
+ simplePage.stressRmvInput.value = '25';
+ simplePage.stressRmvInput.dispatchEvent(new Event('input'));
- class DiverComponentPageObject {
- constructor(private componentFixture: ComponentFixture) {}
+ fixture.detectChanges();
+ expect(simplePage.rmvInput.value).toBe('15');
+ expect(simplePage.stressRmvInput.value).toBe('25');
+ });
- get changed(): boolean {
- let wasEmitted = false;
- this.componentFixture.componentInstance.changed.subscribe(() => wasEmitted = true);
- return wasEmitted;
- }
+ it('should change maxPpO2', () => {
+ simplePage.maxPpO2Input.value = '1.2';
+ simplePage.maxPpO2Input.dispatchEvent(new Event('input'));
+ fixture.detectChanges();
- get rmv(): number {
- return this.componentFixture.componentInstance.diver.rmv;
- }
+ expect(simplePage.maxPpO2Input.value).toBe('1.2');
+ });
- get stressRmv(): number {
- return this.componentFixture.componentInstance.diver.stressRmv;
- }
- setRmvAndStressRmv(rmv: number, stressRmv: number) {
- this.componentFixture.componentInstance.diver.rmv = rmv;
- this.componentFixture.componentInstance.diver.stressRmv = stressRmv;
- this.componentFixture.componentInstance.inputChanged();
- }
- }
+ it('should change maxDecoPpO2', () => {
+ simplePage.maxDecoPpO2Input.value = '1.4';
+ simplePage.maxDecoPpO2Input.dispatchEvent(new Event('input'));
+ fixture.detectChanges();
- 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();
+ expect(simplePage.maxDecoPpO2Input.value).toBe('1.4');
});
- 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();
- });
+ xit('should adjust rmvStep when switching to imperial units', () => {
+ const initialStep = component.rmvStep;
- xit('should change rmvStep when switching to imperial units', () => {
- expect(component.rmvStep).toBe(0.1);
unitConversion.imperialUnits = true;
fixture.detectChanges();
+
expect(component.rmvStep).toBe(0.001);
+ expect(initialStep).toBe(0.1);
});
});
From 88299ecaacc219a9fb2f1954184f2b760a8bba7a Mon Sep 17 00:00:00 2001
From: josefbogar <161020900+josefbogar@users.noreply.github.com>
Date: Fri, 22 Nov 2024 00:41:13 +0100
Subject: [PATCH 09/14] fix stupid minor issue in test correction
---
projects/planner/src/app/diver/diver.component.spec.ts | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/projects/planner/src/app/diver/diver.component.spec.ts b/projects/planner/src/app/diver/diver.component.spec.ts
index 32448294..3014918a 100644
--- a/projects/planner/src/app/diver/diver.component.spec.ts
+++ b/projects/planner/src/app/diver/diver.component.spec.ts
@@ -28,8 +28,7 @@ class DiverPage {
}
}
-// eslint-disable-next-line jasmine/no-focused-tests
-fdescribe('DiverComponent', () => {
+describe('DiverComponent', () => {
let component: DiverComponent;
let fixture: ComponentFixture;
let unitConversion: UnitConversion;
From c60146414c4c5a3a3821dbef47d9955565000150 Mon Sep 17 00:00:00 2001
From: Josef Bogar <161020900+josefbogar@users.noreply.github.com>
Date: Fri, 22 Nov 2024 01:12:10 +0100
Subject: [PATCH 10/14] Update main.yml
---
.github/workflows/main.yml | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index a238d88a..01174f03 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -18,7 +18,10 @@ jobs:
uses: actions/setup-node@v4.0.3
with:
node-version: '20.11.1'
- # not using 'npm ci' because it fails
+ - name: Install Chrome
+ uses: browser-actions/setup-chrome@latest
+ with:
+ chrome-version: stable
- run: npm install
- run: npm run test-lib-ci --configuration=ci
- run: npm run build-lib
From dcc4f34d5ae8d753be7327da27a57ba6e06d540b Mon Sep 17 00:00:00 2001
From: josefbogar <161020900+josefbogar@users.noreply.github.com>
Date: Mon, 25 Nov 2024 20:53:43 +0100
Subject: [PATCH 11/14] correct change rmv and stressRmv values test
---
projects/planner/src/app/diver/diver.component.spec.ts | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/projects/planner/src/app/diver/diver.component.spec.ts b/projects/planner/src/app/diver/diver.component.spec.ts
index 3014918a..3b781806 100644
--- a/projects/planner/src/app/diver/diver.component.spec.ts
+++ b/projects/planner/src/app/diver/diver.component.spec.ts
@@ -28,7 +28,8 @@ class DiverPage {
}
}
-describe('DiverComponent', () => {
+// eslint-disable-next-line jasmine/no-focused-tests
+fdescribe('DiverComponent', () => {
let component: DiverComponent;
let fixture: ComponentFixture;
let unitConversion: UnitConversion;
@@ -85,13 +86,10 @@ describe('DiverComponent', () => {
expect(simplePage.maxDecoPpO2Input.value).toBe('1.4');
});
- xit('should adjust rmvStep when switching to imperial units', () => {
- const initialStep = component.rmvStep;
-
+ xit('should change rmvStep when switching to imperial units', () => {
+ expect(component.rmvStep).toBe(0.1);
unitConversion.imperialUnits = true;
fixture.detectChanges();
-
expect(component.rmvStep).toBe(0.001);
- expect(initialStep).toBe(0.1);
});
});
From d4cd9d0f6b5a4cc6c3b176c97a872eb969189f5f Mon Sep 17 00:00:00 2001
From: josefbogar <161020900+josefbogar@users.noreply.github.com>
Date: Mon, 25 Nov 2024 22:11:32 +0100
Subject: [PATCH 12/14] changes in html ids
---
projects/planner/src/app/diver/diver.component.html | 6 +++---
projects/planner/src/app/pp-o2/pp-o2.component.html | 4 ++--
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/projects/planner/src/app/diver/diver.component.html b/projects/planner/src/app/diver/diver.component.html
index 0455dd73..ad73c96b 100644
--- a/projects/planner/src/app/diver/diver.component.html
+++ b/projects/planner/src/app/diver/diver.component.html
@@ -11,15 +11,15 @@
+ [class.is-invalid]="stressRmvInvalid" />
Needs to be number {{ranges.diverRmvLabel}}
diff --git a/projects/planner/src/app/pp-o2/pp-o2.component.html b/projects/planner/src/app/pp-o2/pp-o2.component.html
index 45926042..4d66ca81 100644
--- a/projects/planner/src/app/pp-o2/pp-o2.component.html
+++ b/projects/planner/src/app/pp-o2/pp-o2.component.html
@@ -1,6 +1,6 @@
-
- {{label}}
+
Needs to be number 0.21-3
From b05e0fcc298ca197c38d988269f61d0df9f8c813 Mon Sep 17 00:00:00 2001
From: josefbogar <161020900+josefbogar@users.noreply.github.com>
Date: Mon, 25 Nov 2024 22:28:36 +0100
Subject: [PATCH 13/14] html ids correction
---
projects/planner/src/app/diver/diver.component.spec.ts | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/projects/planner/src/app/diver/diver.component.spec.ts b/projects/planner/src/app/diver/diver.component.spec.ts
index 3b781806..31234aa9 100644
--- a/projects/planner/src/app/diver/diver.component.spec.ts
+++ b/projects/planner/src/app/diver/diver.component.spec.ts
@@ -7,6 +7,7 @@ import { ValidatorGroups } from '../shared/ValidatorGroups';
import { InputControls } from '../shared/inputcontrols';
import { DecimalPipe } from '@angular/common';
import { DiverOptions } from '../shared/models';
+import { PpO2Component } from '../pp-o2/pp-o2.component';
class DiverPage {
constructor(private componentFixture: ComponentFixture) {}
@@ -20,16 +21,15 @@ class DiverPage {
}
public get maxPpO2Input(): HTMLInputElement {
- return this.componentFixture.debugElement.query(By.css('#maxPpO2')).nativeElement as HTMLInputElement;
+ return this.componentFixture.debugElement.query(By.css('#maxPO2')).nativeElement as HTMLInputElement;
}
public get maxDecoPpO2Input(): HTMLInputElement {
- return this.componentFixture.debugElement.query(By.css('#maxDecoPpO2')).nativeElement as HTMLInputElement;
+ return this.componentFixture.debugElement.query(By.css('#maxDecoPO2')).nativeElement as HTMLInputElement;
}
}
-// eslint-disable-next-line jasmine/no-focused-tests
-fdescribe('DiverComponent', () => {
+describe('DiverComponent', () => {
let component: DiverComponent;
let fixture: ComponentFixture;
let unitConversion: UnitConversion;
@@ -37,7 +37,7 @@ fdescribe('DiverComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
- declarations: [DiverComponent],
+ declarations: [DiverComponent, PpO2Component],
imports: [ReactiveFormsModule],
providers: [
UnitConversion,
From 3b0fbd71f992c7f03fdf0daf818bf7dc00a11b26 Mon Sep 17 00:00:00 2001
From: Josef Bogar <161020900+josefbogar@users.noreply.github.com>
Date: Mon, 25 Nov 2024 22:58:26 +0100
Subject: [PATCH 14/14] Restore previous main.yml
---
.github/workflows/main.yml | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 01174f03..197b59a7 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -18,10 +18,7 @@ jobs:
uses: actions/setup-node@v4.0.3
with:
node-version: '20.11.1'
- - name: Install Chrome
- uses: browser-actions/setup-chrome@latest
- with:
- chrome-version: stable
+ # not using 'npm ci' because it fails
- run: npm install
- run: npm run test-lib-ci --configuration=ci
- run: npm run build-lib