|
| 1 | +import { test, expect } from '@playwright/test' |
| 2 | +import { parseList, parseAliases, filterArtefacts } from '../src/config-parse.ts' |
| 3 | + |
| 4 | +const artefact = (id: string) => ({ _id: id, name: id, category: 'tileset', format: 'file' }) |
| 5 | + |
| 6 | +test.describe('parseList', () => { |
| 7 | + test('returns empty array for empty string', () => { |
| 8 | + expect(parseList('')).toEqual([]) |
| 9 | + }) |
| 10 | + |
| 11 | + test('splits comma-separated values', () => { |
| 12 | + expect(parseList('a,b,c')).toEqual(['a', 'b', 'c']) |
| 13 | + }) |
| 14 | + |
| 15 | + test('trims whitespace', () => { |
| 16 | + expect(parseList(' a , b , c ')).toEqual(['a', 'b', 'c']) |
| 17 | + }) |
| 18 | + |
| 19 | + test('filters out empty segments', () => { |
| 20 | + expect(parseList('a,,b,')).toEqual(['a', 'b']) |
| 21 | + }) |
| 22 | +}) |
| 23 | + |
| 24 | +test.describe('parseAliases', () => { |
| 25 | + test('returns empty object for empty string', () => { |
| 26 | + expect(parseAliases('')).toEqual({}) |
| 27 | + }) |
| 28 | + |
| 29 | + test('parses source:alias pairs', () => { |
| 30 | + expect(parseAliases('world:france')).toEqual({ world: 'france' }) |
| 31 | + }) |
| 32 | + |
| 33 | + test('parses multiple pairs', () => { |
| 34 | + expect(parseAliases('world:france,contours-2026:contours')).toEqual({ |
| 35 | + world: 'france', |
| 36 | + 'contours-2026': 'contours' |
| 37 | + }) |
| 38 | + }) |
| 39 | + |
| 40 | + test('trims whitespace around keys and values', () => { |
| 41 | + expect(parseAliases(' world : france , foo : bar ')).toEqual({ |
| 42 | + world: 'france', |
| 43 | + foo: 'bar' |
| 44 | + }) |
| 45 | + }) |
| 46 | + |
| 47 | + test('skips malformed entries without colon', () => { |
| 48 | + expect(parseAliases('good:pair,nocolon,also:fine')).toEqual({ |
| 49 | + good: 'pair', |
| 50 | + also: 'fine' |
| 51 | + }) |
| 52 | + }) |
| 53 | + |
| 54 | + test('skips entries with empty source or alias', () => { |
| 55 | + expect(parseAliases(':alias,source:,ok:ok')).toEqual({ ok: 'ok' }) |
| 56 | + }) |
| 57 | +}) |
| 58 | + |
| 59 | +test.describe('filterArtefacts', () => { |
| 60 | + const all = [artefact('a'), artefact('b'), artefact('c')] |
| 61 | + |
| 62 | + test('returns all when include and exclude are empty', () => { |
| 63 | + expect(filterArtefacts(all, [], [])).toEqual(all) |
| 64 | + }) |
| 65 | + |
| 66 | + test('include keeps only matching artefacts', () => { |
| 67 | + const result = filterArtefacts(all, ['a', 'c'], []) |
| 68 | + expect(result.map(a => a._id)).toEqual(['a', 'c']) |
| 69 | + }) |
| 70 | + |
| 71 | + test('exclude removes matching artefacts', () => { |
| 72 | + const result = filterArtefacts(all, [], ['b']) |
| 73 | + expect(result.map(a => a._id)).toEqual(['a', 'c']) |
| 74 | + }) |
| 75 | + |
| 76 | + test('include and exclude combine (include first, then exclude)', () => { |
| 77 | + const result = filterArtefacts(all, ['a', 'b'], ['b']) |
| 78 | + expect(result.map(a => a._id)).toEqual(['a']) |
| 79 | + }) |
| 80 | + |
| 81 | + test('include with no matches returns empty', () => { |
| 82 | + expect(filterArtefacts(all, ['x'], [])).toEqual([]) |
| 83 | + }) |
| 84 | + |
| 85 | + test('exclude with no matches returns all', () => { |
| 86 | + expect(filterArtefacts(all, [], ['x'])).toEqual(all) |
| 87 | + }) |
| 88 | +}) |
0 commit comments