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.
thisyahlen/chore: add test coverage for currency switcher card index …
…component (binary-com#8313) * chore: add test coverage for currency switcher card index component * fix: move up observer --------- Co-authored-by: hirad-deriv <hirad@re-work.dev>
- Loading branch information
1 parent
b5c65f4
commit 48ec8f5
Showing
4 changed files
with
95 additions
and
8 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
packages/appstore/src/components/currency-switcher-card/__tests__/index.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,85 @@ | ||
import React from 'react'; | ||
import CurrencySwitcherCard from '../index'; | ||
import { render } from '@testing-library/react'; | ||
import { StoreProvider, mockStore } from '@deriv/stores'; | ||
|
||
jest.mock('../demo/demo-account-card', () => ({ | ||
__esModule: true, | ||
default: () => <div>DemoAccountCard</div>, | ||
})); | ||
|
||
jest.mock('../real/real-account-switcher', () => ({ | ||
__esModule: true, | ||
default: () => <div>RealAccountSwitcher</div>, | ||
})); | ||
|
||
describe('CurrencySwitcherCard', () => { | ||
it('should render empty div if user has no real account', () => { | ||
const mock = mockStore({ | ||
traders_hub: { | ||
is_real: true, | ||
}, | ||
client: { | ||
has_any_real_account: false, | ||
}, | ||
}); | ||
const wrapper = ({ children }: { children: JSX.Element }) => ( | ||
<StoreProvider store={mock}>{children}</StoreProvider> | ||
); | ||
|
||
const { container } = render(<CurrencySwitcherCard />, { wrapper }); | ||
expect(container).toBeEmptyDOMElement(); | ||
}); | ||
it('should render demo account card if user is in demo', () => { | ||
const mock = mockStore({ | ||
traders_hub: { | ||
is_demo: true, | ||
}, | ||
}); | ||
const wrapper = ({ children }: { children: JSX.Element }) => ( | ||
<StoreProvider store={mock}>{children}</StoreProvider> | ||
); | ||
|
||
const { container } = render(<CurrencySwitcherCard />, { wrapper }); | ||
expect(container).toBeInTheDocument(); | ||
expect(container).toHaveTextContent('DemoAccountCard'); | ||
}); | ||
|
||
it('should render real account switcher if user is in real and not an eu user', () => { | ||
const mock = mockStore({ | ||
traders_hub: { | ||
is_real: true, | ||
is_eu_user: false, | ||
}, | ||
client: { | ||
has_any_real_account: true, | ||
}, | ||
}); | ||
const wrapper = ({ children }: { children: JSX.Element }) => ( | ||
<StoreProvider store={mock}>{children}</StoreProvider> | ||
); | ||
|
||
const { container } = render(<CurrencySwitcherCard />, { wrapper }); | ||
expect(container).toBeInTheDocument(); | ||
expect(container).toHaveTextContent('RealAccountSwitcher'); | ||
}); | ||
|
||
it('should render real account switcher if user is in real and is an eu user', () => { | ||
const mock = mockStore({ | ||
traders_hub: { | ||
is_real: true, | ||
is_eu_user: true, | ||
}, | ||
client: { | ||
has_maltainvest_account: true, | ||
}, | ||
}); | ||
const wrapper = ({ children }: { children: JSX.Element }) => ( | ||
<StoreProvider store={mock}>{children}</StoreProvider> | ||
); | ||
|
||
const { container } = render(<CurrencySwitcherCard />, { wrapper }); | ||
expect(container).toBeInTheDocument(); | ||
expect(container).toHaveTextContent('RealAccountSwitcher'); | ||
}); | ||
}); |
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