From 4236a6848509d67b9a99ec889d7d5a2c14fa7699 Mon Sep 17 00:00:00 2001 From: Alejandro Sanchez Date: Thu, 2 Nov 2023 18:19:02 -0700 Subject: [PATCH] Test corrections --- .../FilterContentContainer.test.tsx | 17 +----- .../update/summary/models.test.ts | 60 ++++++------------- .../update/summary/models.ts | 24 ++------ 3 files changed, 26 insertions(+), 75 deletions(-) diff --git a/source/frontend/src/components/maps/leaflet/Control/AdvancedFilter/FilterContentContainer.test.tsx b/source/frontend/src/components/maps/leaflet/Control/AdvancedFilter/FilterContentContainer.test.tsx index 65d7e51e11..fc5af18908 100644 --- a/source/frontend/src/components/maps/leaflet/Control/AdvancedFilter/FilterContentContainer.test.tsx +++ b/source/frontend/src/components/maps/leaflet/Control/AdvancedFilter/FilterContentContainer.test.tsx @@ -5,7 +5,6 @@ import { forwardRef } from 'react'; import { useMapStateMachine } from '@/components/common/mapFSM/MapStateMachineContext'; import { mockLookups } from '@/mocks/lookups.mock'; import { mapMachineBaseMock } from '@/mocks/mapFSM.mock'; -import { getMockApiPropertyManagement } from '@/mocks/propertyManagement.mock'; import { lookupCodesSlice } from '@/store/slices/lookupCodes'; import { render, RenderOptions, waitFor } from '@/utils/test-utils'; @@ -66,22 +65,10 @@ describe('FilterContentContainer component', () => { }); it('fetches filter data from the api', async () => { - mockGetApi.execute.mockResolvedValue(getMockApiPropertyManagement(1)); + mockGetApi.execute.mockResolvedValue([1, 2]); setup({}); viewProps.onChange(new PropertyFilterFormModel()); expect(mockGetApi.execute).toBeCalledWith(new PropertyFilterFormModel().toApi()); - await waitFor(() => - expect(mapMachineBaseMock.setVisiblePimsProperties).toBeCalledWith({ - additionalDetails: 'test', - id: 1, - isLeaseActive: false, - isLeaseExpired: false, - isTaxesPayable: null, - isUtilitiesPayable: null, - leaseExpiryDate: null, - managementPurposes: [], - rowVersion: 1, - }), - ); + await waitFor(() => expect(mapMachineBaseMock.setVisiblePimsProperties).toBeCalledWith([1, 2])); }); }); diff --git a/source/frontend/src/features/mapSideBar/property/tabs/propertyDetailsManagement/update/summary/models.test.ts b/source/frontend/src/features/mapSideBar/property/tabs/propertyDetailsManagement/update/summary/models.test.ts index 4cc5df2fc3..ce2fdbfd20 100644 --- a/source/frontend/src/features/mapSideBar/property/tabs/propertyDetailsManagement/update/summary/models.test.ts +++ b/source/frontend/src/features/mapSideBar/property/tabs/propertyDetailsManagement/update/summary/models.test.ts @@ -18,8 +18,7 @@ describe('Property management model tests', () => { expect(model.additionalDetails).toBe(''); expect(model.isTaxesPayable).toBe(null); expect(model.isUtilitiesPayable).toBe(null); - expect(model.isLeaseActive).toBe(false); - expect(model.leaseExpiryDate).toBe(''); + expect(model.formattedLeaseInformation).toBe('No active Lease/License'); }); it('fromApi sets values as expected from api response', () => { @@ -36,46 +35,26 @@ describe('Property management model tests', () => { expect(model.additionalDetails).toBe('test'); expect(model.isTaxesPayable).toBe(null); expect(model.isUtilitiesPayable).toBe(null); - expect(model.isLeaseActive).toBe(false); - expect(model.leaseExpiryDate).toBe(''); + expect(model.formattedLeaseInformation).toBe('No active Lease/License'); }); - it('returns default text when no lease information is available', () => { - const model = PropertyManagementFormModel.fromApi(getMockApiPropertyManagement()); - expect(model.formatLeaseInformation()).toBe('No active Lease/License'); - }); - - it('returns active lease information and expiry date', () => { - let apiManagement: Api_PropertyManagement = { - ...getMockApiPropertyManagement(), - isLeaseActive: true, - leaseExpiryDate: '2020-03-15', - }; - const model = PropertyManagementFormModel.fromApi(apiManagement); - expect(model.formatLeaseInformation()).toBe('Yes (Mar 15, 2020)'); - }); - - it('returns expired lease information and expiry date', () => { - let apiManagement: Api_PropertyManagement = { - ...getMockApiPropertyManagement(), - isLeaseActive: true, - isLeaseExpired: true, - leaseExpiryDate: '2020-03-15', - }; - const model = PropertyManagementFormModel.fromApi(apiManagement); - expect(model.formatLeaseInformation()).toBe('Expired (Mar 15, 2020)'); - }); - - it('returns available lease information without an expiry date', () => { - let apiManagement: Api_PropertyManagement = { - ...getMockApiPropertyManagement(), - isLeaseActive: true, - isLeaseExpired: false, - leaseExpiryDate: null, - }; - const model = PropertyManagementFormModel.fromApi(apiManagement); - expect(model.formatLeaseInformation()).toBe('Yes'); - }); + it.each([ + ['NO lease found', 0, null, 'No active Lease/License'], + ['ONE lease with expiry date', 1, '2020-03-15', 'Yes (Mar 15, 2020)'], + ['ONE lease with no expiry date', 1, null, 'Yes'], + ['MULTIPLE leases', 5, null, 'Multiple'], + ])( + 'returns lease information as expected - %s', + (_: string, leaseCount: number, expiryDate: string | null, expectedResult: string) => { + let apiManagement: Api_PropertyManagement = { + ...getMockApiPropertyManagement(), + relatedLeases: leaseCount, + leaseExpiryDate: expiryDate, + }; + const model = PropertyManagementFormModel.fromApi(apiManagement); + expect(model.formattedLeaseInformation).toBe(expectedResult); + }, + ); it('toApi converts form values to the api format', () => { const purpose = new ManagementPurposeModel(); @@ -96,7 +75,6 @@ describe('Property management model tests', () => { expect(apiManagement.additionalDetails).toBe('test'); expect(apiManagement.isUtilitiesPayable).toBe(true); expect(apiManagement.isTaxesPayable).toBe(null); - expect(apiManagement.leaseExpiryDate).toBe(null); expect(apiManagement.managementPurposes).toHaveLength(1); expect(apiManagement.managementPurposes[0]).toEqual( expect.objectContaining({ diff --git a/source/frontend/src/features/mapSideBar/property/tabs/propertyDetailsManagement/update/summary/models.ts b/source/frontend/src/features/mapSideBar/property/tabs/propertyDetailsManagement/update/summary/models.ts index 770ef7a5ac..4dbd8fb4c6 100644 --- a/source/frontend/src/features/mapSideBar/property/tabs/propertyDetailsManagement/update/summary/models.ts +++ b/source/frontend/src/features/mapSideBar/property/tabs/propertyDetailsManagement/update/summary/models.ts @@ -1,6 +1,6 @@ import { Api_PropertyManagement, Api_PropertyManagementPurpose } from '@/models/api/Property'; import { ILookupCode } from '@/store/slices/lookupCodes'; -import { prettyFormatDate } from '@/utils'; +import { formatApiPropertyManagementLease } from '@/utils'; import { stringToNull } from '@/utils/formUtils'; export class PropertyManagementFormModel { @@ -10,9 +10,7 @@ export class PropertyManagementFormModel { additionalDetails: string = ''; isUtilitiesPayable: boolean | null = null; isTaxesPayable: boolean | null = null; - isLeaseActive: boolean = false; - isLeaseExpired: boolean = false; - leaseExpiryDate: string | null = null; + formattedLeaseInformation: string | null = null; static fromApi(base: Api_PropertyManagement | null): PropertyManagementFormModel { const newFormModel = new PropertyManagementFormModel(); @@ -23,9 +21,7 @@ export class PropertyManagementFormModel { newFormModel.additionalDetails = base?.additionalDetails || ''; newFormModel.isUtilitiesPayable = base?.isUtilitiesPayable ?? null; newFormModel.isTaxesPayable = base?.isTaxesPayable ?? null; - newFormModel.isLeaseActive = base?.isLeaseActive || false; - newFormModel.isLeaseExpired = base?.isLeaseExpired || false; - newFormModel.leaseExpiryDate = base?.leaseExpiryDate || ''; + newFormModel.formattedLeaseInformation = formatApiPropertyManagementLease(base); return newFormModel; } @@ -41,20 +37,10 @@ export class PropertyManagementFormModel { additionalDetails: stringToNull(this.additionalDetails), isUtilitiesPayable: this.isUtilitiesPayable, isTaxesPayable: this.isTaxesPayable, - isLeaseActive: this.isLeaseActive, - isLeaseExpired: this.isLeaseExpired, - leaseExpiryDate: stringToNull(this.leaseExpiryDate), + relatedLeases: 0, + leaseExpiryDate: null, }; } - - formatLeaseInformation(): string { - if (this.isLeaseActive) { - const expiryDate = this.leaseExpiryDate ? `(${prettyFormatDate(this.leaseExpiryDate)})` : ''; - return this.isLeaseExpired ? `Expired ${expiryDate}`.trim() : `Yes ${expiryDate}`.trim(); - } else { - return 'No active Lease/License'; - } - } } export class ManagementPurposeModel {