ProjectSyncButton: Add tests.

Add 'disable button and set onClick to undefined on sync' and 'should render tooltip on sync'
This commit is contained in:
seiwailai 2021-04-25 01:44:35 +08:00
parent 95634bf0b8
commit bb896c0b02

View File

@ -41,6 +41,32 @@ describe('ProjectSyncButton', () => {
expect(ProjectsAPI.sync).toHaveBeenCalledWith(1);
});
test('disable button and set onClick to undefined on sync', async () => {
await act(async () => {
wrapper = mountWithContexts(
<ProjectSyncButton projectId={1} lastJobStatus="running">
{children}
</ProjectSyncButton>
);
});
expect(wrapper.find('Button').prop('isDisabled')).toBe(true);
expect(wrapper.find('Button').prop('onClick')).toBe(undefined);
});
test('should render tooltip on sync', async () => {
await act(async () => {
wrapper = mountWithContexts(
<ProjectSyncButton projectId={1} lastJobStatus="running">
{children}
</ProjectSyncButton>
);
});
expect(wrapper.find('Tooltip')).toHaveLength(1);
expect(wrapper.find('Tooltip').prop('content')).toEqual(
'This project is currently on sync and cannot be clicked until sync process completed'
);
});
test('displays error modal after unsuccessful sync', async () => {
ProjectsAPI.sync.mockRejectedValue(
new Error({