From adb05440895af80a4c2a5573f30c4c2b981a103e Mon Sep 17 00:00:00 2001 From: danstarns Date: Wed, 14 Aug 2024 13:32:38 -0700 Subject: [PATCH] test: add traint input update coverage --- test/specs/data_sources/index.ts | 84 +++++++++++++++++++++++--------- 1 file changed, 60 insertions(+), 24 deletions(-) diff --git a/test/specs/data_sources/index.ts b/test/specs/data_sources/index.ts index acee0b64c..a4c831610 100644 --- a/test/specs/data_sources/index.ts +++ b/test/specs/data_sources/index.ts @@ -317,33 +317,69 @@ describe('DataSourceManager', () => { fixtures.appendChild(wrapperEl.el); }); - test('component initializes with data-variable trait input', () => { - const inputDataSource: DataSourceProps = { - id: 'test-input', - records: [{ id: 'id1', value: 'test-value' }], - }; - dsm.add(inputDataSource); + describe('input component', () => { + test('component initializes with trait data-variable on input component', () => { + const inputDataSource: DataSourceProps = { + id: 'test-input', + records: [{ id: 'id1', value: 'test-value' }], + }; + dsm.add(inputDataSource); + + const cmp = cmpRoot.append({ + tagName: 'input', + traits: [ + 'name', + 'type', + { + type: 'text', + label: 'Value', + name: 'value', + value: { + type: 'data-variable', + value: 'default', + path: 'test-input.id1.value', + }, + }, + ], + })[0]; - const cmp = cmpRoot.append({ - tagName: 'input', - traits: [ - 'name', - 'type', - { - type: 'text', - label: 'Value', - name: 'value', - value: { - type: 'data-variable', - value: 'default', - path: 'test-input.id1.value', + const input = cmp.getEl(); + expect(input?.getAttribute('value')).toBe('test-value'); + }); + + test('component updates with trait data-variable on input component', () => { + const inputDataSource: DataSourceProps = { + id: 'test-input', + records: [{ id: 'id1', value: 'test-value' }], + }; + dsm.add(inputDataSource); + + const cmp = cmpRoot.append({ + tagName: 'input', + traits: [ + 'name', + 'type', + { + type: 'text', + label: 'Value', + name: 'value', + value: { + type: 'data-variable', + value: 'default', + path: 'test-input.id1.value', + }, }, - }, - ], - })[0]; + ], + })[0]; - const input = cmp.getEl(); - expect(input?.getAttribute('value')).toBe('test-value'); + const input = cmp.getEl(); + expect(input?.getAttribute('value')).toBe('test-value'); + + const testDs = dsm.get('test-input'); + testDs.getRecord('id1')?.set({ value: 'new-value' }); + + expect(input?.getAttribute('value')).toBe('new-value'); + }); }); });