Skip to content

Commit 8786599

Browse files
committed
test: cover redrawing composite children after a definition update
Document that composite child ids are regenerated on purpose: the conversion cache relies on the fresh ids to discard children of a changed definition.
1 parent 66726f7 commit 8786599

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

‎companion/lib/Instance/Connection/Thread/HostContext.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ export class HostContext<TConfig, TSecrets> implements ModuleHostContext<TConfig
205205
undefined,
206206
rawElement.elements || [],
207207
randomIdGenerator,
208-
true // Force new unique IDs for elements within composite definitions
208+
true // Force new unique IDs, so the conversion cache drops children of a changed definition
209209
).slice(
210210
1 // Crop off the canvas element
211211
),

‎companion/test/Graphics/ConvertGraphicsElements.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1810,6 +1810,30 @@ describe('ConvertSomeButtonGraphicsElementForDrawing', () => {
18101810
expect(placeholderText(b.children[0])).toBe('\u221e')
18111811
}
18121812
})
1813+
1814+
test('draws the new children after the definition is replaced', async () => {
1815+
const definitions: Record<string, Record<string, CompositeElementDefinition>> = {
1816+
'test-connection': {
1817+
composite1: makeDefinition('composite1', [makeTextEl({ id: 'gen-1', text: val('Old') })]),
1818+
},
1819+
}
1820+
const instanceDefs = createMockInstanceDefinitions(definitions)
1821+
const cache = new ElementConversionCache()
1822+
1823+
const before = await convert(instanceDefs, [makeCompositeEl('composite1')], cache)
1824+
expect((before.elements[0] as ButtonGraphicsGroupDrawElement).children[0]).toMatchObject({ text: 'Old' })
1825+
1826+
// A module update gives every child a fresh id
1827+
definitions['test-connection'].composite1 = makeDefinition('composite1', [
1828+
makeTextEl({ id: 'gen-2', text: val('New') }),
1829+
])
1830+
cache.queueInvalidateCompositeType(['test-connection:composite1'])
1831+
1832+
const after = await convert(instanceDefs, [makeCompositeEl('composite1')], cache)
1833+
const children = (after.elements[0] as ButtonGraphicsGroupDrawElement).children
1834+
expect(children).toHaveLength(1)
1835+
expect(children[0]).toMatchObject({ text: 'New' })
1836+
})
18131837
})
18141838

18151839
describe('id prefixing', () => {

0 commit comments

Comments
 (0)