Skip to content

Instantly share code, notes, and snippets.

@jdmunro
Last active January 30, 2017 20:27
Show Gist options
  • Save jdmunro/29cf38db8050a5b525e0a76ffb423dae to your computer and use it in GitHub Desktop.
Save jdmunro/29cf38db8050a5b525e0a76ffb423dae to your computer and use it in GitHub Desktop.
it('does not repeat meals within the same week if enough meals are available', () => {
const mealIds = ['1', '2', '3', '4', '5', '6', '7'];
const meals = immutable.fromJS({
[mealIds[0]]: {name: 'Spaghetti'},
[mealIds[1]]: {name: 'Fish and Chips'},
[mealIds[2]]: {name: 'Meat and Potato Pie'},
[mealIds[3]]: {name: 'Lasagne'},
[mealIds[4]]: {name: 'Fish Stew'},
[mealIds[5]]: {name: 'Toad in the Hole'},
[mealIds[6]]: {name: 'Pork Cutlets'},
});
const defaultState = immutable.fromJS({
visibleWeek: null,
meals,
plan: {},
});
const week = 19;
const year = 2016;
const date = immutable.fromJS({week, year});
const state = reducer(defaultState, shuffleWeek(date)).getIn(['plan', '2016', '19']);
expect(mealIds).toContain(state.getIn([0, 'id']));
expect(mealIds).toContain(state.getIn([1, 'id']));
expect(state.get(1)).not.toEqual(state.get(0));
expect(mealIds).toContain(state.getIn([2, 'id']));
expect(state.get(2)).not.toEqual(state.get(1));
expect(mealIds).toContain(state.getIn([3, 'id']));
expect(state.get(3)).not.toEqual(state.get(2));
expect(mealIds).toContain(state.getIn([4, 'id']));
expect(state.get(4)).not.toEqual(state.get(3));
expect(mealIds).toContain(state.getIn([5, 'id']));
expect(state.get(5)).not.toEqual(state.get(4));
expect(mealIds).toContain(state.getIn([6, 'id']));
expect(state.get(6)).not.toEqual(state.get(5));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment