forked from OurHike/OurHike
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharchiveZooms.test.ts
More file actions
50 lines (40 loc) · 1.71 KB
/
Copy patharchiveZooms.test.ts
File metadata and controls
50 lines (40 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { readArchiveZooms } from './archiveZooms'
// The client used to have no idea what the archive on the phone contained -
// it pointed a raster source at it and hoped, which is how #216 survived. What
// matters here is that not knowing is reported as not knowing, never as an
// absence of coverage.
const getHeader = vi.fn()
vi.mock('pmtiles', () => ({
PMTiles: class {
getHeader() {
return getHeader()
}
},
}))
beforeEach(() => {
getHeader.mockReset()
})
describe('readArchiveZooms', () => {
it('reports the range the archive declares', async () => {
getHeader.mockResolvedValue({ minZoom: 6, maxZoom: 12 })
expect(await readArchiveZooms('ourhike:corridor-archive')).toEqual({
minZoom: 6,
maxZoom: 12,
})
})
it('reports null rather than a guess when the archive is not there', async () => {
// IndexedDbArchiveSource throws ArchiveNotDownloadedError on a missing
// key. Answering "minZoom 0" here would be an invented fact, and callers
// would use it to claim the download covers ground it does not.
getHeader.mockRejectedValue(new Error('No offline map archive found'))
expect(await readArchiveZooms('ourhike:corridor-archive')).toBeNull()
})
it('reports null on a header too damaged to parse, rather than throwing', async () => {
// This runs on app start, off the back of a download that may have been
// interrupted (#197). An unhandled rejection here would be a broken app
// rather than a map with one fewer refinement.
getHeader.mockRejectedValue(new SyntaxError('bad magic number'))
expect(await readArchiveZooms('ourhike:corridor-archive')).toBeNull()
})
})