Skip to content

Commit

Permalink
Test updates
Browse files Browse the repository at this point in the history
  • Loading branch information
asanchezr committed Jul 9, 2024
1 parent b38c95c commit dbfcde8
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { act, render, RenderOptions } from '@/utils/test-utils';

import { server } from '@/mocks/msw/server';
import { getUserMock } from '@/mocks/user.mock';
import { ApiGen_CodeTypes_LeaseAccountTypes } from '@/models/api/generated/ApiGen_CodeTypes_LeaseAccountTypes';
import { ApiGen_CodeTypes_LeaseStatusTypes } from '@/models/api/generated/ApiGen_CodeTypes_LeaseStatusTypes';
import { http, HttpResponse } from 'msw';
import { ILeaseHeaderProps, LeaseHeader } from './LeaseHeader';

Expand All @@ -17,6 +19,12 @@ describe('LeaseHeader component', () => {
return { ...utils };
};

beforeAll(() => {
// Lock the current datetime as some of the tests have date-dependent fields (e.g. isLeaseExpired)
vi.useFakeTimers();
vi.setSystemTime(new Date('04 Dec 2023 10:15:00 GMT').getTime());
});

beforeEach(() => {
server.use(
http.get('/api/users/info/*', () => HttpResponse.json(getUserMock())),
Expand All @@ -28,6 +36,11 @@ describe('LeaseHeader component', () => {
vi.clearAllMocks();
});

afterAll(() => {
// back to reality...
vi.useRealTimers();
});

it('renders as expected when no data is provided', async () => {
const testLease = getMockApiLease();
const { asFragment } = setup({ lease: testLease, lastUpdatedBy: null });
Expand Down Expand Up @@ -80,4 +93,87 @@ describe('LeaseHeader component', () => {
getAllByText(new RegExp(prettyFormatUTCDate(testLease.appLastUpdateTimestamp)))[0],
).toBeVisible();
});

it('renders whether the lease is RECEIVABLE or PAYABLE', async () => {
const testLease = getMockApiLease();
const { getByText } = setup({
lease: {
...testLease,
paymentReceivableType: {
id: ApiGen_CodeTypes_LeaseAccountTypes.RCVBL,
description: 'Receivable',
displayOrder: null,
isDisabled: false,
},
},
lastUpdatedBy: null,
});
await act(async () => {});

expect(getByText(testLease.lFileNo!)).toBeVisible();
expect(getByText('Receivable')).toBeVisible();
});

it('renders indicator for EXPIRED leases', async () => {
const testLease = getMockApiLease();
const { getByText } = setup({
lease: {
...testLease,
expiryDate: new Date('2022-05-28').toISOString(),
},
lastUpdatedBy: null,
});
await act(async () => {});

expect(getByText(testLease.lFileNo!)).toBeVisible();
expect(getByText('EXPIRED')).toBeVisible();
});

it.each([
[
ApiGen_CodeTypes_LeaseStatusTypes.TERMINATED,
'Terminated',
new Date('2022-05-28').toISOString(),
true,
],
[
ApiGen_CodeTypes_LeaseStatusTypes.ACTIVE,
'Active',
new Date('2022-05-28').toISOString(),
false,
],
])(
'renders termination date only for TERMINATED leases - status: %s',
async (
statusId: string,
statusDescription: string,
testDate: string,
shouldDisplay: boolean,
) => {
const testLease = getMockApiLease();
const { getByText, getAllByText, queryByText } = setup({
lease: {
...testLease,
fileStatusTypeCode: {
id: statusId,
description: statusDescription,
displayOrder: null,
isDisabled: false,
},
terminationDate: testDate,
},
lastUpdatedBy: null,
});
await act(async () => {});

expect(getByText(testLease.lFileNo!)).toBeVisible();
expect(getByText(statusDescription.toUpperCase())).toBeVisible();

if (shouldDisplay) {
expect(getAllByText(new RegExp(prettyFormatUTCDate(testDate)))[0]).toBeVisible();
} else {
expect(queryByText(new RegExp(prettyFormatUTCDate(testDate)))).toBeNull();
}
},
);
});
22 changes: 19 additions & 3 deletions source/frontend/src/mocks/lease.mock.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ApiGen_CodeTypes_LeaseLicenceTypes } from '@/models/api/generated/ApiGen_CodeTypes_LeaseLicenceTypes';
import { ApiGen_CodeTypes_LeaseTenantTypes } from '@/models/api/generated/ApiGen_CodeTypes_LeaseTenantTypes';
import { ApiGen_Concepts_FileChecklistItem } from '@/models/api/generated/ApiGen_Concepts_FileChecklistItem';
import { ApiGen_Concepts_Lease } from '@/models/api/generated/ApiGen_Concepts_Lease';
import { ApiGen_Concepts_LeaseTenant } from '@/models/api/generated/ApiGen_Concepts_LeaseTenant';
Expand Down Expand Up @@ -94,7 +95,12 @@ export const getMockApiLease: () => ApiGen_Concepts_Lease = () => ({
tenants: [
{
leaseTenantId: 82,
tenantTypeCode: { id: 'TEN', description: null, displayOrder: null, isDisabled: false },
tenantTypeCode: {
id: ApiGen_CodeTypes_LeaseTenantTypes.TEN.toString(),
description: null,
displayOrder: null,
isDisabled: false,
},
leaseId: 1,
organizationId: 2,
organization: {
Expand Down Expand Up @@ -267,7 +273,12 @@ export const getMockApiLease: () => ApiGen_Concepts_Lease = () => ({
leaseTenantId: 83,
leaseId: 1,
organizationId: 3,
tenantTypeCode: { id: 'REP', description: null, displayOrder: null, isDisabled: false },
tenantTypeCode: {
id: ApiGen_CodeTypes_LeaseTenantTypes.REP.toString(),
description: null,
displayOrder: null,
isDisabled: false,
},
organization: {
...getEmptyOrganization(),
id: 3,
Expand Down Expand Up @@ -335,7 +346,12 @@ export const getMockApiLease: () => ApiGen_Concepts_Lease = () => ({
leaseTenantId: 84,
leaseId: 1,
organizationId: 4,
tenantTypeCode: { id: 'PMGR', description: null, displayOrder: null, isDisabled: false },
tenantTypeCode: {
id: ApiGen_CodeTypes_LeaseTenantTypes.PMGR.toString(),
description: null,
displayOrder: null,
isDisabled: false,
},
organization: {
...getEmptyOrganization(),
id: 4,
Expand Down

0 comments on commit dbfcde8

Please sign in to comment.