This commit is contained in:
Rehan Dalal 2017-05-12 14:51:49 -04:00
Родитель 746242e9f4
Коммит 2feda3e7d5
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 410D198EEF339E0B
8 изменённых файлов: 67 добавлений и 28 удалений

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

@ -1,5 +1,5 @@
/* eslint import/prefer-default-export: "off" */
export function getAction(state, id, defaultsTo) {
export function getAction(state, id, defaultsTo = null) {
return state.newState.actions.items.get(id, defaultsTo);
}

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

@ -1,5 +1,5 @@
/* eslint import/prefer-default-export: "off" */
export function getApprovalRequest(state, id, defaultsTo) {
export function getApprovalRequest(state, id, defaultsTo = null) {
return state.newState.approvalRequests.items.get(id, defaultsTo);
}

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

@ -4,7 +4,7 @@ import { getAction } from '../actions/selectors';
import { getRevision } from '../revisions/selectors';
export function getRecipe(state, id, defaultsTo) {
export function getRecipe(state, id, defaultsTo = null) {
const recipe = state.newState.recipes.items.get(id);
if (recipe) {

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

@ -1,7 +1,7 @@
/* eslint import/prefer-default-export: "off" */
import { getAction } from '../actions/selectors';
export function getRevision(state, id, defaultsTo) {
export function getRevision(state, id, defaultsTo = null) {
const revision = state.newState.revisions.items.get(id);
if (revision) {

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

@ -27,8 +27,8 @@ describe('getAction', () => {
expect(getAction(STATE, ACTION.id)).toEqual(fromJS(ACTION));
});
it('should return `undefined` for invalid ID', () => {
expect(getAction(STATE, 0)).toEqual(undefined);
it('should return `null` for invalid ID', () => {
expect(getAction(STATE, 0)).toEqual(null);
});
it('should return default value for invalid ID with default provided', () => {

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

@ -29,8 +29,8 @@ describe('getApprovalRequest', () => {
expect(getApprovalRequest(STATE, APPROVAL_REQUEST.id)).toEqual(fromJS(APPROVAL_REQUEST));
});
it('should return `undefined` for invalid ID', () => {
expect(getApprovalRequest(STATE, 0)).toEqual(undefined);
it('should return `null` for invalid ID', () => {
expect(getApprovalRequest(STATE, 0)).toEqual(null);
});
it('should return default value for invalid ID with default provided', () => {

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

@ -1,6 +1,14 @@
import { fromJS } from 'immutable';
import * as matchers from 'jasmine-immutable-matchers';
import {
ACTION_RECEIVE,
RECIPE_RECEIVE,
REVISION_RECEIVE,
} from 'control/state/action-types';
import actionsReducer from 'control/state/actions/reducers';
import recipesReducer from 'control/state/recipes/reducers';
import revisionsReducer from 'control/state/revisions/reducers';
import {
getRecipe,
getRecipeFilters,
@ -26,19 +34,31 @@ describe('getRecipe', () => {
...INITIAL_STATE,
newState: {
...INITIAL_STATE.newState,
recipes: {
...INITIAL_STATE.newState.recipes,
items: INITIAL_STATE.newState.recipes.items.set(RECIPE.id, fromJS(RECIPE)),
},
actions: actionsReducer(undefined, {
type: ACTION_RECEIVE,
action: RECIPE.action,
}),
recipes: recipesReducer(undefined, {
type: RECIPE_RECEIVE,
recipe: RECIPE,
}),
revisions: revisionsReducer(undefined, {
type: REVISION_RECEIVE,
revision: RECIPE.latest_revision,
}),
},
};
it('should return the recipe', () => {
expect(getRecipe(STATE, RECIPE.id)).toEqual(fromJS(RECIPE));
beforeEach(() => {
jasmine.addMatchers(matchers);
});
it('should return `undefined` for invalid ID', () => {
expect(getRecipe(STATE, 'invalid')).toEqual(undefined);
it('should return the recipe', () => {
expect(getRecipe(STATE, RECIPE.id)).toEqualImmutable(fromJS(RECIPE));
});
it('should return `null` for invalid ID', () => {
expect(getRecipe(STATE, 'invalid')).toEqual(null);
});
it('should return default value for invalid ID with default provided', () => {
@ -74,10 +94,10 @@ describe('getRecipeHistory', () => {
...INITIAL_STATE,
newState: {
...INITIAL_STATE.newState,
revisions: {
...INITIAL_STATE.newState.revisions,
items: INITIAL_STATE.newState.revisions.items.set(REVISION.id, fromJS(REVISION)),
},
actions: actionsReducer(undefined, {
type: ACTION_RECEIVE,
action: REVISION.recipe.action,
}),
recipes: {
...INITIAL_STATE.newState.recipes,
history: INITIAL_STATE.newState.recipes.history.set(
@ -85,6 +105,10 @@ describe('getRecipeHistory', () => {
fromJS([REVISION.id])
),
},
revisions: revisionsReducer(undefined, {
type: REVISION_RECEIVE,
revision: RECIPE.latest_revision,
}),
},
};

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

@ -1,5 +1,12 @@
import { fromJS } from 'immutable';
import * as matchers from 'jasmine-immutable-matchers';
import {
ACTION_RECEIVE,
REVISION_RECEIVE,
} from 'control/state/action-types';
import actionsReducer from 'control/state/actions/reducers';
import revisionsReducer from 'control/state/revisions/reducers';
import { getRevision } from 'control/state/revisions/selectors';
import {
@ -16,19 +23,27 @@ describe('getRevision', () => {
...INITIAL_STATE,
newState: {
...INITIAL_STATE.newState,
revisions: {
...INITIAL_STATE.newState.revisions,
items: INITIAL_STATE.newState.revisions.items.set(REVISION.id, fromJS(REVISION)),
},
actions: actionsReducer(undefined, {
type: ACTION_RECEIVE,
action: REVISION.recipe.action,
}),
revisions: revisionsReducer(undefined, {
type: REVISION_RECEIVE,
revision: REVISION,
}),
},
};
it('should return the revision', () => {
expect(getRevision(STATE, REVISION.id)).toEqual(fromJS(REVISION));
beforeEach(() => {
jasmine.addMatchers(matchers);
});
it('should return `undefined` for invalid ID', () => {
expect(getRevision(STATE, 'invalid')).toEqual(undefined);
it('should return the revision', () => {
expect(getRevision(STATE, REVISION.id)).toEqualImmutable(fromJS(REVISION));
});
it('should return `null` for invalid ID', () => {
expect(getRevision(STATE, 'invalid')).toEqual(null);
});
it('should return default value for invalid ID with default provided', () => {