feat: Use vue-router on widget route management (#3415)
* feat: Add vue-router to widget Co-authored-by: Pranav <pranav@chatwoot.com> * Move to dynamic imports * Move to routerMixin * Fix popup button display * Remove unnecessary import * router -> route * Fix open state * Fix issues * Remove used CSS * Fix specs * Fix specs * Fix widgetColor specs * Fix mutation specs * Fixes broken lint errors * Fixes issues with widget flow Co-authored-by: Nithin <nithin@chatwoot.com> Co-authored-by: Nithin David <1277421+nithindavid@users.noreply.github.com> Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
This commit is contained in:
@@ -18,7 +18,7 @@ describe('#mutations', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setError', () => {
|
||||
describe('#setHasFetched', () => {
|
||||
it('set fetched flag', () => {
|
||||
const state = { records: [], uiFlags: {} };
|
||||
mutations.setHasFetched(state, true);
|
||||
|
||||
@@ -13,10 +13,8 @@ describe('#actions', () => {
|
||||
|
||||
describe('#setWidgetColor', () => {
|
||||
it('creates actions properly', () => {
|
||||
actions.setWidgetColor({ commit }, { widgetColor: '#eaeaea' });
|
||||
expect(commit.mock.calls).toEqual([
|
||||
['SET_WIDGET_COLOR', { widgetColor: '#eaeaea' }],
|
||||
]);
|
||||
actions.setWidgetColor({ commit }, '#eaeaea');
|
||||
expect(commit.mock.calls).toEqual([['SET_WIDGET_COLOR', '#eaeaea']]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -12,7 +12,7 @@ describe('#mutations', () => {
|
||||
describe('#SET_WIDGET_COLOR', () => {
|
||||
it('sets widget color properly', () => {
|
||||
const state = { widgetColor: '' };
|
||||
mutations.SET_WIDGET_COLOR(state, { widgetColor: '#00bcd4' });
|
||||
mutations.SET_WIDGET_COLOR(state, '#00bcd4');
|
||||
expect(state.widgetColor).toEqual('#00bcd4');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -24,7 +24,6 @@ describe('#actions', () => {
|
||||
expect(commit.mock.calls).toEqual([
|
||||
['setCampaigns', campaigns],
|
||||
['setError', false],
|
||||
['setHasFetched', true],
|
||||
]);
|
||||
expect(campaignTimer.initTimers).toHaveBeenCalledWith(
|
||||
{
|
||||
@@ -50,10 +49,7 @@ describe('#actions', () => {
|
||||
isInBusinessHours: true,
|
||||
}
|
||||
);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
['setError', true],
|
||||
['setHasFetched', true],
|
||||
]);
|
||||
expect(commit.mock.calls).toEqual([['setError', true]]);
|
||||
});
|
||||
});
|
||||
describe('#initCampaigns', () => {
|
||||
@@ -99,7 +95,7 @@ describe('#actions', () => {
|
||||
getters: { getCampaigns: campaigns },
|
||||
commit,
|
||||
rootState: {
|
||||
events: { isOpen: true },
|
||||
appConfig: { isWidgetOpen: true },
|
||||
},
|
||||
},
|
||||
{ campaignId: 32 }
|
||||
@@ -113,7 +109,7 @@ describe('#actions', () => {
|
||||
getters: { getCampaigns: campaigns },
|
||||
commit,
|
||||
rootState: {
|
||||
events: { isOpen: false },
|
||||
appConfig: { isWidgetOpen: false },
|
||||
},
|
||||
},
|
||||
{ campaignId: 1 }
|
||||
@@ -127,15 +123,52 @@ describe('#actions', () => {
|
||||
API.post.mockResolvedValue({});
|
||||
await actions.executeCampaign({ commit }, params);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
['setCampaignExecuted'],
|
||||
[
|
||||
'conversation/setConversationUIFlag',
|
||||
{
|
||||
isCreating: true,
|
||||
},
|
||||
{
|
||||
root: true,
|
||||
},
|
||||
],
|
||||
['setActiveCampaign', {}],
|
||||
[
|
||||
'conversation/setConversationUIFlag',
|
||||
{
|
||||
isCreating: false,
|
||||
},
|
||||
{
|
||||
root: true,
|
||||
},
|
||||
],
|
||||
]);
|
||||
});
|
||||
it('sends correct actions if execute campaign API is failed', async () => {
|
||||
const params = { campaignId: 12, websiteToken: 'XDsafmADasd' };
|
||||
API.post.mockRejectedValue({ message: 'Authentication required' });
|
||||
await actions.executeCampaign({ commit }, params);
|
||||
expect(commit.mock.calls).toEqual([['setError', true]]);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[
|
||||
'conversation/setConversationUIFlag',
|
||||
{
|
||||
isCreating: true,
|
||||
},
|
||||
{
|
||||
root: true,
|
||||
},
|
||||
],
|
||||
['setError', true],
|
||||
[
|
||||
'conversation/setConversationUIFlag',
|
||||
{
|
||||
isCreating: false,
|
||||
},
|
||||
{
|
||||
root: true,
|
||||
},
|
||||
],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -129,17 +129,4 @@ describe('#getters', () => {
|
||||
updated_at: '2021-05-03T04:53:36.354Z',
|
||||
});
|
||||
});
|
||||
it('getCampaignHasExecuted', () => {
|
||||
const state = {
|
||||
records: [],
|
||||
uiFlags: {
|
||||
isError: false,
|
||||
hasFetched: false,
|
||||
},
|
||||
activeCampaign: {},
|
||||
campaignHasExecuted: false,
|
||||
};
|
||||
|
||||
expect(getters.getCampaignHasExecuted(state)).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -18,14 +18,6 @@ describe('#mutations', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setHasFetched', () => {
|
||||
it('set fetched flag', () => {
|
||||
const state = { records: [], uiFlags: {} };
|
||||
mutations.setHasFetched(state, true);
|
||||
expect(state.uiFlags.hasFetched).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setActiveCampaign', () => {
|
||||
it('set active campaign', () => {
|
||||
const state = { records: [] };
|
||||
@@ -33,12 +25,4 @@ describe('#mutations', () => {
|
||||
expect(state.activeCampaign).toEqual(campaigns[0]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setCampaignExecuted', () => {
|
||||
it('set campaign executed flag', () => {
|
||||
const state = { records: [], uiFlags: {}, campaignHasExecuted: false };
|
||||
mutations.setCampaignExecuted(state);
|
||||
expect(state.campaignHasExecuted).toEqual(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user