Download static/tests/ButtonMapSendRequest.test.ts from aletrn/samgis: direct link, hf CLI and curl.
- Browser
- Download file 3.77 kB
-
https://huggingface.co/spaces/aletrn/samgis/resolve/main/static/tests/ButtonMapSendRequest.test.ts
- Command line
-
hf download hf://spaces/aletrn/samgis/static/tests/ButtonMapSendRequest.test.ts
-
curl -L -o ButtonMapSendRequest.test.ts https://huggingface.co/spaces/aletrn/samgis/resolve/main/static/tests/ButtonMapSendRequest.test.ts
3.77 kB
| import { describe, it, expect, vi } from 'vitest' | |
| import { mount } from '@vue/test-utils' | |
| import ButtonMapSendRequest from '@/components/buttons/ButtonMapSendRequest.vue' | |
| /** | |
| * The `map` prop expects a Leaflet LMap instance. | |
| * We pass a plain object since the component only forwards it to sendMLRequest β | |
| * no Leaflet methods are called directly by this component. | |
| */ | |
| 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', () => { | |
| // ββ State 1: empty prompt ββββββββββββββββββββββββββββββ | |
| 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() | |
| }) | |
| // ββ State 2: waiting βββββββββββββββββββββββββββββββββββ | |
| 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...') | |
| }) | |
| // ββ State 3: ready (default) βββββββββββββββββββββββββββ | |
| 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() | |
| }) | |
| // ββ State 4: has response message ββββββββββββββββββββββ | |
| it('shows responseMessage when truthy and not "-"', () => { | |
| const wrapper = mount(ButtonMapSendRequest, { | |
| props: { ...baseProps, responseMessage: 'error: timeout' }, | |
| }) | |
| expect(wrapper.find('button').text()).toBe('error: timeout') | |
| }) | |
| // ββ Click behavior βββββββββββββββββββββββββββββββββββββ | |
| 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') | |
| }) | |
| }) | |