61 lines
1.8 KiB
TypeScript
61 lines
1.8 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
import {
|
|
buildThirdPartyMapSearchUri,
|
|
openThirdPartyMapSearch
|
|
} from '@/services/ThirdPartyMapSearchService'
|
|
|
|
afterEach(() => {
|
|
vi.unstubAllGlobals()
|
|
})
|
|
|
|
describe('H5 第三方地图服务', () => {
|
|
it('安全编码中文、空格和特殊字符', () => {
|
|
const uri = buildThirdPartyMapSearchUri('amap', {
|
|
keyword: '深圳自然博物馆 A&B',
|
|
region: '深圳 市'
|
|
})
|
|
|
|
expect(uri).toContain('keyword=%E6%B7%B1%E5%9C%B3%E8%87%AA%E7%84%B6%E5%8D%9A%E7%89%A9%E9%A6%86%20A%26B')
|
|
expect(uri).toContain('city=%E6%B7%B1%E5%9C%B3%20%E5%B8%82')
|
|
})
|
|
|
|
it.each([
|
|
['amap', 'https://uri.amap.com/search?'],
|
|
['baidu', 'https://api.map.baidu.com/place/search?'],
|
|
['tencent', 'https://apis.map.qq.com/uri/v1/search?']
|
|
] as const)('%s 使用对应的地图网页入口', (provider, expectedPrefix) => {
|
|
expect(buildThirdPartyMapSearchUri(provider, {
|
|
keyword: '深圳自然博物馆',
|
|
region: '深圳市'
|
|
})).toMatch(expectedPrefix)
|
|
})
|
|
|
|
it('浏览器中直接跳转到选中的第三方地图', () => {
|
|
const location = { href: 'https://guide.example.com/' }
|
|
vi.stubGlobal('window', { location })
|
|
|
|
openThirdPartyMapSearch('tencent', {
|
|
keyword: '深圳自然博物馆',
|
|
region: '深圳市'
|
|
})
|
|
|
|
expect(location.href).toContain('https://apis.map.qq.com/uri/v1/search?')
|
|
})
|
|
|
|
it('缺少浏览器环境时提供可见提示', () => {
|
|
const showToast = vi.fn()
|
|
vi.stubGlobal('window', undefined)
|
|
vi.stubGlobal('uni', { showToast })
|
|
|
|
openThirdPartyMapSearch('baidu', {
|
|
keyword: '深圳自然博物馆',
|
|
region: '深圳市'
|
|
})
|
|
|
|
expect(showToast).toHaveBeenCalledWith({
|
|
title: '请在 H5 浏览器中打开地图',
|
|
icon: 'none'
|
|
})
|
|
})
|
|
})
|