clone

an offline map explorer where each world, from a game map to a city's open data, ships as one .atlas file

main
atlas / internal / app / legend_test.go
legend_test.go 3.7K
1package app23import "testing"45// The two facts a legend row carries about what a collection looks like: the6// colour it wears, and where its artwork lives. Both had to be checked against7// the seam rather than against themselves, because the disagreement they are8// here to prevent is between two surfaces drawing one world.910// The seam's ladder is `collection.color || collection.iconColor ||11// paletteColor(ordinal)` (render/chart/styles.ts, collectionColor). A curated12// volume declares a colour and any ladder agrees with any other; an enriched13// one -- a city -- declares none, and the fallback is the whole question.14func TestCollectionColorIsTheSeamsLadder(t *testing.T) {15 cases := []struct {16 name string17 collection collectionModel18 want string19 }{20 {21 name: "a declared colour wins",22 collection: collectionModel{ID: "1496244488", Color: "#6984F2", Index: 3},23 want: "#6984F2",24 },25 {26 name: "the older spelling is still a declaration",27 collection: collectionModel{ID: "1496244488", IconColor: "#E25598", Index: 3},28 want: "#E25598",29 },30 {31 name: "an undeclared colour is the palette by payload order",32 collection: collectionModel{ID: "1496244488", Index: 0},33 want: palette[0],34 },35 {36 name: "and it keeps counting round the wheel",37 collection: collectionModel{ID: "39191589", Index: len(palette) + 2},38 want: palette[2],39 },40 }41 for _, tt := range cases {42 t.Run(tt.name, func(t *testing.T) {43 if got := collectionColor(&tt.collection); got != tt.want {44 t.Errorf("collectionColor = %q, want %q", got, tt.want)45 }46 })47 }48}4950// The bend-or fixture's own collection: a city's Historic Resources, which51// declares no colour and carries a standard glyph. It is the case the reader52// reported -- a green swatch beside a blue pin -- and it is first in the53// payload, so the seam draws it in the wheel's first colour.54func TestACityCollectionWearsTheColourTheMapDraws(t *testing.T) {55 historic := &collectionModel{ID: "1496244488", Title: "Historic Resources", Index: 0}56 if got, want := collectionColor(historic), "#4fb3d5"; got != want {57 t.Errorf("Historic Resources wears %q; the chart draws it %q", got, want)58 }59 if colorFor(historic.ID) == collectionColor(historic) {60 // The test stands on the two paths disagreeing for this id. If a61 // palette change ever makes them agree, this data proves nothing and62 // must be re-picked -- loudly, not quietly.63 t.Fatal("the feature hash agrees with the wheel here, so this world proves nothing: pick an id whose two colours differ")64 }65}6667// The seam names an asset one way (render/data/plane.ts, iconURL) and the68// legend has to name it the same way, or one picture is fetched twice and the69// row and the pins it stands for are drawn from two downloads.70func TestIconAssetURLIsSpelledTheWayTheSeamSpellsIt(t *testing.T) {71 const base = "/data/v/fallout/abc123abc123"72 cases := []struct {73 asset string74 want string75 }{76 {"vault.svg", base + "/icons/vault.svg"},77 {"std--maki-monument.svg", base + "/icons/std--maki-monument.svg"},78 // The seam's own case, from render/test/markers.test.ts: the79 // separators stay separators, the brackets stay brackets, and the80 // space goes on the wire encoded.81 {"signs/Vault 101 (Ext).png", base + "/icons/signs/Vault%20101%20(Ext).png"},82 {"a&b.svg", base + "/icons/a%26b.svg"},83 }84 for _, tt := range cases {85 if got := iconAssetURL(base, tt.asset); got != tt.want {86 t.Errorf("iconAssetURL(%q) = %q, want %q", tt.asset, got, tt.want)87 }88 }89 if got := iconAssetURL(base, ""); got != "" {90 t.Errorf("a collection with no artwork named %q; it has no URL to give", got)91 }92 if got := iconAssetURL("", "vault.svg"); got != "" {93 t.Errorf("an asset with no build to hang off named %q", got)94 }95}