map: fix subtype filter dropping every measuring tool
This commit is contained in:
38
frontend/src/utils/mapColors.spec.js
Normal file
38
frontend/src/utils/mapColors.spec.js
Normal 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')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user