Skip to content

Open-source live-chat, email support, omni-channel desk. An alternative to Intercom, Zendesk, Salesforce Service Cloud etc. 🔥💬

fix(whatsapp): keep the selected template across conversations (#16207)

Vishnu Narayananf953bca130ae
diff --git a/app/javascript/dashboard/components/widgets/conversation/WhatsappTemplates/Modal.vue b/app/javascript/dashboard/components/widgets/conversation/WhatsappTemplates/Modal.vue
index 5f01c74ac43..108b2fe02c9 100644
--- a/app/javascript/dashboard/components/widgets/conversation/WhatsappTemplates/Modal.vue
+++ b/app/javascript/dashboard/components/widgets/conversation/WhatsappTemplates/Modal.vue
@@ -48,8 +48,8 @@ export default {
},
},
watch: {
- show(value) {
- if (!value) this.selectedWaTemplate = null;
+ inboxId() {
+ this.selectedWaTemplate = null;
},
requestContactInfoOnly() {
this.selectedWaTemplate = null;
diff --git a/app/javascript/dashboard/components/widgets/conversation/specs/WhatsappTemplatesModal.spec.js b/app/javascript/dashboard/components/widgets/conversation/specs/WhatsappTemplatesModal.spec.js
new file mode 100644
index 00000000000..0cc83a4eb82
--- /dev/null
+++ b/app/javascript/dashboard/components/widgets/conversation/specs/WhatsappTemplatesModal.spec.js
@@ -0,0 +1,40 @@
+import { shallowMount } from '@vue/test-utils';
+import WhatsappTemplates from '../WhatsappTemplates/Modal.vue';
+
+const TEMPLATE = { name: 'follow_up', components: [] };
+
+const mountModal = (props = {}) =>
+ shallowMount(WhatsappTemplates, {
+ props: { show: true, inboxId: 1, ...props },
+ global: { mocks: { $t: key => key } },
+ });
+
+describe('WhatsappTemplates modal', () => {
+ it('keeps the selected template when the modal is closed and reopened', async () => {
+ const wrapper = mountModal();
+ wrapper.vm.pickTemplate(TEMPLATE);
+
+ await wrapper.setProps({ show: false });
+ await wrapper.setProps({ show: true });
+
+ expect(wrapper.vm.selectedWaTemplate).toEqual(TEMPLATE);
+ });
+
+ it('clears the selected template when the inbox changes', async () => {
+ const wrapper = mountModal();
+ wrapper.vm.pickTemplate(TEMPLATE);
+
+ await wrapper.setProps({ inboxId: 2 });
+
+ expect(wrapper.vm.selectedWaTemplate).toBeNull();
+ });
+
+ it('clears the selected template when switching to contact info requests', async () => {
+ const wrapper = mountModal();
+ wrapper.vm.pickTemplate(TEMPLATE);
+
+ await wrapper.setProps({ requestContactInfoOnly: true });
+
+ expect(wrapper.vm.selectedWaTemplate).toBeNull();
+ });
+});