map: fix subtype filter dropping every measuring tool
Some checks failed
CI / backend (push) Has been cancelled
CI / naming (push) Has been cancelled
CI / frontend (push) Has been cancelled
CI / migrations-mysql (push) Has been cancelled

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:
cproudlock
2026-07-31 07:56:09 -04:00
parent 86697a4e7b
commit 71982fc0f1
3 changed files with 46 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')
})
})