From d182ba2a5edc6a96d3cb41a95b27ad5f7a047eeb Mon Sep 17 00:00:00 2001 From: Daniel Lam Date: Mon, 18 Sep 2023 13:40:42 +0100 Subject: [PATCH] Chore/update release with master (#1558) * Fixing exception in unit tests (#1555) * EUI-8679/8770: WorkbasketFiltersComponent and JudicialUser field fixes (#1553) * updated * updated * updated * Updated * Initial fixes for EXUI-623 * Fix issue via making the jurisdiction model object optionally contain the selected case type * create new toolkit version * Update release notes * Fix tests * EUI-8679/8770: WorkbasketFiltersComponent and JudicialUser field fixes EUI-8679: Remove JudicialUser FormControl values from the overall FormGroup value stored and passed as search criteria by the `WorkbasketFiltersComponent` when applying filters; EUI-8770: Ensure the `WorkbasketFiltersComponent` announces the selected jurisdiction and case type via the `JurisdictionService`; in the `WriteJudicialUserField` component, get the current jurisdiction and case type from the `JurisdictionService` if no case info is present. * Fix import ordering * EUI-8679/8770: WorkbasketFiltersComponent and JudicialUser field fixes Re-tag for formal release. Also includes partial reversion of EXUI-623 (`WriteDocumentFieldComponent` changes) due to deficient unit test coverage. --------- Co-authored-by: Muhammad Anjum Co-authored-by: Andy Wilkins Co-authored-by: Andy Wilkins <49269487+andywilkinshmcts@users.noreply.github.com> --------- Co-authored-by: Andy Wilkins <49269487+andywilkinshmcts@users.noreply.github.com> Co-authored-by: Muhammad Anjum Co-authored-by: Andy Wilkins --- RELEASE-NOTES.md | 10 ++ package.json | 2 +- projects/ccd-case-ui-toolkit/package.json | 2 +- .../case-editor/case-editor.module.ts | 2 +- .../create-case-filters.component.spec.ts | 9 +- .../create-case-filters.component.ts | 6 +- .../write-document-field.component.spec.ts | 6 +- ...rite-judicial-user-field.component.spec.ts | 60 +++++++++++- .../write-judicial-user-field.component.ts | 21 ++++- .../components/palette/palette.module.ts | 5 +- .../workbasket-filters.component.spec.ts | 91 +++++++++++++++---- .../workbasket-filters.component.ts | 14 ++- .../domain/definition/jurisdiction.model.ts | 1 + .../jurisdiction/jurisdiction.service.ts | 9 +- 14 files changed, 199 insertions(+), 39 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 7b1b40aa49..58f21e4358 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -1,4 +1,14 @@ ## RELEASE NOTES +### Version 6.19.4-sscs-joh-fixes +**EUI-8679/EUI-8770** Re-tag for formal release. Also includes partial reversion of EXUI-623 (`WriteDocumentFieldComponent` changes) due to deficient unit test coverage + +### Version 6.19.5-hotfix-EUI-8679-8770 +**EUI-8679** Remove JudicialUser FormControl values from the overall FormGroup value stored and passed as search criteria by the `WorkbasketFiltersComponent` when applying filters +**EUI-8770** Ensure the `WorkbasketFiltersComponent` announces the selected jurisdiction and case type via the `JurisdictionService`; in the `WriteJudicialUserField` component, get the current jurisdiction and case type from the `JurisdictionService` if no case info is present + +### Version 6.19.5-secure-doc-case-creation.1 +**EXUI-623** Make secure docstore work during case creation + ### Version 6.19.1-case-flags-v2-reasonable-adjustments **EUI-7243** Case flags v2 reasonable adjustments - updating latest from master diff --git a/package.json b/package.json index e63c3fb9ff..4cc69b12ff 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hmcts/ccd-case-ui-toolkit", - "version": "6.19.3-mv-upgrade", + "version": "6.19.4-sscs-joh-fixes", "engines": { "yarn": "^3.5.0", "npm": "^8.10.0" diff --git a/projects/ccd-case-ui-toolkit/package.json b/projects/ccd-case-ui-toolkit/package.json index d7ef14d145..53f52b77d8 100644 --- a/projects/ccd-case-ui-toolkit/package.json +++ b/projects/ccd-case-ui-toolkit/package.json @@ -1,6 +1,6 @@ { "name": "@hmcts/ccd-case-ui-toolkit", - "version": "6.19.3-mv-upgrade", + "version": "6.19.4-sscs-joh-fixes", "engines": { "yarn": "^3.5.0", "npm": "^8.10.0" diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-editor.module.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-editor.module.ts index 8f534cc384..7150ce9476 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-editor.module.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-editor.module.ts @@ -58,13 +58,13 @@ import { CaseworkerService } from './services/case-worker.service'; FormsModule, ReactiveFormsModule, CaseEditDataModule, - PaletteModule, LabelSubstitutorModule, ConditionalShowModule, ErrorsModule, PortalModule, LoadingSpinnerModule, BannersModule, + PaletteModule, RpxTranslationModule.forChild() ], declarations: [ diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/create-case-filters/create-case-filters.component.spec.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/components/create-case-filters/create-case-filters.component.spec.ts index fcee2f1f9b..4c2bd2fa1a 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/create-case-filters/create-case-filters.component.spec.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/create-case-filters/create-case-filters.component.spec.ts @@ -8,7 +8,7 @@ import { CaseEvent } from '../../domain/definition/case-event.model'; import { CaseTypeLite } from '../../domain/definition/case-type-lite.model'; import { Jurisdiction } from '../../domain/definition/jurisdiction.model'; import { createACL } from '../../fixture/shared.test.fixture'; -import { AlertService, DefinitionsService, OrderService, SessionStorageService } from '../../services'; +import { AlertService, DefinitionsService, JurisdictionService, OrderService, SessionStorageService } from '../../services'; import { MockRpxTranslatePipe } from '../../test/mock-rpx-translate.pipe'; import { CreateCaseFiltersComponent } from './create-case-filters.component'; import createSpyObj = jasmine.createSpyObj; @@ -263,6 +263,7 @@ const FILTERED_CASE_EVENTS: CaseEvent[] = [{ let mockDefinitionsService: any; let mockOrderService: any; let mockAlertService: any; +let jurisdictionService: any; const TEST_FORM_GROUP = new FormGroup({}); @@ -297,6 +298,9 @@ describe('CreateCaseFiltersComponent', () => { sessionStorageService = jasmine.createSpyObj('sessionStorageService', ['getItem']); sessionStorageService.getItem.and.returnValue(`{"id": 1, "forename": "Firstname", "surname": "Surname", "roles": ["role1", "role3"], "email": "test@mail.com","token": null}`); + jurisdictionService = createSpyObj('jurisdictionService', + ['announceSelectedJurisdiction']); + TestBed .configureTestingModule({ @@ -311,7 +315,8 @@ describe('CreateCaseFiltersComponent', () => { { provide: OrderService, useValue: mockOrderService }, { provide: AlertService, useValue: mockAlertService }, { provide: DefinitionsService, useValue: mockDefinitionsService }, - { provide: SessionStorageService, useValue: sessionStorageService} + { provide: SessionStorageService, useValue: sessionStorageService }, + { provide: JurisdictionService, useValue: jurisdictionService} ] }) .compileComponents(); diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/create-case-filters/create-case-filters.component.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/components/create-case-filters/create-case-filters.component.ts index 0e7763933e..130b5f2185 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/create-case-filters/create-case-filters.component.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/create-case-filters/create-case-filters.component.ts @@ -5,6 +5,7 @@ import { CaseEvent } from '../../domain/definition/case-event.model'; import { CaseTypeLite } from '../../domain/definition/case-type-lite.model'; import { Jurisdiction } from '../../domain/definition/jurisdiction.model'; import { DefinitionsService } from '../../services/definitions/definitions.service'; +import { JurisdictionService } from '../../services/jurisdiction/jurisdiction.service'; import { OrderService } from '../../services/order/order.service'; import { SessionStorageService } from '../../services/session/session-storage.service'; import { CreateCaseFiltersSelection } from './create-case-filters-selection.model'; @@ -44,7 +45,8 @@ export class CreateCaseFiltersComponent implements OnInit { constructor( private readonly orderService: OrderService, private readonly definitionsService: DefinitionsService, - private readonly sessionStorageService: SessionStorageService + private readonly sessionStorageService: SessionStorageService, + private readonly jurisdictionService: JurisdictionService ) { } public ngOnInit() { @@ -99,6 +101,8 @@ export class CreateCaseFiltersComponent implements OnInit { } public apply() { + this.selected.jurisdiction.currentCaseType = this.selected.caseType; + this.jurisdictionService.announceSelectedJurisdiction(this.selected.jurisdiction); this.selectionSubmitted.emit({ jurisdictionId: this.selected.jurisdiction.id, caseTypeId: this.selected.caseType.id, diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/document/write-document-field.component.spec.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/document/write-document-field.component.spec.ts index ec96225d78..88749c8bf0 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/document/write-document-field.component.spec.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/document/write-document-field.component.spec.ts @@ -121,7 +121,7 @@ describe('WriteDocumentFieldComponent', () => { of(RESPONSE_SECOND_DOCUMENT) ); mockDialog = createSpyObj('dialog', ['open']); - mockMatDialogRef = createSpyObj>('matDialogRef', ['beforeClosed']); + mockMatDialogRef = createSpyObj>('matDialogRef', ['beforeClosed','close']); casesService = createSpyObj('casesService', ['getCaseViewV2']); mockFileUploadStateService = createSpyObj('fileUploadStateService', [ @@ -204,6 +204,8 @@ describe('WriteDocumentFieldComponent', () => { mockMatDialogRef = { beforeClosed() { return of('Replace'); + }, + close(r: any) { } }; mockDialog.open.and.returnValue(mockMatDialogRef); @@ -219,6 +221,8 @@ describe('WriteDocumentFieldComponent', () => { mockMatDialogRef = { beforeClosed() { return of('Replace'); + }, + close(r: any) { } }; mockDialog.open.and.returnValue(mockMatDialogRef); diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/judicial-user/write-judicial-user-field.component.spec.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/judicial-user/write-judicial-user-field.component.spec.ts index e2734f5cb7..5f6ba1676d 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/judicial-user/write-judicial-user-field.component.spec.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/judicial-user/write-judicial-user-field.component.spec.ts @@ -1,12 +1,12 @@ import { CUSTOM_ELEMENTS_SCHEMA, Pipe, PipeTransform } from '@angular/core'; -import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; +import { ComponentFixture, TestBed, fakeAsync, tick, waitForAsync } from '@angular/core/testing'; import { FormGroup, ReactiveFormsModule, ValidationErrors, Validators } from '@angular/forms'; import { MatAutocompleteModule } from '@angular/material/autocomplete'; import { By } from '@angular/platform-browser'; -import { of, throwError } from 'rxjs'; +import { BehaviorSubject, of, throwError } from 'rxjs'; import { Constants } from '../../../commons/constants'; import { HmctsServiceDetail } from '../../../domain/case-flag'; -import { CaseField, FieldType } from '../../../domain/definition'; +import { CaseField, CaseTypeLite, FieldType, Jurisdiction } from '../../../domain/definition'; import { JudicialUserModel } from '../../../domain/jurisdiction'; import { CaseFlagRefdataService, FieldsUtils, FormValidatorsService, JurisdictionService, SessionStorageService } from '../../../services'; import { FirstErrorPipe, IsCompoundPipe, PaletteUtilsModule } from '../utils'; @@ -499,4 +499,58 @@ describe('WriteJudicialUserFieldComponent', () => { const errorMessageElement = fixture.debugElement.query(By.css('.error-message')).nativeElement; expect(errorMessageElement.textContent).toContain('Judicial User is required'); }); + + it('should get the jurisdiction and case type via the JurisdictionService if there is no case info', fakeAsync(() => { + sessionStorageService.getItem.and.returnValue(null); + const dummyJurisdictionAndCaseType = { + id: 'J1', + name: 'Jurisdiction 1', + description: 'Dummy jurisdiction', + caseTypes: [], + currentCaseType: { + id: 'CT1', + name: 'Case Type 1' + } as CaseTypeLite + } as Jurisdiction; + Object.defineProperty(jurisdictionService, 'selectedJurisdictionBS', { value: new BehaviorSubject(null) }); + jurisdictionService.selectedJurisdictionBS.next(dummyJurisdictionAndCaseType); + spyOn(jurisdictionService.selectedJurisdictionBS, 'subscribe').and.callThrough(); + component.setJurisdictionAndCaseType(); + tick(); + expect(jurisdictionService.selectedJurisdictionBS.subscribe).toHaveBeenCalled(); + expect(component.jurisdiction).toEqual(dummyJurisdictionAndCaseType.id); + expect(component.caseType).toEqual(dummyJurisdictionAndCaseType.currentCaseType.id); + })); + + it('should not get the jurisdiction and case type via the JurisdictionService if there is case info', () => { + Object.defineProperty(jurisdictionService, 'selectedJurisdictionBS', { value: new BehaviorSubject(null) }); + spyOn(jurisdictionService.selectedJurisdictionBS, 'subscribe'); + component.setJurisdictionAndCaseType(); + expect(jurisdictionService.selectedJurisdictionBS.subscribe).not.toHaveBeenCalled(); + expect(component.jurisdiction).toEqual('SSCS'); + expect(component.caseType).toEqual('Benefit'); + }); + + it('should unsubscribe from any subscriptions when the component is destroyed', fakeAsync(() => { + sessionStorageService.getItem.and.returnValue(null); + const dummyJurisdictionAndCaseType = { + id: 'J1', + name: 'Jurisdiction 1', + description: 'Dummy jurisdiction', + caseTypes: [], + currentCaseType: { + id: 'CT1', + name: 'Case Type 1' + } as CaseTypeLite + } as Jurisdiction; + Object.defineProperty(jurisdictionService, 'selectedJurisdictionBS', { value: new BehaviorSubject(null) }); + jurisdictionService.selectedJurisdictionBS.next(dummyJurisdictionAndCaseType); + spyOn(jurisdictionService.selectedJurisdictionBS, 'subscribe').and.callThrough(); + component.setJurisdictionAndCaseType(); + tick(); + expect(jurisdictionService.selectedJurisdictionBS.subscribe).toHaveBeenCalled(); + spyOn(component.jurisdictionSubscription, 'unsubscribe'); + component.ngOnDestroy(); + expect(component.jurisdictionSubscription.unsubscribe).toHaveBeenCalled(); + })); }); diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/judicial-user/write-judicial-user-field.component.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/judicial-user/write-judicial-user-field.component.ts index ce7b7a2922..5f298fe4db 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/judicial-user/write-judicial-user-field.component.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/judicial-user/write-judicial-user-field.component.ts @@ -1,6 +1,6 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnDestroy, OnInit } from '@angular/core'; import { AbstractControl, FormControl, ValidationErrors, Validators } from '@angular/forms'; -import { Observable, of } from 'rxjs'; +import { Observable, Subscription, of } from 'rxjs'; import { catchError, debounceTime, filter, map, switchMap, take, tap } from 'rxjs/operators'; import { Constants } from '../../../commons/constants'; import { JudicialUserModel } from '../../../domain/jurisdiction'; @@ -13,7 +13,7 @@ import { IsCompoundPipe } from '../utils/is-compound.pipe'; styleUrls: ['./write-judicial-user-field.component.scss'], templateUrl: './write-judicial-user-field.component.html' }) -export class WriteJudicialUserFieldComponent extends WriteComplexFieldComponent implements OnInit { +export class WriteJudicialUserFieldComponent extends WriteComplexFieldComponent implements OnInit, OnDestroy { public readonly minSearchCharacters = 2; @@ -27,6 +27,7 @@ export class WriteJudicialUserFieldComponent extends WriteComplexFieldComponent public errors: ValidationErrors; public invalidSearchTerm = false; public judicialUserSelected = false; + public jurisdictionSubscription: Subscription; constructor(private readonly jurisdictionService: JurisdictionService, private readonly sessionStorageService: SessionStorageService, @@ -106,6 +107,16 @@ export class WriteJudicialUserFieldComponent extends WriteComplexFieldComponent const caseInfo = JSON.parse(caseInfoStr); this.jurisdiction = caseInfo?.jurisdiction; this.caseType = caseInfo?.caseType; + } else { + // If there is no case info, attempt to get the current jurisdiction and case type via the JurisdictionService + this.jurisdictionSubscription = this.jurisdictionService.selectedJurisdictionBS.subscribe((jurisdiction) => { + if (jurisdiction) { + this.jurisdiction = jurisdiction.id; + if (jurisdiction.currentCaseType) { + this.caseType = jurisdiction.currentCaseType.id; + } + } + }); } } @@ -155,4 +166,8 @@ export class WriteJudicialUserFieldComponent extends WriteComplexFieldComponent this.judicialUserControl.setValidators(Validators.required); } } + + public ngOnDestroy(): void { + this.jurisdictionSubscription?.unsubscribe(); + } } diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/palette.module.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/palette.module.ts index b13d1ccda1..6bb1c17340 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/palette.module.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/palette.module.ts @@ -338,17 +338,16 @@ const PALETTE_COMPONENTS = [ CaseFlagRefdataService, YesNoService, CollectionCreateCheckerService, + JurisdictionService, PaletteService, FormValidatorsService, FileUploadStateService, FileUploadProgressGuard, WindowService, CommonDataService, - JurisdictionService, LinkedCasesService, {provide: MAT_DATE_LOCALE, useValue: 'en-GB'} - ], - entryComponents: [CaseFileViewFolderSelectorComponent] + ] }) export class PaletteModule { } diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/workbasket-filters/workbasket-filters.component.spec.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/components/workbasket-filters/workbasket-filters.component.spec.ts index f9c0517ed8..6e700c9817 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/workbasket-filters/workbasket-filters.component.spec.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/workbasket-filters/workbasket-filters.component.spec.ts @@ -1,5 +1,5 @@ import { Component, CUSTOM_ELEMENTS_SCHEMA, DebugElement, Input } from '@angular/core'; -import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; +import { ComponentFixture, fakeAsync, TestBed, tick, waitForAsync } from '@angular/core/testing'; import { FormControl, FormGroup, FormsModule, ReactiveFormsModule } from '@angular/forms'; import { By } from '@angular/platform-browser'; import { ActivatedRoute, Router } from '@angular/router'; @@ -193,7 +193,7 @@ describe('Clear localStorage for workbasket filters', () => { httpService = createSpyObj('httpService', ['get', 'post']); jurisdictionService = new JurisdictionService(httpService); windowMockService = createSpyObj('windowService', ['clearLocalStorage', 'locationAssign', - 'getLocalStorage', 'removeLocalStorage']); + 'getLocalStorage', 'removeLocalStorage', 'setLocalStorage']); resetCaseTypes(JURISDICTION_2, CASE_TYPES_2); activatedRoute = { queryParams: of({}), @@ -442,7 +442,6 @@ describe('with defaults', () => { })); it('should submit filters when defaults could be selected, preserving the alerts', () => { - expect(workbasketHandler.applyFilters).toHaveBeenCalledWith({ selected: { jurisdiction: JURISDICTION_2, @@ -508,7 +507,7 @@ describe('with defaults', () => { expect(component.workbasketInputsReady).toBeFalsy(); }); - it('should have form group details added when apply button is clicked ', () => { + it('should have form group details added when apply button is clicked', () => { component.selected.jurisdiction = JURISDICTION_2; component.apply(true); @@ -644,6 +643,31 @@ describe('with defaults', () => { }); }); + it('should remove any "_judicialUserControl"-suffixed FormControl values from the FormGroup value to be stored locally', () => { + const control = new FormControl('test'); + const judicialUserControl = new FormControl('judicialUser1'); + const formControls = { + name: control, + j1_judicialUserControl: judicialUserControl + }; + const formGroup = new FormGroup(formControls); + component.formGroup = formGroup; + component.selected.jurisdiction = JURISDICTION_2; + component.selected.caseType = CASE_TYPES_2[2]; + component.selected.caseState = DEFAULT_CASE_STATE; + + workbasketHandler.applyFilters.calls.reset(); + + const button = de.query(By.css('button')); + button.nativeElement.click(); + + fixture.detectChanges(); + // The "j1_judicialUserControl" property is expected to have been removed, leaving just the "name" property + // Need to check the second call to windowService.setLocalStorage(); the first one is for "savedQueryParams" + expect(windowService.setLocalStorage.calls.argsFor(1)).toEqual( + ['workbasket-filter-form-group-value', JSON.stringify({ name: 'test' })]); + }); + it('should update form group filters', () => { const formGroupLocalStorage = { regionList: 'london', @@ -667,6 +691,15 @@ describe('with defaults', () => { expect(component.formGroup.get('londonFRCList').value).toBe(null); expect(component.formGroup.get('londonCourtList').value).toBe(null); }); + + it('should announce the selected jurisdiction and case type via the JurisdictionService when filters are applied', () => { + spyOn(jurisdictionService, 'announceSelectedJurisdiction'); + component.selected.jurisdiction = JURISDICTION_2; + component.selected.caseType = CASE_TYPES_2[0]; + component.apply(false); + expect(component.selected.jurisdiction.currentCaseType).toEqual(CASE_TYPES_2[0]); + expect(jurisdictionService.announceSelectedJurisdiction).toHaveBeenCalledWith(component.selected.jurisdiction); + }); }); describe('with defaults and CRUD', () => { @@ -1148,7 +1181,7 @@ describe('with no defaults', () => { component = fixture.componentInstance; component.jurisdictions = [ - JURISDICTION_ONE, + JURISDICTION_ONE ]; component.formGroup = TEST_FORM_GROUP; component.defaults = {}; @@ -1244,24 +1277,44 @@ describe('with no defaults', () => { }); }); - it('should remove localStorage and clear selected fields once reset button is clicked', async () => { + it('should remove localStorage and clear selected fields once reset button is clicked', fakeAsync(() => { + // Set some initial values for the jurisdiction, case type and case state + component.selected.jurisdiction = JURISDICTION_ONE; + component.onJurisdictionIdChange(); + component.selected.caseType = CASE_TYPES_1[0]; + component.onCaseTypeIdChange(); + component.selected.caseState = CASE_TYPES_1[0].states[0]; + fixture.detectChanges(); + tick(); + fixture.detectChanges(); + let selector = de.query(By.css('#wb-jurisdiction')); + expect(selector.nativeElement.selectedIndex).toEqual(1); + selector = de.query(By.css('#wb-case-type')); + expect(selector.nativeElement.selectedIndex).toEqual(1); + selector = de.query(By.css('#wb-case-state')); + expect(selector.nativeElement.selectedIndex).toEqual(1); + + spyOn(component, 'apply').and.callThrough(); component.reset(); + // Use same time interval as the component does for setTimeout() in the reset() function + tick(500); fixture.detectChanges(); - await fixture - .whenStable() - .then(() => { - let selector = de.query(By.css('#wb-jurisdiction')); - expect(selector.nativeElement.selectedIndex).toEqual(0); - expect(selector.children[0].nativeElement.textContent).toEqual(SELECT_A_VALUE); - selector = de.query(By.css('#wb-case-type')); - expect(selector.nativeElement.selectedIndex).toEqual(-1); - selector = de.query(By.css('#wb-case-state')); - expect(selector.nativeElement.selectedIndex).toEqual(-1); - }); + selector = de.query(By.css('#wb-jurisdiction')); + // Jurisdiction selection is left unchanged + expect(selector.nativeElement.selectedIndex).toEqual(1); + expect(selector.children[0].nativeElement.textContent).toEqual(SELECT_A_VALUE); + expect(selector.children[1].nativeElement.textContent).toEqual(JURISDICTION_ONE.name); + selector = de.query(By.css('#wb-case-type')); + expect(selector.nativeElement.selectedIndex).toEqual(-1); + selector = de.query(By.css('#wb-case-state')); + expect(selector.nativeElement.selectedIndex).toEqual(-1); - expect(windowService.removeLocalStorage).toHaveBeenCalled(); - }); + expect(windowService.removeLocalStorage).toHaveBeenCalledWith('workbasket-filter-form-group-value'); + expect(windowService.removeLocalStorage).toHaveBeenCalledWith('savedQueryParams'); + expect(component.apply).toHaveBeenCalledWith(true); + expect(windowService.setLocalStorage).toHaveBeenCalledWith('savedQueryParams', jasmine.any(String)); + })); }); diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/workbasket-filters/workbasket-filters.component.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/components/workbasket-filters/workbasket-filters.component.ts index 3f14f966bf..0bb10dfc1d 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/workbasket-filters/workbasket-filters.component.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/workbasket-filters/workbasket-filters.component.ts @@ -82,7 +82,7 @@ export class WorkbasketFiltersComponent implements OnInit { }); } - public apply(init): void { + public apply(init: boolean): void { // Save filters as query parameters for current route const queryParams = {}; if (this.selected.jurisdiction) { @@ -114,9 +114,21 @@ export class WorkbasketFiltersComponent implements OnInit { if (init) { this.windowService.setLocalStorage(SAVED_QUERY_PARAM_LOC_STORAGE, JSON.stringify(queryParams)); if (Object.keys(this.formGroup.controls).length > 0) { + // Find all "special case" JudicialUser FormControl keys and remove the corresponding values from the + // FormGroup value because these values are not intended to be stored and subsequently passed as query string + // parameters when calling searchCases API endpoint + const judicialUserControlValuesToRemove = + Object.keys(this.formGroup.controls).filter((key) => key.endsWith('_judicialUserControl')); + judicialUserControlValuesToRemove.forEach((controlKey) => delete this.formGroup.value[controlKey]); this.windowService.setLocalStorage(FORM_GROUP_VAL_LOC_STORAGE, JSON.stringify(this.formGroup.value)); } } + // Announce selected jurisdiction via JurisdictionService + if (this.selected.jurisdiction) { + // Set the selected case type as the current case type of the selected jurisdiction + this.selected.jurisdiction.currentCaseType = this.selected.caseType; + this.jurisdictionService.announceSelectedJurisdiction(this.selected.jurisdiction); + } // Apply filters this.onApply.emit({selected: this.selected, queryParams}); this.setFocusToTop(); diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/domain/definition/jurisdiction.model.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/domain/definition/jurisdiction.model.ts index 07c3593061..cb3820d2a4 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/domain/definition/jurisdiction.model.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/domain/definition/jurisdiction.model.ts @@ -5,4 +5,5 @@ export class Jurisdiction { public name: string; public description: string; public caseTypes: CaseTypeLite[]; + public currentCaseType?: CaseTypeLite; } diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/services/jurisdiction/jurisdiction.service.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/services/jurisdiction/jurisdiction.service.ts index 127be68c58..8955ea21be 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/services/jurisdiction/jurisdiction.service.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/services/jurisdiction/jurisdiction.service.ts @@ -1,13 +1,14 @@ import { Injectable } from '@angular/core'; -import { Observable, Subject } from 'rxjs'; +import { BehaviorSubject, Observable, Subject } from 'rxjs'; import { Jurisdiction } from '../../domain/definition/jurisdiction.model'; import { JudicialUserModel } from '../../domain/jurisdiction'; import { HttpService } from '../http'; @Injectable() export class JurisdictionService { - - private readonly selectedJurisdictionSource = new Subject(); + // We retain the Subject observable because subscribing code couldn't happen a null value + public readonly selectedJurisdictionSource = new Subject(); + public readonly selectedJurisdictionBS = new BehaviorSubject(null); public readonly selectedJurisdiction: Observable; constructor(private readonly httpService: HttpService) { @@ -19,7 +20,9 @@ export class JurisdictionService { } public announceSelectedJurisdiction(jurisdiction: Jurisdiction): void { + console.info ('Announcing selected jurisdiction = ' + jurisdiction?.id); this.selectedJurisdictionSource.next(jurisdiction); + this.selectedJurisdictionBS.next(jurisdiction); } public searchJudicialUsers(searchTerm: string, serviceId: string): Observable {