forked from binary-com/deriv-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add test coverage for regulators-switcher component (binary-co…
…m#8320) Co-authored-by: Bahar <bahar@regentmarkets.com>
- Loading branch information
1 parent
6262b03
commit 7e14fd0
Showing
4 changed files
with
117 additions
and
7 deletions.
There are no files selected for viewing
103 changes: 103 additions & 0 deletions
103
packages/appstore/src/components/main-title-bar/__tests__/regulators-switcher.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,103 @@ | ||
import React from 'react'; | ||
import RegulatorSwitcher from '../regulators-switcher'; | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import { StoreProvider, mockStore } from '@deriv/stores'; | ||
|
||
jest.mock('../../pre-loader/regulations-switcher-loader', () => ({ | ||
__esModule: true, | ||
default: () => <div>RegulationsSwitcherLoader</div>, | ||
})); | ||
|
||
describe('RegulatorSwitcher', () => { | ||
it('should render correctly', () => { | ||
const mock = mockStore({}); | ||
|
||
const wrapper = ({ children }: { children: JSX.Element }) => ( | ||
<StoreProvider store={mock}>{children}</StoreProvider> | ||
); | ||
|
||
const { container } = render(<RegulatorSwitcher />, { | ||
wrapper, | ||
}); | ||
expect(container).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render the correct text', () => { | ||
const mock = mockStore({}); | ||
|
||
const wrapper = ({ children }: { children: JSX.Element }) => ( | ||
<StoreProvider store={mock}>{children}</StoreProvider> | ||
); | ||
|
||
const { container } = render(<RegulatorSwitcher />, { | ||
wrapper, | ||
}); | ||
expect(container).toBeInTheDocument(); | ||
expect(screen.getByText('Regulation:')).toBeInTheDocument(); | ||
expect(screen.getByText('Non-EU')).toBeInTheDocument(); | ||
expect(screen.getByText('EU')).toBeInTheDocument(); | ||
}); | ||
it('should open toggleRegulatorsCompareModal if the user clicks on the icon', () => { | ||
const mock = mockStore({}); | ||
|
||
const wrapper = ({ children }: { children: JSX.Element }) => ( | ||
<StoreProvider store={mock}>{children}</StoreProvider> | ||
); | ||
|
||
const { container } = render(<RegulatorSwitcher />, { | ||
wrapper, | ||
}); | ||
expect(container).toBeInTheDocument(); | ||
fireEvent.click(screen.getByTestId('dt_regulators-switcher-icon')); | ||
expect(mock.traders_hub.toggleRegulatorsCompareModal).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should switch the region to EU if the user clicks on EU', () => { | ||
const mock = mockStore({}); | ||
|
||
const wrapper = ({ children }: { children: JSX.Element }) => ( | ||
<StoreProvider store={mock}>{children}</StoreProvider> | ||
); | ||
|
||
const { container } = render(<RegulatorSwitcher />, { | ||
wrapper, | ||
}); | ||
expect(container).toBeInTheDocument(); | ||
fireEvent.click(screen.getByText('EU')); | ||
expect(mock.traders_hub.selectRegion).toHaveBeenCalledWith('EU'); | ||
}); | ||
|
||
it('should switch the region to Non-EU if the user clicks on Non-EU', () => { | ||
const mock = mockStore({}); | ||
|
||
const wrapper = ({ children }: { children: JSX.Element }) => ( | ||
<StoreProvider store={mock}>{children}</StoreProvider> | ||
); | ||
|
||
const { container } = render(<RegulatorSwitcher />, { | ||
wrapper, | ||
}); | ||
expect(container).toBeInTheDocument(); | ||
fireEvent.click(screen.getByText('Non-EU')); | ||
expect(mock.traders_hub.selectRegion).toHaveBeenCalledWith('Non-EU'); | ||
}); | ||
|
||
it('should show loader if is_switching is true', () => { | ||
const mock = mockStore({ | ||
client: { | ||
is_switching: true, | ||
}, | ||
}); | ||
|
||
const wrapper = ({ children }: { children: JSX.Element }) => ( | ||
<StoreProvider store={mock}>{children}</StoreProvider> | ||
); | ||
|
||
const { container } = render(<RegulatorSwitcher />, { | ||
wrapper, | ||
}); | ||
|
||
expect(container).toBeInTheDocument(); | ||
expect(screen.getByText('RegulationsSwitcherLoader')).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
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