forked from MapComplete/MapComplete
Rework units to allow picking different default units in different locations, fixes #1011
This commit is contained in:
parent
e981abd2aa
commit
5da76b9418
17 changed files with 149 additions and 100 deletions
|
@ -7,22 +7,21 @@ describe("Unit", () => {
|
|||
|
||||
it("should convert a value back and forth", () => {
|
||||
|
||||
const unit = new Denomination({
|
||||
const denomintion = new Denomination({
|
||||
"canonicalDenomination": "MW",
|
||||
"alternativeDenomination": ["megawatts", "megawatt"],
|
||||
"human": {
|
||||
"en": " megawatts",
|
||||
"nl": " megawatt"
|
||||
},
|
||||
"default": true
|
||||
}, "test");
|
||||
|
||||
const canonical = unit.canonicalValue("5")
|
||||
const canonical = denomintion.canonicalValue("5", true)
|
||||
expect(canonical).eq( "5 MW")
|
||||
const units = new Unit(["key"], [unit], false)
|
||||
const [detected, detectedDenom] = units.findDenomination("5 MW")
|
||||
const units = new Unit(["key"], [denomintion], false)
|
||||
const [detected, detectedDenom] = units.findDenomination("5 MW", () => "be")
|
||||
expect(detected).eq( "5")
|
||||
expect(detectedDenom).eq( unit)
|
||||
expect(detectedDenom).eq( denomintion)
|
||||
}
|
||||
)
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue