Fix update config store

This commit is contained in:
CzBiX
2019-10-16 18:10:08 +08:00
parent f83300ebdf
commit 96d6033ccf
2 changed files with 20 additions and 9 deletions

View File

@@ -40,7 +40,7 @@ export const configStore : Module<ConfigState, any> = {
updateConfig(state, payload) {
const { key, value } = payload;
if (_.isPlainObject(value)) {
const tmp = _.merge({}, state.userConfig, value);
const tmp = _.merge({}, state.userConfig[key], value);
Vue.set(state.userConfig, key, tmp);
} else {
Vue.set(state.userConfig, key, value);

View File

@@ -53,19 +53,30 @@ describe('update config', () => {
});
test('update object', () => {
const value1 = {
foo1: 'bar1',
};
store.commit('updateConfig', {
key: 'obj',
value: {
foo: 'bar',
},
value: value1,
});
expect(store.getters.config).toMatchObject({
obj: {
foo: 'bar',
},
expect(store.state.config.userConfig).toEqual({
obj: value1,
});
const value2 = {
foo2: 'bar2',
};
store.commit('updateConfig', {
key: 'obj',
value: value2,
});
expect(store.state.config.userConfig).toEqual({
obj: Object.assign({}, value1, value2),
});
expect(spySet).toBeCalled();
});
test('update plain type', () => {