Browse Source

Up test

data-source-schema
Artur Arseniev 11 months ago
parent
commit
1952031ae4
  1. 10
      packages/core/src/data_sources/index.ts
  2. 6
      packages/core/test/specs/data_sources/index.ts

10
packages/core/src/data_sources/index.ts

@ -73,14 +73,14 @@ export default class DataSourceManager extends ItemManagerModule<ModuleConfig, D
} }
/** /**
* Get value from data sources by key * Get value from data sources by path.
* @param {String} key Path to value. * @param {String} path Path to value.
* @param {any} defValue * @param {any} defValue Default value if the path is not found.
* @returns {any} * @returns {any}
* const value = dsm.getValue('ds_id.record_id.propName', 'defaultValue'); * const value = dsm.getValue('ds_id.record_id.propName', 'defaultValue');
*/ */
getValue(key: string | string[], defValue: any) { getValue(path: string | string[], defValue?: any) {
return get(this.getContext(), key, defValue); return get(this.getContext(), path, defValue);
} }
private getContext() { private getContext() {

6
packages/core/test/specs/data_sources/index.ts

@ -35,7 +35,7 @@ describe('DataSourceManager', () => {
em.on(dsm.events.add, eventAdd); em.on(dsm.events.add, eventAdd);
const ds = addDataSource(); const ds = addDataSource();
expect(dsm.getAll().length).toBe(1); expect(dsm.getAll().length).toBe(1);
expect(eventAdd).toBeCalledTimes(1); expect(eventAdd).toHaveBeenCalledTimes(1);
expect(ds.getRecords().length).toBe(3); expect(ds.getRecords().length).toBe(3);
}); });
@ -50,7 +50,7 @@ describe('DataSourceManager', () => {
const ds = addDataSource(); const ds = addDataSource();
dsm.remove('ds1'); dsm.remove('ds1');
expect(dsm.getAll().length).toBe(0); expect(dsm.getAll().length).toBe(0);
expect(event).toBeCalledTimes(1); expect(event).toHaveBeenCalledTimes(1);
expect(event).toBeCalledWith(ds, expect.any(Object)); expect(event).toHaveBeenCalledWith(ds, expect.any(Object));
}); });
}); });

Loading…
Cancel
Save