Skip to content

Commit

Permalink
code review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
devinleighsmith committed Jan 17, 2025
1 parent 06e3584 commit 781c882
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ApiGen_CodeTypes_LessorTypes } from '@/models/api/generated/ApiGen_Code
import { ApiGen_Concepts_CompReqLeaseStakeholder } from '@/models/api/generated/ApiGen_Concepts_CompReqLeaseStakeholder';
import { ApiGen_Concepts_LeaseStakeholder } from '@/models/api/generated/ApiGen_Concepts_LeaseStakeholder';
import { getEmptyBaseAudit } from '@/models/defaultInitializers';
import { truncateName } from '@/utils';
import { formatApiPersonNames } from '@/utils/personUtils';

export class CompReqLeaseStakeholderModel {
Expand Down Expand Up @@ -61,9 +62,7 @@ export class CompReqLeaseStakeholderModel {
break;
}
compReqPayeeModel.fullText = `${payeeName} (${payeeDescription})`;
compReqPayeeModel.text = `${CompReqLeaseStakeholderModel.truncateName(
payeeName,
)} (${payeeDescription})`;
compReqPayeeModel.text = `${truncateName(payeeName, 50)} (${payeeDescription})`;
compReqPayeeModel.stakeholderId = apiLeaseStakeholder?.leaseStakeholderId;

return compReqPayeeModel;
Expand All @@ -81,12 +80,4 @@ export class CompReqLeaseStakeholderModel {
};
return compReqPayeeModel;
}

private static truncateName(name: string): string {
if (name.length > 50) {
return name.slice(0, 50) + '...';
} else {
return name;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ApiGen_Concepts_CompensationRequisition } from '@/models/api/generated/
import { ApiGen_Concepts_CompReqPayee } from '@/models/api/generated/ApiGen_Concepts_CompReqPayee';
import { ApiGen_Concepts_InterestHolder } from '@/models/api/generated/ApiGen_Concepts_InterestHolder';
import { getEmptyBaseAudit } from '@/models/defaultInitializers';
import { exists } from '@/utils';
import { exists, truncateName } from '@/utils';
import { formatApiPersonNames } from '@/utils/personUtils';

import { PayeeType } from './PayeeTypeModel';
Expand Down Expand Up @@ -33,7 +33,7 @@ export class PayeeOption {
this.api_id = api_id;
this.compensationRequisitionId = compensationRequisitionId;
this.fullText = `${name} (${key})`;
this.text = `${PayeeOption.truncateName(name)} (${key})`;
this.text = `${truncateName(name, 50)} (${key})`;
this.value = value;
this.payeeType = payeeType;
this.rowVersion = null;
Expand Down Expand Up @@ -113,14 +113,6 @@ export class PayeeOption {
return compReqPayeeModel;
}

private static truncateName(name: string): string {
if (name.length > 50) {
return name.slice(0, 50) + '...';
} else {
return name;
}
}

public static createOwner(
model: ApiGen_Concepts_AcquisitionFileOwner,
compReqPayee?: ApiGen_Concepts_CompReqPayee,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { emptyApiInterestHolder } from '@/mocks/interestHolder.mock';
import { getEmptyOrganization, getMockOrganization } from '@/mocks/organization.mock';
import { ApiGen_Concepts_InterestHolder } from '@/models/api/generated/ApiGen_Concepts_InterestHolder';
import { ApiGen_Concepts_Person } from '@/models/api/generated/ApiGen_Concepts_Person';
import { render, RenderOptions, waitForEffects } from '@/utils/test-utils';
import { getMockRepositoryObj, render, RenderOptions, waitForEffects } from '@/utils/test-utils';

import {
CompensationRequisitionDetailContainer,
Expand All @@ -29,12 +29,8 @@ const getPersonConceptFn = vi.fn();
const getOrganizationConceptFn = vi.fn();
const setEditMode = vi.fn();

const mockGetCompReqPropertiesApi = {
error: undefined,
response: undefined,
execute: vi.fn(),
loading: false,
};
const mockGetCompReqPropertiesApi = getMockRepositoryObj();
const mockPutCompReqPropertiesApi = getMockRepositoryObj();

vi.mock('@/hooks/repositories/useRequisitionCompensationRepository', () => ({
useCompensationRequisitionRepository: () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ export const CompensationRequisitionDetailView: React.FunctionComponent<
<Section header="Payment" isCollapsable initiallyExpanded>
<SectionField label="Payee(s)" labelWidth="4">
{payeeDetails.map(payeeDetail => (
<StyledPayeeDisplayName key={`compenations-payee-${payeeDetail.compReqPayeeId}`}>
<StyledPayeeDisplayName key={`compensations-payee-${payeeDetail.compReqPayeeId}`}>
{payeeDetail?.contactEnabled && payeeDetail?.contactString && (
<StyledLink
target="_blank"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ import { ApiGen_Concepts_FinancialCodeTypes } from '@/models/api/generated/ApiGe
import { getEmptyBaseAudit } from '@/models/defaultInitializers';
import { lookupCodesSlice } from '@/store/slices/lookupCodes';
import { systemConstantsSlice } from '@/store/slices/systemConstants/systemConstantsSlice';
import { act, render, RenderOptions, waitFor, waitForEffects } from '@/utils/test-utils';
import {
act,
getMockRepositoryObj,
render,
RenderOptions,
waitFor,
waitForEffects,
} from '@/utils/test-utils';

import UpdateCompensationRequisitionContainer, {
UpdateCompensationRequisitionContainerProps,
Expand All @@ -24,17 +31,10 @@ import { ApiGen_Concepts_AcquisitionFile } from '@/models/api/generated/ApiGen_C
import { getCompensationRequisitionPayeesApi } from '@/hooks/pims-api/useApiRequisitionCompensations';
import { ApiGen_Concepts_CompensationRequisition } from '@/models/api/generated/ApiGen_Concepts_CompensationRequisition';

const mockGetAcquisitionOwnersApi = {
error: undefined,
response: undefined,
execute: vi.fn(),
loading: false,
};

vi.mock('@/hooks/repositories/useAcquisitionProvider', () => ({
useAcquisitionProvider: () => {
return {
getAcquisitionOwners: mockGetAcquisitionOwnersApi,
getAcquisitionOwners: getMockRepositoryObj(),
getAcquisitionFileSolicitors: {
execute: vi.fn(),
loading: false,
Expand All @@ -47,12 +47,7 @@ vi.mock('@/hooks/repositories/useAcquisitionProvider', () => ({
},
}));

const mockGetApi = {
error: undefined,
response: [],
execute: vi.fn(),
loading: false,
};
const mockGetApi = getMockRepositoryObj();

vi.mock('@/hooks/repositories/useFinancialCodeRepository', () => ({
useFinancialCodeRepository: () => {
Expand All @@ -65,12 +60,7 @@ vi.mock('@/hooks/repositories/useFinancialCodeRepository', () => ({
},
}));

const getLeaseFileInterestHoldersApi = {
error: undefined,
response: undefined,
execute: vi.fn(),
loading: false,
};
const getLeaseFileInterestHoldersApi = getMockRepositoryObj();

vi.mock('@/hooks/repositories/useLeaseStakeholderRepository', () => ({
useLeaseStakeholderRepository: () => {
Expand All @@ -80,31 +70,20 @@ vi.mock('@/hooks/repositories/useLeaseStakeholderRepository', () => ({
},
}));

const getAcquisitionInterestHoldersApi = {
error: undefined,
response: undefined,
execute: vi.fn(),
loading: false,
};
vi.mock('@/hooks/repositories/useInterestHolderRepository', () => ({
useInterestHolderRepository: () => {
return {
getAcquisitionInterestHolders: getAcquisitionInterestHoldersApi,
getAcquisitionInterestHolders: getMockRepositoryObj(),
};
},
}));

const putCompensationRequisitionApi = {
error: undefined,
response: undefined,
execute: vi.fn(),
loading: false,
};
const putCompensationRequisitionApi = getMockRepositoryObj();
vi.mock('@/hooks/repositories/useRequisitionCompensationRepository', () => ({
useCompensationRequisitionRepository: () => {
return {
updateCompensationRequisition: putCompensationRequisitionApi,
getCompensationRequisitionPayees: putCompensationRequisitionApi,
getCompensationRequisitionPayees: getMockRepositoryObj(),
};
},
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
act,
fakeText,
fireEvent,
prettyDOM,
render,
RenderOptions,
screen,
Expand Down
6 changes: 6 additions & 0 deletions source/frontend/src/utils/test-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,12 @@ export async function focusOptionMultiselect(
});
}

export const getMockRepositoryObj = () => ({
error: undefined,
response: undefined,
execute: vi.fn(),
loading: false,
});
// re-export everything from RTL
export * from '@testing-library/react';
export { default as userEvent } from '@testing-library/user-event';
Expand Down
8 changes: 8 additions & 0 deletions source/frontend/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,14 @@ export function isNumber(value: unknown): value is number {
return typeof value === 'number';
}

export function truncateName(name: string, length: number): string {
if (name.length > length) {
return name.slice(0, length) + '...';
} else {
return name;
}
}

/**
* Add a simple retry wrapper to help avoid chunk errors in deployed pims application, recursively calls promise based on attemptsLeft parameter.
* @param lazyComponent
Expand Down

0 comments on commit 781c882

Please sign in to comment.