garage44.eu/jeroen/cartopolis

logclone: git clone https://garage44.eu/jeroen/cartopolis.git

.. /crates/atlas/web/src/lib/feeds.test.ts

raw

import {describe, expect, test} from 'bun:test'

import {colour, PALETTE, project, publisherSlug, slug} from './feeds'

describe('data layers', () => {
    test('an id is made from a name the way atlas accepts it', () => {
        expect(slug('Stuwen — Noorderzijlvest')).toBe('stuwen-noorderzijlvest')
        expect(slug('Wetterskip Fryslân gemalen')).toBe('wetterskip-fryslan-gemalen')
        expect(slug('x'.repeat(60)).length).toBe(40)
        expect(publisherSlug('https://www.triplexl.nl/datasets/archixl/hunzeenaas/')).toBe('hunzeenaas')
    })

    test('a value past the key is other, no colour column is the first colour', () => {
        expect(colour(-1)).toBe(PALETTE[0])
        expect(colour(2)).toBe(PALETTE[2])
        expect(colour(99)).toBe(PALETTE[7])
    })

    test('the preview keeps north up and fits the box', () => {
        const pts = project(
            [
                [53.3, 6.5, 0],
                [53.1, 6.7, 1],
            ],
            200,
            100,
            10,
        )
        // North is up: the first point (further north) is higher on the screen.
        expect(pts[0][1]).toBeLessThan(pts[1][1])
        for (const [x, y] of pts) {
            expect(x).toBeGreaterThanOrEqual(10)
            expect(x).toBeLessThanOrEqual(190)
            expect(y).toBeGreaterThanOrEqual(10)
            expect(y).toBeLessThanOrEqual(90)
        }
        expect(project([], 10, 10)).toEqual([])
    })
})