Skip to content
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
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
829b734
test commit1
Jan 26, 2022
3340761
platform settings font color change for select theme text in dark mode
Feb 3, 2022
677a031
Merge branch 'master' of github.com:binary-com/deriv-app into font-co…
Feb 3, 2022
16175b7
reverted test changes
Feb 3, 2022
055b778
Merge branch 'master' of github.com:binary-com/deriv-app into font-co…
Feb 3, 2022
0495267
Merge branch 'master' of github.com:binary-com/deriv-app into font-co…
Feb 7, 2022
d49a231
Merge branch 'master' of github.com:binary-com/deriv-app into cashier…
ashrafali-v Feb 11, 2022
1632b3a
error component test case initial commit
ashrafali-v Feb 15, 2022
731891e
feat: add error component test
ashrafali-v Feb 15, 2022
6c88bb3
feat: additional error components
ashrafali-v Feb 15, 2022
fbcc8ab
more test coverage
ashrafali-v Feb 15, 2022
84d30d9
Merge branch 'master' of github.com:binary-com/deriv-app into cashier…
ashrafali-v Feb 15, 2022
7edfd7a
rveret un wanted codes
ashrafali-v Feb 15, 2022
360c800
conflicts
ashrafali-v Feb 15, 2022
bfb727b
change test labels
ashraf-deriv Feb 15, 2022
5ebd535
error component test coverage
ashrafali-v Feb 21, 2022
148e999
test case for error component and an update in routes.spec.js
ashrafali-v Feb 23, 2022
f145362
remove commented code blocks
ashrafali-v Feb 23, 2022
e33c5a5
Merge branch 'master' of github.com:binary-com/deriv-app into cashier…
ashrafali-v Feb 23, 2022
d3a26c8
Add more coverage to the test case
ashrafali-v Feb 24, 2022
bac45d4
revert changes done for test case run
ashrafali-v Feb 24, 2022
86af211
remove commented code
ashrafali-v Feb 25, 2022
0e72a5c
Merge branch 'master' of github.com:binary-com/deriv-app into cashier…
ashrafali-v Feb 25, 2022
145d254
Merge branch 'master' of github.com:binary-com/deriv-app into cashier…
ashrafali-v Mar 10, 2022
25788bc
fix - prop data type update for redirect_urls and redirect_labels
ashrafali-v Mar 10, 2022
23a9928
delete unwanted folder
ashrafali-v Mar 30, 2022
7ba5334
Merge branch 'master' of github.com:binary-com/deriv-app into cashier…
ashrafali-v Mar 31, 2022
608e11b
code cleaning
ashrafali-v Apr 1, 2022
67c1b10
Merge branch 'master' of github.com:binary-com/deriv-app into cashier…
ashrafali-v Apr 1, 2022
055d05f
Merge branch 'master' into cashier-errorcomponent-testcase
farrah-deriv Apr 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
});
});
4 changes: 2 additions & 2 deletions packages/cashier/src/Components/error-component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ const ErrorComponent = ({
refresh_message,
]
}
redirect_url={redirect_to}
redirect_label={redirect_label || <Localize i18n_default_text='Refresh' />}
redirect_urls={[redirect_to]}
redirect_labels={[redirect_label || <Localize key={0} i18n_default_text='Refresh' />]}
Copy link
Contributor

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}?

Copy link
Contributor Author

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.

buttonOnClick={redirectOnClick || (() => location.reload())}
should_clear_error_on_click={should_clear_error_on_click}
setError={setError}
Expand Down
13 changes: 11 additions & 2 deletions packages/cashier/src/Containers/__tests__/routes.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,19 @@ jest.mock('Components/Routes/binary-routes', () => () => <div>BinaryRoutes</div>
describe('<Routes />', () => {
it('should show error messages when "has_error = true"', () => {
const history = createBrowserHistory();

const error = {
header:'',
message:'',
redirect_label:['test label'],
redirectOnClick:jest.fn(),
should_clear_error_on_click:true,
setError:jest.fn(),
redirect_to:['/testurl'],
should_show_refresh:true,
}
render(
<Router history={history}>
<Routes has_error />
<Routes has_error error={error}/>
</Router>
);

Expand Down
3,840 changes: 3,840 additions & 0 deletions packages/dashboard/lib/index.js

Large diffs are not rendered by default.