44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
|
|
import { act } from 'react-test-renderer';
|
||
|
|
|
||
|
|
import { useToolkitSocketStore } from '../src/state/toolkitSocketStore';
|
||
|
|
|
||
|
|
describe('useToolkitSocketStore', () => {
|
||
|
|
beforeEach(() => {
|
||
|
|
useToolkitSocketStore.setState({
|
||
|
|
lastConnectedAt: null,
|
||
|
|
socketId: null,
|
||
|
|
status: 'disconnected',
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
it('tracks connecting, connected, and disconnected socket state', () => {
|
||
|
|
act(() => {
|
||
|
|
useToolkitSocketStore.getState().setConnecting();
|
||
|
|
});
|
||
|
|
|
||
|
|
expect(useToolkitSocketStore.getState()).toMatchObject({
|
||
|
|
socketId: null,
|
||
|
|
status: 'connecting',
|
||
|
|
});
|
||
|
|
|
||
|
|
act(() => {
|
||
|
|
useToolkitSocketStore.getState().setConnected('socket-1');
|
||
|
|
});
|
||
|
|
|
||
|
|
expect(useToolkitSocketStore.getState()).toMatchObject({
|
||
|
|
socketId: 'socket-1',
|
||
|
|
status: 'connected',
|
||
|
|
});
|
||
|
|
expect(useToolkitSocketStore.getState().lastConnectedAt).not.toBeNull();
|
||
|
|
|
||
|
|
act(() => {
|
||
|
|
useToolkitSocketStore.getState().setDisconnected();
|
||
|
|
});
|
||
|
|
|
||
|
|
expect(useToolkitSocketStore.getState()).toMatchObject({
|
||
|
|
socketId: null,
|
||
|
|
status: 'disconnected',
|
||
|
|
});
|
||
|
|
});
|
||
|
|
});
|