forked from MapComplete/MapComplete
		
	Rename tests to test; add a few tests
This commit is contained in:
		
							parent
							
								
									df706d2f97
								
							
						
					
					
						commit
						c3859d56c6
					
				
					 28 changed files with 33 additions and 5 deletions
				
			
		|  | @ -0,0 +1,32 @@ | |||
| import {describe} from 'mocha' | ||||
| import {expect} from 'chai' | ||||
| import {Utils} from "../../../../Utils"; | ||||
| import {DesugaringContext} from "../../../../Models/ThemeConfig/Conversion/Conversion"; | ||||
| import {LayerConfigJson} from "../../../../Models/ThemeConfig/Json/LayerConfigJson"; | ||||
| import {TagRenderingConfigJson} from "../../../../Models/ThemeConfig/Json/TagRenderingConfigJson"; | ||||
| import {PrepareLayer} from "../../../../Models/ThemeConfig/Conversion/PrepareLayer"; | ||||
| import * as bookcases from "../../../../assets/layers/public_bookcase/public_bookcase.json"; | ||||
| import CreateNoteImportLayer from "../../../../Models/ThemeConfig/Conversion/CreateNoteImportLayer"; | ||||
| 
 | ||||
| describe("CreateNoteImportLayer", () => { | ||||
|      | ||||
|         it("should generate a layerconfig", () => { | ||||
|             const desugaringState: DesugaringContext = { | ||||
|                 sharedLayers: new Map<string, LayerConfigJson>(), | ||||
|                 tagRenderings: new Map<string, TagRenderingConfigJson>() | ||||
| 
 | ||||
|             } | ||||
|             const layerPrepare = new PrepareLayer(desugaringState) | ||||
|             const layer = layerPrepare.convertStrict(bookcases, "ImportLayerGeneratorTest:Parse bookcases") | ||||
|             const generator = new CreateNoteImportLayer() | ||||
|             const generatedLayer: LayerConfigJson = generator.convertStrict(layer, "ImportLayerGeneratorTest: convert") | ||||
|             expect(generatedLayer.isShown.mappings[1].if["and"][1].or[0].and[0]).deep.equal("_tags~(^|.*;)amenity=public_bookcase($|;.*)") | ||||
|             expect(generatedLayer.minzoom <= layer.minzoom, "Zoomlevel is to high").true | ||||
|             let renderings = Utils.NoNull(Utils.NoNull(generatedLayer.tagRenderings | ||||
|                 .map(tr => (<TagRenderingConfigJson>tr).render)) | ||||
|                 .map(render => render["en"])) | ||||
|             expect(renderings.some(r => r.indexOf("import_button") > 0), "no import button found").true | ||||
|              | ||||
|              | ||||
|         }) | ||||
| }) | ||||
							
								
								
									
										153
									
								
								test/Models/ThemeConfig/Conversion/FixLegacyTheme.spec.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										153
									
								
								test/Models/ThemeConfig/Conversion/FixLegacyTheme.spec.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,153 @@ | |||
| import {describe} from 'mocha' | ||||
| import {expect} from 'chai' | ||||
| import LayoutConfig from "../../../../Models/ThemeConfig/LayoutConfig"; | ||||
| import {FixLegacyTheme} from "../../../../Models/ThemeConfig/Conversion/LegacyJsonConvert"; | ||||
| 
 | ||||
| 
 | ||||
| describe("FixLegacyTheme", () => { | ||||
|      | ||||
|     it("should create a working theme config", () => { | ||||
|             const walking_node_theme = { | ||||
|                 "id": "walkingnodenetworks", | ||||
|                 "title": { | ||||
|                     "en": "Walking node networks" | ||||
|                 }, | ||||
|                 "maintainer": "L'imaginaire", | ||||
|                 "icon": "https://upload.wikimedia.org/wikipedia/commons/3/30/Man_walking_icon_1410105361.svg", | ||||
|                 "description": { | ||||
|                     "en": "This map shows walking node networks" | ||||
|                 }, | ||||
|                 "language": [ | ||||
|                     "en" | ||||
|                 ], | ||||
|                 socialImage: "img.jpg", | ||||
|                 "version": "2021-10-02", | ||||
|                 "startLat": 51.1599, | ||||
|                 "startLon": 3.34750, | ||||
|                 "startZoom": 12, | ||||
|                 "clustering": { | ||||
|                     "maxZoom": 12 | ||||
|                 }, | ||||
|                 "layers": [ | ||||
|                     { | ||||
|                         "id": "node2node", | ||||
|                         "name": { | ||||
|                             "en": "node to node links" | ||||
|                         }, | ||||
|                         "source": { | ||||
|                             "osmTags": { | ||||
|                                 "and": [ | ||||
|                                     "network=rwn", | ||||
|                                     "network:type=node_network" | ||||
|                                 ] | ||||
|                             } | ||||
|                         }, | ||||
|                         "minzoom": 12, | ||||
|                         "title": { | ||||
|                             "render": { | ||||
|                                 "en": "node to node link" | ||||
|                             }, | ||||
|                             "mappings": [ | ||||
|                                 { | ||||
|                                     "if": "ref~*", | ||||
|                                     "then": { | ||||
|                                         "en": "node to node link <strong>{ref}</strong>" | ||||
|                                     } | ||||
|                                 } | ||||
|                             ] | ||||
|                         }, | ||||
|                         "width": { | ||||
|                             "render": "4" | ||||
|                         }, | ||||
|                         "color": { | ||||
|                             "render": "#8b1e20" | ||||
|                         }, | ||||
|                         "tagRenderings": [ | ||||
|                             { | ||||
|                                 "question": { | ||||
|                                     "en": "When was this node to node link last surveyed?" | ||||
|                                 }, | ||||
|                                 "render": { | ||||
|                                     "en": "This node to node link was last surveyed on {survey:date}" | ||||
|                                 }, | ||||
|                                 "freeform": { | ||||
|                                     "key": "survey:date", | ||||
|                                     "type": "date" | ||||
|                                 }, | ||||
|                                 "mappings": [ | ||||
|                                     { | ||||
|                                         "if": "survey:date:={_now:date}", | ||||
|                                         "then": "Surveyed today!" | ||||
|                                     } | ||||
|                                 ] | ||||
|                             } | ||||
|                         ] | ||||
|                     }, | ||||
|                     { | ||||
|                         "id": "node", | ||||
|                         "name": { | ||||
|                             "en": "nodes" | ||||
|                         }, | ||||
|                         "source": { | ||||
|                             "osmTags": "rwn_ref~*" | ||||
|                         }, | ||||
|                         "minzoom": 12, | ||||
|                         "title": { | ||||
|                             "render": { | ||||
|                                 "en": "walking node <strong>{rwn_ref}</strong>" | ||||
|                             } | ||||
|                         }, | ||||
|                         "label": { | ||||
|                             "mappings": [ | ||||
|                                 { | ||||
|                                     "if": "rwn_ref~*", | ||||
|                                     "then": "<div style='position: absolute; top: 10px; right: 10px; color: white; background-color: #8b1e20; width: 20px; height: 20px; border-radius: 100%'>{rwn_ref}</div>" | ||||
|                                 } | ||||
|                             ] | ||||
|                         }, | ||||
|                         "tagRenderings": [ | ||||
|                             { | ||||
|                                 "question": { | ||||
|                                     "en": "When was this walking node last surveyed?" | ||||
|                                 }, | ||||
|                                 "render": { | ||||
|                                     "en": "This walking node was last surveyed on {survey:date}" | ||||
|                                 }, | ||||
|                                 "freeform": { | ||||
|                                     "key": "survey:date", | ||||
|                                     "type": "date" | ||||
|                                 }, | ||||
|                                 "mappings": [ | ||||
|                                     { | ||||
|                                         "if": "survey:date:={_now:date}", | ||||
|                                         "then": "Surveyed today!" | ||||
|                                     } | ||||
|                                 ] | ||||
|                             }, | ||||
|                             { | ||||
|                                 "question": { | ||||
|                                     "en": "How many other walking nodes does this node link to?" | ||||
|                                 }, | ||||
|                                 "render": { | ||||
|                                     "en": "This node links to {expected_rwn_route_relations} other walking nodes." | ||||
|                                 }, | ||||
|                                 "freeform": { | ||||
|                                     "key": "expected_rwn_route_relations", | ||||
|                                     "type": "int" | ||||
|                                 } | ||||
|                             }, | ||||
|                             "images" | ||||
|                         ] | ||||
|                     } | ||||
|                 ] | ||||
|             } | ||||
|             const fixed = new FixLegacyTheme().convert( | ||||
|                 <any> walking_node_theme, | ||||
|                 "While testing") | ||||
|             expect(fixed.errors, "Could not fix the legacy theme").empty | ||||
|             const theme = new LayoutConfig(fixed.result, false,"test") | ||||
|             expect(theme).not.undefined | ||||
| 
 | ||||
|     }) | ||||
| }) | ||||
| 
 | ||||
							
								
								
									
										130
									
								
								test/Models/ThemeConfig/Conversion/PrepareLayer.spec.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										130
									
								
								test/Models/ThemeConfig/Conversion/PrepareLayer.spec.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,130 @@ | |||
| import {describe} from 'mocha' | ||||
| import {expect} from 'chai' | ||||
| import {LayerConfigJson} from "../../../../Models/ThemeConfig/Json/LayerConfigJson"; | ||||
| import {TagRenderingConfigJson} from "../../../../Models/ThemeConfig/Json/TagRenderingConfigJson"; | ||||
| import LineRenderingConfigJson from "../../../../Models/ThemeConfig/Json/LineRenderingConfigJson"; | ||||
| import {ExpandRewrite, PrepareLayer, RewriteSpecial} from "../../../../Models/ThemeConfig/Conversion/PrepareLayer"; | ||||
| import { | ||||
|     QuestionableTagRenderingConfigJson | ||||
| } from "../../../../Models/ThemeConfig/Json/QuestionableTagRenderingConfigJson"; | ||||
| import RewritableConfigJson from "../../../../Models/ThemeConfig/Json/RewritableConfigJson"; | ||||
| 
 | ||||
| 
 | ||||
| describe("ExpandRewrite", () => { | ||||
| 
 | ||||
|     it("should not allow overlapping keys", () => { | ||||
|         const spec = <RewritableConfigJson<string>>{ | ||||
|             rewrite: { | ||||
|                 sourceString: ["xyz", "longer_xyz"], | ||||
|                 into: [["a", "b"], ["A, B"]], | ||||
|             }, | ||||
|             renderings: "The value of xyz is longer_xyz" | ||||
|         } | ||||
|         const rewrite = new ExpandRewrite() | ||||
|         expect(() => rewrite.convert(spec, "test")).to.throw | ||||
|     }) | ||||
| }) | ||||
| 
 | ||||
| describe("PrepareLayer", () => { | ||||
| 
 | ||||
|     it("should expand rewrites in map renderings", () => { | ||||
|         const exampleLayer: LayerConfigJson = { | ||||
|             id: "testlayer", | ||||
|             source: { | ||||
|                 osmTags: "key=value" | ||||
|             }, | ||||
|             mapRendering: [ | ||||
|                 { | ||||
|                     "rewrite": { | ||||
|                         sourceString: ["left|right", "lr_offset"], | ||||
|                         into: [ | ||||
|                             ["left", -6], | ||||
|                            [ "right", +6], | ||||
|                         ] | ||||
|                     }, | ||||
|                     renderings: <LineRenderingConfigJson>{ | ||||
|                         "color": { | ||||
|                             "render": "#888", | ||||
|                             "mappings": [ | ||||
|                                 { | ||||
|                                     "if": "parking:condition:left|right=free", | ||||
|                                     "then": "#299921" | ||||
|                                 }, | ||||
|                                 { | ||||
|                                     "if": "parking:condition:left|right=disc", | ||||
|                                     "then": "#219991" | ||||
|                                 } | ||||
|                             ] | ||||
|                         }, | ||||
|                         "offset": "lr_offset" | ||||
|                     } | ||||
|                 } | ||||
|             ] | ||||
|         } | ||||
|         const prep = new PrepareLayer({ | ||||
|             tagRenderings: new Map<string, TagRenderingConfigJson>(), | ||||
|             sharedLayers: new Map<string, LayerConfigJson>() | ||||
|         }) | ||||
|         const result = prep.convertStrict(exampleLayer, "test") | ||||
| 
 | ||||
|         const expected = { | ||||
|             "id": "testlayer", | ||||
|             "source": {"osmTags": "key=value"}, | ||||
|             "mapRendering": [{ | ||||
|                 "color": { | ||||
|                     "render": "#888", | ||||
|                     "mappings": [{ | ||||
|                         "if": "parking:condition:left=free", | ||||
|                         "then": "#299921" | ||||
|                     }, | ||||
|                         { | ||||
|                             "if": "parking:condition:left=disc", | ||||
|                             "then": "#219991" | ||||
|                         }] | ||||
|                 }, | ||||
|                 "offset": -6 | ||||
|             }, { | ||||
|                 "color": { | ||||
|                     "render": "#888", | ||||
|                     "mappings": [{ | ||||
|                         "if": "parking:condition:right=free", | ||||
|                         "then": "#299921" | ||||
|                     }, | ||||
|                         { | ||||
|                             "if": "parking:condition:right=disc", | ||||
|                             "then": "#219991" | ||||
|                         }] | ||||
|                 }, | ||||
|                 "offset": 6 | ||||
|             }], | ||||
|             "titleIcons": [{"render": "defaults", "id": "defaults"}] | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         expect(result).deep.eq(expected) | ||||
|     }) | ||||
| }) | ||||
| 
 | ||||
| describe('RewriteSpecial', function () { | ||||
|     it("should rewrite the UK import button", () => { | ||||
|         const tr = <QuestionableTagRenderingConfigJson>{ | ||||
|             "id": "uk_addresses_import_button", | ||||
|             "render": { | ||||
|                 "special": { | ||||
|                     "type": "import_button", | ||||
|                     "targetLayer": "address", | ||||
|                     "tags": "urpn_count=$urpn_count;ref:GB:uprn=$ref:GB:uprn$", | ||||
|                     "text": "Add this address", | ||||
|                     "icon": "./assets/themes/uk_addresses/housenumber_add.svg", | ||||
|                     "location_picker": "none" | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         const r = new RewriteSpecial().convert(tr, "test").result | ||||
|         expect(r).to.deep.eq({ | ||||
|             "id": "uk_addresses_import_button", | ||||
|             "render":  {'*': "{import_button(address,urpn_count=$urpn_count;ref:GB:uprn=$ref:GB:uprn$,Add this address,./assets/themes/uk_addresses/housenumber_add.svg,,,,none)}"} | ||||
|         }) | ||||
|     }) | ||||
| }); | ||||
| 
 | ||||
							
								
								
									
										106
									
								
								test/Models/ThemeConfig/Conversion/PrepareTheme.spec.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										106
									
								
								test/Models/ThemeConfig/Conversion/PrepareTheme.spec.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,106 @@ | |||
| import {describe} from 'mocha' | ||||
| import {expect} from 'chai' | ||||
| import {LayoutConfigJson} from "../../../../Models/ThemeConfig/Json/LayoutConfigJson"; | ||||
| import {LayerConfigJson} from "../../../../Models/ThemeConfig/Json/LayerConfigJson"; | ||||
| import {PrepareTheme} from "../../../../Models/ThemeConfig/Conversion/PrepareTheme"; | ||||
| import {TagRenderingConfigJson} from "../../../../Models/ThemeConfig/Json/TagRenderingConfigJson"; | ||||
| import LayoutConfig from "../../../../Models/ThemeConfig/LayoutConfig"; | ||||
| import * as bookcaseLayer from "../../../../assets/generated/layers/public_bookcase.json" | ||||
| import LayerConfig from "../../../../Models/ThemeConfig/LayerConfig"; | ||||
| import {ExtractImages} from "../../../../Models/ThemeConfig/Conversion/FixImages"; | ||||
| import * as cyclofix from "../../../../assets/generated/themes/cyclofix.json" | ||||
| import {Tag} from "../../../../Logic/Tags/Tag"; | ||||
| 
 | ||||
| 
 | ||||
| const themeConfigJson: LayoutConfigJson = { | ||||
|      | ||||
|     description: "Descr", | ||||
|     icon: "", | ||||
|     layers: [ | ||||
|         { | ||||
|             builtin: "public_bookcase", | ||||
|             override: { | ||||
|                 source: { | ||||
|                     geoJson: "xyz" | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     ], | ||||
|     maintainer: "", | ||||
|     startLat: 0, | ||||
|     startLon: 0, | ||||
|     startZoom: 0, | ||||
|     title: { | ||||
|         en: "Title" | ||||
|     }, | ||||
|     version: "", | ||||
|     id: "test" | ||||
| } | ||||
| 
 | ||||
| describe("PrepareTheme", () => { | ||||
| 
 | ||||
|     it("should substitute layers", () => { | ||||
| 
 | ||||
|         const sharedLayers = new Map<string, LayerConfigJson>() | ||||
|         sharedLayers.set("public_bookcase", bookcaseLayer["default"]) | ||||
|         const theme ={...themeConfigJson, layers: ["public_bookcase"]} | ||||
|         const prepareStep =  new PrepareTheme({ | ||||
|             tagRenderings: new Map<string, TagRenderingConfigJson>(), | ||||
|             sharedLayers: sharedLayers | ||||
|         }) | ||||
|         let themeConfigJsonPrepared = prepareStep.convert(theme, "test").result | ||||
|         const themeConfig = new LayoutConfig(themeConfigJsonPrepared); | ||||
|         const layerUnderTest = <LayerConfig> themeConfig.layers.find(l => l.id === "public_bookcase") | ||||
|         expect(layerUnderTest.source.osmTags).deep.eq(new Tag("amenity","public_bookcase")) | ||||
| 
 | ||||
|     }) | ||||
|      | ||||
|     it("should apply override", () => { | ||||
| 
 | ||||
|         const sharedLayers = new Map<string, LayerConfigJson>() | ||||
|         sharedLayers.set("public_bookcase", bookcaseLayer["default"]) | ||||
|         let themeConfigJsonPrepared = new PrepareTheme({ | ||||
|             tagRenderings: new Map<string, TagRenderingConfigJson>(), | ||||
|             sharedLayers: sharedLayers | ||||
|         }).convert( themeConfigJson, "test").result | ||||
|         const themeConfig = new LayoutConfig(themeConfigJsonPrepared); | ||||
|         const layerUnderTest = <LayerConfig> themeConfig.layers.find(l => l.id === "public_bookcase") | ||||
|         expect(layerUnderTest.source.geojsonSource).eq("xyz") | ||||
| 
 | ||||
|     }) | ||||
| 
 | ||||
| 
 | ||||
|     it("should apply override", () => { | ||||
| 
 | ||||
|         const sharedLayers = new Map<string, LayerConfigJson>() | ||||
|         sharedLayers.set("public_bookcase", bookcaseLayer["default"]) | ||||
|         let themeConfigJsonPrepared = new PrepareTheme({ | ||||
|             tagRenderings: new Map<string, TagRenderingConfigJson>(), | ||||
|             sharedLayers: sharedLayers | ||||
|         }).convert({...themeConfigJson, overrideAll: {source: {geoJson: "https://example.com/data.geojson"}}}, "test").result | ||||
|         const themeConfig = new LayoutConfig(themeConfigJsonPrepared); | ||||
|         const layerUnderTest = <LayerConfig> themeConfig.layers.find(l => l.id === "public_bookcase") | ||||
|         expect(layerUnderTest.source.geojsonSource).eq("https://example.com/data.geojson") | ||||
|     }) | ||||
| }) | ||||
| 
 | ||||
| 
 | ||||
| describe("ExtractImages", () => { | ||||
|     it("should find all images in a themefile", () => { | ||||
|                 const images = new Set(new ExtractImages(true, new Map<string, any>()).convertStrict(<any> cyclofix, "test")) | ||||
|                 const expectedValues = [ | ||||
|                     './assets/layers/bike_repair_station/repair_station.svg', | ||||
|                     './assets/layers/bike_repair_station/repair_station_pump.svg', | ||||
|                     './assets/layers/bike_repair_station/broken_pump.svg', | ||||
|                     './assets/layers/bike_repair_station/pump.svg', | ||||
|                     './assets/themes/cyclofix/fietsambassade_gent_logo_small.svg', | ||||
|                     './assets/layers/bike_repair_station/pump_example_manual.jpg', | ||||
|                     './assets/layers/bike_repair_station/pump_example.png', | ||||
|                     './assets/layers/bike_repair_station/pump_example_round.jpg', | ||||
|                     './assets/layers/bike_repair_station/repair_station_example_2.jpg', | ||||
|                     'close'] | ||||
|                 for (const expected of expectedValues) { | ||||
|                     expect(images).contains(expected) | ||||
|                 } | ||||
|     }) | ||||
| }) | ||||
							
								
								
									
										71
									
								
								test/Models/ThemeConfig/TagRenderingConfig.spec.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										71
									
								
								test/Models/ThemeConfig/TagRenderingConfig.spec.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,71 @@ | |||
| import {describe} from 'mocha' | ||||
| import {expect} from 'chai' | ||||
| import TagRenderingConfig from "../../../Models/ThemeConfig/TagRenderingConfig"; | ||||
| import Locale from "../../../UI/i18n/Locale"; | ||||
| 
 | ||||
| describe("TagRenderingConfig", () => { | ||||
|      | ||||
|     describe("isKnown", () => { | ||||
|          | ||||
|         it("should give correct render values", () => { | ||||
|             Locale.language.setData("nl"); | ||||
|             const tr = new TagRenderingConfig({ | ||||
|                 render: ({"en": "Name is {name}", "nl": "Ook een {name}"} as any), | ||||
|                 question: "Wat is de naam van dit object?", | ||||
|                 freeform: { | ||||
|                     key: "name", | ||||
|                 }, | ||||
| 
 | ||||
|                 mappings: [ | ||||
|                     { | ||||
|                         if: "noname=yes", | ||||
|                         "then": "Has no name" | ||||
|                     } | ||||
|                 ], | ||||
|                 condition: "x=" | ||||
|             }, "Tests"); | ||||
|              | ||||
|             expect(tr.GetRenderValue({"foo": "bar"})).undefined | ||||
| 
 | ||||
|         expect    (tr.GetRenderValue({"noname": "yes"})?.textFor("nl")).eq("Has no name") | ||||
|             expect( tr.GetRenderValue({"name": "xyz"})?.textFor("nl")).eq("Ook een {name}") | ||||
|             expect( tr.GetRenderValue({"foo": "bar"})).undefined | ||||
| 
 | ||||
|         }) | ||||
|          | ||||
|         it("should give a correct indication", () => { | ||||
|             // tests a regression in parsing
 | ||||
|             const config = { | ||||
|                 "#": "Bottle refill", | ||||
|                 "question": { | ||||
|                     "en": "How easy is it to fill water bottles?", | ||||
|                     "nl": "Hoe gemakkelijk is het om drinkbussen bij te vullen?", | ||||
|                     "de": "Wie einfach ist es, Wasserflaschen zu füllen?" | ||||
|                 }, | ||||
|                 "mappings": [ | ||||
|                     { | ||||
|                         "if": "bottle=yes", | ||||
|                         "then": { | ||||
|                             "en": "It is easy to refill water bottles", | ||||
|                             "nl": "Een drinkbus bijvullen gaat makkelijk", | ||||
|                             "de": "Es ist einfach, Wasserflaschen nachzufüllen" | ||||
|                         } | ||||
|                     }, | ||||
|                     { | ||||
|                         "if": "bottle=no", | ||||
|                         "then": { | ||||
|                             "en": "Water bottles may not fit", | ||||
|                             "nl": "Een drinkbus past moeilijk", | ||||
|                             "de": "Wasserflaschen passen möglicherweise nicht" | ||||
|                         } | ||||
|                     } | ||||
|                 ] | ||||
|             }; | ||||
| 
 | ||||
|             const tagRendering = new TagRenderingConfig(config, "test"); | ||||
|             expect(tagRendering.IsKnown({bottle: "yes"})).true | ||||
|             expect(tagRendering.IsKnown({})).false | ||||
|         }) | ||||
|     }) | ||||
| }) | ||||
| 
 | ||||
							
								
								
									
										30
									
								
								test/Models/Units.spec.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								test/Models/Units.spec.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,30 @@ | |||
| import {describe} from 'mocha' | ||||
| import {expect} from 'chai' | ||||
| import {Unit} from "../../Models/Unit"; | ||||
| import {Denomination} from "../../Models/Denomination"; | ||||
| 
 | ||||
| describe("Unit", () => { | ||||
| 
 | ||||
|         it("should convert a value back and forth", () => { | ||||
| 
 | ||||
|             const unit = new Denomination({ | ||||
|                 "canonicalDenomination": "MW", | ||||
|                 "alternativeDenomination": ["megawatts", "megawatt"], | ||||
|                 "human": { | ||||
|                     "en": " megawatts", | ||||
|                     "nl": " megawatt" | ||||
|                 }, | ||||
|                 "default": true | ||||
|             }, "test"); | ||||
| 
 | ||||
|             const canonical = unit.canonicalValue("5") | ||||
|             expect(canonical).eq( "5 MW") | ||||
|             const units = new Unit(["key"], [unit], false) | ||||
|             const [detected, detectedDenom] = units.findDenomination("5 MW") | ||||
|             expect(detected).eq( "5") | ||||
|             expect(detectedDenom).eq( unit) | ||||
|         } | ||||
|     ) | ||||
| }) | ||||
| 
 | ||||
| 
 | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue