Commits
noltrifork authored d2abf9e0fb2
1 - | import {ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing'; |
2 - | import {of} from 'rxjs'; |
3 - | import {FormsModule, NgForm} from '@angular/forms'; |
4 - | import {map} from 'rxjs/operators'; |
5 - | import {DataCardService} from '../../api/data-card.service'; |
6 - | import {ObservationService} from '../../api/observation.service'; |
7 - | import {MeasurementsModalComponent} from './measurements-modal.component'; |
8 - | import { |
9 - | Activity, |
10 - | ObservationTable, |
11 - | ObservationTableFetuses, |
12 - | ScanningObservationTable, |
13 - | ScanningObservationTableFetuses |
14 - | } from '@nspop/gm-web-facade-api'; |
15 - | import {SimpleChange} from '@angular/core'; |
16 - | import {NoteService} from '../../api/note.service'; |
17 - | import {ModalComponent} from '../../modals/modal/modal.component'; |
18 - | import {AngularMaterialModule} from '../../modules/angular-material.module'; |
19 - | import {UltrasoundModalSectionComponent} from './ultrasound-section/ultrasound-modal-section.component'; |
20 - | import {DatePickerComponent} from '../../date-picker/date-picker.component'; |
21 - | import {TieToActivityModalComponent} from '../tie-to-activity-modal/tie-to-activity-modal.component'; |
22 - | import {RegularModalSectionComponent} from './regular-section/regular-modal-section.component'; |
23 - | import {DropdownComponent} from '../../dropdown/dropdown.component'; |
24 - | import {TextAreaComponent} from '../../text-area/text-area.component'; |
25 - | import {CarePlanService} from '../../api/care-plan.service'; |
26 - | import {BrowserAnimationsModule, NoopAnimationsModule} from '@angular/platform-browser/animations'; |
1 + | import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing'; |
2 + | import { of } from 'rxjs'; |
3 + | import { FormsModule } from '@angular/forms'; |
4 + | import { map } from 'rxjs/operators'; |
5 + | import { DataCardService } from '../../api/data-card.service'; |
6 + | import { ObservationService } from '../../api/observation.service'; |
7 + | import { MeasurementsModalComponent } from './measurements-modal.component'; |
8 + | import { Activity, ObservationTable, ScanningObservationTable } from '@nspop/gm-web-facade-api'; |
9 + | import { SimpleChange } from '@angular/core'; |
10 + | import { NoteService } from '../../api/note.service'; |
11 + | import { ModalComponent } from '../../modals/modal/modal.component'; |
12 + | import { AngularMaterialModule } from '../../modules/angular-material.module'; |
13 + | import { UltrasoundModalSectionComponent } from './ultrasound-section/ultrasound-modal-section.component'; |
14 + | import { DatePickerComponent } from '../../date-picker/date-picker.component'; |
15 + | import { TieToActivityModalComponent } from '../tie-to-activity-modal/tie-to-activity-modal.component'; |
16 + | import { RegularModalSectionComponent } from './regular-section/regular-modal-section.component'; |
17 + | import { DropdownComponent } from '../../dropdown/dropdown.component'; |
18 + | import { TextAreaComponent } from '../../text-area/text-area.component'; |
19 + | import { CarePlanService } from '../../api/care-plan.service'; |
20 + | import { BrowserAnimationsModule, NoopAnimationsModule } from '@angular/platform-browser/animations'; |
27 21 | |
28 22 | function getActivity(): Activity { |
29 23 | return {title: 'some activity', id: '1234abcd'} as Activity; |
30 24 | } |
31 25 | |
32 26 | describe('MeasurementsModalComponent', () => { |
33 27 | let component: MeasurementsModalComponent; |
34 28 | let fixture: ComponentFixture<MeasurementsModalComponent>; |
35 29 | let dataCardServiceStub: DataCardService; |
36 30 | let observationServiceStub: ObservationService; |
180 174 | component.doSave(); |
181 175 | expect(component?.observationDataRegular?.offsetDate).toBeUndefined(); |
182 176 | })); |
183 177 | |
184 178 | |
185 179 | it('just creates observation when in "regular" mode', fakeAsync(() => { |
186 180 | component.isOpen = true; |
187 181 | component.activity = getActivity(); |
188 182 | component.ngOnChanges({isOpen: new SimpleChange(false, true, true)}); |
189 183 | component.observationType = 'regular'; |
190 - | const dataCardSpy = spyOn(dataCardServiceStub, 'update').and.callThrough(); |
191 184 | const regularObservationSpy = spyOn(observationServiceStub, 'createRegularObservations').and.callThrough(); |
192 185 | fixture.detectChanges(); |
193 186 | component.doSave(); |
194 187 | tick(); |
195 188 | expect(regularObservationSpy).toHaveBeenCalled(); |
196 189 | })); |
197 190 | |
198 191 | it('saves datacard and creates observations when in "ultrasound" mode', fakeAsync(() => { |
199 192 | component.isOpen = true; |
200 193 | component.activity = getActivity(); |
231 224 | |
232 225 | it('should do nothing if dialog is closed while already closed', () => { |
233 226 | component.isOpen = true; |
234 227 | expect(component.modalComponent?.isModalVisible).toBeFalse(); |
235 228 | component.ngOnChanges({isOpen: new SimpleChange(false, false, false)}); |
236 229 | expect(component.modalComponent?.isModalVisible).toBeFalse(); |
237 230 | }); |
238 231 | |
239 232 | describe('Edit existing activity measurements', () => { |
240 233 | const activityId = '1234-abcd'; |
241 - | const obsFetuses = [ |
242 - | {rows: [{activityId, fetusPresentation: 'UK', gestationAge: '25+1', fetusWeightEstimate: {unit: 'g', value: 3001}, id: '123', weeksIntoPregnancy: 25}]}, |
243 - | {rows: [{activityId: 'fake-id', fetusPresentation: 'H', gestationAge: '9+3', fetusWeightEstimate: {unit: 'g', value: 1020}, id: '1', weeksIntoPregnancy: 10}]} |
244 - | ]; |
245 234 | beforeEach(() => { |
246 235 | component.activity = { |
247 236 | id: activityId, |
248 237 | observations: [ |
249 238 | {id: '1', activityReference: activityId, fetus: 'A', dateOfMeasurement: new Date(10, 8, 2019), type: 'fetus_weight_estimate', values: [{value: '2344', name: 'vægt', unit: 'g'}]}, |
250 239 | {id: '2', activityReference: activityId, fetus: 'A', dateOfMeasurement: new Date(10, 8, 2019), type: 'fetus_presentation', values: [{value: 'UK', name: 'Præsentation'}]} |
251 240 | ], |
252 241 | title: 'Vigtig Aktivitet', |
253 242 | status: 'finished' |
254 243 | }; |
255 244 | }); |
256 - | it('should return an empty array when missing either activity id or fetuses in the fetus rows', () => { |
257 - | const fetusRows: ScanningObservationTableFetuses[] = [ |
258 - | {rows: [], id: '123', name: 'A'}, |
259 - | {rows: [], id: '222', name: 'B'}, |
260 - | ]; |
261 - | let relevantFetusRows = MeasurementsModalComponent.getRelevantObservationFetusRows(undefined, fetusRows); |
262 - | expect(relevantFetusRows.length).toBe(0); |
263 - | relevantFetusRows = MeasurementsModalComponent.getRelevantScanningFetusRows(undefined, fetusRows); |
264 - | expect(relevantFetusRows.length).toBe(0); |
265 - | }); |
266 - | |
267 - | it('should find the appropriate scanning fetus rows when given an activity id', () => { |
268 - | const fetusRows: ScanningObservationTableFetuses[] = [ |
269 - | {rows: [{activityId, fetusPresentation: 'UK', gestationAge: '30+1', ulWeight: {unit: 'g', value: 2344}}], id: '123', name: 'A'}, |
270 - | {rows: [{activityId: 'not-this-one', fetusPresentation: 'H', gestationAge: '10+2', ulWeight: {unit: 'g', value: 506}}], id: '2', name: 'A'}, |
271 - | ]; |
272 - | const relevantFetusRows = MeasurementsModalComponent.getRelevantScanningFetusRows(activityId, fetusRows); |
273 - | expect(relevantFetusRows.length).toBe(1); |
274 - | expect(relevantFetusRows[0].fetusPresentation).toBe('UK'); |
275 - | }); |
276 - | |
277 - | it('should find the appropriate observation fetus rows when given an activity id', () => { |
278 - | const fetusRows: ObservationTableFetuses[] = obsFetuses; |
279 - | const relevantFetusRows = MeasurementsModalComponent.getRelevantObservationFetusRows(activityId, fetusRows); |
280 - | expect(relevantFetusRows.length).toBe(1); |
281 - | expect(relevantFetusRows[0].fetusWeightEstimate).toBe(3001); |
282 - | }); |
283 245 | |
284 246 | it('should initiate observation data with ultrasound scannings', fakeAsync(async () => { |
285 247 | const expectedDvpValue = 1337; |
286 248 | observationServiceStub.clinicalObservationTable$ = of({mother: {rows: [{id: '2'}]}, fetuses: [{id: '1'}]}); |
287 249 | observationServiceStub.ultrasoundObservationTable$ = of({mother: {rows: [{id: '2', activityId, dvp: {value: expectedDvpValue}}]}, fetuses: [{id: '1'}]}); |
288 250 | await component.initObservationData(); |
289 251 | expect(component.observationDataUltrasound?.dvp).toBe(expectedDvpValue); |
290 252 | })); |
291 253 | |
292 254 | it('should initiate observation data with regular observations', fakeAsync(async () => { |
335 297 | component.initObservationData(); |
336 298 | expect(component.observationDataUltrasound?.flow).toBe('abnormal'); |
337 299 | observationServiceStub.ultrasoundObservationTable$ = of({mother: {rows: [{activityId: '1234-abcd', id: '1', flow: 'normal'}]}} as ScanningObservationTable); |
338 300 | component.initObservationData(); |
339 301 | expect(component.observationDataUltrasound?.flow).toBe('normal'); |
340 302 | observationServiceStub.ultrasoundObservationTable$ = of({mother: {rows: [{activityId: '1234-abcd', id: '1', flow: 'der følges op'}]}} as ScanningObservationTable); |
341 303 | component.initObservationData(); |
342 304 | expect(component.observationDataUltrasound?.flow).toBe('tobecontinued'); |
343 305 | observationServiceStub.ultrasoundObservationTable$ = of({mother: {rows: [{activityId: '1234-abcd', id: '1', flow: 'ugyldig værdi'}]}} as ScanningObservationTable); |
344 306 | component.initObservationData(); |
345 - | expect(component.observationDataUltrasound?.flow).toBe('normal'); |
307 + | expect(component.observationDataUltrasound?.flow).toBe(undefined); |
346 308 | }); |
347 309 | it('should return true when data is initialized', () => { |
348 310 | expect(component.isObservationDataInitialized()).toBeTrue(); |
349 311 | }); |
350 312 | it('should set offset date on uSound table data ', () => { |
351 313 | const offsetDate = new Date(2010, 6, 10); |
352 314 | component.dataCard = { |
353 315 | expectedDateOfDeliverySection: { |
354 316 | offsetDate |
355 317 | } |