-
Notifications
You must be signed in to change notification settings - Fork 303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Maryia/WEBREL-2578/test: coverage for routes & routes-config in Reports #14973
Merged
balakrishna-deriv
merged 6 commits into
deriv-com:master
from
maryia-deriv:maryia/WEBREL-2578/test-coverage-reports-routes
May 9, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ec4eceb
test: routes.tsx in reports
maryia-deriv e3b8b14
Merge branch 'master' of github.com:binary-com/deriv-app into maryia/…
maryia-deriv 7bcfb9e
test: routes-config
maryia-deriv c93ea23
refactor: test for routes-config
maryia-deriv 78028fa
fix: remove extra async expect
maryia-deriv 980bef1
refactor: packages/reports/src/Constants/__tests__/routes-config.spec…
maryia-deriv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
94 changes: 94 additions & 0 deletions
94
packages/reports/src/Constants/__tests__/routes-config.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,94 @@ | ||
import React from 'react'; | ||
import { RouteComponentProps, Router } from 'react-router'; | ||
import { createMemoryHistory } from 'history'; | ||
import { mockStore } from '@deriv/stores'; | ||
import { routes } from '@deriv/shared'; | ||
import { render, screen, waitFor } from '@testing-library/react'; | ||
import BinaryRoutes from '../../Components/Routes'; | ||
import ReportsProviders from '../../reports-providers'; | ||
import getRoutesConfig from '../routes-config'; | ||
|
||
const mockedError404 = 'Error 404'; | ||
const mockedOpenPositions = 'Open positions'; | ||
const mockedStatement = 'Statement'; | ||
const mockedTradeTable = 'Trade table'; | ||
const reportsPageTitle = 'Reports'; | ||
|
||
jest.mock('Modules/Page404', () => ({ | ||
__esModule: true, | ||
default: () => <div>{mockedError404}</div>, | ||
})); | ||
|
||
jest.mock('../../Containers', () => ({ | ||
__esModule: true, | ||
default: { | ||
...jest.requireActual('../../Containers').default, | ||
OpenPositions: () => <div>{mockedOpenPositions}</div>, | ||
ProfitTable: () => <div>{mockedTradeTable}</div>, | ||
Statement: () => <div>{mockedStatement}</div>, | ||
}, | ||
})); | ||
|
||
describe('Routes Config', () => { | ||
// we need to render BinaryRoutes component that uses routes-config to test that lazy-loaded components are loaded | ||
const MockBinaryRoutes = ({ history }: Partial<RouteComponentProps>) => ( | ||
<ReportsProviders store={mockStore({ client: { is_logged_in: true }, ui: { is_reports_visible: true } })}> | ||
<Router history={history}> | ||
<BinaryRoutes is_logged_in /> | ||
</Router> | ||
</ReportsProviders> | ||
); | ||
|
||
it('should return default routes config', () => { | ||
const routesConfig = getRoutesConfig(); | ||
expect(routesConfig).toHaveLength(2); | ||
}); | ||
it('should return routes with Reports / Open positions route', async () => { | ||
const routesConfig = getRoutesConfig(); | ||
expect(routesConfig?.[0]?.path).toBe(routes.reports); | ||
expect(routesConfig?.[0]?.getTitle?.()).toBe(reportsPageTitle); | ||
expect(routesConfig?.[0]?.is_authenticated).toBe(true); | ||
expect(routesConfig?.[0].routes?.[0].path).toBe(routes.positions); | ||
const history = createMemoryHistory(); | ||
history.push(routes.positions); | ||
render(<MockBinaryRoutes history={history} />); | ||
await waitFor(() => { | ||
expect(screen.getByText(reportsPageTitle)).toBeInTheDocument(); | ||
expect(screen.getByText(mockedOpenPositions)).toBeInTheDocument(); | ||
}); | ||
}); | ||
it('should return routes with Reports / Trade table route', async () => { | ||
const routesConfig = getRoutesConfig(); | ||
expect(routesConfig?.[0].routes?.[1].path).toBe(routes.profit); | ||
expect(routesConfig?.[0].routes?.[1].getTitle()).toBe(mockedTradeTable); | ||
const history = createMemoryHistory(); | ||
history.push(routes.profit); | ||
render(<MockBinaryRoutes history={history} />); | ||
await waitFor(() => { | ||
expect(screen.getByText(reportsPageTitle)).toBeInTheDocument(); | ||
expect(screen.getByText(mockedTradeTable)).toBeInTheDocument(); | ||
}); | ||
}); | ||
it('should return routes with Reports / Statement route', async () => { | ||
const routesConfig = getRoutesConfig(); | ||
expect(routesConfig?.[0].routes?.[2].path).toBe(routes.statement); | ||
expect(routesConfig?.[0].routes?.[2].getTitle()).toBe(mockedStatement); | ||
const history = createMemoryHistory(); | ||
history.push(routes.statement); | ||
render(<MockBinaryRoutes history={history} />); | ||
await waitFor(() => { | ||
expect(screen.getByText(reportsPageTitle)).toBeInTheDocument(); | ||
expect(screen.getByText(mockedStatement)).toBeInTheDocument(); | ||
}); | ||
}); | ||
it('should return routes with route for Page 404 which loads when the path does not exist', async () => { | ||
const routesConfig = getRoutesConfig(); | ||
expect(routesConfig?.[1]?.getTitle?.()).toBe(mockedError404); | ||
const history = createMemoryHistory(); | ||
history.push('/non-existent-path'); | ||
render(<MockBinaryRoutes history={history} />); | ||
await waitFor(() => { | ||
expect(screen.getByText(mockedError404)).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
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,43 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { createMemoryHistory } from 'history'; | ||
import { mockStore } from '@deriv/stores'; | ||
import { Router } from 'react-router-dom'; | ||
import { TCoreStores } from '@deriv/stores/types'; | ||
import BinaryRoutes from '../../Components/Routes'; | ||
import Routes from '../routes'; | ||
import ReportsProviders from '../../reports-providers'; | ||
|
||
const mockedBinaryRoutes = 'BinaryRoutes'; | ||
const mockedErrorComponent = 'ErrorComponent'; | ||
|
||
jest.mock('../../../src/Components/Routes', () => jest.fn(() => mockedBinaryRoutes)); | ||
jest.mock('../../../src/Components/Errors', () => jest.fn(() => mockedErrorComponent)); | ||
|
||
describe('Routes', () => { | ||
const history = createMemoryHistory(); | ||
const store = mockStore({}); | ||
|
||
const renderMockedRoutes = ( | ||
mockedStore: TCoreStores = store, | ||
passthrough?: React.ComponentProps<typeof BinaryRoutes>['passthrough'] | ||
) => { | ||
return render( | ||
<ReportsProviders store={mockedStore}> | ||
<Router history={history}> | ||
<Routes passthrough={passthrough} /> | ||
</Router> | ||
</ReportsProviders> | ||
); | ||
}; | ||
|
||
it('should render BinaryRoutes', () => { | ||
renderMockedRoutes(); | ||
expect(screen.getByText(mockedBinaryRoutes)).toBeInTheDocument(); | ||
}); | ||
it('should render ErrorComponent', () => { | ||
renderMockedRoutes(mockStore({ common: { has_error: true } })); | ||
expect(screen.queryByText(mockedBinaryRoutes)).not.toBeInTheDocument(); | ||
expect(screen.getByText(mockedErrorComponent)).toBeInTheDocument(); | ||
}); | ||
}); |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, didn't get why this line is sync and next - async
Please, ignore if not relevant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary, removed👌🏻 thank you)