map: fix subtype filter dropping every measuring tool

This commit is contained in:
2026-07-31 07:59:20 -04:00
parent d6e3edb33f
commit a595eaffd5
4 changed files with 63 additions and 30 deletions

View File

@@ -0,0 +1,38 @@
import { describe, it, expect } from 'vitest'
import { getSubtypeId, resolveMarkerColor } from './mapColors'
// One case per asset type that carries a subtype. A missing branch here means
// the map subtype filter silently drops every asset of that type.
const cases = [
['Machine', { machinetypeid: 3 }],
['Computer', { computertypeid: 3 }],
['Network Device', { networkdevicetypeid: 3 }],
['network_device', { networkdevicetypeid: 3 }],
['Printer', { printertypeid: 3 }],
['Measuring Tool', { measuringtooltypeid: 3 }],
]
describe('getSubtypeId', () => {
it.each(cases)('resolves the subtype id for %s', (assettype, typedata) => {
expect(getSubtypeId({ assettype, typedata })).toBe(3)
})
it('returns null without typedata', () => {
expect(getSubtypeId({ assettype: 'Machine' })).toBeNull()
})
it('returns null for an asset type with no subtype table', () => {
expect(getSubtypeId({ assettype: 'Furniture', typedata: {} })).toBeNull()
})
})
describe('resolveMarkerColor', () => {
it('colors a measuring tool by its subtype when a type is selected', () => {
const asset = { assettype: 'Measuring Tool', typedata: { measuringtooltypeid: 7 } }
const color = resolveMarkerColor(asset, {
selectedType: 'Measuring Tool',
subtypeColors: { 7: '#00BCD4' },
})
expect(color).toBe('#00BCD4')
})
})