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

test: add unit test for localeNotification in workbench #398

Merged
merged 1 commit into from
Sep 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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,39 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`The LocaleNotification Component Match Snapshot 1`] = `
<div
style={
Object {
"lineHeight": "1.5",
"textAlign": "left",
"width": 350,
}
}
>
<p>
The current locale has changed to
chinese
, click the button to reload the Page and applying the changes.
</p>
<p
style={
Object {
"fontWeight": "bold",
}
}
>
Notice: Reload the Page could lose the data, Please confirm you have saved before.
</p>
<a
className="mo-btn mo-btn--normal"
onClick={[Function]}
style={
Object {
"width": 150,
}
}
>
Confirm Reload
</a>
</div>
`;
29 changes: 29 additions & 0 deletions src/workbench/notification/__tests__/localeNotification.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { fireEvent, render } from '@testing-library/react';
import React from 'react';
import { create } from 'react-test-renderer';
import LocaleNotification from '../notificationPane/localeNotification';

describe('The LocaleNotification Component', () => {
test('Match Snapshot', () => {
const component = create(<LocaleNotification locale="chinese" />);
expect(component.toJSON()).toMatchSnapshot();
});

test('Should support to reload via button', () => {
const originalFunction = window.location.reload;
const mockFn = jest.fn();
Reflect.deleteProperty(window, 'location');
Object.defineProperty(window, 'location', {
writable: true,
value: { reload: mockFn },
});
const { getByText } = render(<LocaleNotification locale="chinese" />);

fireEvent.click(getByText('Confirm Reload'));

expect(jest.isMockFunction(window.location.reload)).toBeTruthy();
expect(mockFn).toBeCalled();

window.location.reload = originalFunction;
});
});