This commit is contained in:
Rehan Dalal 2017-05-02 14:40:42 -04:00
Родитель aadd08be10
Коммит 61695ec0aa
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 410D198EEF339E0B
14 изменённых файлов: 285 добавлений и 3 удалений

Просмотреть файл

@ -5,6 +5,7 @@ import { reducer as form } from 'redux-form';
import actions from './actions/reducers';
import approvalRequests from './approvalRequests/reducers';
import recipes from './recipes/reducers';
import requests from './requests/reducers';
import revisions from './revisions/reducers';
@ -13,6 +14,7 @@ const reducer = combineReducers({
approvalRequests,
form,
recipes,
requests,
revisions,
routing,
});

Просмотреть файл

@ -168,6 +168,7 @@ export const initialState = {
history: new Map(),
items: new Map(),
},
requests: new Map(),
revisions: {
items: new Map(),
},

Просмотреть файл

@ -16,7 +16,7 @@ describe('Actions reducer', () => {
expect(actionsReducer(undefined, {})).toEqual(INITIAL_STATE);
});
it('should handle ACTION_RECEIVED', () => {
it('should handle ACTION_RECEIVE', () => {
expect(actionsReducer(undefined, {
type: ACTION_RECEIVE,
action: ACTION,

Просмотреть файл

@ -11,7 +11,7 @@ import {
} from '..';
describe('getRevision', () => {
describe('getApprovalRequest', () => {
const STATE = {
...INITIAL_STATE,
newState: {

Просмотреть файл

@ -2,6 +2,8 @@
import { INITIAL_STATE as actions } from './actions';
import { INITIAL_STATE as approvalRequests } from './approvalRequests';
import { INITIAL_STATE as recipes } from './recipes';
import { INITIAL_STATE as requests } from './requests';
import { INITIAL_STATE as revisions } from './revisions';
@ -9,6 +11,8 @@ export const INITIAL_STATE = {
newState: {
actions,
approvalRequests,
recipes,
requests,
revisions,
},
};

Просмотреть файл

@ -0,0 +1,26 @@
import { Map } from 'immutable';
export const INITIAL_STATE = {
filters: new Map(),
history: new Map(),
items: new Map(),
};
export const RECIPE = {
id: 1,
};
export const FILTERS = {
status: [
{
key: 'enabled',
value: 'Enabled',
},
{
key: 'disabled',
value: 'Disabled',
},
],
};

Просмотреть файл

@ -0,0 +1,56 @@
import { fromJS, List } from 'immutable';
import {
RECIPE_RECEIVE,
RECIPE_FILTERS_RECEIVE,
RECIPE_HISTORY_RECEIVE,
} from 'control/state/action-types';
import recipesReducer from 'control/state/recipes/reducers';
import {
FILTERS,
INITIAL_STATE,
RECIPE,
} from '.';
import {
REVISION,
} from '../revisions';
describe('Recipes reducer', () => {
it('should return initial state by default', () => {
expect(recipesReducer(undefined, {})).toEqual(INITIAL_STATE);
});
it('should handle RECIPE_RECEIVE', () => {
expect(recipesReducer(undefined, {
type: RECIPE_RECEIVE,
recipe: RECIPE,
})).toEqual({
...INITIAL_STATE,
items: INITIAL_STATE.items.set(RECIPE.id, fromJS(RECIPE)),
});
});
it('should handle RECIPE_FILTERS_RECEIVE', () => {
expect(recipesReducer(undefined, {
type: RECIPE_FILTERS_RECEIVE,
filters: FILTERS,
})).toEqual({
...INITIAL_STATE,
filters: INITIAL_STATE.filters.merge(fromJS(FILTERS)),
});
});
it('should handle RECIPE_HISTORY_RECEIVE', () => {
expect(recipesReducer(undefined, {
type: RECIPE_HISTORY_RECEIVE,
recipeId: RECIPE.id,
revisions: [REVISION],
})).toEqual({
...INITIAL_STATE,
history: INITIAL_STATE.history.set(RECIPE.id, new List([REVISION.id])),
});
});
});

Просмотреть файл

@ -0,0 +1,98 @@
import { fromJS } from 'immutable';
import * as matchers from 'jasmine-immutable-matchers';
import {
getRecipe,
getRecipeFilters,
getRecipeHistory,
} from 'control/state/recipes/selectors';
import {
FILTERS,
RECIPE,
} from '.';
import {
INITIAL_STATE,
} from '..';
import {
REVISION,
} from '../revisions';
describe('getRecipe', () => {
const STATE = {
...INITIAL_STATE,
newState: {
...INITIAL_STATE.newState,
recipes: {
...INITIAL_STATE.newState.recipes,
items: INITIAL_STATE.newState.recipes.items.set(RECIPE.id, fromJS(RECIPE)),
},
},
};
it('should return the recipe', () => {
expect(getRecipe(STATE, RECIPE.id)).toEqual(fromJS(RECIPE));
});
it('should return `undefined` for invalid ID', () => {
expect(getRecipe(STATE, 'invalid')).toEqual(undefined);
});
it('should return default value for invalid ID with default provided', () => {
expect(getRecipe(STATE, 'invalid', 'default')).toEqual('default');
});
});
describe('getRecipeFilters', () => {
const STATE = {
...INITIAL_STATE,
newState: {
...INITIAL_STATE.newState,
recipes: {
...INITIAL_STATE.newState.recipes,
filters: fromJS(FILTERS),
},
},
};
beforeEach(() => {
jasmine.addMatchers(matchers);
});
it('should return the list of filters', () => {
expect(getRecipeFilters(STATE)).toEqualImmutable(fromJS(FILTERS));
});
});
describe('getRecipeHistory', () => {
const STATE = {
...INITIAL_STATE,
newState: {
...INITIAL_STATE.newState,
revisions: {
...INITIAL_STATE.newState.revisions,
items: INITIAL_STATE.newState.revisions.items.set(REVISION.id, fromJS(REVISION)),
},
recipes: {
...INITIAL_STATE.newState.recipes,
history: INITIAL_STATE.newState.recipes.history.set(
REVISION.recipe.id,
fromJS([REVISION.id])
),
},
},
};
beforeEach(() => {
jasmine.addMatchers(matchers);
});
it('should return the list of revisions', () => {
expect(getRecipeHistory(STATE, REVISION.recipe.id)).toEqualImmutable(fromJS([REVISION]));
});
});

Просмотреть файл

@ -0,0 +1,4 @@
import { Map } from 'immutable';
export const INITIAL_STATE = new Map();

Просмотреть файл

@ -0,0 +1,51 @@
import { Map } from 'immutable';
import * as matchers from 'jasmine-immutable-matchers';
import {
REQUEST_FAILURE,
REQUEST_SEND,
REQUEST_SUCCESS,
} from 'control/state/action-types';
import {
DEFAULT_REQUEST,
} from 'control/state/constants';
import requestsReducer from 'control/state/requests/reducers';
import {
INITIAL_STATE,
} from '.';
describe('Requests reducer', () => {
beforeEach(() => {
jasmine.addMatchers(matchers);
});
it('should return initial state by default', () => {
expect(requestsReducer(undefined, {})).toEqual(INITIAL_STATE);
});
it('should handle REQUEST_SEND', () => {
expect(requestsReducer(undefined, {
type: REQUEST_SEND,
requestId: 'test',
})).toEqualImmutable(INITIAL_STATE.set('test', DEFAULT_REQUEST.set('inProgress', true)));
});
it('should handle REQUEST_SUCCESS', () => {
expect(requestsReducer(undefined, {
type: REQUEST_SUCCESS,
requestId: 'test',
})).toEqualImmutable(INITIAL_STATE.set('test', DEFAULT_REQUEST));
});
const ERROR = { message: 'test message' };
it('should handle REQUEST_FAILURE', () => {
expect(requestsReducer(undefined, {
type: REQUEST_FAILURE,
error: ERROR,
requestId: 'test',
})).toEqualImmutable(INITIAL_STATE.set('test', DEFAULT_REQUEST.set('error', new Map(ERROR))));
});
});

Просмотреть файл

@ -0,0 +1,36 @@
import * as matchers from 'jasmine-immutable-matchers';
import { DEFAULT_REQUEST } from 'control/state/constants';
import { getRequest } from 'control/state/requests/selectors';
import {
INITIAL_STATE,
} from '..';
describe('getRequest', () => {
const REQUEST = DEFAULT_REQUEST.set('inProgress', true);
const STATE = {
...INITIAL_STATE,
newState: {
...INITIAL_STATE.newState,
requests: INITIAL_STATE.newState.requests.set('test', REQUEST),
},
};
beforeEach(() => {
jasmine.addMatchers(matchers);
});
it('should return the request', () => {
expect(getRequest(STATE, 'test')).toEqualImmutable(REQUEST);
});
it('should return the DEFAULT_REQUEST object for invalid ID', () => {
expect(getRequest(STATE, 'invalid')).toEqualImmutable(DEFAULT_REQUEST);
});
it('should return default value for invalid ID with default provided', () => {
expect(getRequest(STATE, 'invalid', 'default')).toEqual('default');
});
});

Просмотреть файл

@ -8,4 +8,7 @@ export const INITIAL_STATE = {
export const REVISION = {
id: '9f86d081',
recipe: {
id: 1,
},
};

Просмотреть файл

@ -16,7 +16,7 @@ describe('Revisions reducer', () => {
expect(revisionsReducer(undefined, {})).toEqual(INITIAL_STATE);
});
it('should handle REVISION_RECEIVED', () => {
it('should handle REVISION_RECEIVE', () => {
expect(revisionsReducer(undefined, {
type: REVISION_RECEIVE,
revision: REVISION,

Просмотреть файл

@ -70,6 +70,7 @@
"file-loader": "0.9.0",
"imports-loader": "0.6.5",
"jasmine-core": "2.5.0",
"jasmine-immutable-matchers": "1.0.1",
"jasmine-promises": "0.4.1",
"karma": "1.2.0",
"karma-firefox-launcher": "1.0.0",