-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
1,367 additions
and
358 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import React from 'react'; | ||
import { | ||
render, | ||
screen, | ||
} from '@testing-library/react'; | ||
|
||
import IncomeExpenseStatementForm from '@/components/forms/reports/IncomeExpenseStatementForm'; | ||
import ReportsDropdown from '@/components/buttons/ReportsDropdown'; | ||
import FormButton from '@/components/buttons/FormButton'; | ||
|
||
jest.mock('@/components/buttons/FormButton', () => jest.fn( | ||
(props: React.PropsWithChildren) => ( | ||
<div data-testid="FormButton"> | ||
{props.children} | ||
</div> | ||
), | ||
)); | ||
|
||
jest.mock('@/components/forms/reports/IncomeExpenseStatementForm', () => jest.fn( | ||
() => <div data-testid="IncomeExpenseStatementForm" />, | ||
)); | ||
|
||
describe('ReportsDropdown', () => { | ||
beforeEach(async () => { | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('renders as expected', async () => { | ||
const { container } = render(<ReportsDropdown />); | ||
|
||
await screen.findAllByTestId('FormButton'); | ||
expect(FormButton).toHaveBeenCalledTimes(1); | ||
expect(FormButton).toHaveBeenNthCalledWith( | ||
1, | ||
expect.objectContaining({ | ||
id: 'IE report', | ||
modalTitle: 'Income statement', | ||
}), | ||
{}, | ||
); | ||
expect(IncomeExpenseStatementForm).toHaveBeenCalledTimes(1); | ||
expect(IncomeExpenseStatementForm).toHaveBeenNthCalledWith(1, {}, {}); | ||
|
||
expect(container).toMatchSnapshot(); | ||
}); | ||
}); |
48 changes: 48 additions & 0 deletions
48
src/__tests__/components/buttons/__snapshots__/ReportsDropdown.test.tsx.snap
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,48 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`ReportsDropdown renders as expected 1`] = ` | ||
<div> | ||
<div | ||
class="group relative h-full" | ||
> | ||
<button | ||
class="group-hover:bg-cyan-700/80 dark:group-hover:bg-cyan-600 flex h-full w-full items-center btn btn-primary" | ||
type="button" | ||
> | ||
<svg | ||
class="mr-1" | ||
fill="currentColor" | ||
height="1em" | ||
stroke="currentColor" | ||
stroke-width="0" | ||
viewBox="0 0 24 24" | ||
width="1em" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
d="M19 4h-3V2h-2v2h-4V2H8v2H5c-1.103 0-2 .897-2 2v14c0 1.103.897 2 2 2h14c1.103 0 2-.897 2-2V6c0-1.103-.897-2-2-2zM5 20V7h14V6l.002 14H5z" | ||
/> | ||
<path | ||
d="M7 9h10v2H7zm0 4h5v2H7z" | ||
/> | ||
</svg> | ||
Reports | ||
</button> | ||
<ul | ||
class="absolute rounded-md w-40 hidden py-2 group-hover:block bg-background-800" | ||
> | ||
<li | ||
class="text-sm hover:bg-background-700" | ||
> | ||
<div | ||
data-testid="FormButton" | ||
> | ||
<div | ||
data-testid="IncomeExpenseStatementForm" | ||
/> | ||
</div> | ||
</li> | ||
</ul> | ||
</div> | ||
</div> | ||
`; |
40 changes: 40 additions & 0 deletions
40
src/__tests__/components/forms/reports/IncomeExpenseStatementForm.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,40 @@ | ||
import React from 'react'; | ||
import { | ||
render, | ||
screen, | ||
} from '@testing-library/react'; | ||
import { DefinedUseQueryResult, QueryClientProvider } from '@tanstack/react-query'; | ||
import type { Interval } from 'luxon'; | ||
|
||
import IncomeExpenseStatementForm from '@/components/forms/reports/IncomeExpenseStatementForm'; | ||
import * as stateHooks from '@/hooks/state'; | ||
|
||
jest.mock('@/hooks/state', () => ({ | ||
__esModule: true, | ||
...jest.requireActual('@/hooks/state'), | ||
})); | ||
|
||
jest.mock('@/components/DateRangeInput', () => jest.fn( | ||
() => <input id="intervalInput" data-testid="DateRangeInput" />, | ||
)); | ||
|
||
const wrapper = ({ children }: React.PropsWithChildren) => ( | ||
<QueryClientProvider client={QUERY_CLIENT}>{children}</QueryClientProvider> | ||
); | ||
|
||
describe('IncomeExpenseStatementForm', () => { | ||
beforeEach(async () => { | ||
jest.spyOn(stateHooks, 'useInterval').mockReturnValue({ data: TEST_INTERVAL } as DefinedUseQueryResult<Interval>); | ||
}); | ||
|
||
afterEach(async () => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it('renders as expected', async () => { | ||
const { container } = render(<IncomeExpenseStatementForm />, { wrapper }); | ||
|
||
screen.getByLabelText('Select dates'); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.