mirror of
https://forge.chapril.org/tykayn/wololo
synced 2025-06-20 01:34:42 +02:00
add tests and utils : limit values, get max in enums
This commit is contained in:
parent
aa35803a0b
commit
b4c28335b2
10 changed files with 153 additions and 43 deletions
|
@ -6,6 +6,8 @@ import {
|
|||
mappingName,
|
||||
mappingSame, mappingTruthy, mappingFalsy, mappingIgnoreFalsy, mappingIgnoreTruthy
|
||||
} from './data/mappings_to_test'
|
||||
import utils from '../mappings/utils'
|
||||
import Formatters from '../mappings/formatters'
|
||||
|
||||
const testingGeoJson = require('./data/testing.json')
|
||||
|
||||
|
@ -29,10 +31,10 @@ describe('mapping properties with rich mapping engine', () => {
|
|||
let newProperties = Mapping_engine.convertProperty('equal',
|
||||
Object.keys(mappingSame.tags),
|
||||
feature_to_test,
|
||||
mappingSame.default_properties_of_point )
|
||||
mappingSame.default_properties_of_point)
|
||||
|
||||
expect(newProperties).toStrictEqual({
|
||||
equal : "same value"
|
||||
equal: "same value"
|
||||
})
|
||||
})
|
||||
test('retrieve config name in mapping engine', () => {
|
||||
|
@ -41,11 +43,11 @@ describe('mapping properties with rich mapping engine', () => {
|
|||
})
|
||||
test('maps nom_amenageur to name, and keep the same value', () => {
|
||||
let Mapping_engine = new mapping_engine(mappingName)
|
||||
let newProperties = Mapping_engine.convertProperty('nom_amenageur',Object.keys(mappingName.tags),feature_to_test,mappingName.default_properties_of_point )
|
||||
let newProperties = Mapping_engine.convertProperty('nom_amenageur', Object.keys(mappingName.tags), feature_to_test, mappingName.default_properties_of_point)
|
||||
expect(Mapping_engine.getConfig().config_name).toBe('testing config mappingName')
|
||||
|
||||
expect(newProperties).toStrictEqual({
|
||||
name : "Bob"
|
||||
name: "Bob"
|
||||
})
|
||||
})
|
||||
test('ignore one value if it is truthy', () => {
|
||||
|
@ -123,7 +125,7 @@ describe('mapping properties with rich mapping engine', () => {
|
|||
|
||||
feature_to_test.properties.telephone_operateur = 'Stations-e'
|
||||
mapped_point = Mapping_engine.mapElementFromConf(feature_to_test)
|
||||
expect(mapped_point.properties).toStrictEqual({ })
|
||||
expect(mapped_point.properties).toStrictEqual({})
|
||||
|
||||
feature_to_test.properties.telephone_operateur = '+33 0 7 66 38 74 96'
|
||||
expected_converted_phone = '+33 7 66 38 74 96'
|
||||
|
@ -162,3 +164,43 @@ xdescribe('infer domain of values from geojson file', () => {
|
|||
xdescribe('build mapping engine config from unique values', () => {
|
||||
test('builds a valid mapping config', () => { })
|
||||
})
|
||||
|
||||
describe('find max in enum', () => {
|
||||
test('value has enums', () => {
|
||||
let value = '1;2;3;10;4;5;6;7;8;9;'
|
||||
let max = utils.find_max_in_string(value)
|
||||
expect(max).toBe(10)
|
||||
})
|
||||
test('value has enums with maybe units', () => {
|
||||
let value = '1;2;3;10 km;4;5 kw;6;7;8;9;'
|
||||
let max = utils.find_max_in_string(value)
|
||||
expect(max).toBe(10)
|
||||
})
|
||||
|
||||
test('value has no enums', () => {
|
||||
let max = utils.find_max_in_string('10')
|
||||
console.log('max', max)
|
||||
expect(max).toBe(10)
|
||||
})
|
||||
})
|
||||
|
||||
describe('truncate enums to limit', () => {
|
||||
test('truncate enums to limit', () => {
|
||||
let value = '1;2;3;10 km;4;5 kw;6;7;8;9;'
|
||||
let truncated = utils.truncate_enums_to_limit(value, 5)
|
||||
expect(truncated).toBe('1;2;')
|
||||
})
|
||||
})
|
||||
|
||||
describe('formatters tests', () => {
|
||||
test('format phone', () => {
|
||||
let phone = '+331 2345 6789'
|
||||
let formatted = Formatters.convertToPhone(phone)
|
||||
expect(formatted).toBe('+33 1 23 45 67 89')
|
||||
})
|
||||
test('format name', () => {
|
||||
let name = 'bob lénon'
|
||||
let formatted = Formatters.convertToName(name)
|
||||
expect(formatted).toBe('Bob lénon')
|
||||
})
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue