|
@@ -3,6 +3,7 @@ import React from 'react';
|
|
|
import { render, screen, waitFor, act, fireEvent, renderHook } from '../../../../../../tests/test-utils';
|
|
|
import { getTRPCMockError } from '../../../../mocks/getTrpcMock';
|
|
|
import { server } from '../../../../mocks/server';
|
|
|
+import { useSystemStore } from '../../../../state/systemStore';
|
|
|
import { useToastStore } from '../../../../state/toastStore';
|
|
|
import { SettingsContainer } from './SettingsContainer';
|
|
|
|
|
@@ -41,34 +42,40 @@ describe('Test: SettingsContainer', () => {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- describe('Update', () => {
|
|
|
+ describe('Restart', () => {
|
|
|
it('should remove token from local storage on success', async () => {
|
|
|
- const current = '0.0.1';
|
|
|
- const latest = faker.system.semver();
|
|
|
+ const { result, unmount } = renderHook(() => useSystemStore());
|
|
|
+ const current = faker.system.semver();
|
|
|
const removeItem = jest.spyOn(localStorage, 'removeItem');
|
|
|
- render(<SettingsContainer data={{ current, latest }} />);
|
|
|
|
|
|
- const updateButton = screen.getByText('Update');
|
|
|
+ render(<SettingsContainer data={{ current, latest: current }} />);
|
|
|
+ expect(result.current.pollStatus).toBe(false);
|
|
|
+
|
|
|
+ const restartButton = screen.getByTestId('settings-modal-restart-button');
|
|
|
+
|
|
|
act(() => {
|
|
|
- fireEvent.click(updateButton);
|
|
|
+ fireEvent.click(restartButton);
|
|
|
});
|
|
|
|
|
|
await waitFor(() => {
|
|
|
expect(removeItem).toBeCalledWith('token');
|
|
|
+ expect(result.current.pollStatus).toBe(true);
|
|
|
});
|
|
|
+
|
|
|
+ removeItem.mockRestore();
|
|
|
+ unmount();
|
|
|
});
|
|
|
|
|
|
it('should display error toast on error', async () => {
|
|
|
const { result, unmount } = renderHook(() => useToastStore());
|
|
|
- const current = '0.0.1';
|
|
|
- const latest = faker.system.semver();
|
|
|
+ const current = faker.system.semver();
|
|
|
const error = faker.lorem.sentence();
|
|
|
- server.use(getTRPCMockError({ path: ['system', 'update'], type: 'mutation', message: error }));
|
|
|
- render(<SettingsContainer data={{ current, latest }} />);
|
|
|
+ server.use(getTRPCMockError({ path: ['system', 'restart'], type: 'mutation', message: error }));
|
|
|
+ render(<SettingsContainer data={{ current }} />);
|
|
|
|
|
|
- const updateButton = screen.getByText('Update');
|
|
|
+ const restartButton = screen.getByTestId('settings-modal-restart-button');
|
|
|
act(() => {
|
|
|
- fireEvent.click(updateButton);
|
|
|
+ fireEvent.click(restartButton);
|
|
|
});
|
|
|
|
|
|
await waitFor(() => {
|
|
@@ -79,32 +86,39 @@ describe('Test: SettingsContainer', () => {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- describe('Restart', () => {
|
|
|
+ describe('Update', () => {
|
|
|
it('should remove token from local storage on success', async () => {
|
|
|
- const current = faker.system.semver();
|
|
|
+ const { result, unmount } = renderHook(() => useSystemStore());
|
|
|
+ const current = '0.0.1';
|
|
|
+ const latest = faker.system.semver();
|
|
|
const removeItem = jest.spyOn(localStorage, 'removeItem');
|
|
|
|
|
|
- render(<SettingsContainer data={{ current }} />);
|
|
|
- const restartButton = screen.getByTestId('settings-modal-restart-button');
|
|
|
+ render(<SettingsContainer data={{ current, latest }} />);
|
|
|
+
|
|
|
+ const updateButton = screen.getByText('Update');
|
|
|
act(() => {
|
|
|
- fireEvent.click(restartButton);
|
|
|
+ fireEvent.click(updateButton);
|
|
|
});
|
|
|
|
|
|
await waitFor(() => {
|
|
|
expect(removeItem).toBeCalledWith('token');
|
|
|
+ expect(result.current.pollStatus).toBe(true);
|
|
|
});
|
|
|
+
|
|
|
+ unmount();
|
|
|
});
|
|
|
|
|
|
it('should display error toast on error', async () => {
|
|
|
const { result, unmount } = renderHook(() => useToastStore());
|
|
|
- const current = faker.system.semver();
|
|
|
+ const current = '0.0.1';
|
|
|
+ const latest = faker.system.semver();
|
|
|
const error = faker.lorem.sentence();
|
|
|
- server.use(getTRPCMockError({ path: ['system', 'restart'], type: 'mutation', message: error }));
|
|
|
- render(<SettingsContainer data={{ current }} />);
|
|
|
+ server.use(getTRPCMockError({ path: ['system', 'update'], type: 'mutation', message: error }));
|
|
|
+ render(<SettingsContainer data={{ current, latest }} />);
|
|
|
|
|
|
- const restartButton = screen.getByTestId('settings-modal-restart-button');
|
|
|
+ const updateButton = screen.getByText('Update');
|
|
|
act(() => {
|
|
|
- fireEvent.click(restartButton);
|
|
|
+ fireEvent.click(updateButton);
|
|
|
});
|
|
|
|
|
|
await waitFor(() => {
|