completion
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
/* global describe: true, test:true, expect:true */
|
||||
import { framePairing as framePairingReducer, initialState } from '~/reducers/framePairing';
|
||||
import {
|
||||
FRAME_DISCOVER_START,
|
||||
FRAME_DISCOVER_STARTED_SUCCESS,
|
||||
FRAME_DISCOVER_ERROR,
|
||||
FRAME_DISCOVER_SUCCESS,
|
||||
} from '~/store/actionTypes';
|
||||
|
||||
describe('framePairing reducer', () => {
|
||||
test('CASE 1: should return initial state', () => {
|
||||
expect(framePairingReducer(undefined, { type: 'Default' }))
|
||||
.toEqual(initialState);
|
||||
});
|
||||
|
||||
test('CASE 2: should return state with loading when type is FRAME_DISCOVER_START or FRAME_DISCOVER_STARTED_SUCCESS', () => {
|
||||
const expectedState = { ...initialState, meta: { ...initialState.meta, loading: true } };
|
||||
expect(framePairingReducer(initialState, {
|
||||
type: FRAME_DISCOVER_START,
|
||||
})).toEqual(expectedState);
|
||||
expect(framePairingReducer(initialState, {
|
||||
type: FRAME_DISCOVER_STARTED_SUCCESS,
|
||||
})).toEqual(expectedState);
|
||||
});
|
||||
|
||||
test('CASE 3: should return frames with meta property when type is FRAME_DISCOVER_SUCCESS', () => {
|
||||
const services = [{
|
||||
txt: {
|
||||
serialNumber: '',
|
||||
model: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
txt: {
|
||||
serialNumber: '',
|
||||
model: 2,
|
||||
},
|
||||
}];
|
||||
const specs = {
|
||||
1: {
|
||||
name: '',
|
||||
colors: [1, 2],
|
||||
photo: [
|
||||
'',
|
||||
'',
|
||||
],
|
||||
},
|
||||
2: {
|
||||
name: '',
|
||||
colors: [1, 2],
|
||||
photo: [
|
||||
'',
|
||||
'',
|
||||
],
|
||||
},
|
||||
};
|
||||
const stateResult = framePairingReducer(undefined, {
|
||||
type: FRAME_DISCOVER_SUCCESS,
|
||||
payload: { services, specs },
|
||||
});
|
||||
expect(stateResult).toHaveProperty('frames');
|
||||
expect(stateResult.frames).toHaveLength(services.length);
|
||||
expect(stateResult).toHaveProperty('meta');
|
||||
});
|
||||
|
||||
test('CASE 5: should return correct state when type is FRAME_DISCOVER_ERROR', () => {
|
||||
const err = new Error('discoverFrameErr');
|
||||
const expectedState = { ...initialState, meta: { error: err, loading: false } };
|
||||
expect(framePairingReducer(initialState, {
|
||||
type: FRAME_DISCOVER_ERROR,
|
||||
payload: { error: err },
|
||||
})).toEqual(expectedState);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user