Skip to content

Commit

Permalink
Add basic component test for ImportHistoryPage
Browse files Browse the repository at this point in the history
  • Loading branch information
einal3m committed Sep 29, 2024
1 parent 3b42dc6 commit 535f808
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 57 deletions.
4 changes: 3 additions & 1 deletion app/javascript/components/import/ImportHistoryPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ const ImportHistoryPage = () => {
{ skip: !currentAccount },
)

const isLoading = !currentAccount || !bankStatements

return (
<div className="import-history">
<PageHeader title="import history" apiStatus={{}} />
<PageHeader title="import history" isLoading={isLoading} />
<SearchCriteria filters={[{ name: ACCOUNT_FILTER }]} />
{bankStatements && (
<div className="container">
Expand Down
55 changes: 55 additions & 0 deletions spec/javascript/components/import/ImportHIstoryPage.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React from 'react'
import { render, screen, waitFor } from '@testing-library/react'
import { Provider } from 'react-redux'
import { http, HttpResponse } from 'msw'
import { setupServer } from 'msw/node'
import { expect, test, beforeAll, afterEach, afterAll } from 'vitest'

import store from 'stores/store'
import { accountsMock, accountTypesMock } from 'mocks/accountMocks'
import { bankStatementsMock } from 'mocks/bankStatementMocks'
import ImportHistoryPage from 'components/import/ImportHistoryPage'

const handlers = [
http.get('/api/account_types', async () => {
return HttpResponse.json(accountTypesMock)
}),
http.get('/api/accounts', async () => {
return HttpResponse.json(accountsMock)
}),
http.get('/api/accounts/1/bank_statements', async () => {
return HttpResponse.json(bankStatementsMock)
}),
]
const server = setupServer(...handlers)

beforeAll(() => server.listen())
afterEach(() => server.resetHandlers())
afterAll(() => server.close())

test('renders a list of accounts', async () => {
render(
<Provider store={store}>
<ImportHistoryPage />
</Provider>,
)

// page header
const pageTitle = screen.getByRole('heading', { level: 1 })
expect(pageTitle.textContent).toEqual('import history')

await waitFor(() => {
// delete button for each row
expect(screen.getAllByText('Delete').length).toEqual(2)

// bank statement 1
expect(screen.getByText('19-Oct-2001')).toBeDefined()
expect(screen.getByText('one.ofx')).toBeDefined()
expect(screen.getByText('6')).toBeDefined()

// bank statement 2
expect(screen.getByText('20-Oct-2001')).toBeDefined()
expect(screen.getByText('two.ofx')).toBeDefined()
expect(screen.getByText('8')).toBeDefined()
})
})
56 changes: 0 additions & 56 deletions spec/javascript/components/import/ImportHistoryPage.test.js

This file was deleted.

24 changes: 24 additions & 0 deletions spec/javascript/mocks/bankStatementMocks.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { BankStatementResponse } from 'types/api'
import { BankStatement } from 'types/models'

export const ofxTransactions = [
{
accountId: 1,
Expand All @@ -22,3 +25,24 @@ export const ofxTransactions = [
subcategoryId: 46,
},
]

const bankStatements: BankStatementResponse[] = [
{
id: 123,
account_id: 1,
date: '2001-10-19',
file_name: 'one.ofx',
transaction_count: 6,
},
{
id: 456,
account_id: 1,
date: '2001-10-20',
file_name: 'two.ofx',
transaction_count: 8,
},
]

export const bankStatementsMock = {
bank_statements: bankStatements,
}

0 comments on commit 535f808

Please sign in to comment.