import CustomerMap from '@/views/customer/map.vue' import { getparameter } from '@/api/system/dictionary' jest.mock('@/api/system/dictionary', () => ({ getparameter: jest.fn() })) jest.mock('@/api/customer', () => ({ getList: jest.fn() })) jest.mock('@/utils/auth', () => ({ getAuthAreas: () => [], getAuthTypes: () => [] })) jest.mock('@/utils/tianditu', () => ({})) describe('customer map with an empty local database', () => { beforeEach(() => getparameter.mockReset()) it('does not stop map initialization when the city dictionary is missing', async() => { getparameter.mockResolvedValue(null) const state = { areas: [], areaMap: new Map(), selector: { area_id: '' } } await CustomerMap.methods.getAreas.call(state) expect(state.areas).toEqual([]) expect(state.selector.area_id).toBe('') }) it('tolerates a city without a child area dictionary', async() => { getparameter.mockResolvedValueOnce({ detail: [{ id: 1, value: '常州市' }] }).mockResolvedValueOnce(null) const state = { areas: [], areaMap: new Map(), selector: { area_id: '' } } await CustomerMap.methods.getAreas.call(state) expect(state.areas[0].children).toEqual([]) }) })