mirror of
https://github.com/CzBiX/qb-web.git
synced 2026-04-02 02:20:31 +08:00
Fix update config store
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
Reference in New Issue
Block a user