forked from owid/owid-grapher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
formatting.test.ts
executable file
·55 lines (48 loc) · 2.18 KB
/
formatting.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#! /usr/bin/env jest
import {
extractDataValuesConfiguration,
parseFormattingOptions,
parseKeyValueArgs,
} from "./formatting.js"
it("parses formatting options", () => {
const formattingOptions =
"subnavId:coronavirus isTrue isAlsoTrue:true isFalse:false"
expect(parseFormattingOptions(formattingOptions)).toStrictEqual({
subnavId: "coronavirus",
isTrue: true,
isAlsoTrue: true,
isFalse: false,
})
})
it("parses LastUpdated options", () => {
const lastUpdatedOptions =
"timestampUrl:https://covid.ourworldindata.org/data/internal/timestamp/owid-covid-data-last-updated-timestamp-root.txt"
expect(parseKeyValueArgs(lastUpdatedOptions)).toStrictEqual({
timestampUrl:
"https://covid.ourworldindata.org/data/internal/timestamp/owid-covid-data-last-updated-timestamp-root.txt",
})
})
it("extracts DataValue tags configurations", async () => {
const queryArgs = { year: 2001, variableId: 146684, entityId: 12 }
const template = "%value %unit in %year in %entity"
const dataValueConfigurationString = `year:${queryArgs.year} variableId:${queryArgs.variableId} entityId:${queryArgs.entityId} | ${template}`
const dataValueTag = `{{DataValue ${dataValueConfigurationString}}}`
const queryArgs2 = { year: 1990, variableId: 146, entityId: 13 }
const template2 = "%unit in %year in %entity"
const dataValueConfigurationString2 = `year:${queryArgs2.year} variableId:${queryArgs2.variableId} entityId:${queryArgs2.entityId} | ${template2}`
const dataValueTag2 = `{{ DataValue ${dataValueConfigurationString2} }}`
const html = `Lorem ipsum dolor ${dataValueTag}. <span>sit amet</span>
Fusce eu vestibulum ${dataValueTag2} urna, at laoreet ${dataValueTag2} purus.`
const dataValuesConfigurationsMap = new Map()
dataValuesConfigurationsMap.set(dataValueConfigurationString, {
queryArgs,
template,
})
dataValuesConfigurationsMap.set(dataValueConfigurationString2, {
queryArgs: queryArgs2,
template: template2,
})
expect(await extractDataValuesConfiguration(html)).toEqual(
dataValuesConfigurationsMap
)
})