Skip to content

Commit

Permalink
test: add unit test for localeNotification in workbench
Browse files Browse the repository at this point in the history
  • Loading branch information
mortalYoung committed Sep 3, 2021
1 parent d43dee4 commit 5f5e2d8
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
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;
});
});

0 comments on commit 5f5e2d8

Please sign in to comment.