import assert from 'assert';
import { shallow } from 'enzyme';
import React from 'react';
import { submit } from 'redux-form';
import TestContext, { defaultStore } from './TestContext';
const primedStore = {
admin: {
auth: {
isLoggedIn: false,
},
loading: 0,
notifications: [],
record: {},
references: {
oneToMany: {},
possibleValues: {},
},
resources: {},
saving: false,
ui: {
viewVersion: 1,
},
},
form: {},
i18n: {
loading: false,
locale: 'en',
messages: {},
},
router: {
location: null,
},
};
describe('TestContext.js', () => {
let testStore;
it('should render the given children', () => {
const component = shallow(
foo
);
assert.equal(component.html(), 'foo');
});
it('should return a default store as a renderProp', () => {
const component = shallow(
{({ store }) => {
testStore = store;
return foo;
}}
);
assert.equal(component.html(), 'foo');
assert.equal(typeof testStore, 'object');
assert.equal(typeof testStore.dispatch, 'function');
assert.deepStrictEqual(testStore.getState(), defaultStore);
});
describe('enableReducers options', () => {
it('should update the state when set to TRUE', () => {
shallow(
{({ store }) => {
testStore = store;
return foo;
}}
);
assert.deepStrictEqual(testStore.getState(), primedStore);
testStore.dispatch(submit('foo'));
assert.deepStrictEqual(testStore.getState(), {
...primedStore,
form: {
foo: {
triggerSubmit: true,
},
},
});
});
it('should NOT update the state when set to FALSE (default)', () => {
shallow(
{({ store }) => {
testStore = store;
return foo;
}}
);
assert.deepStrictEqual(testStore.getState(), defaultStore);
testStore.dispatch(submit('foo'));
assert.deepStrictEqual(testStore.getState(), defaultStore);
});
});
});