UNPKG

react-redux-fetch

Version:

A declarative and customizable way to fetch data for React components and manage that data in the Redux state

90 lines (74 loc) 2.27 kB
'use strict'; var _chai = require('chai'); var _chai2 = _interopRequireDefault(_chai); var _seamlessImmutable = require('seamless-immutable'); var _seamlessImmutable2 = _interopRequireDefault(_seamlessImmutable); var _actionTypes = require('../constants/actionTypes'); var _createRemoveFromListAction = require('./createRemoveFromListAction'); var _createRemoveFromListAction2 = _interopRequireDefault(_createRemoveFromListAction); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } _chai2.default.should(); describe('createRemoveFromListAction()', function () { var state = (0, _seamlessImmutable2.default)({ pending: true, fulfilled: false, value: [{ id: 1, text: 'old text' }, { id: 2, text: 'old text' }, { id: 3, text: 'old text' }] }); var action = { type: _actionTypes.FETCH.for('get').FULFILL, key: 'myList', value: { id: 2, text: 'new text' }, request: { meta: { removeFromList: { idName: 'id' } } } }; it('should remove the item', function () { var newAction = (0, _createRemoveFromListAction2.default)(state, action); newAction.value.should.eql([{ id: 1, text: 'old text' }, { id: 3, text: 'old text' }]); }); describe('deep path', function () { var deepState = { pending: true, fulfilled: false, value: { prop1: 'a', prop2: { a: 1, b: 2 }, prop3: { prop4: 'b', prop5: [{ id: 1, text: 'old text' }, { id: 2, text: 'old text' }, { id: 3, text: 'old text' }] } } }; var deepAction = { type: _actionTypes.FETCH.for('get').FULFILL, key: 'myList', request: { meta: { removeFromList: { path: 'prop3.prop5', idName: 'id', id: 2 } } } }; it('only replaces the correct leaf', function () { var action2 = (0, _createRemoveFromListAction2.default)(deepState, deepAction); action2.value.should.eql({ prop1: 'a', prop2: { a: 1, b: 2 }, prop3: { prop4: 'b', prop5: [{ id: 1, text: 'old text' }, { id: 3, text: 'old text' }] } }); }); }); });