| import { describe, it, expect, vi } from 'vitest' |
| import { mount } from '@vue/test-utils' |
| import ButtonMapSendRequest from '@/components/buttons/ButtonMapSendRequest.vue' |
|
|
| |
| |
| |
| |
| |
| const mockMap = {} as any |
|
|
| const samplePrompt = { id: 1, type: 'point', data: { lat: 45, lng: 9 }, label: 1 } |
|
|
| const baseProps = { |
| class: 'test-class', |
| currentBaseMapName: 'OpenStreetMap', |
| promptsArray: [samplePrompt], |
| responseMessage: '-', |
| map: mockMap, |
| sendMLRequest: vi.fn(), |
| waitingString: 'waiting...', |
| } |
|
|
| describe('ButtonMapSendRequest', () => { |
| |
| it('shows disabled button with empty prompt text when promptsArray is empty', () => { |
| const wrapper = mount(ButtonMapSendRequest, { |
| props: { ...baseProps, promptsArray: [] }, |
| }) |
| const button = wrapper.find('button') |
| expect(button.text()).toContain('Empty prompt (disabled)') |
| expect(button.attributes('disabled')).toBeDefined() |
| }) |
|
|
| |
| it('shows disabled button with waitingString when responseMessage equals waitingString', () => { |
| const wrapper = mount(ButtonMapSendRequest, { |
| props: { ...baseProps, responseMessage: 'waiting...' }, |
| }) |
| const button = wrapper.find('button') |
| expect(button.text()).toBe('waiting...') |
| expect(button.attributes('disabled')).toBeDefined() |
| }) |
|
|
| it('waiting state takes priority over empty prompt when both conditions true', () => { |
| const wrapper = mount(ButtonMapSendRequest, { |
| props: { ...baseProps, promptsArray: [], responseMessage: 'waiting...' }, |
| }) |
| expect(wrapper.find('button').text()).toBe('waiting...') |
| }) |
|
|
| |
| it('shows send ML request text when prompts present and responseMessage is "-"', () => { |
| const wrapper = mount(ButtonMapSendRequest, { props: baseProps }) |
| expect(wrapper.find('button').text()).toContain('send ML request') |
| }) |
|
|
| it('shows send ML request text when prompts present and responseMessage is empty', () => { |
| const wrapper = mount(ButtonMapSendRequest, { |
| props: { ...baseProps, responseMessage: '' }, |
| }) |
| expect(wrapper.find('button').text()).toContain('send ML request') |
| }) |
|
|
| it('enabled button is not disabled', () => { |
| const wrapper = mount(ButtonMapSendRequest, { props: baseProps }) |
| expect(wrapper.find('button').attributes('disabled')).toBeUndefined() |
| }) |
|
|
| |
| it('shows responseMessage when truthy and not "-"', () => { |
| const wrapper = mount(ButtonMapSendRequest, { |
| props: { ...baseProps, responseMessage: 'error: timeout' }, |
| }) |
| expect(wrapper.find('button').text()).toBe('error: timeout') |
| }) |
|
|
| |
| it('calls sendMLRequest with map, promptsArray, currentBaseMapName on click', async () => { |
| const sendFn = vi.fn() |
| const wrapper = mount(ButtonMapSendRequest, { |
| props: { ...baseProps, sendMLRequest: sendFn }, |
| }) |
| await wrapper.find('button').trigger('click') |
| expect(sendFn).toHaveBeenCalledOnce() |
| expect(sendFn).toHaveBeenCalledWith(mockMap, [samplePrompt], 'OpenStreetMap') |
| }) |
| }) |
|
|