|
1 | 1 | import { describe, it } from 'vitest'; |
2 | | -import { parsePB } from '../../../src/map/utils/parsePB'; |
| 2 | +import { parsePB, tileTypes } from '../../../src/map/utils/parsePB'; |
| 3 | +import { experiments } from 'webextension-polyfill'; |
3 | 4 |
|
4 | 5 | describe.concurrent('Parse PB', () => { |
5 | | - it('empty', ({ expect }) => { |
| 6 | + it('empty list', ({ expect }) => { |
6 | 7 | const res = parsePB([]); |
| 8 | + |
7 | 9 | expect(res).empty; |
| 10 | + expect(res).toEqual([]); |
| 11 | + }); |
| 12 | + |
| 13 | + it('contains empty list', ({ expect }) => { |
| 14 | + const res = parsePB(['1m0']); |
| 15 | + |
| 16 | + expect(res).toStrictEqual([[]]); |
| 17 | + }); |
| 18 | + |
| 19 | + it('double', ({ expect }) => { |
| 20 | + const res = parsePB(['1d1.1'])[0]; |
| 21 | + |
| 22 | + expect(res).toBeTypeOf('number'); |
| 23 | + expect(res).toBe(1.1); |
| 24 | + }); |
| 25 | + |
| 26 | + it('float', ({ expect }) => { |
| 27 | + const res = parsePB(['1f1.1'])[0]; |
| 28 | + |
| 29 | + expect(res).toBeTypeOf('number'); |
| 30 | + expect(res).toBe(1.1); |
| 31 | + }); |
| 32 | + |
| 33 | + it('int', ({ expect }) => { |
| 34 | + const res = parsePB(['1i1'])[0]; |
| 35 | + |
| 36 | + expect(res).toBeTypeOf('number'); |
| 37 | + expect(res).toBe(1); |
| 38 | + expect(res).to; |
| 39 | + }); |
| 40 | + |
| 41 | + it('enum roadmap', ({ expect }) => { |
| 42 | + const res = parsePB(['1e0'])[0]; |
| 43 | + |
| 44 | + expect(res).toBeTypeOf('string'); |
| 45 | + expect(res).toBe('roadmap'); |
| 46 | + expect(res).toBe(tileTypes[0]); |
| 47 | + }); |
| 48 | + |
| 49 | + it('enum satellite', ({ expect }) => { |
| 50 | + const res = parsePB(['1e1'])[0]; |
| 51 | + |
| 52 | + expect(res).toBeTypeOf('string'); |
| 53 | + expect(res).toBe('satellite'); |
| 54 | + expect(res).toBe(tileTypes[1]); |
| 55 | + }); |
| 56 | + |
| 57 | + it('enum empty', ({ expect }) => { |
| 58 | + const res = parsePB(['1e'])[0]; |
| 59 | + |
| 60 | + expect(res).toBeTypeOf('string'); |
| 61 | + expect(res).toBe('roadmap'); |
| 62 | + expect(res).toBe(tileTypes[0]); |
| 63 | + }); |
| 64 | + |
| 65 | + it('enum >1', ({ expect }) => { |
| 66 | + const res = parsePB(['1e2'])[0]; |
| 67 | + |
| 68 | + expect(res).toBeTypeOf('string'); |
| 69 | + expect(res).toBe('roadmap'); |
| 70 | + expect(res).toBe(tileTypes[0]); |
| 71 | + }); |
| 72 | + |
| 73 | + it('wrongly encoded base64', ({ expect }) => { |
| 74 | + expect(() => parsePB(['1zM'])).toThrowError('The string to be decoded is not correctly encoded.'); |
| 75 | + }); |
| 76 | + |
| 77 | + it('base64 encoded coordinates', ({ expect }) => { |
| 78 | + const res = parsePB(['1zM'])[0]; |
| 79 | + |
| 80 | + expect(res).toBeTypeOf('string'); |
| 81 | + expect(res).toBe('M'); |
8 | 82 | }); |
9 | 83 | }); |
0 commit comments