|
8 | 8 | * disagrees between instances. |
9 | 9 | */ |
10 | 10 | import {describe, test, expect} from 'vitest'; |
11 | | -import {plopsaDecideOperating} from '../plopsa.js'; |
| 11 | +import type {Entity} from '@themeparks/typelib'; |
| 12 | +import {plopsaDecideOperating, Plopsaland} from '../plopsa.js'; |
12 | 13 |
|
13 | 14 | describe('plopsaDecideOperating', () => { |
14 | 15 | test('park closed → ride always CLOSED regardless of other inputs', () => { |
@@ -36,3 +37,100 @@ describe('plopsaDecideOperating', () => { |
36 | 37 | expect(plopsaDecideOperating(true, true, false)).toBe(false); |
37 | 38 | }); |
38 | 39 | }); |
| 40 | + |
| 41 | +describe('De Panne POI location wiring', () => { |
| 42 | + const fallbackLocation = {latitude: 1, longitude: 2}; |
| 43 | + |
| 44 | + class Probe extends Plopsaland { |
| 45 | + protected override mapCoordinates( |
| 46 | + coords: {x: number; y: number} | undefined, |
| 47 | + ): {latitude: number; longitude: number} | undefined { |
| 48 | + return coords ? fallbackLocation : undefined; |
| 49 | + } |
| 50 | + |
| 51 | + public buildEntitiesForTest(): Promise<Entity[]> { |
| 52 | + return this.buildEntityList(); |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + function jsonResponse(payload: unknown) { |
| 57 | + return {json: async () => payload}; |
| 58 | + } |
| 59 | + |
| 60 | + function createProbe(poiItems: unknown[]): Probe { |
| 61 | + const park = new Probe(); |
| 62 | + park.fetchPOI = async () => jsonResponse({items: poiItems}) as any; |
| 63 | + park.fetchEntertainments = async () => jsonResponse({items: []}) as any; |
| 64 | + return park; |
| 65 | + } |
| 66 | + |
| 67 | + test('populates attraction location from the bundled snapshot', async () => { |
| 68 | + const entities = await createProbe([{ |
| 69 | + id: 'poi-1', |
| 70 | + title: 'Attractions', |
| 71 | + type: {label: 'Attractions'}, |
| 72 | + map_coordinates: {x: 10, y: 20}, |
| 73 | + contains: [{ |
| 74 | + id: 'anubis', |
| 75 | + title: 'Anubis The Ride', |
| 76 | + type: 'attraction', |
| 77 | + }], |
| 78 | + }]).buildEntitiesForTest(); |
| 79 | + |
| 80 | + const anubis = entities.find((e) => e.id === 'anubis'); |
| 81 | + expect(anubis?.location).toEqual({latitude: 51.081837, longitude: 2.597878}); |
| 82 | + }); |
| 83 | + |
| 84 | + test('prefers snapshot coordinates over mapped POI coordinates', async () => { |
| 85 | + const entities = await createProbe([{ |
| 86 | + id: 'poi-1', |
| 87 | + title: 'Attractions', |
| 88 | + type: {label: 'Attractions'}, |
| 89 | + map_coordinates: {x: 10, y: 20}, |
| 90 | + contains: [{ |
| 91 | + id: 'anubis', |
| 92 | + title: 'Anubis The Ride', |
| 93 | + type: 'attraction', |
| 94 | + }], |
| 95 | + }]).buildEntitiesForTest(); |
| 96 | + |
| 97 | + const anubis = entities.find((e) => e.id === 'anubis'); |
| 98 | + expect(anubis?.location).toEqual({latitude: 51.081837, longitude: 2.597878}); |
| 99 | + expect(anubis?.location).not.toEqual(fallbackLocation); |
| 100 | + }); |
| 101 | + |
| 102 | + test('matches snapshot titles with curly apostrophes through buildEntityList', async () => { |
| 103 | + const entities = await createProbe([{ |
| 104 | + id: 'poi-1', |
| 105 | + title: 'Attractions', |
| 106 | + type: {label: 'Attractions'}, |
| 107 | + map_coordinates: {x: 10, y: 20}, |
| 108 | + contains: [{ |
| 109 | + id: 'vics', |
| 110 | + title: 'Vic’s Whirlwind', |
| 111 | + type: 'attraction', |
| 112 | + }], |
| 113 | + }]).buildEntitiesForTest(); |
| 114 | + |
| 115 | + const vics = entities.find((e) => e.id === 'vics'); |
| 116 | + expect(vics?.location).toEqual({latitude: 51.082082, longitude: 2.5958043}); |
| 117 | + }); |
| 118 | + |
| 119 | + test('skips POI children without a usable title', async () => { |
| 120 | + const entities = await createProbe([{ |
| 121 | + id: 'poi-1', |
| 122 | + title: 'Attractions', |
| 123 | + type: {label: 'Attractions'}, |
| 124 | + map_coordinates: {x: 10, y: 20}, |
| 125 | + contains: [ |
| 126 | + {id: 'missing-title', type: 'attraction'}, |
| 127 | + {id: 'null-title', title: null, type: 'foods_and_drinks'}, |
| 128 | + {id: 'anubis', title: 'Anubis The Ride', type: 'attraction'}, |
| 129 | + ], |
| 130 | + }]).buildEntitiesForTest(); |
| 131 | + |
| 132 | + expect(entities.find((e) => e.id === 'missing-title')).toBeUndefined(); |
| 133 | + expect(entities.find((e) => e.id === 'null-title')).toBeUndefined(); |
| 134 | + expect(entities.find((e) => e.id === 'anubis')).toBeDefined(); |
| 135 | + }); |
| 136 | +}); |
0 commit comments