-
Notifications
You must be signed in to change notification settings - Fork 298
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
Niloofar Sadeghi / Refactor tests in the network-status.spec.tsx file #7230
Merged
farrah-deriv
merged 5 commits into
binary-com:develop
from
niloofar-deriv:niloofar/83404/tests-for-network-status
Jan 9, 2023
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e50a97c
test: writting test for network-status component
0d5d74d
refactor: improve namings
9692835
refactor: improve tests
b29213d
build: remove extra packages from core
3f88f03
Merge branch 'develop' of github.com:binary-com/deriv-app into niloof…
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
90 changes: 41 additions & 49 deletions
90
packages/core/src/App/Components/Layout/Footer/__tests__/network-status.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 |
---|---|---|
@@ -1,56 +1,48 @@ | ||
// TODO refactor old tests in this component | ||
import React from 'react'; | ||
import { Popover } from '@deriv/components'; | ||
import { NetworkStatus } from '../network-status.jsx'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { NetworkStatus } from '../network-status.jsx'; | ||
|
||
const MockNetworkStatus = ({ is_mobile = true }) => ( | ||
<NetworkStatus status={{ class: 'offline' }} is_mobile={is_mobile} /> | ||
); | ||
|
||
describe('network-status component', () => { | ||
it('should has "network-status__wrapper--is-mobile" class when the "is_mobile" property is true', () => { | ||
render(<MockNetworkStatus />); | ||
const div_element = screen.getByTestId('dt_network_status'); | ||
expect(div_element).toHaveClass('network-status__wrapper--is-mobile'); | ||
}); | ||
|
||
const status = { | ||
class: 'online', | ||
tooltip: 'Online', | ||
}; | ||
it('should has correct class based on class passed in the "status" property', () => { | ||
const { rerender } = render(<NetworkStatus status={{ class: 'offline' }} />); | ||
expect(screen.getByTestId('dt_network_status_element')).toHaveClass('network-status__circle--offline'); | ||
|
||
describe('NetworkStatus Component', () => { | ||
it('should has "network-status__wrapper--is-mobile" class when the "is_mobile" is true', () => { | ||
render(<NetworkStatus status={status} is_mobile />); | ||
const divElement = screen.getByTestId('dt_network_status_id'); | ||
expect(divElement).toHaveClass('network-status__wrapper--is-mobile'); | ||
rerender(<NetworkStatus status={{ class: 'online' }} />); | ||
expect(screen.getByTestId('dt_network_status_element')).toHaveClass('network-status__circle--online'); | ||
|
||
rerender(<NetworkStatus status={{ class: 'blinker' }} />); | ||
expect(screen.getByTestId('dt_network_status_element')).toHaveClass('network-status__circle--blinker'); | ||
}); | ||
|
||
it('should contain "Popover" with default message when "status.tooltip" is empty', () => { | ||
render(<MockNetworkStatus is_mobile={false} />); | ||
const popover_wrapper = screen.getByTestId('dt_popover_wrapper'); | ||
userEvent.hover(popover_wrapper); | ||
const network_status = screen.getByText(/connecting to server/i); | ||
expect(network_status).toBeInTheDocument(); | ||
}); | ||
|
||
// it('should render one <NetworkStatus /> component', () => { | ||
// const wrapper = shallow(<NetworkStatus status={status} />); | ||
// expect(wrapper).toHaveLength(1); | ||
// }); | ||
// it('should have correct class based on class passed in status', () => { | ||
// const wrapper = shallow(<NetworkStatus status={status} />); | ||
// expect(wrapper.find('.network-status__circle--online').exists()).toBe(true); | ||
// wrapper.setProps({ status: { class: 'offline' } }); | ||
// expect(wrapper.find('.network-status__circle--offline').exists()).toBe(true); | ||
// wrapper.setProps({ status: { class: 'blinker' } }); | ||
// expect(wrapper.find('.network-status__circle--blinker').exists()).toBe(true); | ||
// }); | ||
// it('should contain Tooltip message passed in status', () => { | ||
// const wrapper = shallow(<NetworkStatus status={status} />); | ||
// expect( | ||
// wrapper.contains( | ||
// <Popover classNameBubble='network-status__tooltip' alignment='top' message='Network status: Online'> | ||
// <div className='network-status__circle network-status__circle--online' /> | ||
// </Popover> | ||
// ) | ||
// ).toBe(true); | ||
// }); | ||
// it('should contain Popover with default message and div with only default class if status does not contain them', () => { | ||
// status = {}; | ||
// const wrapper = shallow(<NetworkStatus status={status} />); | ||
// expect( | ||
// wrapper.contains( | ||
// <Popover | ||
// classNameBubble='network-status__tooltip' | ||
// alignment='top' | ||
// message='Network status: Connecting to server' | ||
// > | ||
// <div className='network-status__circle' /> | ||
// </Popover> | ||
// ) | ||
// ).toBe(true); | ||
// }); | ||
it('should contain "Tooltip" message passed in the status property', () => { | ||
const status = { | ||
class: 'online', | ||
tooltip: 'Online', | ||
}; | ||
|
||
render(<NetworkStatus status={status} />); | ||
const popover_wrapper = screen.getByTestId('dt_popover_wrapper'); | ||
userEvent.hover(popover_wrapper); | ||
const network_status = screen.getByText(/online/i); | ||
expect(network_status).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
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.
why do you need to run rerender on this?
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.
Thank u @ali-hosseini-fs for your revision
I'm passing different props in each render because of that I rerender the component