broadcast/ui/src/features/radio/radioSlice.spec.ts

76 lines
2.3 KiB
TypeScript

import { RadioState, ConnectionState } from '../../app/types';
import reducer, {
AppState,
toggleRadioLoading,
setRadioStarted,
setRadioStopped,
toggleRadio,
setConnected,
setDisconnected,
toggleConnection,
selectRadioLoading,
selectRadio,
selectConnection,
} from './radioSlice';
describe('radio reducer', () => {
const initialState: AppState = {
loading: { radio: false, logs: false },
connection: ConnectionState.DISCONNECTED,
};
const connectedStarted: AppState = {
radio: RadioState.STARTED,
loading: { radio: false, logs: false },
connection: ConnectionState.CONNECTED,
};
const connectedStopped: AppState = {
radio: RadioState.STOPPED,
loading: { radio: false, logs: false },
connection: ConnectionState.CONNECTED,
};
it('should handle initial state', () => {
expect(reducer(undefined, { type: 'unknown' })).toEqual({
loading: { radio: false, logs: false },
connection: ConnectionState.DISCONNECTED,
});
});
it('should handle set loading', () => {
const actual = reducer(initialState, toggleRadioLoading());
expect(actual.loading.radio).toEqual(true);
});
it('should hande toggle radio started', () => {
const actual = reducer(connectedStopped, toggleRadio());
expect(actual.radio).toEqual(RadioState.STARTED);
})
it('should hande toggle radio stopped', () => {
const actual = reducer(connectedStarted, toggleRadio());
expect(actual.radio).toEqual(RadioState.STOPPED);
})
it('should hande set radio started', () => {
const actual = reducer(connectedStopped, setRadioStarted());
expect(actual.radio).toEqual(RadioState.STARTED);
})
it('should hande set radio stopped', () => {
const actual = reducer(connectedStarted, setRadioStopped());
expect(actual.radio).toEqual(RadioState.STOPPED);
})
it('should noop set radio started', () => {
const actual = reducer(connectedStarted, setRadioStarted());
expect(actual.radio).toEqual(RadioState.STARTED);
})
it('should noop set radio stopped', () => {
const actual = reducer(connectedStopped, setRadioStopped());
expect(actual.radio).toEqual(RadioState.STOPPED);
})
});