add test and split codebase

This commit is contained in:
Tykayn 2024-12-17 11:53:02 +01:00 committed by tykayn
parent 0614feaa03
commit be0ea5263c
8 changed files with 6928 additions and 117 deletions

45
tests/main.test.js Normal file
View file

@ -0,0 +1,45 @@
import utils from '../js/utils'
import colorUtils from '../js/color-utils'
describe('testing on features', () => {
const featureWithOutput = {
properties: {
tags: {
'socket:type2:output': '30 kW'
}
}
}
const featureWithBadOutput = {
properties: {
tags: {
'socket:type2:output': '50000'
}
}
}
const featureWithoutOutput = {
properties: {
tags: {
'socket:type2': '2'
}
}
}
describe('testing outputPower', () => {
it('finds max outputpower when existing', () => {
let outputFound = utils.guessOutputPowerFromFeature(featureWithOutput)
expect(outputFound).toEqual(30)
})
})
describe('testing corresponding color', () => {
it('finds undefined color', () => {
let color = colorUtils.getColor(featureWithoutOutput)
expect(color).toEqual('#c0b1b1')
})
it('finds bad color', () => {
let color = colorUtils.getColor(featureWithBadOutput)
expect(color).toEqual('#ff1414')
})
})
})