Skip to content

Commit

Permalink
Add appState reducer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shaunsaker committed Jun 10, 2018
1 parent 2bf155d commit 97f6ec3
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions reducers/appState/__tests__/appState.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import reducer from '../';
import initialState from '../initialState';

it('should return the initial state', () => {
expect(reducer(undefined, {})).toEqual(initialState);
});

it('should handle TOGGLE_LOADING', () => {
const action = {
type: 'TOGGLE_LOADING',
};

expect(reducer(undefined, action).loading).toEqual(false); // initial is true
});

it('should handle SET_DEVICE_LOCATION', () => {
const payload = {
coords: {
lat: 'lat',
lng: 'lng',
},
};

const action = {
type: 'SET_DEVICE_LOCATION',
payload,
};

expect(reducer(undefined, action).deviceLocation).toEqual(payload.coords);
});

it('should handle SET_SYSTEM_MESSAGE', () => {
const payload = {
message: 'Test',
code: 12345,
};

const action = {
type: 'SET_SYSTEM_MESSAGE',
payload,
error: true,
};

const expectedPayload = payload;
expectedPayload.error = action.error;

expect(reducer(undefined, action).systemMessage).toEqual(expectedPayload);
});

it('should handle RESET_SYSTEM_MESSAGE', () => {
const action = {
type: 'RESET_SYSTEM_MESSAGE',
};

expect(reducer(undefined, action).systemMessage).toEqual(initialState.systemMessage);
});

it('should handle SET_NETWORK_CONNECTION_INFO', () => {
const payload = {
network: {
ConnectionType: 'wifi',
EffectiveConnectionType: '4g',
},
};

const action = {
type: 'SET_NETWORK_CONNECTION_INFO',
payload,
};

expect(reducer(undefined, action).network).toEqual(payload.network);
});

it('should handle TOGGLE_REALTIME_DATABASE_MODE', () => {
const action = {
type: 'TOGGLE_REALTIME_DATABASE_MODE',
};

expect(reducer(undefined, action).realtimeDatabaseMode).toEqual(false); // initial is true
});

0 comments on commit 97f6ec3

Please sign in to comment.