Browse Source

test: add image trait datasource coverage

ci/dependabot
danstarns 2 years ago
parent
commit
69c6395197
  1. 46
      test/specs/data_sources/model/TraitDataVariable.ts

46
test/specs/data_sources/model/TraitDataVariable.ts

@ -53,7 +53,7 @@ describe('TraitDataVariable', () => {
value: { value: {
type: DataVariableType, type: DataVariableType,
value: 'default', value: 'default',
path: 'test-input.id1.value', path: `${inputDataSource.id}.id1.value`,
}, },
}, },
], ],
@ -81,7 +81,7 @@ describe('TraitDataVariable', () => {
value: { value: {
type: DataVariableType, type: DataVariableType,
value: 'default', value: 'default',
path: 'test-input.id1.value', path: `${inputDataSource.id}.id1.value`,
}, },
}, },
], ],
@ -90,7 +90,7 @@ describe('TraitDataVariable', () => {
const input = cmp.getEl(); const input = cmp.getEl();
expect(input?.getAttribute('placeholder')).toBe('test-value'); expect(input?.getAttribute('placeholder')).toBe('test-value');
const testDs = dsm.get('test-input'); const testDs = dsm.get(inputDataSource.id);
testDs.getRecord('id1')?.set({ value: 'new-value' }); testDs.getRecord('id1')?.set({ value: 'new-value' });
expect(input?.getAttribute('placeholder')).toBe('new-value'); expect(input?.getAttribute('placeholder')).toBe('new-value');
}); });
@ -114,7 +114,7 @@ describe('TraitDataVariable', () => {
value: { value: {
type: DataVariableType, type: DataVariableType,
value: 'default', value: 'default',
path: 'test-input.id1.value', path: `${inputDataSource.id}.id1.value`,
}, },
}, },
], ],
@ -123,7 +123,7 @@ describe('TraitDataVariable', () => {
const input = cmp.getEl(); const input = cmp.getEl();
expect(input?.getAttribute('value')).toBe('test-value'); expect(input?.getAttribute('value')).toBe('test-value');
const testDs = dsm.get('test-input'); const testDs = dsm.get(inputDataSource.id);
testDs.getRecord('id1')?.set({ value: 'new-value' }); testDs.getRecord('id1')?.set({ value: 'new-value' });
expect(input?.getAttribute('value')).toBe('new-value'); expect(input?.getAttribute('value')).toBe('new-value');
}); });
@ -149,7 +149,7 @@ describe('TraitDataVariable', () => {
value: { value: {
type: 'data-variable', type: 'data-variable',
value: 'false', value: 'false',
path: 'test-checkbox-datasource.id1.value', path: `${inputDataSource.id}.id1.value`,
}, },
valueTrue: 'true', valueTrue: 'true',
valueFalse: 'false', valueFalse: 'false',
@ -160,9 +160,41 @@ describe('TraitDataVariable', () => {
const input = cmp.getEl() as HTMLInputElement; const input = cmp.getEl() as HTMLInputElement;
expect(input?.checked).toBe(true); expect(input?.checked).toBe(true);
const testDs = dsm.get('test-checkbox-datasource'); const testDs = dsm.get(inputDataSource.id);
testDs.getRecord('id1')?.set({ value: 'false' }); testDs.getRecord('id1')?.set({ value: 'false' });
expect(input?.getAttribute('checked')).toBe('false'); expect(input?.getAttribute('checked')).toBe('false');
}); });
}); });
describe('image component', () => {
test('component initializes and updates data-variable value', () => {
const inputDataSource: DataSourceProps = {
id: 'test-image-datasource',
records: [{ id: 'id1', value: 'url-to-cat-image' }],
};
dsm.add(inputDataSource);
const cmp = cmpRoot.append({
type: 'image',
tagName: 'img',
traits: [
{
type: 'text',
name: 'src',
value: {
type: 'data-variable',
value: 'default',
path: `${inputDataSource.id}.id1.value`,
},
},
],
})[0];
const img = cmp.getEl() as HTMLImageElement;
const testDs = dsm.get(inputDataSource.id);
testDs.getRecord('id1')?.set({ value: 'url-to-dog-image' });
expect(img?.getAttribute('src')).toBe('url-to-dog-image');
});
});
}); });

Loading…
Cancel
Save