2021-02-07 07:24:32 +00:00
|
|
|
import { shallowMount, createLocalVue } from '@vue/test-utils';
|
2021-11-13 07:02:53 +00:00
|
|
|
import uiSettingsMixin, {
|
|
|
|
DEFAULT_CONVERSATION_SIDEBAR_ITEMS_ORDER,
|
|
|
|
DEFAULT_CONTACT_SIDEBAR_ITEMS_ORDER,
|
2022-10-03 22:27:34 +00:00
|
|
|
isEditorHotKeyEnabled,
|
2021-11-13 07:02:53 +00:00
|
|
|
} from '../uiSettings';
|
2021-02-07 07:24:32 +00:00
|
|
|
import Vuex from 'vuex';
|
|
|
|
const localVue = createLocalVue();
|
|
|
|
localVue.use(Vuex);
|
|
|
|
|
|
|
|
describe('uiSettingsMixin', () => {
|
|
|
|
let getters;
|
|
|
|
let actions;
|
|
|
|
let store;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2021-09-13 12:38:58 +00:00
|
|
|
actions = { updateUISettings: jest.fn(), toggleSidebarUIState: jest.fn() };
|
2021-02-07 07:24:32 +00:00
|
|
|
getters = {
|
|
|
|
getUISettings: () => ({
|
|
|
|
enter_to_send_enabled: false,
|
2021-09-13 12:38:58 +00:00
|
|
|
is_ct_labels_open: true,
|
2021-11-13 07:02:53 +00:00
|
|
|
conversation_sidebar_items_order: DEFAULT_CONVERSATION_SIDEBAR_ITEMS_ORDER,
|
|
|
|
contact_sidebar_items_order: DEFAULT_CONTACT_SIDEBAR_ITEMS_ORDER,
|
2021-02-07 07:24:32 +00:00
|
|
|
}),
|
|
|
|
};
|
|
|
|
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({
|
|
|
|
enter_to_send_enabled: false,
|
2021-09-13 12:38:58 +00:00
|
|
|
is_ct_labels_open: true,
|
2021-11-13 07:02:53 +00:00
|
|
|
conversation_sidebar_items_order: DEFAULT_CONVERSATION_SIDEBAR_ITEMS_ORDER,
|
|
|
|
contact_sidebar_items_order: DEFAULT_CONTACT_SIDEBAR_ITEMS_ORDER,
|
2021-02-07 07:24:32 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-09-13 12:38:58 +00:00
|
|
|
describe('#updateUISettings', () => {
|
|
|
|
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: {
|
|
|
|
enter_to_send_enabled: true,
|
|
|
|
is_ct_labels_open: true,
|
2021-11-13 07:02:53 +00:00
|
|
|
conversation_sidebar_items_order: DEFAULT_CONVERSATION_SIDEBAR_ITEMS_ORDER,
|
|
|
|
contact_sidebar_items_order: DEFAULT_CONTACT_SIDEBAR_ITEMS_ORDER,
|
2021-09-13 12:38:58 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
undefined
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#toggleSidebarUIState', () => {
|
|
|
|
it('dispatches store actions correctly', () => {
|
|
|
|
const Component = {
|
|
|
|
render() {},
|
|
|
|
title: 'TestComponent',
|
|
|
|
mixins: [uiSettingsMixin],
|
|
|
|
};
|
|
|
|
const wrapper = shallowMount(Component, { store, localVue });
|
|
|
|
wrapper.vm.toggleSidebarUIState('is_ct_labels_open');
|
|
|
|
expect(actions.updateUISettings).toHaveBeenCalledWith(
|
|
|
|
expect.anything(),
|
|
|
|
{
|
|
|
|
uiSettings: {
|
|
|
|
enter_to_send_enabled: false,
|
|
|
|
is_ct_labels_open: false,
|
2021-11-13 07:02:53 +00:00
|
|
|
conversation_sidebar_items_order: DEFAULT_CONVERSATION_SIDEBAR_ITEMS_ORDER,
|
|
|
|
contact_sidebar_items_order: DEFAULT_CONTACT_SIDEBAR_ITEMS_ORDER,
|
2021-09-13 12:38:58 +00:00
|
|
|
},
|
2021-02-07 07:24:32 +00:00
|
|
|
},
|
2021-09-13 12:38:58 +00:00
|
|
|
undefined
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#isContactSidebarItemOpen', () => {
|
|
|
|
it('returns correct values', () => {
|
|
|
|
const Component = {
|
|
|
|
render() {},
|
|
|
|
title: 'TestComponent',
|
|
|
|
mixins: [uiSettingsMixin],
|
|
|
|
};
|
|
|
|
const wrapper = shallowMount(Component, { store, localVue });
|
|
|
|
expect(wrapper.vm.isContactSidebarItemOpen('is_ct_labels_open')).toEqual(
|
|
|
|
true
|
|
|
|
);
|
|
|
|
expect(
|
|
|
|
wrapper.vm.isContactSidebarItemOpen('is_ct_prev_conv_open')
|
|
|
|
).toEqual(false);
|
|
|
|
});
|
2021-02-07 07:24:32 +00:00
|
|
|
});
|
2021-11-13 07:02:53 +00:00
|
|
|
|
|
|
|
describe('#conversationSidebarItemsOrder', () => {
|
|
|
|
it('returns correct values', () => {
|
|
|
|
const Component = {
|
|
|
|
render() {},
|
|
|
|
title: 'TestComponent',
|
|
|
|
mixins: [uiSettingsMixin],
|
|
|
|
};
|
|
|
|
const wrapper = shallowMount(Component, { store, localVue });
|
|
|
|
expect(wrapper.vm.conversationSidebarItemsOrder).toEqual([
|
2021-11-15 05:04:57 +00:00
|
|
|
{ name: 'conversation_actions' },
|
2021-11-13 07:02:53 +00:00
|
|
|
{ name: 'conversation_info' },
|
|
|
|
{ name: 'contact_attributes' },
|
|
|
|
{ name: 'previous_conversation' },
|
2022-10-25 03:33:59 +00:00
|
|
|
{ name: 'macros' },
|
2021-11-13 07:02:53 +00:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('#contactSidebarItemsOrder', () => {
|
|
|
|
it('returns correct values', () => {
|
|
|
|
const Component = {
|
|
|
|
render() {},
|
|
|
|
title: 'TestComponent',
|
|
|
|
mixins: [uiSettingsMixin],
|
|
|
|
};
|
|
|
|
const wrapper = shallowMount(Component, { store, localVue });
|
|
|
|
expect(wrapper.vm.contactSidebarItemsOrder).toEqual([
|
|
|
|
{ name: 'contact_attributes' },
|
|
|
|
{ name: 'contact_labels' },
|
|
|
|
{ name: 'previous_conversation' },
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
2021-02-07 07:24:32 +00:00
|
|
|
});
|
2022-10-03 22:27:34 +00:00
|
|
|
|
|
|
|
describe('isEditorHotKeyEnabled', () => {
|
|
|
|
it('returns true if hot key is not configured and enter to send flag is true', () => {
|
|
|
|
expect(
|
|
|
|
isEditorHotKeyEnabled({ enter_to_send_enabled: true }, 'enter')
|
|
|
|
).toEqual(true);
|
|
|
|
expect(
|
|
|
|
isEditorHotKeyEnabled({ enter_to_send_enabled: true }, 'cmd_enter')
|
|
|
|
).toEqual(false);
|
|
|
|
|
|
|
|
expect(isEditorHotKeyEnabled({}, 'cmd_enter')).toEqual(true);
|
|
|
|
expect(isEditorHotKeyEnabled({}, 'enter')).toEqual(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns correct value if hot key is configured', () => {
|
|
|
|
expect(
|
|
|
|
isEditorHotKeyEnabled({ editor_message_key: 'enter' }, 'enter')
|
|
|
|
).toEqual(true);
|
|
|
|
expect(
|
|
|
|
isEditorHotKeyEnabled({ editor_message_key: 'cmd_enter' }, 'enter')
|
|
|
|
).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|