diff --git a/src/components/chats/ContactInfo/ModalStartDiscussion.vue b/src/components/chats/ContactInfo/ModalStartDiscussion.vue index f07ee0be..abbcaa6e 100644 --- a/src/components/chats/ContactInfo/ModalStartDiscussion.vue +++ b/src/components/chats/ContactInfo/ModalStartDiscussion.vue @@ -4,7 +4,10 @@ :text="$t('discussions.start_discussion.title')" @close="close" > -
+
@@ -29,6 +33,7 @@ autocomplete autocompleteIconLeft autocompleteClearOnFocus + data-testid="select-queue" />
@@ -38,6 +43,7 @@ :maxlength="50" :placeholder="$t('discussions.start_discussion.form.discussion_reason')" :label="$t('discussions.start_discussion.form.subject')" + data-testid="input-subject" />
diff --git a/src/components/chats/ContactInfo/__tests__/ModalStartDiscussion.spec.js b/src/components/chats/ContactInfo/__tests__/ModalStartDiscussion.spec.js new file mode 100644 index 00000000..5b4751d2 --- /dev/null +++ b/src/components/chats/ContactInfo/__tests__/ModalStartDiscussion.spec.js @@ -0,0 +1,138 @@ +import { describe, it, expect, beforeEach, vi } from 'vitest'; +import { flushPromises, mount } from '@vue/test-utils'; + +import ModalStartDiscussion from '../ModalStartDiscussion.vue'; + +import { createTestingPinia } from '@pinia/testing'; +import { createMemoryHistory, createRouter } from 'vue-router'; + +import { useDiscussions } from '@/store/modules/chats/discussions'; + +import Queue from '@/services/api/resources/settings/queue'; + +vi.mock('@/services/api/resources/chats/discussion', () => ({ + default: { + getSectors: vi.fn(() => + Promise.resolve({ results: [{ uuid: '1', name: 'Sector' }] }), + ), + }, +})); + +vi.mock('@/services/api/resources/settings/queue', () => ({ + default: { + list: vi.fn(() => + Promise.resolve({ results: [{ uuid: '1', name: 'Queue' }] }), + ), + }, +})); + +const routes = [{ path: '/settings', name: 'settings' }]; +const router = createRouter({ + history: createMemoryHistory(), + routes, +}); + +router.push = vi.fn(); + +describe('ModalStartDiscussion', () => { + let wrapper; + let discussionsStore; + + beforeEach(() => { + wrapper = mount(ModalStartDiscussion, { + global: { plugins: [createTestingPinia({ stubActions: true }), router] }, + }); + discussionsStore = useDiscussions(); + }); + + it('renders correctly with initial data', () => { + expect(wrapper.find('[data-testid="start-discussion-form"]').exists()).toBe( + true, + ); + + expect( + wrapper.findComponent('[data-testid="select-sector"]').exists(), + ).toBe(true); + + expect(wrapper.findComponent('[data-testid="select-queue"]').exists()).toBe( + true, + ); + + expect( + wrapper.findComponent('[data-testid="input-subject"]').exists(), + ).toBe(true); + + expect( + wrapper.findComponent('[data-testid="input-explain-situation"]').exists(), + ).toBe(true); + }); + + it('enables confirm button only when all fields are filled', async () => { + const confirmButton = wrapper.findComponent( + '[data-testid="confirm-button"]', + ); + + expect(confirmButton.props('disabled')).toBe(true); + + await wrapper.setData({ + sector: [{ value: '1', label: 'Sector' }], + queue: [{ value: '1', label: 'Queue' }], + subject: 'Test Subject', + message: 'Test Message', + }); + + await wrapper.vm.$nextTick(); + + await expect(confirmButton.props('disabled')).toBe(false); + }); + + it('should emit close event on click cancel button', async () => { + const closeSpy = vi.spyOn(wrapper.vm, 'close'); + const cancelButton = wrapper.findComponent('[data-testid="cancel-button"]'); + await cancelButton.trigger('click'); + expect(closeSpy).toHaveBeenCalled(); + expect(wrapper.emitted('close')).toBeTruthy(); + }); + + it('loads queues when sector is selected', async () => { + await wrapper.setData({ sector: [{ value: '1', label: 'Sector' }] }); + + expect(Queue.list).toHaveBeenCalledWith('1'); + + expect(wrapper.vm.queuesToSelect).toEqual([ + { + value: '', + label: wrapper.vm.$t('discussions.start_discussion.form.search_queue'), + }, + { value: '1', label: 'Queue' }, + ]); + }); + + it('creates a new discussion and redirects', async () => { + await wrapper.setData({ + sector: [{ value: '1', label: 'Sector' }], + queue: [{ value: '1', label: 'Queue' }], + subject: 'Test Subject', + message: 'Test Message', + }); + + await flushPromises(); + + discussionsStore.create = vi.fn(() => Promise.resolve({ uuid: '1' })); + + await wrapper + .findComponent('[data-testid="confirm-button"]') + .trigger('click'); + + expect(discussionsStore.create).toHaveBeenCalledWith({ + queue: '1', + subject: 'Test Subject', + initial_message: 'Test Message', + }); + + expect(wrapper.vm.$router.push).toHaveBeenCalledWith({ + name: 'discussion', + params: { discussionId: '1' }, + }); + }); +}); diff --git a/src/components/chats/FlowsTrigger/ModalAddNewContact.vue b/src/components/chats/FlowsTrigger/ModalAddNewContact.vue index 5aa75aa8..a79d7b92 100644 --- a/src/components/chats/FlowsTrigger/ModalAddNewContact.vue +++ b/src/components/chats/FlowsTrigger/ModalAddNewContact.vue @@ -3,6 +3,7 @@
@@ -27,6 +30,7 @@ v-if="!isMobile" :text="$t('cancel')" type="secondary" + data-testid="cancel-button" @click="$emit('close')" /> @@ -68,7 +73,7 @@ export default { isValidForm() { const { contact, telMask } = this; - return ( + return !!( contact.name && (contact.tel.length === telMask.telephone.length || contact.tel.length === telMask.cellphone.length) diff --git a/src/components/chats/FlowsTrigger/ModalListTriggeredFlows.vue b/src/components/chats/FlowsTrigger/ModalListTriggeredFlows.vue index ab234b91..9f9225f6 100644 --- a/src/components/chats/FlowsTrigger/ModalListTriggeredFlows.vue +++ b/src/components/chats/FlowsTrigger/ModalListTriggeredFlows.vue @@ -1,8 +1,8 @@ -