diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 7f54199..e92dbcb 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -10,6 +10,7 @@ on: - "**.tsx" - "**.astro" - "**.lockb" + - "!**.test.ts" push: branches: - main @@ -22,6 +23,7 @@ on: - "**.tsx" - "**.astro" - "**.lockb" + - "!**.test.ts" jobs: deploy: diff --git a/package.json b/package.json index 0d692b7..e7d8c8c 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "start": "bun run dev", "build": "cd site && bun run build", "preview": "cd site && bun run preview", - "test": "vitest" + "test": "TZ=America/New_York vitest" }, "devDependencies": { "@types/bun": "latest" diff --git a/site/src/lib/server/__snapshots__/timeline.test.ts.snap b/site/src/lib/server/__snapshots__/timeline.test.ts.snap index 66f22d6..f98f777 100644 --- a/site/src/lib/server/__snapshots__/timeline.test.ts.snap +++ b/site/src/lib/server/__snapshots__/timeline.test.ts.snap @@ -3,7 +3,7 @@ exports[`timeline datamodel integration 1`] = ` { "clipPathTimes": "0;0.17444717444717445;0.18673218673218672;0.2457002457002457;0.257985257985258;0.32186732186732187;0.33415233415233414;0.40786240786240785;0.4201474201474201;0.5724815724815725;0.5847665847665847;0.6240786240786241;0.6363636363636364;0.7297297297297297;0.742014742014742;0.7764127764127764;0.7886977886977887;0.7985257985257985;0.8108108108108109;0.85995085995086;0.8722358722358723;0.9754299754299754;0.9877149877149877;1", - "clipPathValues": "7.265483521194563;7.265483521194563;7.461064832333399;7.461064832333399;11.438448228443644;11.438448228443644;17.9451889430103;17.9451889430103;21.47048171168563;21.47048171168563;54.04805022878668;54.04805022878668;87.25522154686861;87.25522154686861;98.99424525121678;98.99424525121678;99.15489557921396;99.15489557921396;112.77314983628851;112.77314983628851;248.1516359056855;248.1516359056855;400;400", + "clipPathValues": "9.714285715592453;9.714285715592453;9.975786926281383;9.975786926281383;15.293731505958267;15.293731505958267;23.9935431832114;23.9935431832114;28.70702179562914;28.70702179562914;72.26472963038266;72.26472963038266;116.66424537485395;116.66424537485395;132.35986012003764;132.35986012003764;132.5746569992702;132.5746569992702;150.78288944724008;150.78288944724008;331.7901533941068;331.7901533941068;400;400", "dayTexts": [ { "dayAnimId": "dayanim00", @@ -714,7 +714,7 @@ exports[`timeline datamodel integration 1`] = ` "2023-10-08", "2023-10-09", ], - "distance": 7.265483521194563, + "distance": 9.714285715592453, "distanceBefore": 0, "killedCounts": [ 198, @@ -722,8 +722,8 @@ exports[`timeline datamodel integration 1`] = ` 436, ], "markerPoint": [ - 8.02081070783249, - 230.32111889351592, + 10.86481987187927, + 229.20674638231648, ], "markerTooltip": "October 9th 2023", "postTime": 1696831740000, @@ -734,12 +734,12 @@ exports[`timeline datamodel integration 1`] = ` }, { "dates": [], - "distance": 0.1955813111388367, - "distanceBefore": 7.265483521194563, + "distance": 0.2615012106889294, + "distanceBefore": 9.714285715592453, "killedCounts": [], "markerPoint": [ - 8.201248972743082, - 230.17180141202113, + 11.11546909495079, + 229.01794405508028, ], "markerTooltip": "October 9th 2023", "postTime": 1696836600000, @@ -752,14 +752,14 @@ exports[`timeline datamodel integration 1`] = ` "dates": [ "2023-10-10", ], - "distance": 3.9773833961102443, - "distanceBefore": 7.461064832333399, + "distance": 5.317944579676882, + "distanceBefore": 9.975786926281383, "killedCounts": [ 765, ], "markerPoint": [ - 11.936285096730685, - 227.21964873848097, + 16.303088968360747, + 225.3061116532412, ], "markerTooltip": "October 10th 2023", "postTime": 1696935434000, @@ -773,15 +773,15 @@ exports[`timeline datamodel integration 1`] = ` "2023-10-11", "2023-10-12", ], - "distance": 6.506740714566657, - "distanceBefore": 11.438448228443644, + "distance": 8.699811677253136, + "distanceBefore": 15.293731505958267, "killedCounts": [ 1055, 1203, ], "markerPoint": [ - 18.43804653833968, - 223.24053780270765, + 25.12475742248997, + 220.18339294764647, ], "markerTooltip": "October 12th 2023", "postTime": 1697097120000, @@ -794,14 +794,14 @@ exports[`timeline datamodel integration 1`] = ` "dates": [ "2023-10-13", ], - "distance": 3.525292768675328, - "distanceBefore": 17.9451889430103, + "distance": 4.71347861241774, + "distanceBefore": 23.9935431832114, "killedCounts": [ 1709, ], "markerPoint": [ - 21.04619899170109, - 219.92106124314708, + 28.820640796673512, + 215.90171638451963, ], "markerTooltip": "October 13th 2023", "postTime": 1697184720000, @@ -822,8 +822,8 @@ exports[`timeline datamodel integration 1`] = ` "2023-10-21", "2023-10-22", ], - "distance": 32.57756851710105, - "distanceBefore": 21.47048171168563, + "distance": 43.55770783475352, + "distanceBefore": 28.70702179562914, "killedCounts": [ 2215, 2450, @@ -836,8 +836,8 @@ exports[`timeline datamodel integration 1`] = ` 4651, ], "markerPoint": [ - 50.708178983296904, - 195.24142581204012, + 70.35648091519003, + 185.03369796669548, ], "markerTooltip": "October 22nd 2023", "postTime": 1697994240000, @@ -859,8 +859,8 @@ exports[`timeline datamodel integration 1`] = ` "2023-10-31", "2023-11-01", ], - "distance": 33.20717131808193, - "distanceBefore": 54.04805022878668, + "distance": 44.39951574447129, + "distanceBefore": 72.26472963038266, "killedCounts": [ 5087, 5791, @@ -874,8 +874,8 @@ exports[`timeline datamodel integration 1`] = ` 8805, ], "markerPoint": [ - 75.94966045375378, - 165.300391058581, + 106.32519408831709, + 146.83290455908633, ], "markerTooltip": "November 1st 2023", "postTime": 1698819405000, @@ -890,16 +890,16 @@ exports[`timeline datamodel integration 1`] = ` "2023-11-03", "2023-11-04", ], - "distance": 11.739023704348165, - "distanceBefore": 87.25522154686861, + "distance": 15.695614745183697, + "distanceBefore": 116.66424537485395, "killedCounts": [ 9061, 9257, 9488, ], "markerPoint": [ - 87.55456264293207, - 157.41296591929697, + 122.54718699503644, + 137.30848681598366, ], "markerTooltip": "November 4th 2023", "postTime": 1699111108000, @@ -910,12 +910,12 @@ exports[`timeline datamodel integration 1`] = ` }, { "dates": [], - "distance": 0.16065032799716794, - "distanceBefore": 98.99424525121678, + "distance": 0.21479687923255272, + "distanceBefore": 132.35986012003764, "killedCounts": [], "markerPoint": [ - 87.71254644975649, - 157.30322852798625, + 122.7823506438893, + 137.20295793230434, ], "markerTooltip": "November 4th 2023", "postTime": 1699115100000, @@ -931,8 +931,8 @@ exports[`timeline datamodel integration 1`] = ` "2023-11-07", "2023-11-08", ], - "distance": 13.618254257074556, - "distanceBefore": 99.15489557921396, + "distance": 18.2082324479699, + "distanceBefore": 132.5746569992702, "killedCounts": [ 9770, 10000, @@ -940,8 +940,8 @@ exports[`timeline datamodel integration 1`] = ` 10569, ], "markerPoint": [ - 101.63469419044512, - 148.86451235354727, + 141.9598629138591, + 126.81744444458798, ], "markerTooltip": "November 8th 2023", "postTime": 1699453500000, @@ -992,8 +992,8 @@ exports[`timeline datamodel integration 1`] = ` "2023-12-16", "2023-12-17", ], - "distance": 135.37848606939698, - "distanceBefore": 112.77314983628851, + "distance": 181.00726394686671, + "distanceBefore": 150.78288944724008, "killedCounts": [ 10818, 11078, @@ -1036,8 +1036,8 @@ exports[`timeline datamodel integration 1`] = ` 19235, ], "markerPoint": [ - 233.940753364097, - 71.42951814923794, + 325.2340696631509, + 32.299674011957876, ], "markerTooltip": "December 17th 2023", "postTime": 1702817520000, @@ -1063,8 +1063,8 @@ exports[`timeline datamodel integration 1`] = ` "2023-12-30", "2023-12-31", ], - "distance": 151.8483640943145, - "distanceBefore": 248.1516359056855, + "distance": 68.20984660589318, + "distanceBefore": 331.7901533941068, "killedCounts": [ 19453, 19667, @@ -1088,7 +1088,7 @@ exports[`timeline datamodel integration 1`] = ` ], }, ], - "totalDistance": 248.1516359056855, + "totalDistance": 331.7901533941068, }, "postDelayLookup": { "0": 40200, diff --git a/site/src/lib/server/svg.ts b/site/src/lib/server/svg.ts index 3c27eed..a9ee654 100644 --- a/site/src/lib/server/svg.ts +++ b/site/src/lib/server/svg.ts @@ -2,8 +2,10 @@ import pathPoint from "point-at-length"; import generatedData from "../../generated/data.json"; -export const getSvgDomain = () => { - const { pathData, svgViewbox } = generatedData; +const getData = () => generatedData; + +export const getSvgDomain = (dataFetcher = getData) => { + const { pathData, svgViewbox } = dataFetcher(); const aspectRatio = svgViewbox.width / svgViewbox.height; const pathPoints = pathPoint(pathData); diff --git a/site/src/lib/server/timeline.test.ts b/site/src/lib/server/timeline.test.ts index 994cc89..12acb2e 100644 --- a/site/src/lib/server/timeline.test.ts +++ b/site/src/lib/server/timeline.test.ts @@ -8,7 +8,7 @@ test("timeline datamodel integration", () => { const posts = getEnhancedPosts( require("../../content/enabler/talbroda.json").posts ); - const svgDomain = getSvgDomain(); + const svgDomain = getSvgDomain(() => dataFixture); const timeline = getTimeline({ svgDomain, posts, diff --git a/site/src/lib/server/timeline.ts b/site/src/lib/server/timeline.ts index 7d4e284..f0f6be5 100644 --- a/site/src/lib/server/timeline.ts +++ b/site/src/lib/server/timeline.ts @@ -10,8 +10,10 @@ const getData = () => { const getTimelineBounds = (dataFetcher = getData) => { const { dates } = dataFetcher(); - const firstDate = startOfDay(parseISO(dates[0])); - const lastDate = endOfDay(parseISO(dates[dates.length - 1])); + const headDate = dates[0]; + const tailDate = dates[dates.length - 1]; + const firstDate = startOfDay(parseISO(headDate)); + const lastDate = endOfDay(parseISO(tailDate)); const firstDateVal = firstDate.valueOf(); const lastDateVal = lastDate.valueOf(); const realTimeDuration = lastDateVal - firstDateVal; @@ -47,7 +49,7 @@ export const getTimeline = ({ svgDomain: ReturnType; dataFetcher?: typeof getData; }) => { - const { firstDateVal, realTimeDuration } = getTimelineBounds(); + const { firstDateVal, realTimeDuration } = getTimelineBounds(dataFetcher); const { dates, killed } = dataFetcher ? dataFetcher() : getData(); const postDates = posts.map((post) => post.dateValue).sort(); const allDates = dates.map((date) => parseISO(date).valueOf());