forked from binary-com/deriv-app
-
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.
refactor: add tests for reports package (binary-com#15622)
- Loading branch information
1 parent
8e2e29d
commit b1bf4ec
Showing
7 changed files
with
128 additions
and
6 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
32 changes: 32 additions & 0 deletions
32
packages/reports/src/Components/__tests__/placeholder-component.spec.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,32 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import PlaceholderComponent from '../placeholder-component'; | ||
import EmptyTradeHistoryMessage from 'Components/empty-trade-history-message'; | ||
|
||
describe('PlaceholderComponent', () => { | ||
it('should not render component without props', () => { | ||
const { container } = render(<PlaceholderComponent />); | ||
|
||
expect(container).toBeEmptyDOMElement(); | ||
}); | ||
|
||
it('should render loader if is_loading === true', () => { | ||
render(<PlaceholderComponent is_loading />); | ||
|
||
expect(screen.getByTestId('dt_loading_component')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render passed component (as empty_message_component prop) if is_empty === true', () => { | ||
const mockProps = { | ||
component_icon: 'icon', | ||
empty_message_component: EmptyTradeHistoryMessage, | ||
is_empty: true, | ||
localized_message: 'localized message', | ||
localized_period_message: 'localized period message', | ||
}; | ||
render(<PlaceholderComponent {...mockProps} />); | ||
|
||
expect(screen.getByTestId('dt_empty_trade_history_icon')).toBeInTheDocument(); | ||
expect(screen.getByText('localized message')).toBeInTheDocument(); | ||
}); | ||
}); |
29 changes: 29 additions & 0 deletions
29
packages/reports/src/Components/__tests__/profit-loss-cell.spec.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,29 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import ProfitLossCell from '../profit-loss-cell'; | ||
|
||
const mockChild = 'mockChild'; | ||
const mockProps = { | ||
value: '+23,06', | ||
children: mockChild, | ||
}; | ||
|
||
describe('ProfitLossCell', () => { | ||
it('should render passed children', () => { | ||
render(<ProfitLossCell {...mockProps} />); | ||
|
||
expect(screen.getByText(mockChild)).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render passed children with correct className if passed value >= 0', () => { | ||
render(<ProfitLossCell {...mockProps} />); | ||
|
||
expect(screen.getByText(mockChild)).toHaveClass('amount--profit'); | ||
}); | ||
|
||
it('should render passed children with correct className if passed value < 0', () => { | ||
render(<ProfitLossCell {...mockProps} value='-0,34' />); | ||
|
||
expect(screen.getByText(mockChild)).toHaveClass('amount--loss'); | ||
}); | ||
}); |
25 changes: 25 additions & 0 deletions
25
packages/reports/src/Components/__tests__/reports-meta.spec.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,25 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { ReportsMeta } from '../reports-meta'; | ||
|
||
const mockFilterComponent = 'mockFilterComponent'; | ||
const mockClassName = 'mockClassName'; | ||
const mockProps = { | ||
filter_component: mockFilterComponent, | ||
className: mockClassName, | ||
}; | ||
|
||
describe('ReportsMeta', () => { | ||
it('should render passed filter_component inside of wrapper div with specific className if className was passed', () => { | ||
render(<ReportsMeta {...mockProps} />); | ||
|
||
expect(screen.getByTestId('dt_reports_meta_wrapper')).toHaveClass(mockClassName); | ||
expect(screen.getByText(mockFilterComponent)).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render filter_component with specific className if is_statement === true', () => { | ||
render(<ReportsMeta {...mockProps} is_statement />); | ||
|
||
expect(screen.getByText(mockFilterComponent)).toHaveClass('reports__meta-filter--statement'); | ||
}); | ||
}); |
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