chore: Replace campaign mixin with composable [CW-3463] (#9987)
# Pull Request Template ## Description Repalces campaignMixin and its usage with the new useCampaign mixin Fixes https://linear.app/chatwoot/issue/CW-3463/rewrite-campaignmixin-mixin-to-a-composable --------- Co-authored-by: Shivam Mishra <scm.mymail@gmail.com> Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
This commit is contained in:
@@ -1,19 +0,0 @@
|
||||
import { CAMPAIGN_TYPES } from '../constants/campaign';
|
||||
|
||||
export default {
|
||||
computed: {
|
||||
campaignType() {
|
||||
const campaignTypeMap = {
|
||||
ongoing_campaigns: CAMPAIGN_TYPES.ONGOING,
|
||||
one_off: CAMPAIGN_TYPES.ONE_OFF,
|
||||
};
|
||||
return campaignTypeMap[this.$route.name];
|
||||
},
|
||||
isOngoingType() {
|
||||
return this.campaignType === CAMPAIGN_TYPES.ONGOING;
|
||||
},
|
||||
isOneOffType() {
|
||||
return this.campaignType === CAMPAIGN_TYPES.ONE_OFF;
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -1,34 +0,0 @@
|
||||
import { shallowMount } from '@vue/test-utils';
|
||||
import campaignMixin from '../campaignMixin';
|
||||
|
||||
const buildComponent = routeName => ({
|
||||
template: '<div></div>',
|
||||
computed: {
|
||||
$route() {
|
||||
return { name: routeName };
|
||||
},
|
||||
},
|
||||
mixins: [campaignMixin],
|
||||
});
|
||||
|
||||
describe('campaignMixin', () => {
|
||||
beforeEach(() => {
|
||||
global.window = Object.create(window);
|
||||
});
|
||||
it('returns the correct campaign type', () => {
|
||||
const Component = buildComponent('one_off');
|
||||
const wrapper = shallowMount(Component);
|
||||
expect(wrapper.vm.campaignType).toBe('one_off');
|
||||
});
|
||||
it('isOneOffType returns true if path is one_off', () => {
|
||||
const Component = buildComponent('one_off');
|
||||
const wrapper = shallowMount(Component);
|
||||
expect(wrapper.vm.isOneOffType).toBe(true);
|
||||
});
|
||||
|
||||
it('isOngoingType returns true if path is ongoing_campaigns', () => {
|
||||
const Component = buildComponent('ongoing_campaigns');
|
||||
const wrapper = shallowMount(Component);
|
||||
expect(wrapper.vm.isOngoingType).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user