map: fix subtype filter dropping every measuring tool
MapView carried its own copy of the per-type subtype-id lookup and it never gained a Measuring Tool branch, so selecting any measuring-tool subtype filtered out all assets. Marker coloring and the PDF export were unaffected because both already used the shared getSubtypeId helper. Point the filter at that shared helper and delete the duplicate copy in ShopFloorMap too, so one definition serves filter, coloring and export. Adds a table-driven spec covering every subtype-carrying asset type.
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