You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.9 KiB
46 lines
1.9 KiB
import Picker from '@/components/TiandituPicker'
|
|
import { reverseGeocode } from '@/utils/tianditu'
|
|
|
|
jest.mock('@/utils/tianditu', () => ({ reverseGeocode: jest.fn(), addMarker: jest.fn(), disposeMap: jest.fn() }))
|
|
|
|
const point = (lng, lat) => ({ getLng: () => lng, getLat: () => lat })
|
|
const state = () => ({ ...Picker.data(), _tdtMap: { clearOverLays: jest.fn() }, $message: { error: jest.fn() }, $emit: jest.fn() })
|
|
|
|
describe('shared Tianditu picker', () => {
|
|
beforeEach(() => reverseGeocode.mockReset())
|
|
it('keeps the newest selection when address responses arrive out of order', async() => {
|
|
let finishFirst
|
|
reverseGeocode.mockImplementationOnce(() => new Promise(resolve => { finishFirst = resolve })).mockResolvedValueOnce('第二个地址')
|
|
const vm = state()
|
|
const first = Picker.methods.select.call(vm, point(119.9, 31.7), 0)
|
|
await Picker.methods.select.call(vm, point(119.91, 31.71), 1)
|
|
finishFirst('第一个地址')
|
|
await first
|
|
expect(vm.address).toBe('第二个地址')
|
|
expect(vm.selectedIndex).toBe(1)
|
|
expect(vm.busy).toBe(false)
|
|
})
|
|
it('cannot confirm while the address is unresolved or a lookup failed', async() => {
|
|
const vm = state()
|
|
vm.point = point(119.9, 31.7)
|
|
vm.busy = true
|
|
Picker.methods.confirm.call(vm)
|
|
expect(vm.$emit).not.toHaveBeenCalled()
|
|
reverseGeocode.mockRejectedValue(new Error('unavailable'))
|
|
await Picker.methods.select.call(vm, vm.point)
|
|
Picker.methods.confirm.call(vm)
|
|
expect(vm.address).toBe('')
|
|
expect(vm.selectionError).toContain('地址查询失败')
|
|
expect(vm.$emit).not.toHaveBeenCalled()
|
|
})
|
|
it('returns the same coordinate/address array expected by both parent forms', () => {
|
|
const vm = state()
|
|
vm.visible = true
|
|
vm.point = point(-0.127, 51.507)
|
|
vm.address = '测试地址'
|
|
Picker.methods.confirm.call(vm)
|
|
expect(vm.$emit).toHaveBeenCalledWith('input', [-0.127, 51.507, '测试地址'])
|
|
expect(vm.visible).toBe(false)
|
|
})
|
|
})
|