From 6074af57d508046bbd800810fbbf2766544775a8 Mon Sep 17 00:00:00 2001 From: Daniel Starns Date: Wed, 2 Oct 2024 23:20:02 -0700 Subject: [PATCH] test: coverage using data-var with .addCollection (#6186) * feat: expose class creation * test: coverage for data-var using .addCollection * Cleanup --------- Co-authored-by: Artur Arseniev --- .../data_sources/model/StyleDataVariable.ts | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/packages/core/test/specs/data_sources/model/StyleDataVariable.ts b/packages/core/test/specs/data_sources/model/StyleDataVariable.ts index ba273d83c..431b67a2b 100644 --- a/packages/core/test/specs/data_sources/model/StyleDataVariable.ts +++ b/packages/core/test/specs/data_sources/model/StyleDataVariable.ts @@ -156,4 +156,54 @@ describe('StyleDataVariable', () => { const updatedStyle = cmp.getStyle(); expect(updatedStyle).toHaveProperty('color', 'blue'); }); + + describe('.addToCollection', () => { + test('should add a datavariable to css rule made via .addToCollection', () => { + const dsId = 'globalStyles'; + const drId = 'red-header'; + const selector = 'h1'; + + const addToCollectionDataSource: DataSourceProps = { + id: dsId, + records: [ + { + id: drId, + property: 'color', + value: 'red', + selector, + label: 'Red Header', + }, + ], + }; + dsm.add(addToCollectionDataSource); + + cmpRoot.append({ + tagName: 'h1', + type: 'text', + content: 'Hello World', + })[0]; + + em.getEditor().CssComposer.addCollection([ + { + selectors: [], + selectorsAdd: selector, + group: `globalStyles:${drId}`, + style: { + color: { + type: DataVariableType, + defaultValue: 'black', + path: `${dsId}.${drId}.value`, + }, + }, + }, + ]); + + expect(em.getEditor().getCss()).toContain(`${selector}{color:red;}`); + + const ds = dsm.get(dsId); + ds.getRecord(drId)?.set({ value: 'blue' }); + + expect(em.getEditor().getCss()).toContain(`${selector}{color:blue;}`); + }); + }); });