Skip to content

Commit

Permalink
test: coverage using data-var with .addCollection (#6186)
Browse files Browse the repository at this point in the history
* feat: expose class creation

* test: coverage for data-var using .addCollection

* Cleanup

---------

Co-authored-by: Artur Arseniev <artur.catch@hotmail.it>
  • Loading branch information
danstarns and artf authored Oct 3, 2024
1 parent d6647a9 commit 6074af5
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions packages/core/test/specs/data_sources/model/StyleDataVariable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;}`);
});
});
});

0 comments on commit 6074af5

Please sign in to comment.