diff --git a/src/components/whatsAppCatalogs/Card.vue b/src/components/whatsAppCatalogs/Card.vue
index 258e153d..18b1d8d6 100644
--- a/src/components/whatsAppCatalogs/Card.vue
+++ b/src/components/whatsAppCatalogs/Card.vue
@@ -19,6 +19,7 @@
{},
+ default: /* istanbul ignore next */ () => {},
},
enabledCart: {
type: Boolean,
diff --git a/src/components/whatsAppCatalogs/List.vue b/src/components/whatsAppCatalogs/List.vue
index f5c70381..75e504d6 100644
--- a/src/components/whatsAppCatalogs/List.vue
+++ b/src/components/whatsAppCatalogs/List.vue
@@ -160,7 +160,7 @@
await this.getCommerceSettings({ appUuid });
await this.getWhatsAppCloudCatalogs({ appUuid, params });
- if (this.errorWhatsAppCloudCatalog) {
+ if (this.errorWhatsAppCloudCatalogs) {
unnnicCallAlert({
props: {
text: this.$t('WhatsApp.catalog.error.fetch_catalogs'),
diff --git a/tests/unit/specs/components/config/external/chatgpt/Config.spec.js b/tests/unit/specs/components/config/external/chatgpt/Config.spec.js
index e1ef15b9..88f2c120 100644
--- a/tests/unit/specs/components/config/external/chatgpt/Config.spec.js
+++ b/tests/unit/specs/components/config/external/chatgpt/Config.spec.js
@@ -18,16 +18,18 @@ singleApp.config = {
rules: 'rules',
knowledge_base: 'base',
ai_model: 'gpt-3.5-turbo-16k',
- voice_tone: [{
- 'value': '1',
- 'label': 'Neutral',
- }],
+ voice_tone: [
+ {
+ value: '1',
+ label: 'Neutral',
+ },
+ ],
conversation_style: [
{
- 'value': '0.7,0.8',
- 'label': 'Creative',
- 'description': 'Responds creatively, less objectively'
- }
+ value: '0.7,0.8',
+ label: 'Creative',
+ description: 'Responds creatively, less objectively',
+ },
],
};
@@ -226,9 +228,9 @@ describe('components/config/external/chatgpt/Config.vue', () => {
ai_model: 'gpt-3.5-turbo-16k',
rules: 'rules 1',
knowledge_base: 'knowledge base 1',
- temperature: "0.7",
- top_p: "0.8",
- voice_tone: "Em tom Neutral",
+ temperature: '0.7',
+ top_p: '0.8',
+ voice_tone: 'Em tom Neutral',
},
},
});
diff --git a/tests/unit/specs/components/whatsAppCatalogs/Card.spec.js b/tests/unit/specs/components/whatsAppCatalogs/Card.spec.js
new file mode 100644
index 00000000..3b329303
--- /dev/null
+++ b/tests/unit/specs/components/whatsAppCatalogs/Card.spec.js
@@ -0,0 +1,80 @@
+import Vuex from 'vuex';
+import { mount, createLocalVue } from '@vue/test-utils';
+import Card from '@/components/whatsAppCatalogs/Card.vue';
+import '@weni/unnnic-system';
+import i18n from '@/utils/plugins/i18n';
+
+const localVue = createLocalVue();
+localVue.use(Vuex);
+
+const mountComponent = async ({
+ errorDisableCatalog = false,
+ enabledCart = false,
+ catalog = {},
+} = {}) => {
+ const state = {
+ errorDisableCatalog,
+ };
+
+ const actions = {
+ disableWhatsAppCloudCatalogs: jest.fn(),
+ };
+
+ const store = new Vuex.Store({
+ modules: {
+ WhatsAppCloud: {
+ namespaced: true,
+ actions,
+ state,
+ },
+ },
+ });
+
+ const wrapper = mount(Card, {
+ localVue,
+ store,
+ i18n,
+ propsData: {
+ catalog,
+ enabledCart,
+ },
+ });
+
+ return { wrapper, actions, state };
+};
+
+describe('components/whatsAppCatalog/Card.vue', () => {
+ beforeEach(() => {
+ jest.clearAllMocks();
+ });
+
+ it('should be rendered properly', async () => {
+ const { wrapper } = await mountComponent();
+ expect(wrapper).toMatchSnapshot();
+ });
+
+ describe('catalog connect emits', () => {
+ it('should emit enable on toggle catalog connect', async () => {
+ const { wrapper } = await mountComponent();
+ const toggle = wrapper.findComponent({ ref: 'catalogConnectSwitch' });
+ toggle.vm.$emit('input', true);
+ expect(wrapper.emitted().enable).toBeTruthy();
+ });
+
+ it('should emit disable on toggle catalog connect', async () => {
+ const { wrapper } = await mountComponent();
+ const toggle = wrapper.findComponent({ ref: 'catalogConnectSwitch' });
+ toggle.vm.$emit('input', false);
+ expect(wrapper.emitted().disable).toBeTruthy();
+ });
+ });
+
+ describe('toggleCart emit', () => {
+ it('should emit toggleCart on switch click', async () => {
+ const { wrapper } = await mountComponent({ catalog: { is_connected: true } });
+ const toggle = wrapper.findComponent({ ref: 'cartEnableSwitch' });
+ toggle.trigger('click');
+ expect(wrapper.emitted().toggleCart).toBeTruthy();
+ });
+ });
+});
diff --git a/tests/unit/specs/components/whatsAppCatalogs/List.spec.js b/tests/unit/specs/components/whatsAppCatalogs/List.spec.js
new file mode 100644
index 00000000..19941438
--- /dev/null
+++ b/tests/unit/specs/components/whatsAppCatalogs/List.spec.js
@@ -0,0 +1,555 @@
+jest.mock('lodash.debounce', () => jest.fn((fn) => fn));
+import { unnnicCallAlert as mockUnnnicCallAlert } from '@weni/unnnic-system';
+
+jest.mock('@weni/unnnic-system', () => ({
+ ...jest.requireActual('@weni/unnnic-system'),
+ unnnicCallAlert: jest.fn(),
+}));
+
+import Vuex from 'vuex';
+import { mount, createLocalVue } from '@vue/test-utils';
+import List from '@/components/whatsAppCatalogs/List.vue';
+import Card from '@/components/whatsAppCatalogs/Card.vue';
+import '@weni/unnnic-system';
+import { unnnicModalNext } from '@weni/unnnic-system';
+import i18n from '@/utils/plugins/i18n';
+import VueRouter from 'vue-router';
+const router = new VueRouter();
+
+const localVue = createLocalVue();
+localVue.use(VueRouter);
+localVue.use(Vuex);
+
+const mountComponent = async ({
+ errorDisableCatalog = false,
+ loadingWhatsAppCloudCatalogs = false,
+ errorWhatsAppCloudCatalogs = false,
+ whatsAppCloudCatalogs = {},
+ errorEnableCatalog = false,
+ commerceSettings = {},
+ errorToggleCartVisibility = false,
+} = {}) => {
+ const state = {
+ errorDisableCatalog,
+ loadingWhatsAppCloudCatalogs,
+ errorWhatsAppCloudCatalogs,
+ whatsAppCloudCatalogs,
+ errorEnableCatalog,
+ commerceSettings,
+ errorToggleCartVisibility,
+ };
+
+ const actions = {
+ getWhatsAppCloudCatalogs: jest.fn(),
+ disableWhatsAppCloudCatalogs: jest.fn(),
+ enableWhatsAppCloudCatalogs: jest.fn(),
+ getCommerceSettings: jest.fn(),
+ toggleCartVisibility: jest.fn(),
+ };
+
+ const store = new Vuex.Store({
+ modules: {
+ WhatsAppCloud: {
+ namespaced: true,
+ actions,
+ state,
+ },
+ },
+ });
+
+ const wrapper = mount(List, {
+ localVue,
+ store,
+ i18n,
+ router,
+ stubs: {
+ Card,
+ },
+ mocks: {
+ $router: {
+ push: jest.fn(),
+ },
+ },
+ });
+
+ await wrapper.vm.$nextTick();
+ await jest.runAllTimers();
+
+ return { wrapper, actions, state };
+};
+
+describe('components/whatsAppCatalog/List.vue', () => {
+ beforeEach(() => {
+ jest.clearAllMocks();
+ });
+
+ it('should be rendered properly', async () => {
+ const { wrapper } = await mountComponent();
+ expect(wrapper).toMatchSnapshot();
+ });
+
+ describe('computed', () => {
+ describe('listItems', () => {
+ it('listItems should return empty array if whatsAppCloudCatalogs does not have a result', async () => {
+ const { wrapper } = await mountComponent();
+ expect(wrapper.vm.listItems).toEqual([]);
+ });
+
+ it('listItems should return whatsAppCloudCatalogs results', async () => {
+ const { wrapper } = await mountComponent({
+ whatsAppCloudCatalogs: {
+ results: [
+ {
+ uuid: 'uuid',
+ },
+ ],
+ },
+ });
+ expect(wrapper.vm.listItems).toEqual([
+ {
+ uuid: 'uuid',
+ },
+ ]);
+ });
+ });
+
+ describe('totalCount', () => {
+ it('totalCount should return pageSize if whatAppCloudCatgalogs does not have a count', async () => {
+ const { wrapper } = await mountComponent();
+ expect(wrapper.vm.totalCount).toEqual(wrapper.vm.pageSize);
+ });
+
+ it('totalCount should return whatsAppCloudCatalogs count', async () => {
+ const { wrapper } = await mountComponent({
+ whatsAppCloudCatalogs: {
+ count: 1,
+ },
+ });
+ expect(wrapper.vm.totalCount).toEqual(1);
+ });
+ });
+
+ describe('pageCount', () => {
+ it('should return the ceil of whatsAppCloudCatalogs count divided by pageSize', async () => {
+ const { wrapper } = await mountComponent({
+ whatsAppCloudCatalogs: {
+ count: 32,
+ },
+ });
+ expect(wrapper.vm.pageCount).toEqual(3);
+ });
+
+ it('should return 1 if whatsAppCloudCatalogs count is not provided', async () => {
+ const { wrapper } = await mountComponent();
+ expect(wrapper.vm.pageCount).toEqual(1);
+ });
+ });
+
+ describe('currentPageStart', () => {
+ it('should return 1 if its the first page', async () => {
+ const { wrapper } = await mountComponent();
+ expect(wrapper.vm.currentPageStart).toBe(1);
+ });
+
+ it('should return page limit start based on the current page', async () => {
+ const { wrapper } = await mountComponent();
+ await wrapper.setData({ page: 2 });
+ expect(wrapper.vm.currentPageStart).toBe(wrapper.vm.pageSize);
+ });
+ });
+
+ describe('currentPageCount', () => {
+ it('should return current page maximum', async () => {
+ const { wrapper } = await mountComponent({
+ whatsAppCloudCatalogs: {
+ count: 32,
+ },
+ });
+ await wrapper.setData({ page: 2 });
+ expect(wrapper.vm.currentPageCount).toEqual(30);
+ });
+ it('should return current page value', async () => {
+ const { wrapper } = await mountComponent({
+ whatsAppCloudCatalogs: {
+ count: 7,
+ },
+ });
+ expect(wrapper.vm.currentPageCount).toEqual(7);
+ });
+ });
+ });
+
+ describe('methods', () => {
+ beforeEach(() => {
+ jest.clearAllMocks();
+ });
+
+ describe('fetchData', () => {
+ it('should call modal when fetch data fails', async () => {
+ const { wrapper } = await mountComponent({
+ errorWhatsAppCloudCatalogs: true,
+ });
+
+ await wrapper.vm.$nextTick();
+
+ expect(mockUnnnicCallAlert).toHaveBeenCalledTimes(1);
+ });
+ });
+
+ describe('handleDisableCatalog', () => {
+ it('should call disableCatalog when a Card components emits a disable event', async () => {
+ const { wrapper } = await mountComponent({
+ whatsAppCloudCatalogs: {
+ results: [
+ {
+ uuid: 'uuid123',
+ },
+ ],
+ },
+ });
+
+ const card = wrapper.findAll('.whatsapp-catalog-card').at(0);
+ expect(wrapper.vm.openModal).toBe(false);
+ card.vm.$emit('disable');
+ expect(wrapper.vm.openModal).toBe(true);
+ });
+ });
+
+ describe('handleEnableCatalog', () => {
+ it('should not call enableCatalog when a Card components emits a enable event and it has a connected catalog', async () => {
+ const { wrapper, actions } = await mountComponent({
+ whatsAppCloudCatalogs: {
+ results: [
+ {
+ uuid: 'uuid1',
+ },
+ {
+ uuid: 'uuid12',
+ },
+ {
+ uuid: 'uuid123',
+ is_connected: true,
+ },
+ ],
+ },
+ });
+
+ const card = wrapper.findAll('.whatsapp-catalog-card').at(0);
+ expect(actions.enableWhatsAppCloudCatalogs).not.toHaveBeenCalled();
+ expect(wrapper.vm.openModal).toBe(false);
+ expect(wrapper.vm.catalogToEnable).not.toEqual({
+ uuid: 'uuid1',
+ });
+ card.vm.$emit('enable');
+ expect(wrapper.vm.openModal).toBe(true);
+ expect(wrapper.vm.catalogToEnable).toEqual({
+ uuid: 'uuid1',
+ });
+ expect(actions.enableWhatsAppCloudCatalogs).not.toHaveBeenCalled();
+ });
+ });
+
+ describe('enableCatalog', () => {
+ it('should call enableWhatsappCloudCatalogs when a Card components emits a enable event and it does not have a connected catalog', async () => {
+ const { wrapper, actions } = await mountComponent({
+ whatsAppCloudCatalogs: {
+ results: [
+ {
+ uuid: 'uuid123',
+ },
+ ],
+ },
+ });
+
+ const card = wrapper.findAll('.whatsapp-catalog-card').at(0);
+ expect(actions.enableWhatsAppCloudCatalogs).not.toHaveBeenCalled();
+ card.vm.$emit('enable', 'uuid123');
+
+ await wrapper.vm.$nextTick();
+ expect(actions.enableWhatsAppCloudCatalogs).toHaveBeenCalled();
+ });
+
+ it('should call enableWhatsappCloudCatalogs when a Card components emits a enable event and it does not have a connected catalog and call error modal on error', async () => {
+ const { wrapper, actions } = await mountComponent({
+ whatsAppCloudCatalogs: {
+ results: [
+ {
+ uuid: 'uuid123',
+ },
+ ],
+ },
+ errorEnableCatalog: true,
+ });
+
+ const card = wrapper.findAll('.whatsapp-catalog-card').at(0);
+ expect(actions.enableWhatsAppCloudCatalogs).not.toHaveBeenCalled();
+ card.vm.$emit('enable', 'uuid123');
+
+ await wrapper.vm.$nextTick();
+
+ expect(actions.enableWhatsAppCloudCatalogs).toHaveBeenCalled();
+ expect(mockUnnnicCallAlert).toHaveBeenCalledTimes(1);
+ });
+ });
+
+ describe('disableCatalog', () => {
+ it('should call disableCatalog and if disableCatalog is successful, it should call enableCatalog with the newer catalog', async () => {
+ const { wrapper, actions } = await mountComponent({
+ whatsAppCloudCatalogs: {
+ results: [
+ {
+ uuid: 'uuid1',
+ name: 'catalog 1',
+ },
+ {
+ uuid: 'uuid12',
+ name: 'catalog 2',
+ },
+ {
+ uuid: 'uuid123',
+ name: 'catalog 3',
+ is_connected: true,
+ },
+ ],
+ },
+ });
+
+ const card = wrapper.findAll('.whatsapp-catalog-card').at(0);
+ card.vm.$emit('enable');
+
+ await wrapper.vm.$nextTick();
+
+ const modal = wrapper.findComponent(unnnicModalNext);
+ expect(actions.disableWhatsAppCloudCatalogs).not.toHaveBeenCalled();
+ modal.vm.$emit('click-action-primary');
+ await wrapper.vm.$nextTick();
+
+ expect(actions.disableWhatsAppCloudCatalogs).toHaveBeenCalled();
+ });
+
+ it('should call disableWhatsappCloudCatalogs when a Card components emits a disable event and call error modal on error', async () => {
+ const { wrapper, actions } = await mountComponent({
+ whatsAppCloudCatalogs: {
+ results: [
+ {
+ uuid: 'uuid1',
+ name: 'catalog 1',
+ },
+ {
+ uuid: 'uuid12',
+ name: 'catalog 2',
+ },
+ {
+ uuid: 'uuid123',
+ name: 'catalog 3',
+ is_connected: true,
+ },
+ ],
+ },
+ errorDisableCatalog: true,
+ });
+
+ const card = wrapper.findAll('.whatsapp-catalog-card').at(0);
+ card.vm.$emit('enable');
+
+ await wrapper.vm.$nextTick();
+
+ const modal = wrapper.findComponent(unnnicModalNext);
+ expect(actions.disableWhatsAppCloudCatalogs).not.toHaveBeenCalled();
+ expect(mockUnnnicCallAlert).not.toHaveBeenCalled();
+ modal.vm.$emit('click-action-primary');
+ await wrapper.vm.$nextTick();
+
+ expect(actions.disableWhatsAppCloudCatalogs).toHaveBeenCalled();
+ expect(mockUnnnicCallAlert).toHaveBeenCalled();
+ });
+ });
+
+ describe('handleCatalogConfirmation', () => {
+ it('should call disableCatalog and if disableCatalog is successful, it should call enableCatalog with the newer catalog', async () => {
+ const { wrapper, actions } = await mountComponent({
+ whatsAppCloudCatalogs: {
+ results: [
+ {
+ uuid: 'uuid1',
+ name: 'catalog 1',
+ },
+ {
+ uuid: 'uuid12',
+ name: 'catalog 2',
+ },
+ {
+ uuid: 'uuid123',
+ name: 'catalog 3',
+ is_connected: true,
+ },
+ ],
+ },
+ });
+
+ const card = wrapper.findAll('.whatsapp-catalog-card').at(0);
+ card.vm.$emit('enable');
+
+ await wrapper.vm.$nextTick();
+
+ const modal = wrapper.findComponent(unnnicModalNext);
+ expect(actions.disableWhatsAppCloudCatalogs).not.toHaveBeenCalled();
+ expect(actions.enableWhatsAppCloudCatalogs).not.toHaveBeenCalled();
+
+ modal.vm.$emit('click-action-primary');
+ await wrapper.vm.$nextTick();
+
+ expect(actions.disableWhatsAppCloudCatalogs).toHaveBeenCalled();
+ expect(actions.enableWhatsAppCloudCatalogs).not.toHaveBeenCalled();
+
+ await wrapper.vm.$nextTick();
+
+ expect(actions.enableWhatsAppCloudCatalogs).toHaveBeenCalled();
+ });
+ });
+
+ describe('closeModal', () => {
+ it('should unset catalogToEnable and openModal', async () => {
+ const { wrapper } = await mountComponent();
+ wrapper.setData({
+ catalogToEnable: {
+ uuid: 'uuid123',
+ },
+ openModal: true,
+ });
+
+ wrapper.vm.closeModal();
+
+ expect(wrapper.vm.catalogToEnable).toEqual(null);
+ expect(wrapper.vm.openModal).toBe(false);
+ });
+ });
+
+ describe('toggleCart', () => {
+ it('should call toggleCartVisibility when a Card components emits a toggleCart event', async () => {
+ const { wrapper, actions } = await mountComponent({
+ whatsAppCloudCatalogs: {
+ results: [
+ {
+ uuid: 'uuid123',
+ },
+ ],
+ },
+ });
+
+ const card = wrapper.findAll('.whatsapp-catalog-card').at(0);
+ expect(actions.toggleCartVisibility).not.toHaveBeenCalled();
+ card.vm.$emit('toggleCart');
+ expect(actions.toggleCartVisibility).toHaveBeenCalled();
+ });
+
+ it('should call toggleCartVisibility when a Card components emits a toggleCart event and call error modal on error', async () => {
+ const { wrapper, actions } = await mountComponent({
+ whatsAppCloudCatalogs: {
+ results: [
+ {
+ uuid: 'uuid123',
+ },
+ ],
+ },
+ errorToggleCartVisibility: true,
+ });
+
+ const card = wrapper.findAll('.whatsapp-catalog-card').at(0);
+ expect(actions.toggleCartVisibility).not.toHaveBeenCalled();
+ card.vm.$emit('toggleCart');
+
+ await wrapper.vm.$nextTick();
+
+ expect(actions.toggleCartVisibility).toHaveBeenCalled();
+ expect(mockUnnnicCallAlert).toHaveBeenCalledTimes(1);
+ });
+ });
+ });
+
+ describe('watch', () => {
+ describe('page', () => {
+ it('should call getWhatsAppCloudCatalogs when page changes', async () => {
+ const { wrapper, actions } = await mountComponent();
+
+ jest.clearAllMocks();
+
+ expect(actions.getWhatsAppCloudCatalogs).not.toHaveBeenCalled();
+ await wrapper.setData({ page: 2 });
+
+ await wrapper.vm.$nextTick();
+
+ expect(actions.getWhatsAppCloudCatalogs).toHaveBeenCalled();
+ });
+ });
+
+ describe('whatsappCloudCatalogs', () => {
+ it('should have have firstLoad to false after whatsAppCloudCatalogs change', async () => {
+ const { wrapper } = await mountComponent();
+
+ expect(wrapper.vm.firstLoad).toBe(true);
+
+ await wrapper.setData({ whatsAppCloudCatalogs: { results: [] } });
+
+ expect(wrapper.vm.firstLoad).toBe(false);
+ });
+ });
+
+ describe('searchTerm', () => {
+ it('should call getWhatsAppCloudCatalogs when searchTerm changes', async () => {
+ const { wrapper, actions } = await mountComponent();
+
+ jest.clearAllMocks();
+
+ expect(actions.getWhatsAppCloudCatalogs).not.toHaveBeenCalled();
+ await wrapper.setData({ searchTerm: 'test' });
+
+ await wrapper.vm.$nextTick();
+
+ expect(actions.getWhatsAppCloudCatalogs).toHaveBeenCalled();
+ });
+
+ it('should call getWhatsAppCloudCatalogs when searchTerm changes and set page to one', async () => {
+ const { wrapper, actions } = await mountComponent();
+ await wrapper.setData({ page: 2 });
+
+ await wrapper.vm.$nextTick();
+
+ jest.clearAllMocks();
+
+ expect(actions.getWhatsAppCloudCatalogs).not.toHaveBeenCalled();
+ await wrapper.setData({ searchTerm: 'test' });
+
+ await wrapper.vm.$nextTick();
+
+ expect(actions.getWhatsAppCloudCatalogs).toHaveBeenCalled();
+ expect(wrapper.vm.page).toBe(1);
+ });
+ });
+ });
+
+ // describe('catalog connect emits', () => {
+ // it('should emit enable on toggle catalog connect', async () => {
+ // const { wrapper } = await mountComponent();
+ // const toggle = wrapper.findComponent({ ref: 'catalogConnectSwitch' });
+ // toggle.vm.$emit('input', true);
+ // expect(wrapper.emitted().enable).toBeTruthy();
+ // });
+
+ // it('should emit disable on toggle catalog connect', async () => {
+ // const { wrapper } = await mountComponent();
+ // const toggle = wrapper.findComponent({ ref: 'catalogConnectSwitch' });
+ // toggle.vm.$emit('input', false);
+ // expect(wrapper.emitted().disable).toBeTruthy();
+ // });
+ // });
+
+ // describe('toggleCart emit', () => {
+ // it('should emit toggleCart on switch click', async () => {
+ // const { wrapper } = await mountComponent({ catalog: { is_connected: true } });
+ // const toggle = wrapper.findComponent({ ref: 'cartEnableSwitch' });
+ // toggle.trigger('click');
+ // expect(wrapper.emitted().toggleCart).toBeTruthy();
+ // });
+ // });
+});
diff --git a/tests/unit/specs/components/whatsAppCatalogs/__snapshots__/Card.spec.js.snap b/tests/unit/specs/components/whatsAppCatalogs/__snapshots__/Card.spec.js.snap
new file mode 100644
index 00000000..7f624803
--- /dev/null
+++ b/tests/unit/specs/components/whatsAppCatalogs/__snapshots__/Card.spec.js.snap
@@ -0,0 +1,25 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`components/whatsAppCatalog/Card.vue should be rendered properly 1`] = `
+
+`;
diff --git a/tests/unit/specs/components/whatsAppCatalogs/__snapshots__/List.spec.js.snap b/tests/unit/specs/components/whatsAppCatalogs/__snapshots__/List.spec.js.snap
new file mode 100644
index 00000000..22253887
--- /dev/null
+++ b/tests/unit/specs/components/whatsAppCatalogs/__snapshots__/List.spec.js.snap
@@ -0,0 +1,43 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`components/whatsAppCatalog/List.vue should be rendered properly 1`] = `
+
+`;
diff --git a/tests/unit/specs/store/appType/whatsapp_cloud/actions.spec.js b/tests/unit/specs/store/appType/whatsapp_cloud/actions.spec.js
index 6bd4edfe..88270dfc 100644
--- a/tests/unit/specs/store/appType/whatsapp_cloud/actions.spec.js
+++ b/tests/unit/specs/store/appType/whatsapp_cloud/actions.spec.js
@@ -4,6 +4,12 @@ jest.mock('@/api/appType/whatsapp_cloud', () => {
getWhatsAppPhoneNumbers: jest.fn(),
configurePhoneNumber: jest.fn(),
getWhatsAppCloudCatalogs: jest.fn(),
+ fetchCatalogData: jest.fn(),
+ disableWhatsAppCloudCatalogs: jest.fn(),
+ enableWhatsAppCloudCatalogs: jest.fn(),
+ toggleCartVisibility: jest.fn(),
+ toggleCatalogVisibility: jest.fn(),
+ getCommerceSettings: jest.fn(),
};
});
import WhatsAppCloudApi from '@/api/appType/whatsapp_cloud';
@@ -238,4 +244,322 @@ describe('store/appType/whatsapp_cloud/actions.js', () => {
expect(store.state.WhatsAppCloud.errorWhatsAppCloudCatalogs).toEqual(error);
});
});
+
+ describe('fetchCatalogData()', () => {
+ const data = {
+ code: 'code',
+ appUuid: '123',
+ catalogUuid: '123',
+ };
+
+ const mockedResult = { status: 'ok' };
+
+ beforeEach(() => {
+ jest.resetAllMocks();
+
+ WhatsAppCloudApi.fetchCatalogData.mockImplementation(() => {
+ return Promise.resolve({ data: mockedResult });
+ });
+ });
+
+ it('should call fetchCatalogData from API', async () => {
+ expect(WhatsAppCloudApi.fetchCatalogData).not.toHaveBeenCalled();
+ await store.dispatch('WhatsAppCloud/fetchCatalogData', data);
+ expect(WhatsAppCloudApi.fetchCatalogData).toHaveBeenCalledTimes(1);
+ expect(WhatsAppCloudApi.fetchCatalogData).toHaveBeenCalledWith(
+ data.appUuid,
+ data.catalogUuid,
+ );
+ });
+
+ it('should set whatsAppCloudCatalog as result data', async () => {
+ store.state.WhatsAppCloud.whatsAppCloudCatalog = {};
+ expect(store.state.WhatsAppCloud.whatsAppCloudCatalog).not.toEqual(mockedResult);
+ await store.dispatch('WhatsAppCloud/fetchCatalogData', data);
+ expect(store.state.WhatsAppCloud.whatsAppCloudCatalog).toEqual(mockedResult);
+ });
+
+ it('should set loadingFetchWhatsAppCloudCatalog to false', async () => {
+ store.state.WhatsAppCloud.loadingFetchWhatsAppCloudCatalog = true;
+ expect(store.state.WhatsAppCloud.loadingFetchWhatsAppCloudCatalog).toBe(true);
+ await store.dispatch('WhatsAppCloud/fetchCatalogData', data);
+ expect(store.state.WhatsAppCloud.loadingFetchWhatsAppCloudCatalog).toBe(false);
+ });
+
+ it('should set errorFetchWhatsAppCloudCatalog as result data', async () => {
+ const error = { error: 'failed' };
+ WhatsAppCloudApi.fetchCatalogData.mockImplementation(() => {
+ return Promise.reject(error);
+ });
+ store.state.WhatsAppCloud.errorFetchWhatsAppCloudCatalog = {};
+ expect(store.state.WhatsAppCloud.errorFetchWhatsAppCloudCatalog).not.toEqual(error);
+ await store.dispatch('WhatsAppCloud/fetchCatalogData', data);
+ expect(store.state.WhatsAppCloud.errorFetchWhatsAppCloudCatalog).toEqual(error);
+ });
+ });
+
+ describe('disableWhatsAppCloudCatalogs()', () => {
+ const data = {
+ code: 'code',
+ appUuid: '123',
+ catalogUuid: '123',
+ };
+
+ const mockedResult = { status: 'ok' };
+
+ beforeEach(() => {
+ jest.resetAllMocks();
+
+ WhatsAppCloudApi.disableWhatsAppCloudCatalogs.mockImplementation(() => {
+ return Promise.resolve({ data: mockedResult });
+ });
+ });
+
+ it('should call disableWhatsAppCloudCatalogs from API', async () => {
+ expect(WhatsAppCloudApi.disableWhatsAppCloudCatalogs).not.toHaveBeenCalled();
+ await store.dispatch('WhatsAppCloud/disableWhatsAppCloudCatalogs', data);
+ expect(WhatsAppCloudApi.disableWhatsAppCloudCatalogs).toHaveBeenCalledTimes(1);
+ expect(WhatsAppCloudApi.disableWhatsAppCloudCatalogs).toHaveBeenCalledWith(
+ data.appUuid,
+ data.catalogUuid,
+ );
+ });
+
+ it('should set disabledCatalog as result data', async () => {
+ store.state.WhatsAppCloud.disabledCatalog = {};
+ expect(store.state.WhatsAppCloud.disabledCatalog).not.toEqual(mockedResult);
+ await store.dispatch('WhatsAppCloud/disableWhatsAppCloudCatalogs', data);
+ expect(store.state.WhatsAppCloud.disabledCatalog).toEqual(mockedResult);
+ });
+
+ it('should set loadingDisableCatalog to false', async () => {
+ store.state.WhatsAppCloud.loadingDisableCatalog = true;
+ expect(store.state.WhatsAppCloud.loadingDisableCatalog).toBe(true);
+ await store.dispatch('WhatsAppCloud/disableWhatsAppCloudCatalogs', data);
+ expect(store.state.WhatsAppCloud.loadingDisableCatalog).toBe(false);
+ });
+
+ it('should set errorDisableCatalog as result data', async () => {
+ const error = { error: 'failed' };
+ WhatsAppCloudApi.disableWhatsAppCloudCatalogs.mockImplementation(() => {
+ return Promise.reject(error);
+ });
+ store.state.WhatsAppCloud.errorDisableCatalog = {};
+ expect(store.state.WhatsAppCloud.errorDisableCatalog).not.toEqual(error);
+ await store.dispatch('WhatsAppCloud/disableWhatsAppCloudCatalogs', data);
+ expect(store.state.WhatsAppCloud.errorDisableCatalog).toEqual(error);
+ });
+ });
+
+ describe('enableWhatsAppCloudCatalogs()', () => {
+ const data = {
+ code: 'code',
+ appUuid: '123',
+ catalogUuid: '123',
+ };
+
+ const mockedResult = { status: 'ok' };
+
+ beforeEach(() => {
+ jest.resetAllMocks();
+
+ WhatsAppCloudApi.enableWhatsAppCloudCatalogs.mockImplementation(() => {
+ return Promise.resolve({ data: mockedResult });
+ });
+ });
+
+ it('should call enableWhatsAppCloudCatalogs from API', async () => {
+ expect(WhatsAppCloudApi.enableWhatsAppCloudCatalogs).not.toHaveBeenCalled();
+ await store.dispatch('WhatsAppCloud/enableWhatsAppCloudCatalogs', data);
+ expect(WhatsAppCloudApi.enableWhatsAppCloudCatalogs).toHaveBeenCalledTimes(1);
+ expect(WhatsAppCloudApi.enableWhatsAppCloudCatalogs).toHaveBeenCalledWith(
+ data.appUuid,
+ data.catalogUuid,
+ );
+ });
+
+ it('should set enabledCatalog as result data', async () => {
+ store.state.WhatsAppCloud.enabledCatalog = {};
+ expect(store.state.WhatsAppCloud.enabledCatalog).not.toEqual(mockedResult);
+ await store.dispatch('WhatsAppCloud/enableWhatsAppCloudCatalogs', data);
+ expect(store.state.WhatsAppCloud.enabledCatalog).toEqual(mockedResult);
+ });
+
+ it('should set loadingEnableCatalog to false', async () => {
+ store.state.WhatsAppCloud.loadingEnableCatalog = true;
+ expect(store.state.WhatsAppCloud.loadingEnableCatalog).toBe(true);
+ await store.dispatch('WhatsAppCloud/enableWhatsAppCloudCatalogs', data);
+ expect(store.state.WhatsAppCloud.loadingEnableCatalog).toBe(false);
+ });
+
+ it('should set errorEnableCatalog as result data', async () => {
+ const error = { error: 'failed' };
+ WhatsAppCloudApi.enableWhatsAppCloudCatalogs.mockImplementation(() => {
+ return Promise.reject(error);
+ });
+ store.state.WhatsAppCloud.errorEnableCatalog = {};
+ expect(store.state.WhatsAppCloud.errorEnableCatalog).not.toEqual(error);
+ await store.dispatch('WhatsAppCloud/enableWhatsAppCloudCatalogs', data);
+ expect(store.state.WhatsAppCloud.errorEnableCatalog).toEqual(error);
+ });
+ });
+
+ describe('toggleCartVisibility()', () => {
+ const data = {
+ code: 'code',
+ appUuid: '123',
+ payload: {
+ catalogUuid: '123',
+ },
+ };
+
+ const mockedResult = { status: 'ok' };
+
+ beforeEach(() => {
+ jest.resetAllMocks();
+
+ WhatsAppCloudApi.toggleCartVisibility.mockImplementation(() => {
+ return Promise.resolve({ data: mockedResult });
+ });
+ });
+
+ it('should call toggleCartVisibility from API', async () => {
+ expect(WhatsAppCloudApi.toggleCartVisibility).not.toHaveBeenCalled();
+ await store.dispatch('WhatsAppCloud/toggleCartVisibility', data);
+ expect(WhatsAppCloudApi.toggleCartVisibility).toHaveBeenCalledTimes(1);
+ expect(WhatsAppCloudApi.toggleCartVisibility).toHaveBeenCalledWith(
+ data.appUuid,
+ data.payload,
+ );
+ });
+
+ it('should set toggledCartVisibility as result data', async () => {
+ store.state.WhatsAppCloud.toggledCartVisibility = {};
+ expect(store.state.WhatsAppCloud.toggledCartVisibility).not.toEqual(mockedResult);
+ await store.dispatch('WhatsAppCloud/toggleCartVisibility', data);
+ expect(store.state.WhatsAppCloud.toggledCartVisibility).toEqual(mockedResult);
+ });
+
+ it('should set loadingToggleCartVisibility to false', async () => {
+ store.state.WhatsAppCloud.loadingToggleCartVisibility = true;
+ expect(store.state.WhatsAppCloud.loadingToggleCartVisibility).toBe(true);
+ await store.dispatch('WhatsAppCloud/toggleCartVisibility', data);
+ expect(store.state.WhatsAppCloud.loadingToggleCartVisibility).toBe(false);
+ });
+
+ it('should set errorToggleCartVisibility as result data', async () => {
+ const error = { error: 'failed' };
+ WhatsAppCloudApi.toggleCartVisibility.mockImplementation(() => {
+ return Promise.reject(error);
+ });
+ store.state.WhatsAppCloud.errorToggleCartVisibility = {};
+ expect(store.state.WhatsAppCloud.errorToggleCartVisibility).not.toEqual(error);
+ await store.dispatch('WhatsAppCloud/toggleCartVisibility', data);
+ expect(store.state.WhatsAppCloud.errorToggleCartVisibility).toEqual(error);
+ });
+ });
+
+ describe('toggleCatalogVisibility()', () => {
+ const data = {
+ code: 'code',
+ appUuid: '123',
+ payload: {
+ catalogUuid: '123',
+ },
+ };
+
+ const mockedResult = { status: 'ok' };
+
+ beforeEach(() => {
+ jest.resetAllMocks();
+
+ WhatsAppCloudApi.toggleCatalogVisibility.mockImplementation(() => {
+ return Promise.resolve({ data: mockedResult });
+ });
+ });
+
+ it('should call toggleCatalogVisibility from API', async () => {
+ expect(WhatsAppCloudApi.toggleCatalogVisibility).not.toHaveBeenCalled();
+ await store.dispatch('WhatsAppCloud/toggleCatalogVisibility', data);
+ expect(WhatsAppCloudApi.toggleCatalogVisibility).toHaveBeenCalledTimes(1);
+ expect(WhatsAppCloudApi.toggleCatalogVisibility).toHaveBeenCalledWith(
+ data.appUuid,
+ data.payload,
+ );
+ });
+
+ it('should set toggledCatalogVisibility as result data', async () => {
+ store.state.WhatsAppCloud.toggledCatalogVisibility = {};
+ expect(store.state.WhatsAppCloud.toggledCatalogVisibility).not.toEqual(mockedResult);
+ await store.dispatch('WhatsAppCloud/toggleCatalogVisibility', data);
+ expect(store.state.WhatsAppCloud.toggledCatalogVisibility).toEqual(mockedResult);
+ });
+
+ it('should set loadingToggleCatalogVisibility to false', async () => {
+ store.state.WhatsAppCloud.loadingToggleCatalogVisibility = true;
+ expect(store.state.WhatsAppCloud.loadingToggleCatalogVisibility).toBe(true);
+ await store.dispatch('WhatsAppCloud/toggleCatalogVisibility', data);
+ expect(store.state.WhatsAppCloud.loadingToggleCatalogVisibility).toBe(false);
+ });
+
+ it('should set errorToggleCatalogVisibility as result data', async () => {
+ const error = { error: 'failed' };
+ WhatsAppCloudApi.toggleCatalogVisibility.mockImplementation(() => {
+ return Promise.reject(error);
+ });
+ store.state.WhatsAppCloud.errorToggleCatalogVisibility = {};
+ expect(store.state.WhatsAppCloud.errorToggleCatalogVisibility).not.toEqual(error);
+ await store.dispatch('WhatsAppCloud/toggleCatalogVisibility', data);
+ expect(store.state.WhatsAppCloud.errorToggleCatalogVisibility).toEqual(error);
+ });
+ });
+
+ describe('getCommerceSettings()', () => {
+ const data = {
+ code: 'code',
+ appUuid: '123',
+ };
+
+ const mockedResult = { data: ['ok'] };
+
+ beforeEach(() => {
+ jest.resetAllMocks();
+
+ WhatsAppCloudApi.getCommerceSettings.mockImplementation(() => {
+ return Promise.resolve({ data: mockedResult });
+ });
+ });
+
+ it('should call getCommerceSettings from API', async () => {
+ expect(WhatsAppCloudApi.getCommerceSettings).not.toHaveBeenCalled();
+ await store.dispatch('WhatsAppCloud/getCommerceSettings', data);
+ expect(WhatsAppCloudApi.getCommerceSettings).toHaveBeenCalledTimes(1);
+ expect(WhatsAppCloudApi.getCommerceSettings).toHaveBeenCalledWith(data.appUuid);
+ });
+
+ it('should set commerceSettings as result data', async () => {
+ store.state.WhatsAppCloud.commerceSettings = {};
+ expect(store.state.WhatsAppCloud.commerceSettings).not.toEqual(mockedResult.data[0]);
+ await store.dispatch('WhatsAppCloud/getCommerceSettings', data);
+ expect(store.state.WhatsAppCloud.commerceSettings).toEqual(mockedResult.data[0]);
+ });
+
+ it('should set loadingCommerceSettings to false', async () => {
+ store.state.WhatsAppCloud.loadingCommerceSettings = true;
+ expect(store.state.WhatsAppCloud.loadingCommerceSettings).toBe(true);
+ await store.dispatch('WhatsAppCloud/getCommerceSettings', data);
+ expect(store.state.WhatsAppCloud.loadingCommerceSettings).toBe(false);
+ });
+
+ it('should set errorCommerceSettings as result data', async () => {
+ const error = { error: 'failed' };
+ WhatsAppCloudApi.getCommerceSettings.mockImplementation(() => {
+ return Promise.reject(error);
+ });
+ store.state.WhatsAppCloud.errorCommerceSettings = {};
+ expect(store.state.WhatsAppCloud.errorCommerceSettings).not.toEqual(error);
+ await store.dispatch('WhatsAppCloud/getCommerceSettings', data);
+ expect(store.state.WhatsAppCloud.errorCommerceSettings).toEqual(error);
+ });
+ });
});