2020-10-08 06:32:08 +00:00
|
|
|
import { createLocalVue, mount } from '@vue/test-utils';
|
|
|
|
import Vuex from 'vuex';
|
|
|
|
import VueI18n from 'vue-i18n';
|
2021-09-29 14:03:51 +00:00
|
|
|
import VTooltip from 'v-tooltip';
|
2020-10-08 06:32:08 +00:00
|
|
|
|
|
|
|
import Button from 'dashboard/components/buttons/Button';
|
|
|
|
import i18n from 'dashboard/i18n';
|
2021-12-09 05:50:14 +00:00
|
|
|
import FluentIcon from 'shared/components/FluentIcon/DashboardIcon';
|
2020-10-08 06:32:08 +00:00
|
|
|
import MoreActions from '../MoreActions';
|
|
|
|
|
|
|
|
const localVue = createLocalVue();
|
|
|
|
localVue.use(Vuex);
|
|
|
|
localVue.use(VueI18n);
|
2021-09-29 14:03:51 +00:00
|
|
|
localVue.use(VTooltip);
|
2020-12-12 06:38:36 +00:00
|
|
|
|
2021-12-09 05:50:14 +00:00
|
|
|
localVue.component('fluent-icon', FluentIcon);
|
2020-10-08 06:32:08 +00:00
|
|
|
localVue.component('woot-button', Button);
|
|
|
|
|
2020-12-12 06:38:36 +00:00
|
|
|
const i18nConfig = new VueI18n({
|
|
|
|
locale: 'en',
|
|
|
|
messages: i18n,
|
|
|
|
});
|
|
|
|
|
2020-10-08 06:32:08 +00:00
|
|
|
describe('MoveActions', () => {
|
|
|
|
let currentChat = { id: 8, muted: false };
|
|
|
|
let state = null;
|
|
|
|
let muteConversation = null;
|
|
|
|
let unmuteConversation = null;
|
|
|
|
let modules = null;
|
|
|
|
let getters = null;
|
|
|
|
let store = null;
|
|
|
|
let moreActions = null;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
window.bus = {
|
|
|
|
$emit: jest.fn(),
|
2021-11-15 11:52:44 +00:00
|
|
|
$on: jest.fn(),
|
|
|
|
$off: jest.fn(),
|
2020-10-08 06:32:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
state = {
|
|
|
|
authenticated: true,
|
|
|
|
currentChat,
|
|
|
|
};
|
|
|
|
|
|
|
|
muteConversation = jest.fn(() => Promise.resolve());
|
|
|
|
unmuteConversation = jest.fn(() => Promise.resolve());
|
|
|
|
|
|
|
|
modules = {
|
|
|
|
conversations: {
|
|
|
|
actions: {
|
|
|
|
muteConversation,
|
|
|
|
unmuteConversation,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
getters = {
|
|
|
|
getSelectedChat: () => currentChat,
|
|
|
|
};
|
|
|
|
|
|
|
|
store = new Vuex.Store({
|
|
|
|
state,
|
|
|
|
modules,
|
|
|
|
getters,
|
|
|
|
});
|
|
|
|
|
2020-12-12 06:38:36 +00:00
|
|
|
moreActions = mount(MoreActions, { store, localVue, i18n: i18nConfig });
|
2020-10-08 06:32:08 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('muting discussion', () => {
|
|
|
|
it('triggers "muteConversation"', async () => {
|
2021-09-29 14:03:51 +00:00
|
|
|
await moreActions.find('button:first-child').trigger('click');
|
2020-10-08 06:32:08 +00:00
|
|
|
|
|
|
|
expect(muteConversation).toBeCalledWith(
|
|
|
|
expect.any(Object),
|
|
|
|
currentChat.id,
|
|
|
|
undefined
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows alert', async () => {
|
2021-09-29 14:03:51 +00:00
|
|
|
await moreActions.find('button:first-child').trigger('click');
|
2020-10-08 06:32:08 +00:00
|
|
|
|
|
|
|
expect(window.bus.$emit).toBeCalledWith(
|
|
|
|
'newToastMessage',
|
|
|
|
'This conversation is muted for 6 hours'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('unmuting discussion', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
currentChat.muted = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('triggers "unmuteConversation"', async () => {
|
2021-09-29 14:03:51 +00:00
|
|
|
await moreActions.find('button:first-child').trigger('click');
|
2020-10-08 06:32:08 +00:00
|
|
|
|
|
|
|
expect(unmuteConversation).toBeCalledWith(
|
|
|
|
expect.any(Object),
|
|
|
|
currentChat.id,
|
|
|
|
undefined
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows alert', async () => {
|
2021-09-29 14:03:51 +00:00
|
|
|
await moreActions.find('button:first-child').trigger('click');
|
2020-10-08 06:32:08 +00:00
|
|
|
|
|
|
|
expect(window.bus.$emit).toBeCalledWith(
|
|
|
|
'newToastMessage',
|
|
|
|
'This conversation is unmuted'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|