Skip to content

Commit

Permalink
lint correction. (#3733)
Browse files Browse the repository at this point in the history
  • Loading branch information
devinleighsmith authored Jan 22, 2024
1 parent 408710d commit fcdc584
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const cannotEditMessage =
'This section of the file is in a non-editable state. Contact a System administrator to change it to an editable state';
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,13 @@ describe('UpdateAgreementsForm component', () => {

it('Cannot edit if not allowed', async () => {
organizerMock.canEditOrDeleteAgreement.mockReturnValue(false);
setup();
const { getByTestId } = setup();

const element: HTMLSelectElement | null = document.querySelector(
`select[name="agreements.0.agreementStatusTypeCode"]`,
);

expect(element).toHaveAttribute('disabled');
expect(getByTestId('tooltip-icon-1-agreement-cannot-edit-tooltip')).toBeVisible();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Api_AcquisitionFile } from '@/models/api/AcquisitionFile';
import { Api_Agreement } from '@/models/api/Agreement';
import { ILookupCode } from '@/store/slices/lookupCodes';

import { cannotEditMessage } from '../../../common/constants';
import StatusUpdateSolver from '../../fileDetails/detail/statusUpdateSolver';
import AgreementSubForm from './AgreementSubForm';
import { AgreementsFormModel, SingleAgreementFormModel } from './models';
Expand Down Expand Up @@ -45,9 +46,6 @@ export const UpdateAgreementsForm: React.FC<IUpdateAgreementsFormProps> = ({

const statusSolver = new StatusUpdateSolver(acquistionFile);

const cannotEditMessage =
'The file you are viewing is in a non-editable state. Change the file status to active or draft to allow editing.';

return (
<StyledFormWrapper>
<Formik<AgreementsFormModel>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Api_AcquisitionFile } from '@/models/api/AcquisitionFile';
import { Api_Agreement } from '@/models/api/Agreement';
import { stringToUndefined, toTypeCode } from '@/utils/formUtils';

Expand Down Expand Up @@ -95,3 +96,6 @@ export class AgreementsFormModel {
return this.agreements.map(x => x.toApi(this.acquisitionFileId));
}
}

export const isAcquisitionFile = (file: unknown): file is Api_AcquisitionFile =>
!!file && Object.prototype.hasOwnProperty.call(file, 'acquisitionTypeCode');
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ describe('Compensation Detail View Component', () => {
it('User does not have the option to Edit Compensation when is in "FINAL" status', async () => {
const acquistionFile = mockAcquisitionFileResponse();
const mockFinalCompensation = getMockApiDefaultCompensation();
const { queryByTitle } = await setup({
const { queryByTitle, getByTestId } = await setup({
claims: [Claims.COMPENSATION_REQUISITION_EDIT],
props: {
acquisitionFile: {
Expand All @@ -171,6 +171,8 @@ describe('Compensation Detail View Component', () => {

const editButton = queryByTitle('Edit compensation requisition');
expect(editButton).not.toBeInTheDocument();
const warningIcon = getByTestId(`tooltip-icon-1-compensation-cannot-edit-tooltip`);
expect(warningIcon).toBeVisible();
});

it('Admin user should be able to Edit Compensation when is in "FINAL" status', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { Api_Person } from '@/models/api/Person';
import { formatMoney, prettyFormatDate } from '@/utils';
import { formatApiPersonNames } from '@/utils/personUtils';

import { cannotEditMessage } from '../../../common/constants';
import { DetailAcquisitionFileOwner } from '../../../models/DetailAcquisitionFileOwner';
import StatusUpdateSolver from '../../fileDetails/detail/statusUpdateSolver';

Expand Down Expand Up @@ -144,9 +145,6 @@ export const CompensationRequisitionDetailView: React.FunctionComponent<
return false;
};

const cannotEditMessage =
'The file you are viewing is in a non-editable state. Change the file status to active or draft to allow editing.';

const editButtonBlock = (
<EditButton
title="Edit compensation requisition"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,35 @@ describe('AcquisitionSummaryView component', () => {

it('does not render the edit button for users that do not have acquisition edit permissions', async () => {
const { queryByTitle } = setup(
{ acquisitionFile: mockAcquisitionFileResponse() },
{
acquisitionFile: {
...mockAcquisitionFileResponse(),
},
},
{ claims: [] },
);
await waitForEffects();
const editButton = queryByTitle('Edit acquisition file');
expect(editButton).toBeNull();
});

it('does not render the edit button for non-admin users when the file is finalized', async () => {
const { queryByTitle, getByTestId } = setup(
{
acquisitionFile: {
...mockAcquisitionFileResponse(),
fileStatusTypeCode: { id: 'COMPLETE' },
},
},
{ claims: [Claims.ACQUISITION_EDIT] },
);
await waitForEffects();
const editButton = queryByTitle('Edit acquisition file');
expect(editButton).toBeNull();
const editWarningText = getByTestId('tooltip-icon-1-summary-cannot-edit-tooltip');
expect(editWarningText).toBeVisible();
});

it('renders historical file number', async () => {
const mockResponse = mockAcquisitionFileResponse();
const { getByText } = setup({ acquisitionFile: mockResponse }, { claims: [] });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { Api_AcquisitionFile } from '@/models/api/AcquisitionFile';
import { prettyFormatDate } from '@/utils';
import { formatApiPersonNames } from '@/utils/personUtils';

import { cannotEditMessage } from '../../../common/constants';
import AcquisitionOwnersSummaryContainer from './AcquisitionOwnersSummaryContainer';
import AcquisitionOwnersSummaryView from './AcquisitionOwnersSummaryView';
import { DetailAcquisitionFile } from './models';
Expand Down Expand Up @@ -65,9 +66,6 @@ const AcquisitionSummaryView: React.FC<IAcquisitionSummaryViewProps> = ({

const statusSolver = new StatusUpdateSolver(acquisitionFile);

const cannotEditMessage =
'The file you are viewing is in a non-editable state. Change the file status to active or draft to allow editing.';

const canEditDetails = () => {
if (hasRole(Roles.SYSTEM_ADMINISTRATOR) || statusSolver.canEditDetails()) {
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createMemoryHistory } from 'history';

import { AcquisitionStatus } from '@/constants/acquisitionFileStatus';
import { Claims } from '@/constants/claims';
import { mockLookups } from '@/mocks/lookups.mock';
import { getMockApiPropertyFiles } from '@/mocks/properties.mock';
Expand Down Expand Up @@ -64,6 +65,24 @@ describe('TakesDetailView component', () => {
expect(onEdit).toHaveBeenCalled();
});

it('hides the edit button when the file has been completed', () => {
const fileProperty = getMockApiPropertyFiles()[0];
const { queryByTitle, getByTestId } = setup({
props: {
loading: true,
fileProperty: {
...fileProperty,
file: { ...fileProperty.file, fileStatusTypeCode: { id: AcquisitionStatus.Complete } },
},
},
claims: [Claims.PROPERTY_EDIT],
});
const editButton = queryByTitle('Edit takes');
expect(editButton).toBeNull();
const tooltip = getByTestId('tooltip-icon-1-summary-cannot-edit-tooltip');
expect(tooltip).toBeVisible();
});

it('displays the number of takes in other files', () => {
setup({
props: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ import { Section } from '@/components/common/Section/Section';
import { SectionField } from '@/components/common/Section/SectionField';
import { StyledEditWrapper, StyledSummarySection } from '@/components/common/Section/SectionStyles';
import { H2 } from '@/components/common/styles';
import TooltipIcon from '@/components/common/TooltipIcon';
import AreaContainer from '@/components/measurements/AreaContainer';
import * as API from '@/constants/API';
import { Claims } from '@/constants/claims';
import Roles from '@/constants/roles';
import { TakesStatusTypes } from '@/constants/takesStatusTypes';
import { cannotEditMessage } from '@/features/mapSideBar/acquisition/common/constants';
import { isAcquisitionFile } from '@/features/mapSideBar/acquisition/tabs/agreement/update/models';
import StatusUpdateSolver from '@/features/mapSideBar/acquisition/tabs/fileDetails/detail/statusUpdateSolver';
import useKeycloakWrapper from '@/hooks/useKeycloakWrapper';
import useLookupCodeHelpers from '@/hooks/useLookupCodeHelpers';
import { Api_PropertyFile } from '@/models/api/PropertyFile';
Expand Down Expand Up @@ -44,19 +49,36 @@ export const TakesDetailView: React.FunctionComponent<ITakesDetailViewProps> = (
const takesNotInFile = allTakesCount - (takes?.length ?? 0);

const { getCodeById } = useLookupCodeHelpers();
const { hasClaim } = useKeycloakWrapper();
const { hasClaim, hasRole } = useKeycloakWrapper();

const file = fileProperty.file;

const statusSolver = new StatusUpdateSolver(isAcquisitionFile(file) ? file : null);

const canEditDetails = () => {
if (hasRole(Roles.SYSTEM_ADMINISTRATOR) || statusSolver.canEditDetails()) {
return true;
}
return false;
};

return (
<StyledSummarySection>
<LoadingBackdrop show={loading} parentScreen={true} />
<StyledEditWrapper>
{onEdit !== undefined && hasClaim(Claims.PROPERTY_EDIT) && (
{onEdit !== undefined && hasClaim(Claims.PROPERTY_EDIT) && canEditDetails() ? (
<EditButton
title="Edit takes"
onClick={() => {
onEdit(true);
}}
/>
) : null}
{!canEditDetails() && (
<TooltipIcon
toolTipId={`${fileProperty?.fileId || 0}-summary-cannot-edit-tooltip`}
toolTip={cannotEditMessage}
/>
)}
</StyledEditWrapper>
<Section>
Expand Down
5 changes: 4 additions & 1 deletion source/frontend/src/mocks/properties.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { PropertyDataSourceTypes } from '@/constants/propertyDataSourceTypes';
import { PropertyStatusTypes } from '@/constants/propertyStatusTypes';
import { PropertyTenureTypes } from '@/constants/propertyTenureTypes';
import { IProperty } from '@/interfaces';
import { mockAddress } from '@/mocks/index.mock';
import { mockAcquisitionFileResponse, mockAddress } from '@/mocks/index.mock';
import { Api_Property } from '@/models/api/Property';

import { Api_PropertyFile } from '../models/api/PropertyFile';
Expand Down Expand Up @@ -170,6 +170,7 @@ export const getMockApiPropertyFiles = (): Api_PropertyFile[] => [
{
id: 1,
fileId: 1,
file: mockAcquisitionFileResponse(),
propertyName: 'test property name',
propertyId: 1,
property: {
Expand Down Expand Up @@ -209,6 +210,8 @@ export const getMockApiPropertyFiles = (): Api_PropertyFile[] => [
{
id: 2,
propertyId: 2,
fileId: 2,
file: mockAcquisitionFileResponse(),
property: {
id: 2,
anomalies: [],
Expand Down

0 comments on commit fcdc584

Please sign in to comment.