-
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
Cashier errorcomponent testcase #4879
Merged
farrah-deriv
merged 30 commits into
binary-com:master
from
ashraf-deriv:cashier-errorcomponent-testcase
Apr 27, 2022
Merged
Changes from 25 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
829b734
test commit1
3340761
platform settings font color change for select theme text in dark mode
677a031
Merge branch 'master' of github.com:binary-com/deriv-app into font-co…
16175b7
reverted test changes
055b778
Merge branch 'master' of github.com:binary-com/deriv-app into font-co…
0495267
Merge branch 'master' of github.com:binary-com/deriv-app into font-co…
d49a231
Merge branch 'master' of github.com:binary-com/deriv-app into cashier…
ashrafali-v 1632b3a
error component test case initial commit
ashrafali-v 731891e
feat: add error component test
ashrafali-v 6c88bb3
feat: additional error components
ashrafali-v fbcc8ab
more test coverage
ashrafali-v 84d30d9
Merge branch 'master' of github.com:binary-com/deriv-app into cashier…
ashrafali-v 7edfd7a
rveret un wanted codes
ashrafali-v 360c800
conflicts
ashrafali-v bfb727b
change test labels
ashraf-deriv 5ebd535
error component test coverage
ashrafali-v 148e999
test case for error component and an update in routes.spec.js
ashrafali-v f145362
remove commented code blocks
ashrafali-v e33c5a5
Merge branch 'master' of github.com:binary-com/deriv-app into cashier…
ashrafali-v d3a26c8
Add more coverage to the test case
ashrafali-v bac45d4
revert changes done for test case run
ashrafali-v 86af211
remove commented code
ashrafali-v 0e72a5c
Merge branch 'master' of github.com:binary-com/deriv-app into cashier…
ashrafali-v 145d254
Merge branch 'master' of github.com:binary-com/deriv-app into cashier…
ashrafali-v 25788bc
fix - prop data type update for redirect_urls and redirect_labels
ashrafali-v 23a9928
delete unwanted folder
ashrafali-v 7ba5334
Merge branch 'master' of github.com:binary-com/deriv-app into cashier…
ashrafali-v 608e11b
code cleaning
ashrafali-v 67c1b10
Merge branch 'master' of github.com:binary-com/deriv-app into cashier…
ashrafali-v 055d05f
Merge branch 'master' into cashier-errorcomponent-testcase
farrah-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
81 changes: 81 additions & 0 deletions
81
packages/cashier/src/Components/__tests__/error-component.spec.js
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,81 @@ | ||
import React, { useEffect } from 'react'; | ||
import { screen, render, fireEvent } from '@testing-library/react'; | ||
import ErrorComponent from '../error-component'; | ||
import { Router } from 'react-router-dom'; | ||
import { createBrowserHistory } from 'history'; | ||
import { unmountComponentAtNode } from 'react-dom'; | ||
describe('<ErrorComponent/>', () => { | ||
let history; | ||
const renderWithRouter = component => { | ||
history = createBrowserHistory(); | ||
return render(<Router history={history}>{component}</Router>); | ||
}; | ||
const reloadFn = () => { | ||
window.location.reload(true); | ||
}; | ||
beforeAll(() => { | ||
Object.defineProperty(window, 'location', { | ||
configurable: true, | ||
value: { reload: jest.fn() }, | ||
}); | ||
}); | ||
const props = { | ||
redirect_to: ['/testurl'], | ||
redirect_label: ['testlabel'], | ||
}; | ||
it('should show the default message when message is not passed', () => { | ||
const message = ''; | ||
renderWithRouter(<ErrorComponent {...props} message={message} />); | ||
expect(screen.getByText('Sorry, an error occured while processing your request.')).toBeInTheDocument(); | ||
}); | ||
it('should show the actual message when message is passed', () => { | ||
const message = 'This is the error message'; | ||
renderWithRouter(<ErrorComponent {...props} message={message} />); | ||
expect(screen.getByText(message)).toBeInTheDocument(); | ||
}); | ||
it('should show refresh message when should_show_refresh is true', () => { | ||
renderWithRouter(<ErrorComponent {...props} should_show_refresh={true} />); | ||
expect(screen.getByText('Please refresh this page to continue.')).toBeInTheDocument(); | ||
}); | ||
it('do not show refresh message when should_show_refresh is false', () => { | ||
const refreshRequestText = screen.queryByText('Please refresh this page to continue.'); | ||
renderWithRouter(<ErrorComponent {...props} should_show_refresh={false} />); | ||
expect(refreshRequestText).toBeNull(); | ||
}); | ||
it('should show default message when header message is not passed', () => { | ||
const header = ''; | ||
renderWithRouter(<ErrorComponent {...props} header={header} />); | ||
expect(screen.getByText('Something’s not right')).toBeInTheDocument(); | ||
}); | ||
it('should show actual message when header message is passed', () => { | ||
const header = 'Header Text'; | ||
renderWithRouter(<ErrorComponent {...props} header={header} />); | ||
expect(screen.getByText(header)).toBeInTheDocument(); | ||
}); | ||
it('should refresh the page when redirectOnClick is not passed or empty', () => { | ||
const redirectOnClick = ''; | ||
renderWithRouter(<ErrorComponent {...props} buttonOnClick={redirectOnClick} />); | ||
reloadFn(); // as defined above.. | ||
expect(window.location.reload).toHaveBeenCalled(); | ||
}); | ||
it('should show the redirect button label as refresh when there is no redirect_label', () => { | ||
const redirectOnClick = ''; | ||
const redirect_to = ['/testurl']; | ||
renderWithRouter(<ErrorComponent redirect_to={redirect_to} buttonOnClick={redirectOnClick} />); | ||
expect(screen.getByText('Refresh')).toBeInTheDocument(); | ||
}); | ||
it('should trigger the history.listen and call the setError function when redirect button get clicked', () => { | ||
const redirectOnClick = jest.fn(); | ||
const history = createBrowserHistory(); | ||
const setError = jest.fn(); | ||
render( | ||
<Router history={history}> | ||
<ErrorComponent {...props} buttonOnClick={redirectOnClick} setError={setError} /> | ||
</Router> | ||
); | ||
fireEvent.click(screen.getByText('testlabel')); | ||
if (typeof setError === 'function') { | ||
expect(setError).toHaveBeenCalledTimes(1); | ||
} | ||
}); | ||
}); |
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
Large diffs are not rendered by default.
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.
Why do we need key={0}?
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.
It is throwing error without the key for the element.