76 lines
2.2 KiB
TypeScript
76 lines
2.2 KiB
TypeScript
import { RadioState, ConnectionState } from '../../app/types';
|
|
import reducer, {
|
|
AppState,
|
|
toggleLoading,
|
|
setRadioStarted,
|
|
setRadioStopped,
|
|
toggleRadio,
|
|
setConnected,
|
|
setDisconnected,
|
|
toggleConnection,
|
|
selectLoading,
|
|
selectRadio,
|
|
selectConnection,
|
|
} from './radioSlice';
|
|
|
|
describe('radio reducer', () => {
|
|
const initialState: AppState = {
|
|
loading: false,
|
|
connection: ConnectionState.DISCONNECTED,
|
|
};
|
|
|
|
const connectedStarted: AppState = {
|
|
radio: RadioState.STARTED,
|
|
loading: false,
|
|
connection: ConnectionState.CONNECTED,
|
|
};
|
|
|
|
const connectedStopped: AppState = {
|
|
radio: RadioState.STOPPED,
|
|
loading: false,
|
|
connection: ConnectionState.CONNECTED,
|
|
};
|
|
|
|
it('should handle initial state', () => {
|
|
expect(reducer(undefined, { type: 'unknown' })).toEqual({
|
|
loading: false,
|
|
connection: ConnectionState.DISCONNECTED,
|
|
});
|
|
});
|
|
|
|
it('should handle set loading', () => {
|
|
const actual = reducer(initialState, toggleLoading());
|
|
expect(actual.loading).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);
|
|
})
|
|
});
|