Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSP-5715 : Sec3/Sec6 add forms to acquisition file #3292

Merged
merged 13 commits into from
Jun 26, 2023
3 changes: 0 additions & 3 deletions source/frontend/src/components/common/TabView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ const TabView: React.FunctionComponent<
};

const StyledTabWrapper = styled.div`
.nav-tabs {
height: 2.4rem;
}
.tab-content {
.tab-pane {
position: relative;
Expand Down
3 changes: 2 additions & 1 deletion source/frontend/src/components/common/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,14 @@ export const Tabs = styled(BsTabs)`
font-size: 1.4rem;
border-color: transparent;
.nav-tabs {
height: 2.4rem;
height: auto;
}
.nav-item {
min-width: 5rem;
padding: 0.1rem 0.6rem;

&:hover {
color: ${props => props.theme.css.secondaryVariantColor};
border-color: transparent;
}
&.active {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ exports[`MapSelectorContainer component renders as expected when provided no pro
}

.c2 .nav-tabs {
height: 2.4rem;
height: auto;
}

.c2 .nav-item {
Expand Down Expand Up @@ -243,10 +243,6 @@ exports[`MapSelectorContainer component renders as expected when provided no pro
height: 100%;
}

.c0 .nav-tabs {
height: 2.4rem;
}

.c0 .tab-content {
border-radius: 0 0.4rem 0.4rem 0.4rem;
height: calc(100% - 2.4rem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ exports[`AddLeaseContainer component renders as expected 1`] = `
}

.c11 .nav-tabs {
height: 2.4rem;
height: auto;
}

.c11 .nav-item {
Expand Down Expand Up @@ -379,10 +379,6 @@ exports[`AddLeaseContainer component renders as expected 1`] = `
height: 100%;
}

.c9 .nav-tabs {
height: 2.4rem;
}

.c9 .tab-content {
border-radius: 0 0.4rem 0.4rem 0.4rem;
height: calc(100% - 2.4rem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ exports[`Update lease container component renders as expected 1`] = `
}

.c9 .nav-tabs {
height: 2.4rem;
height: auto;
}

.c9 .nav-item {
Expand Down Expand Up @@ -347,10 +347,6 @@ exports[`Update lease container component renders as expected 1`] = `
height: 100%;
}

.c7 .nav-tabs {
height: 2.4rem;
}

.c7 .tab-content {
border-radius: 0 0.4rem 0.4rem 0.4rem;
height: calc(100% - 2.4rem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ exports[`AcquisitionView component renders as expected 1`] = `
}

.c12 .nav-tabs {
height: 2.4rem;
height: auto;
}

.c12 .nav-item {
Expand Down Expand Up @@ -319,10 +319,6 @@ exports[`AcquisitionView component renders as expected 1`] = `
height: 100%;
}

.c11 .nav-tabs {
height: 2.4rem;
}

.c11 .tab-content {
border-radius: 0 0.4rem 0.4rem 0.4rem;
height: calc(100% - 2.4rem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ exports[`AcquisitionProperties component renders as expected 1`] = `
}

.c2 .nav-tabs {
height: 2.4rem;
height: auto;
}

.c2 .nav-item {
Expand Down Expand Up @@ -248,10 +248,6 @@ exports[`AcquisitionProperties component renders as expected 1`] = `
height: 100%;
}

.c0 .nav-tabs {
height: 2.4rem;
}

.c0 .tab-content {
border-radius: 0 0.4rem 0.4rem 0.4rem;
height: calc(100% - 2.4rem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ exports[`AddAcquisitionContainer component renders as expected 1`] = `
}

.c12 .nav-tabs {
height: 2.4rem;
height: auto;
}

.c12 .nav-item {
Expand Down Expand Up @@ -375,10 +375,6 @@ exports[`AddAcquisitionContainer component renders as expected 1`] = `
height: 100%;
}

.c10 .nav-tabs {
height: 2.4rem;
}

.c10 .tab-content {
border-radius: 0 0.4rem 0.4rem 0.4rem;
height: calc(100% - 2.4rem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ exports[`AddAcquisitionForm component renders as expected 1`] = `
}

.c9 .nav-tabs {
height: 2.4rem;
height: auto;
}

.c9 .nav-item {
Expand Down Expand Up @@ -292,10 +292,6 @@ exports[`AddAcquisitionForm component renders as expected 1`] = `
height: 100%;
}

.c7 .nav-tabs {
height: 2.4rem;
}

.c7 .tab-content {
border-radius: 0 0.4rem 0.4rem 0.4rem;
height: calc(100% - 2.4rem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,51 @@ describe('AcquisitionFileTabs component', () => {
expect(getByText('Documents')).toHaveClass('active');
});
});

it('hides the expropriation tab when the Acquisition file type is "Consensual Agreement"', () => {
const { queryByText } = setup({
acquisitionFile: mockAcquisitionFileResponse(),
defaultTab: FileTabType.FILE_DETAILS,
setContainerState,
});

const expropriationButton = queryByText('Expropriation');
expect(expropriationButton).not.toBeInTheDocument();
});

it('shows the expropriation tab when the Acquisition file type is "Section 3"', () => {
const mockAcquisitionFile = mockAcquisitionFileResponse();
mockAcquisitionFile.acquisitionTypeCode = {
id: 'SECTN3',
description: 'Section 3 Agreement',
isDisabled: false,
};

const { queryByText } = setup({
acquisitionFile: mockAcquisitionFile,
defaultTab: FileTabType.FILE_DETAILS,
setContainerState,
});

const editButton = queryByText('Expropriation');
expect(editButton).toBeInTheDocument();
});

it('shows the expropriation tab when the Acquisition file type is "Section 6"', () => {
const mockAcquisitionFile = mockAcquisitionFileResponse();
mockAcquisitionFile.acquisitionTypeCode = {
id: 'SECTN6',
description: 'Section 6 Expropriation',
isDisabled: false,
};

const { queryByText } = setup({
acquisitionFile: mockAcquisitionFile,
defaultTab: FileTabType.FILE_DETAILS,
setContainerState,
});

const editButton = queryByText('Expropriation');
expect(editButton).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { NoteTypes } from '@/constants/noteTypes';
import NoteListView from '@/features/notes/list/NoteListView';
import ActivityListView from '@/features/properties/map/activity/list/ActivityListView';
import useKeycloakWrapper from '@/hooks/useKeycloakWrapper';
import { Api_AcquisitionFile } from '@/models/api/AcquisitionFile';
import { Api_AcquisitionFile, EnumAcquisitionFileType } from '@/models/api/AcquisitionFile';

import { FileTabs, FileTabType, TabFileView } from '../../shared/detail/FileTabs';
import { AcquisitionContainerState } from '../AcquisitionContainer';
Expand All @@ -18,6 +18,8 @@ import { AcquisitionChecklistView } from './checklist/detail/AcquisitionChecklis
import CompensationListContainer from './compensation/list/CompensationListContainer';
import CompensationListView from './compensation/list/CompensationListView';
import AcquisitionDocumentsTab from './documents/AcquisitionDocumentsTab';
import ExpropriationTabContainer from './expropriation/ExpropriationTabContainer';
import ExpropriationTabcontainerView from './expropriation/ExpropriationTabContainerView';
import AcquisitionSummaryView from './fileDetails/detail/AcquisitionSummaryView';
import StakeHolderContainer from './stakeholders/detail/StakeHolderContainer';
import StakeHolderView from './stakeholders/detail/StakeHolderView';
Expand Down Expand Up @@ -155,6 +157,24 @@ export const AcquisitionFileTabs: React.FC<IAcquisitionFileTabsProps> = ({
});
}

if (
acquisitionFile?.id &&
(acquisitionFile.acquisitionTypeCode?.id === EnumAcquisitionFileType.SECTN3 ||
acquisitionFile.acquisitionTypeCode?.id === EnumAcquisitionFileType.SECTN6)
) {
tabViews.push({
content: (
<ExpropriationTabContainer
acquisitionFileId={acquisitionFile.id}
acquisitionFileTypeCode={acquisitionFile.acquisitionTypeCode?.id}
View={ExpropriationTabcontainerView}
></ExpropriationTabContainer>
),
key: FileTabType.EXPROPRIATION,
name: 'Expropriation',
});
}

const onSetActiveTab = (tab: FileTabType) => {
let previousTab = activeTab;
setActiveTab(tab);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ exports[`AcquisitionFileTabs component matches snapshot 1`] = `
}

.c1 .nav-tabs {
height: 2.4rem;
height: auto;
}

.c1 .nav-item {
Expand Down Expand Up @@ -223,10 +223,6 @@ exports[`AcquisitionFileTabs component matches snapshot 1`] = `
height: 100%;
}

.c0 .nav-tabs {
height: 2.4rem;
}

.c0 .tab-content {
border-radius: 0 0.4rem 0.4rem 0.4rem;
height: calc(100% - 2.4rem);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { useContext } from 'react';

import { SideBarContext } from '@/features/mapSideBar/context/sidebarContext';

import { IExpropriationTabcontainerViewProps } from './ExpropriationTabContainerView';

export interface IExpropriationTabContainer {
acquisitionFileId: number;
acquisitionFileTypeCode: string;
View: React.FunctionComponent<React.PropsWithChildren<IExpropriationTabcontainerViewProps>>;
}

export const ExpropriationTabContainer: React.FunctionComponent<
React.PropsWithChildren<IExpropriationTabContainer>
> = ({ View, acquisitionFileTypeCode }) => {
const { file, fileLoading } = useContext(SideBarContext);
if (!!file && file?.id === undefined && fileLoading === false) {
throw new Error('Unable to determine id of current file.');
}

return !!file?.id ? (
<>
<View loading={fileLoading} acquisitionFileTypeCode={acquisitionFileTypeCode}></View>
</>
) : null;
};

export default ExpropriationTabContainer;
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { EnumAcquisitionFileType } from '@/models/api/AcquisitionFile';
import { render, RenderOptions } from '@/utils/test-utils';

import ExpropiationTabcontainerView, {
IExpropriationTabcontainerViewProps,
} from './ExpropriationTabContainerView';

describe('Expropiatin Tab Container View', () => {
const setup = async (
renderOptions: RenderOptions & { props?: Partial<IExpropriationTabcontainerViewProps> },
) => {
const utils = render(
<ExpropiationTabcontainerView
{...renderOptions.props}
loading={renderOptions.props?.loading ?? false}
acquisitionFileTypeCode={
renderOptions.props?.acquisitionFileTypeCode ?? EnumAcquisitionFileType.SECTN6
}
/>,
{
...renderOptions,
},
);

return {
...utils,
};
};

afterEach(() => {
jest.clearAllMocks();
});

it('displays a loading spinner when loading', async () => {
const { getByTestId } = await setup({ props: { loading: true } });
const spinner = getByTestId('filter-backdrop-loading');
expect(spinner).toBeVisible();
});

it('shows the sections for Acquisition file type "Section 6"', async () => {
const { queryByTestId } = await setup({});
expect(queryByTestId('form-1-section')).toBeInTheDocument();
expect(queryByTestId('form-5-section')).toBeInTheDocument();
expect(queryByTestId('form-8-section')).toBeInTheDocument();
expect(queryByTestId('form-9-section')).toBeInTheDocument();
});

it('shows the sections for Acquisition file type "Section 3"', async () => {
const { queryByTestId } = await setup({
props: { acquisitionFileTypeCode: EnumAcquisitionFileType.SECTN3 },
});

expect(queryByTestId('form-1-section')).not.toBeInTheDocument();
expect(queryByTestId('form-5-section')).not.toBeInTheDocument();
expect(queryByTestId('form-8-section')).toBeInTheDocument();
expect(queryByTestId('form-9-section')).not.toBeInTheDocument();
});
});
Loading