From b911c08cec0dc42b466151ef07e27ec491dfe1f4 Mon Sep 17 00:00:00 2001 From: danstarns Date: Fri, 16 Aug 2024 14:32:42 -0700 Subject: [PATCH] test: add checkbox datasources trait coverage --- .../data_sources/model/TraitDataVariable.ts | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/test/specs/data_sources/model/TraitDataVariable.ts b/test/specs/data_sources/model/TraitDataVariable.ts index fdf938ca4..fab008960 100644 --- a/test/specs/data_sources/model/TraitDataVariable.ts +++ b/test/specs/data_sources/model/TraitDataVariable.ts @@ -128,4 +128,41 @@ describe('TraitDataVariable', () => { expect(input?.getAttribute('value')).toBe('new-value'); }); }); + + describe('checkbox input component', () => { + test('component initializes and updates data-variable value', () => { + const inputDataSource: DataSourceProps = { + id: 'test-checkbox-datasource', + records: [{ id: 'id1', value: 'true' }], + }; + dsm.add(inputDataSource); + + const cmp = cmpRoot.append({ + type: 'checkbox', + tagName: 'input', + attributes: { type: 'checkbox', name: 'my-checkbox' }, + traits: [ + { + type: 'checkbox', + label: 'Checked', + name: 'checked', + value: { + type: 'data-variable', + value: 'false', + path: 'test-checkbox-datasource.id1.value', + }, + valueTrue: 'true', + valueFalse: 'false', + }, + ], + })[0]; + + const input = cmp.getEl() as HTMLInputElement; + expect(input?.checked).toBe(true); + + const testDs = dsm.get('test-checkbox-datasource'); + testDs.getRecord('id1')?.set({ value: 'false' }); + expect(input?.getAttribute('checked')).toBe('false'); + }); + }); });