-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4187 from stairaku/PSP-8317
PSP-8317: Lease and Licence Edit/View Fee Denomination forms
- Loading branch information
Showing
16 changed files
with
1,192 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
source/frontend/src/features/leases/add/FeeDeterminationSubForm.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import { act, getByText, render, RenderOptions } from '@testing-library/react'; | ||
import { getDefaultFormLease, LeaseFormModel } from '../models'; | ||
import { AddLeaseYupSchema } from './AddLeaseYupSchema'; | ||
import { createMemoryHistory } from 'history'; | ||
import FeeDeterminationSubForm, { IFeeDeterminationSubFormProps } from './FeeDeterminationSubForm'; | ||
import { Formik, FormikProps } from 'formik'; | ||
import React from 'react'; | ||
import { noop } from 'lodash'; | ||
import { fillInput, renderAsync } from '@/utils/test-utils'; | ||
import { lookupCodesSlice } from '@/store/slices/lookupCodes'; | ||
import { mockLookups } from '@/mocks/lookups.mock'; | ||
import { Simulate } from 'react-dom/test-utils'; | ||
|
||
const history = createMemoryHistory(); | ||
const storeState = { | ||
[lookupCodesSlice.name]: { lookupCodes: mockLookups }, | ||
}; | ||
|
||
describe('LeaseFeeDeterminationSubForm component', () => { | ||
const setup = async ( | ||
renderOptions: RenderOptions & Partial<IFeeDeterminationSubFormProps> = {}, | ||
) => { | ||
// render component under test | ||
const component = await renderAsync( | ||
<Formik onSubmit={noop} initialValues={getDefaultFormLease()}> | ||
{formikProps => <FeeDeterminationSubForm formikProps={formikProps} />} | ||
</Formik>, | ||
{ | ||
...renderOptions, | ||
claims: [], | ||
store: storeState, | ||
history, | ||
}, | ||
); | ||
|
||
return { | ||
component, | ||
}; | ||
}; | ||
it('renders as expected', async () => { | ||
const { component } = await setup({}); | ||
expect(component.asFragment()).toMatchSnapshot(); | ||
}); | ||
|
||
it('displays expected Nominal fee', async () => { | ||
const { | ||
component: { container }, | ||
} = await setup({}); | ||
|
||
let suggestedFeeField = await container.querySelector("span[data-testid='suggestedFee']"); | ||
|
||
expect(suggestedFeeField).toHaveTextContent('Unknown'); | ||
|
||
await act(async () => { | ||
await fillInput(container, 'isPublicBenefit', 'true', 'select'); | ||
await fillInput(container, 'isFinancialGain', 'false', 'select'); | ||
}); | ||
|
||
expect(suggestedFeeField).toHaveTextContent('$1 - Nominal'); | ||
}); | ||
|
||
it('displays expected LAF fee', async () => { | ||
const { | ||
component: { container }, | ||
} = await setup({}); | ||
|
||
let suggestedFeeField = await container.querySelector("span[data-testid='suggestedFee']"); | ||
|
||
expect(suggestedFeeField).toHaveTextContent('Unknown'); | ||
|
||
await act(async () => { | ||
await fillInput(container, 'isPublicBenefit', 'true', 'select'); | ||
await fillInput(container, 'isFinancialGain', 'true', 'select'); | ||
}); | ||
|
||
expect(suggestedFeeField).toHaveTextContent('Licence Administration Fee (LAF) *'); | ||
}); | ||
|
||
it('displays expected FMV fee', async () => { | ||
const { | ||
component: { container }, | ||
} = await setup({}); | ||
|
||
let suggestedFeeField = await container.querySelector("span[data-testid='suggestedFee']"); | ||
|
||
expect(suggestedFeeField).toHaveTextContent('Unknown'); | ||
|
||
await act(async () => { | ||
await fillInput(container, 'isPublicBenefit', 'false', 'select'); | ||
await fillInput(container, 'isFinancialGain', 'true', 'select'); | ||
}); | ||
|
||
expect(suggestedFeeField).toHaveTextContent('Fair Market Value (FMV) - (Licence Administration Fee Minimum)'); | ||
}); | ||
|
||
it('displays expected LAF fee', async () => { | ||
const { | ||
component: { container }, | ||
} = await setup({}); | ||
|
||
let suggestedFeeField = await container.querySelector("span[data-testid='suggestedFee']"); | ||
|
||
expect(suggestedFeeField).toHaveTextContent('Unknown'); | ||
|
||
await act(async () => { | ||
await fillInput(container, 'isPublicBenefit', 'true', 'select'); | ||
await fillInput(container, 'isFinancialGain', 'true', 'select'); | ||
}); | ||
|
||
expect(suggestedFeeField).toHaveTextContent('Licence Administration Fee (LAF) *'); | ||
}); | ||
|
||
it('displays expected LAF fee', async () => { | ||
const { | ||
component: { container }, | ||
} = await setup({}); | ||
|
||
let suggestedFeeField = await container.querySelector("span[data-testid='suggestedFee']"); | ||
|
||
expect(suggestedFeeField).toHaveTextContent('Unknown'); | ||
|
||
await act(async () => { | ||
await fillInput(container, 'isPublicBenefit', 'true', 'select'); | ||
await fillInput(container, 'isFinancialGain', 'true', 'select'); | ||
}); | ||
|
||
expect(suggestedFeeField).toHaveTextContent('Licence Administration Fee (LAF) *'); | ||
}); | ||
}); |
60 changes: 60 additions & 0 deletions
60
source/frontend/src/features/leases/add/FeeDeterminationSubForm.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { FormikProps, getIn } from 'formik'; | ||
import { useEffect, useState } from 'react'; | ||
|
||
import { TextArea } from '@/components/common/form'; | ||
import { InlineYesNoSelect } from '@/components/common/form/styles'; | ||
import { Section } from '@/components/common/Section/Section'; | ||
import { SectionField } from '@/components/common/Section/SectionField'; | ||
|
||
import { getSuggestedFee } from '../leaseUtils'; | ||
import { LeaseFormModel } from '../models'; | ||
|
||
export interface IFeeDeterminationSubFormProps { | ||
formikProps: FormikProps<LeaseFormModel>; | ||
} | ||
|
||
const FeeDeterminationSubForm: React.FunctionComponent<IFeeDeterminationSubFormProps> = ({ | ||
formikProps, | ||
}) => { | ||
const { values } = formikProps; | ||
const isPublicBenefit = getIn(values, 'isPublicBenefit'); | ||
const financialGain = getIn(values, 'isFinancialGain'); | ||
|
||
const [fee, setFee] = useState(''); | ||
|
||
useEffect(() => { | ||
setFee(getSuggestedFee(isPublicBenefit, financialGain)); | ||
}, [isPublicBenefit, financialGain]); | ||
|
||
return ( | ||
<Section header="Fee Determination"> | ||
<SectionField label="Public benefit" labelWidth="2" contentWidth="8"> | ||
<InlineYesNoSelect field="isPublicBenefit" /> | ||
</SectionField> | ||
|
||
<SectionField label="Financial gain" labelWidth="2" contentWidth="8"> | ||
<InlineYesNoSelect field="isFinancialGain" /> | ||
</SectionField> | ||
|
||
<SectionField | ||
label="Sugested fee" | ||
tooltip="Licence Administration Fee (LAF) *: If the financial gain far outweighs the public benefit, Fair Market Value should be considered over Licence Administration Fee." | ||
labelWidth="2" | ||
contentWidth="8" | ||
> | ||
<span data-testid="suggestedFee">{fee}</span> | ||
</SectionField> | ||
|
||
<SectionField | ||
label="Notes" | ||
tooltip="Deviations from standard fees should be explained here" | ||
labelWidth="2" | ||
contentWidth="8" | ||
> | ||
<TextArea field="feeDeterminationNote" /> | ||
</SectionField> | ||
</Section> | ||
); | ||
}; | ||
|
||
export default FeeDeterminationSubForm; |
Oops, something went wrong.