-
Notifications
You must be signed in to change notification settings - Fork 50
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 #791 from Ekep-Obasi/test-budget-steps
test: unit tests for budget steps
- Loading branch information
Showing
2 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
src/components/AddContentModal/BudgetStep/__tests__/index.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,63 @@ | ||
import '@testing-library/jest-dom/extend-expect' | ||
import { fireEvent, render } from '@testing-library/react' | ||
import React from 'react' | ||
import { BudgetStep } from '..' | ||
|
||
window.React = React | ||
|
||
jest.mock('~/stores/useUserStore', () => ({ | ||
...jest.requireActual('~/stores/useUserStore'), | ||
useUserStore: () => ({ | ||
isAdmin: false, | ||
pubKey: '', | ||
budget: 10, | ||
nodeCount: 0, | ||
tribeUuid: '', | ||
tribeHost: '', | ||
setIsAdmin: jest.fn(), | ||
setPubKey: jest.fn(), | ||
setBudget: jest.fn(), | ||
setNodeCount: jest.fn(), | ||
setTribeUuid: jest.fn(), | ||
setTribeHost: jest.fn(), | ||
}), | ||
})) | ||
|
||
describe('Rendering', () => { | ||
test('renders "BudgetStep" component with correct elements', () => { | ||
const { getByText, getByTestId } = render(<BudgetStep loading={false} onClick={() => null} />) | ||
|
||
expect(getByText('Approve Cost')).toBeInTheDocument() | ||
expect(getByText('COST')).toBeInTheDocument() | ||
expect(getByText('BUDGET')).toBeInTheDocument() | ||
expect(getByText('10 sats')).toBeInTheDocument() | ||
expect(getByTestId('check-icon')).toBeInTheDocument() | ||
expect(getByText('Approve')).toBeInTheDocument() | ||
}) | ||
|
||
test('displays the correct formatted budget', () => { | ||
const { getByText } = render(<BudgetStep loading={false} onClick={() => null} />) | ||
|
||
expect(getByText('10 sats')).toBeInTheDocument() | ||
}) | ||
}) | ||
|
||
describe('Behavior', () => { | ||
test('calls onClick when "Approve" button is clicked and not loading', () => { | ||
const onClickMock = jest.fn() | ||
|
||
const { getByTestId } = render(<BudgetStep loading={false} onClick={onClickMock} />) | ||
|
||
fireEvent.click(getByTestId('check-icon')) | ||
|
||
expect(onClickMock).toHaveBeenCalledTimes(1) | ||
}) | ||
|
||
test('disables "Approve" button when loading is true', () => { | ||
const { getByText } = render(<BudgetStep loading onClick={() => null} />) | ||
|
||
const approveButton = getByText('Approve') | ||
|
||
expect(approveButton).toBeDisabled() | ||
}) | ||
}) |
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