-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add unit test for localeNotification in workbench (#398)
- Loading branch information
1 parent
d43dee4
commit e5971b7
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/workbench/notification/__tests__/__snapshots__/localeNotification.test.tsx.snap
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,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
29
src/workbench/notification/__tests__/localeNotification.test.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 |
---|---|---|
@@ -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; | ||
}); | ||
}); |