From e5c5ebc3989b73d84b48351340f66d6450339d2c Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Wed, 4 Oct 2023 15:20:11 +0530 Subject: [PATCH] test: inboxHasFeature --- app/javascript/shared/mixins/inboxMixin.js | 2 +- .../shared/mixins/specs/inboxMixin.spec.js | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/app/javascript/shared/mixins/inboxMixin.js b/app/javascript/shared/mixins/inboxMixin.js index 2c559454f..fdb953479 100644 --- a/app/javascript/shared/mixins/inboxMixin.js +++ b/app/javascript/shared/mixins/inboxMixin.js @@ -120,7 +120,7 @@ export default { }, methods: { inboxHasFeature(feature) { - return INBOX_FEATURE_MAP[feature]?.includes(this.channelType); + return INBOX_FEATURE_MAP[feature]?.includes(this.channelType) ?? false; }, }, }; diff --git a/app/javascript/shared/mixins/specs/inboxMixin.spec.js b/app/javascript/shared/mixins/specs/inboxMixin.spec.js index 4ab2a4028..0104c79bc 100644 --- a/app/javascript/shared/mixins/specs/inboxMixin.spec.js +++ b/app/javascript/shared/mixins/specs/inboxMixin.spec.js @@ -215,4 +215,40 @@ describe('inboxMixin', () => { expect(wrapper.vm.isATwitterInbox).toBe(false); expect(wrapper.vm.channelType).toBe('Channel::Telegram'); }); + + describe('#inboxHasFeature', () => { + it('detects the correct feature', () => { + const Component = { + render() {}, + mixins: [inboxMixin], + data() { + return { + inbox: { + channel_type: 'Channel::Telegram', + }, + }; + }, + }; + const wrapper = shallowMount(Component); + expect(wrapper.vm.inboxHasFeature('replyTo')).toBe(true); + expect(wrapper.vm.inboxHasFeature('feature-does-not-exist')).toBe(false); + }); + + it('returns false for feature not included', () => { + const Component = { + render() {}, + mixins: [inboxMixin], + data() { + return { + inbox: { + channel_type: 'Channel::SMS', + }, + }; + }, + }; + const wrapper = shallowMount(Component); + expect(wrapper.vm.inboxHasFeature('replyTo')).toBe(false); + expect(wrapper.vm.inboxHasFeature('feature-does-not-exist')).toBe(false); + }); + }); });