UNPKG

twreporter-redux

Version:

redux actions and reducers for twreporter website

83 lines (70 loc) 2.08 kB
'use strict'; var _topics = require('../topics'); var _actionTypes = require('../../constants/action-types'); var _actionTypes2 = _interopRequireDefault(_actionTypes); var _chai = require('chai'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var topic1 = { id: 'topic-id-1', slug: 'topic-slug-1' }; /* global describe, it*/ var topic2 = { id: 'topic-id-2', slug: 'topic-slug-2' }; describe('topic reducer', function () { it('should return the initial state', function () { (0, _chai.expect)((0, _topics.topic)({}, {})).to.deep.equal({}); }); it('should handle GET_A_FULL_TOPIC', function () { (0, _chai.expect)((0, _topics.topic)({}, { type: _actionTypes2.default.GET_A_FULL_TOPIC, payload: topic1 })).to.deep.equal({ slug: topic1.slug, error: null }); }); it('should handle ERROR_TO_GET_A_FULL_TOPIC ', function () { var err = new Error('error occurs'); (0, _chai.expect)((0, _topics.topic)({}, { type: _actionTypes2.default.ERROR_TO_GET_A_FULL_TOPIC, error: err })).to.deep.equal({ error: err }); }); }); describe('topics reducer', function () { it('should return the initial state', function () { (0, _chai.expect)((0, _topics.topics)({}, {})).to.deep.equal({}); }); it('should handle GET_TOPICS', function () { (0, _chai.expect)((0, _topics.topics)({}, { type: _actionTypes2.default.GET_TOPICS, payload: { items: [topic1, topic2], total: 10 } })).to.deep.equal({ items: [topic1.slug, topic2.slug], total: 10, error: null }); }); it('should handle ERROR_TO_GET_TOPICS', function () { var err = new Error('error occurs'); (0, _chai.expect)((0, _topics.topics)({ items: [topic1.slug, topic2.slug], total: 10, error: null }, { type: _actionTypes2.default.ERROR_TO_GET_TOPICS, error: err })).to.deep.equal({ items: [topic1.slug, topic2.slug], total: 10, error: err }); }); });