import { fireEvent, render } from '@@/test/kalimotxo-test-utils' import KaCallModule from './KaCallModule.vue' import * as createPhoneLeadApplication from '@kalimotxo/application/CallMe/createPhoneLead' describe('KaCallModule should', () => { test('Show correct copies if is work time', () => { const { getByText, getByTestId } = renderComponent() expect(getByTestId('ka-call-module__phone-label')).toHaveTextContent( 'Déjanos tu número y un asesor virtual te llamará ahora:', ) expect(getByText('Contactar con un Asesor Virtual')).toBeInTheDocument() }) test('Show correct copies if is NOT work time', () => { const { getByText, getByTestId } = renderComponent({ isWorkTime: { default: false }, }) expect(getByTestId('ka-call-module__phone-label')).toHaveTextContent( 'Déjanos tu número y un asesor virtual te llamará ahora:', ) expect(getByText('Contactar con un Asesor Virtual')).toBeInTheDocument() }) describe('pass the current URL to createPhoneLead', () => { test('when referer prop is not provided', async () => { const spyFn = jest.fn() jest .spyOn(createPhoneLeadApplication, 'handleCreatePhoneLead') .mockImplementation(() => { return { execute: spyFn, } }) const { getByRole } = renderComponent() await fireEvent.update(getByRole('textbox'), '612345678') await fireEvent.click(getByRole('checkbox')) await fireEvent.click(getByRole('button')) expect(spyFn).toHaveBeenCalledWith( expect.objectContaining({ url: location.href, }), expect.anything(), ) }) test('when referer prop is provided', async () => { const spyFn = jest.fn() jest .spyOn(createPhoneLeadApplication, 'handleCreatePhoneLead') .mockImplementation(() => { return { execute: spyFn, } }) const testReferer = 'https://example.com/some-page' const { getByRole } = renderComponent({ referer: testReferer, }) await fireEvent.update(getByRole('textbox'), '612345678') await fireEvent.click(getByRole('checkbox')) await fireEvent.click(getByRole('button')) expect(spyFn).toHaveBeenCalledWith( expect.objectContaining({ url: testReferer, }), expect.anything(), ) }) }) }) function renderComponent({ isWorkTime = { default: true }, referer = '', } = {}) { const view = render(KaCallModule, { props: { eventLabel: 'irrelevant', eventCategory: 'irrelevant', referer, }, mocks: { $isWorkTime: Promise.resolve(isWorkTime), }, }) return { ...view } }