mirror of
https://github.com/kennethnym/aris.git
synced 2026-03-20 00:51:20 +00:00
Compare commits
4 Commits
ec083c3c77
...
feat/tfl-r
| Author | SHA1 | Date | |
|---|---|---|---|
|
78fc028ee5
|
|||
|
adbc2c17ac
|
|||
|
f7f91316f1
|
|||
|
1dd14da71d
|
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@@ -21,4 +21,4 @@ jobs:
|
|||||||
run: bun install --frozen-lockfile
|
run: bun install --frozen-lockfile
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: bun test
|
run: bun run test
|
||||||
|
|||||||
9
bun.lock
9
bun.lock
@@ -6,7 +6,7 @@
|
|||||||
"name": "aelis",
|
"name": "aelis",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@json-render/core": "^0.12.1",
|
"@json-render/core": "^0.12.1",
|
||||||
"@nym.sh/jrx": "^0.1.0",
|
"@nym.sh/jrx": "^0.2.0",
|
||||||
"@types/bun": "latest",
|
"@types/bun": "latest",
|
||||||
"oxfmt": "^0.24.0",
|
"oxfmt": "^0.24.0",
|
||||||
"oxlint": "^1.39.0",
|
"oxlint": "^1.39.0",
|
||||||
@@ -177,10 +177,15 @@
|
|||||||
"name": "@aelis/source-tfl",
|
"name": "@aelis/source-tfl",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@aelis/components": "workspace:*",
|
||||||
"@aelis/core": "workspace:*",
|
"@aelis/core": "workspace:*",
|
||||||
"@aelis/source-location": "workspace:*",
|
"@aelis/source-location": "workspace:*",
|
||||||
"arktype": "^2.1.0",
|
"arktype": "^2.1.0",
|
||||||
},
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@json-render/core": "*",
|
||||||
|
"@nym.sh/jrx": "*",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"packages/aelis-source-weatherkit": {
|
"packages/aelis-source-weatherkit": {
|
||||||
"name": "@aelis/source-weatherkit",
|
"name": "@aelis/source-weatherkit",
|
||||||
@@ -691,7 +696,7 @@
|
|||||||
|
|
||||||
"@nolyfill/is-core-module": ["@nolyfill/is-core-module@1.0.39", "", {}, "sha512-nn5ozdjYQpUCZlWGuxcJY/KpxkWQs4DcbMCmKojjyrYDEAGy4Ce19NN4v5MduafTwJlbKc99UA8YhSVqq9yPZA=="],
|
"@nolyfill/is-core-module": ["@nolyfill/is-core-module@1.0.39", "", {}, "sha512-nn5ozdjYQpUCZlWGuxcJY/KpxkWQs4DcbMCmKojjyrYDEAGy4Ce19NN4v5MduafTwJlbKc99UA8YhSVqq9yPZA=="],
|
||||||
|
|
||||||
"@nym.sh/jrx": ["@nym.sh/jrx@0.1.0", "", { "peerDependencies": { "@json-render/core": ">=0.10.0" } }, "sha512-mu6fkAP/TI9FuP8A4WMCrcucpUtWF5xBTcETnrjOtvEED9i+7sQKuoOyhJeF6QaSuUkAA/8t3Xx3kYUjcAPFbw=="],
|
"@nym.sh/jrx": ["@nym.sh/jrx@0.2.0", "", { "peerDependencies": { "@json-render/core": ">=0.10.0" } }, "sha512-jd7Z1Q6T21366MtSUnwCFiu6Yl1AdNc9s5m6HxeUg265P+0enZCiyyxOuHsFwvpUcSEs/2DVBsqfMptdca44lA=="],
|
||||||
|
|
||||||
"@oclif/core": ["@oclif/core@4.8.4", "", { "dependencies": { "ansi-escapes": "^4.3.2", "ansis": "^3.17.0", "clean-stack": "^3.0.1", "cli-spinners": "^2.9.2", "debug": "^4.4.3", "ejs": "^3.1.10", "get-package-type": "^0.1.0", "indent-string": "^4.0.0", "is-wsl": "^2.2.0", "lilconfig": "^3.1.3", "minimatch": "^10.2.4", "semver": "^7.7.3", "string-width": "^4.2.3", "supports-color": "^8", "tinyglobby": "^0.2.14", "widest-line": "^3.1.0", "wordwrap": "^1.0.0", "wrap-ansi": "^7.0.0" } }, "sha512-UTAqwXJJyRvLBvosL+1uPZYSpr8lEHgUb/EVGbPXo5WZqUIBHfJ0sR2bkBEsrj00/ar4IegKxx4YK0wn2c8SQg=="],
|
"@oclif/core": ["@oclif/core@4.8.4", "", { "dependencies": { "ansi-escapes": "^4.3.2", "ansis": "^3.17.0", "clean-stack": "^3.0.1", "cli-spinners": "^2.9.2", "debug": "^4.4.3", "ejs": "^3.1.10", "get-package-type": "^0.1.0", "indent-string": "^4.0.0", "is-wsl": "^2.2.0", "lilconfig": "^3.1.3", "minimatch": "^10.2.4", "semver": "^7.7.3", "string-width": "^4.2.3", "supports-color": "^8", "tinyglobby": "^0.2.14", "widest-line": "^3.1.0", "wordwrap": "^1.0.0", "wrap-ansi": "^7.0.0" } }, "sha512-UTAqwXJJyRvLBvosL+1uPZYSpr8lEHgUb/EVGbPXo5WZqUIBHfJ0sR2bkBEsrj00/ar4IegKxx4YK0wn2c8SQg=="],
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@json-render/core": "^0.12.1",
|
"@json-render/core": "^0.12.1",
|
||||||
"@nym.sh/jrx": "^0.1.0",
|
"@nym.sh/jrx": "^0.2.0",
|
||||||
"@types/bun": "latest",
|
"@types/bun": "latest",
|
||||||
"oxfmt": "^0.24.0",
|
"oxfmt": "^0.24.0",
|
||||||
"oxlint": "^1.39.0"
|
"oxlint": "^1.39.0"
|
||||||
|
|||||||
@@ -10,7 +10,12 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@aelis/core": "workspace:*",
|
"@aelis/core": "workspace:*",
|
||||||
|
"@aelis/components": "workspace:*",
|
||||||
"@aelis/source-location": "workspace:*",
|
"@aelis/source-location": "workspace:*",
|
||||||
"arktype": "^2.1.0"
|
"arktype": "^2.1.0"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@json-render/core": "*",
|
||||||
|
"@nym.sh/jrx": "*"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,3 +11,4 @@ export {
|
|||||||
type TflLineStatus,
|
type TflLineStatus,
|
||||||
type TflSourceOptions,
|
type TflSourceOptions,
|
||||||
} from "./types.ts"
|
} from "./types.ts"
|
||||||
|
export { renderTflAlert } from "./renderer.tsx"
|
||||||
|
|||||||
103
packages/aelis-source-tfl/src/renderer.test.tsx
Normal file
103
packages/aelis-source-tfl/src/renderer.test.tsx
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
/** @jsxImportSource @nym.sh/jrx */
|
||||||
|
import { render } from "@nym.sh/jrx"
|
||||||
|
import { describe, expect, test } from "bun:test"
|
||||||
|
|
||||||
|
import type { TflAlertFeedItem } from "./types.ts"
|
||||||
|
|
||||||
|
import { renderTflAlert } from "./renderer.tsx"
|
||||||
|
|
||||||
|
function makeItem(overrides: Partial<TflAlertFeedItem["data"]> = {}): TflAlertFeedItem {
|
||||||
|
return {
|
||||||
|
id: "tfl-alert-northern-minor-delays",
|
||||||
|
type: "tfl-alert",
|
||||||
|
timestamp: new Date("2026-01-15T12:00:00Z"),
|
||||||
|
data: {
|
||||||
|
line: "northern",
|
||||||
|
lineName: "Northern",
|
||||||
|
severity: "minor-delays",
|
||||||
|
description: "Minor delays due to signal failure",
|
||||||
|
closestStationDistance: null,
|
||||||
|
...overrides,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("renderTflAlert", () => {
|
||||||
|
test("renders a FeedCard with title and description", () => {
|
||||||
|
const node = renderTflAlert(makeItem())
|
||||||
|
const spec = render(node)
|
||||||
|
|
||||||
|
const root = spec.elements[spec.root]!
|
||||||
|
expect(root.type).toBe("FeedCard")
|
||||||
|
expect(root.children!.length).toBeGreaterThanOrEqual(2)
|
||||||
|
|
||||||
|
const title = spec.elements[root.children![0]!]!
|
||||||
|
expect(title.type).toBe("SansSerifText")
|
||||||
|
expect(title.props.content).toBe("Northern · Minor delays")
|
||||||
|
|
||||||
|
const body = spec.elements[root.children![1]!]!
|
||||||
|
expect(body.type).toBe("SansSerifText")
|
||||||
|
expect(body.props.content).toBe("Minor delays due to signal failure")
|
||||||
|
})
|
||||||
|
|
||||||
|
test("shows nearest station distance when available", () => {
|
||||||
|
const node = renderTflAlert(makeItem({ closestStationDistance: 0.35 }))
|
||||||
|
const spec = render(node)
|
||||||
|
|
||||||
|
const root = spec.elements[spec.root]!
|
||||||
|
expect(root.children).toHaveLength(3)
|
||||||
|
|
||||||
|
const caption = spec.elements[root.children![2]!]!
|
||||||
|
expect(caption.type).toBe("SansSerifText")
|
||||||
|
expect(caption.props.content).toBe("Nearest station: 350m away")
|
||||||
|
})
|
||||||
|
|
||||||
|
test("formats distance in km when >= 1km", () => {
|
||||||
|
const node = renderTflAlert(makeItem({ closestStationDistance: 2.456 }))
|
||||||
|
const spec = render(node)
|
||||||
|
|
||||||
|
const root = spec.elements[spec.root]!
|
||||||
|
const caption = spec.elements[root.children![2]!]!
|
||||||
|
expect(caption.props.content).toBe("Nearest station: 2.5km away")
|
||||||
|
})
|
||||||
|
|
||||||
|
test("formats near-1km boundary as km not meters", () => {
|
||||||
|
const node = renderTflAlert(makeItem({ closestStationDistance: 0.9999 }))
|
||||||
|
const spec = render(node)
|
||||||
|
|
||||||
|
const root = spec.elements[spec.root]!
|
||||||
|
const caption = spec.elements[root.children![2]!]!
|
||||||
|
expect(caption.props.content).toBe("Nearest station: 1.0km away")
|
||||||
|
})
|
||||||
|
|
||||||
|
test("omits station distance when null", () => {
|
||||||
|
const node = renderTflAlert(makeItem({ closestStationDistance: null }))
|
||||||
|
const spec = render(node)
|
||||||
|
|
||||||
|
const root = spec.elements[spec.root]!
|
||||||
|
// Title + body only, no caption (empty fragment doesn't produce a child)
|
||||||
|
const children = root.children!.filter((key) => {
|
||||||
|
const el = spec.elements[key]
|
||||||
|
return el && el.type !== "Fragment"
|
||||||
|
})
|
||||||
|
expect(children).toHaveLength(2)
|
||||||
|
})
|
||||||
|
|
||||||
|
test("renders closure severity label", () => {
|
||||||
|
const node = renderTflAlert(makeItem({ severity: "closure", lineName: "Central" }))
|
||||||
|
const spec = render(node)
|
||||||
|
|
||||||
|
const root = spec.elements[spec.root]!
|
||||||
|
const title = spec.elements[root.children![0]!]!
|
||||||
|
expect(title.props.content).toBe("Central · Closed")
|
||||||
|
})
|
||||||
|
|
||||||
|
test("renders major delays severity label", () => {
|
||||||
|
const node = renderTflAlert(makeItem({ severity: "major-delays", lineName: "Jubilee" }))
|
||||||
|
const spec = render(node)
|
||||||
|
|
||||||
|
const root = spec.elements[spec.root]!
|
||||||
|
const title = spec.elements[root.children![0]!]!
|
||||||
|
expect(title.props.content).toBe("Jubilee · Major delays")
|
||||||
|
})
|
||||||
|
})
|
||||||
40
packages/aelis-source-tfl/src/renderer.tsx
Normal file
40
packages/aelis-source-tfl/src/renderer.tsx
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
/** @jsxImportSource @nym.sh/jrx */
|
||||||
|
import type { FeedItemRenderer } from "@aelis/core"
|
||||||
|
|
||||||
|
import { FeedCard, SansSerifText } from "@aelis/components"
|
||||||
|
|
||||||
|
import type { TflAlertData } from "./types.ts"
|
||||||
|
|
||||||
|
import { TflAlertSeverity } from "./types.ts"
|
||||||
|
|
||||||
|
const SEVERITY_LABEL: Record<TflAlertSeverity, string> = {
|
||||||
|
[TflAlertSeverity.Closure]: "Closed",
|
||||||
|
[TflAlertSeverity.MajorDelays]: "Major delays",
|
||||||
|
[TflAlertSeverity.MinorDelays]: "Minor delays",
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatDistance(km: number): string {
|
||||||
|
const meters = Math.round(km * 1000)
|
||||||
|
if (meters < 1000) {
|
||||||
|
return `${meters}m away`
|
||||||
|
}
|
||||||
|
return `${(meters / 1000).toFixed(1)}km away`
|
||||||
|
}
|
||||||
|
|
||||||
|
export const renderTflAlert: FeedItemRenderer<"tfl-alert", TflAlertData> = (item) => {
|
||||||
|
const { lineName, severity, description, closestStationDistance } = item.data
|
||||||
|
const severityLabel = SEVERITY_LABEL[severity]
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FeedCard>
|
||||||
|
<SansSerifText content={`${lineName} · ${severityLabel}`} style="text-base font-semibold" />
|
||||||
|
<SansSerifText content={description} style="text-sm" />
|
||||||
|
{closestStationDistance !== null ? (
|
||||||
|
<SansSerifText
|
||||||
|
content={`Nearest station: ${formatDistance(closestStationDistance)}`}
|
||||||
|
style="text-xs text-stone-500"
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
</FeedCard>
|
||||||
|
)
|
||||||
|
}
|
||||||
7
packages/aelis-source-tfl/tsconfig.json
Normal file
7
packages/aelis-source-tfl/tsconfig.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"extends": "../../tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"jsxImportSource": "@nym.sh/jrx"
|
||||||
|
},
|
||||||
|
"include": ["src"]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user