-
Notifications
You must be signed in to change notification settings - Fork 1
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 #66 from DSACMS/k8/FFS-1487/expenses-under-jobs-da…
…ta-model-change Job data model change
- Loading branch information
Showing
42 changed files
with
1,014 additions
and
564 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
'use client' | ||
|
||
import ErrorSummary from "@/app/components/ErrorSummary" | ||
import RequiredFieldDescription from "@/app/components/RequiredFieldDescription" | ||
import TextFieldWithValidation from "@/app/components/TextFieldWithValidation" | ||
import { ExpenseItem } from "@/lib/features/job/expenses/expensesSlice" | ||
import { Button, Form, FormGroup, Checkbox, DatePicker, ComboBox, Label, RequiredMarker } from '@trussworks/react-uswds' | ||
import { Controller, SubmitHandler, useForm } from "react-hook-form" | ||
import { useTranslation } from "react-i18next" | ||
|
||
interface ExpenseFormPaymentProps { | ||
onSubmit: SubmitHandler<ExpenseFormPaymentData> | ||
item?: ExpenseItem | ||
} | ||
|
||
export type ExpenseFormPaymentData = { | ||
job: string | ||
name: string | ||
expenseType: string | ||
amount: number | ||
date: string | ||
isMileage: boolean | ||
} | ||
|
||
export default function FormExpense(params: ExpenseFormPaymentProps) { | ||
const { t } = useTranslation() | ||
|
||
const expenseTypeOptions = [ | ||
t('add_expense_materials'), | ||
t('add_expense_travel'), | ||
t('add_expense_equipment'), | ||
t('add_expense_advertising'), | ||
t('add_expense_cost'), | ||
t('add_expense_other') | ||
].map((str) => { | ||
return { value: str, label: str } | ||
}) | ||
|
||
const { | ||
register, | ||
control, | ||
formState: { errors }, | ||
handleSubmit | ||
} = useForm<ExpenseFormPaymentData>() | ||
|
||
return (<Form onSubmit={handleSubmit(params.onSubmit)}> | ||
<RequiredFieldDescription /> | ||
<ErrorSummary errors={errors} headingText={t('add_income_error_header')} /> | ||
|
||
<FormGroup> | ||
<TextFieldWithValidation | ||
id="name" | ||
{...register("name", {required:{value: true, message: t('add_expense_name_required')}})} | ||
label={t('add_expense_name_field')} | ||
error={errors.name?.message} | ||
data-testid="name" | ||
requiredMarker | ||
/> | ||
</FormGroup> | ||
|
||
<FormGroup> | ||
<Controller | ||
name="isMileage" | ||
control={control} | ||
render={({ field }) => | ||
<Checkbox | ||
id="isMileage" | ||
{...field} | ||
label={t('add_expense_mileage_field')} | ||
value="true" | ||
data-testid="isMileage" | ||
/> | ||
} | ||
/> | ||
|
||
</FormGroup> | ||
|
||
<FormGroup> | ||
<Controller | ||
name="date" | ||
control={control} | ||
rules={{ required: {value:true, message: t('add_expense_date_required')} }} | ||
render={({ field }) => ( | ||
<> | ||
<Label htmlFor="date">{t('add_expense_date_field')}<RequiredMarker /></Label> | ||
<p className="usa-hint font-body-2xs">{t('add_expense_date_hint')}</p> | ||
<DatePicker | ||
id="date" | ||
data-testid="date" | ||
{...field} | ||
{...(errors.date?.message !== undefined ? {validationStatus: 'error'} : {})} | ||
/> | ||
</> | ||
) | ||
} | ||
/> | ||
</FormGroup> | ||
|
||
<FormGroup> | ||
<TextFieldWithValidation | ||
id="amount" | ||
{...register("amount", { valueAsNumber:true, validate: (value) => value > 0, required:{value: true, message: t('add_expense_amount_required')}})} | ||
label={t('add_expense_amount_field')} | ||
error={errors.amount?.message} | ||
data-testid="amount" | ||
requiredMarker | ||
/> | ||
</FormGroup> | ||
|
||
<FormGroup> | ||
<Controller | ||
name="expenseType" | ||
control={control} | ||
// Question if this field is optional or required https://confluenceent.cms.gov/pages/viewpage.action?spaceKey=SFIV&title=IRT+Epics+and+Stories | ||
// rules={{ required: {value: true, message: t('add_expense_type_required')}}} | ||
render={({ field }) => ( | ||
<> | ||
<Label htmlFor="expenseType">{t('add_expense_type_field')}</Label> | ||
<p className="usa-hint font-body-2xs">{t('add_expense_type_hint')}</p> | ||
<ComboBox | ||
id="expenseType" | ||
options={expenseTypeOptions} | ||
{...field} | ||
data-testid="expenseType" | ||
/> | ||
</> | ||
) | ||
} | ||
/> | ||
</FormGroup> | ||
|
||
<Button type="submit" data-testid="continue_button">{t('add_expense_continue_button')}</Button> | ||
</Form>) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
'use client' | ||
import { useTranslation } from 'react-i18next' | ||
import { Grid, GridContainer } from '@trussworks/react-uswds' | ||
import { useAppDispatch } from "@/lib/hooks" | ||
import { SetExpensePayload, addExpense } from "@/lib/features/job/expenses/expensesSlice" | ||
import { useRouter } from "next/navigation" | ||
import VerifyNav from "@/app/components/VerifyNav" | ||
import FormExpense, { ExpenseFormPaymentData } from '../FormExpense' | ||
import { createUuid } from '@/lib/store' | ||
|
||
|
||
export default function Page({ params }: { params: { idx: string } }) { | ||
const { t } = useTranslation() | ||
const dispatch = useAppDispatch() | ||
const router = useRouter() | ||
|
||
function addExpenseClicked ({job=params.idx, name, expenseType, amount, isMileage=false, date }: ExpenseFormPaymentData) { | ||
const id = createUuid() | ||
|
||
const expenseItem: SetExpensePayload = { | ||
id, | ||
item: { | ||
job, | ||
name, | ||
expenseType, | ||
amount, | ||
isMileage, | ||
date, | ||
} | ||
} | ||
|
||
dispatch(addExpense(expenseItem)) | ||
router.push('/job/list') | ||
} | ||
|
||
return ( | ||
<div> | ||
<VerifyNav title={t('add_expense_title')} /> | ||
<div className="usa-section"> | ||
<GridContainer> | ||
<Grid row gap> | ||
<main className="usa-layout-docs"> | ||
<h3>{t('add_expense_header')}</h3> | ||
<h4 className="margin-top-2">{t('add_expense_subheader', {month_count: '3'})}</h4> | ||
<FormExpense onSubmit={addExpenseClicked} /> | ||
</main> | ||
</Grid> | ||
</GridContainer> | ||
</div> | ||
</div> | ||
) | ||
} |
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,64 @@ | ||
import { afterEach, beforeEach, describe, expect, it } from 'vitest' | ||
import { cleanup, render, screen } from '@testing-library/react' | ||
import { Provider } from 'react-redux' | ||
import Page from './page' | ||
import { makeStore, createUuid } from '@/lib/store' | ||
import { vi } from 'vitest' | ||
import { EnhancedStore } from '@reduxjs/toolkit' | ||
import mockRouter from 'next-router-mock' | ||
import { SetExpensePayload, addExpense } from '@/lib/features/job/expenses/expensesSlice' | ||
|
||
describe('List Income in Ledger Page', async () => { | ||
let store: EnhancedStore | ||
beforeEach(() => { | ||
vi.mock('next/navigation', () => ({ | ||
useRouter: () => mockRouter, | ||
usePathname: () => mockRouter.asPath, | ||
})) | ||
mockRouter.push('/job/expense/add') | ||
store = makeStore() | ||
}) | ||
afterEach(cleanup) | ||
|
||
it('shows navigation buttons', () => { | ||
render (<Provider store={store}><Page /></Provider>) | ||
expect(screen.getByTestId('add_another_button')).toBeDefined() | ||
expect(screen.getByTestId('continue_button')).toBeDefined() | ||
}) | ||
|
||
it('shows expenses in a list', () => { | ||
const expense1: SetExpensePayload = { | ||
id: createUuid(), | ||
item: { | ||
job: createUuid(), | ||
name: "Supplies", | ||
date: "2024/11/07", | ||
amount: 20, | ||
isMileage: true, | ||
expenseType: "Other" | ||
} | ||
} | ||
|
||
const expense2: SetExpensePayload = { | ||
id: createUuid(), | ||
item: { | ||
job: createUuid(), | ||
name: "Clothing for work", | ||
date: "2024/11/09", | ||
amount: 49, | ||
isMileage: false, | ||
expenseType: "Other" | ||
} | ||
} | ||
const expenses = [expense1, expense2] | ||
for (const expense of expenses) { | ||
store.dispatch(addExpense(expense)) | ||
} | ||
render(<Provider store={store}><Page /></Provider>) | ||
|
||
for (const expense of expenses) { | ||
expect(screen.findByText(expense.item.name)).toBeDefined() | ||
expect(screen.findByText("$" + expense.item.amount)).toBeDefined() | ||
} | ||
}) | ||
}) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
Oops, something went wrong.