feat: Save rich content editor state to user.uiSettings (#1736)
Co-authored-by: Nithin David Thomas <webofnithin@gmail.com>
This commit is contained in:
56
app/javascript/dashboard/mixins/specs/uiSettings.spec.js
Normal file
56
app/javascript/dashboard/mixins/specs/uiSettings.spec.js
Normal file
@@ -0,0 +1,56 @@
|
||||
import { shallowMount, createLocalVue } from '@vue/test-utils';
|
||||
import uiSettingsMixin from '../uiSettings';
|
||||
import Vuex from 'vuex';
|
||||
|
||||
const localVue = createLocalVue();
|
||||
localVue.use(Vuex);
|
||||
|
||||
describe('uiSettingsMixin', () => {
|
||||
let getters;
|
||||
let actions;
|
||||
let store;
|
||||
|
||||
beforeEach(() => {
|
||||
actions = { updateUISettings: jest.fn() };
|
||||
getters = {
|
||||
getUISettings: () => ({
|
||||
display_rich_content_editor: false,
|
||||
enter_to_send_enabled: false,
|
||||
}),
|
||||
};
|
||||
store = new Vuex.Store({ actions, getters });
|
||||
});
|
||||
|
||||
it('returns uiSettings', () => {
|
||||
const Component = {
|
||||
render() {},
|
||||
title: 'TestComponent',
|
||||
mixins: [uiSettingsMixin],
|
||||
};
|
||||
const wrapper = shallowMount(Component, { store, localVue });
|
||||
expect(wrapper.vm.uiSettings).toEqual({
|
||||
display_rich_content_editor: false,
|
||||
enter_to_send_enabled: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('dispatches store actions correctly', () => {
|
||||
const Component = {
|
||||
render() {},
|
||||
title: 'TestComponent',
|
||||
mixins: [uiSettingsMixin],
|
||||
};
|
||||
const wrapper = shallowMount(Component, { store, localVue });
|
||||
wrapper.vm.updateUISettings({ enter_to_send_enabled: true });
|
||||
expect(actions.updateUISettings).toHaveBeenCalledWith(
|
||||
expect.anything(),
|
||||
{
|
||||
uiSettings: {
|
||||
display_rich_content_editor: false,
|
||||
enter_to_send_enabled: true,
|
||||
},
|
||||
},
|
||||
undefined
|
||||
);
|
||||
});
|
||||
});
|
||||
19
app/javascript/dashboard/mixins/uiSettings.js
Normal file
19
app/javascript/dashboard/mixins/uiSettings.js
Normal file
@@ -0,0 +1,19 @@
|
||||
import { mapGetters } from 'vuex';
|
||||
|
||||
export default {
|
||||
computed: {
|
||||
...mapGetters({
|
||||
uiSettings: 'getUISettings',
|
||||
}),
|
||||
},
|
||||
methods: {
|
||||
updateUISettings(uiSettings = {}) {
|
||||
this.$store.dispatch('updateUISettings', {
|
||||
uiSettings: {
|
||||
...this.uiSettings,
|
||||
...uiSettings,
|
||||
},
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user