mirror of
https://github.com/apache/superset.git
synced 2026-04-21 00:54:44 +00:00
[Refactor] Extend color scheme management to sequential schemes (#6150)
* refactor color scheme * Update data structure * Update color scheme files * wip * convert all sequential schemes * Update how color schemes are managed. Extend it for sequential schemes * extract color setup into separate file * Update imports * update imports * Add new functions to Registry * Update ColorSchemeManager to extends Registry and update unit tests * Add test for Registry * Rename ColorSchemeManager to ColorSchemeRegistry * Fix unit tests * Update API * Fix imports * Add label field * Fix reference to colors * update SequentialScheme contructor * Fix controls * rename manager to registry * Split sequential schemes into multiple files * update sequential color labels * add values and valuesAsPromise() * use .values()
This commit is contained in:
committed by
Chris Williams
parent
a71e6eb0a3
commit
b9257b2a09
@@ -17,6 +17,20 @@ describe('Registry', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('.clear()', () => {
|
||||
it('clears all registered items', () => {
|
||||
const registry = new Registry();
|
||||
registry.registerValue('a', 'testValue');
|
||||
registry.clear();
|
||||
expect(Object.keys(registry.items)).toHaveLength(0);
|
||||
expect(Object.keys(registry.promises)).toHaveLength(0);
|
||||
});
|
||||
it('returns the registry itself', () => {
|
||||
const registry = new Registry();
|
||||
expect(registry.clear()).toBe(registry);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.has(key)', () => {
|
||||
it('returns true if an item with the given key exists', () => {
|
||||
const registry = new Registry();
|
||||
@@ -134,6 +148,34 @@ describe('Registry', () => {
|
||||
);
|
||||
});
|
||||
|
||||
describe('.getMap()', () => {
|
||||
it('returns key-value map as plain object', () => {
|
||||
const registry = new Registry();
|
||||
registry.registerValue('a', 'cat');
|
||||
registry.registerLoader('b', () => 'dog');
|
||||
expect(registry.getMap()).toEqual({
|
||||
a: 'cat',
|
||||
b: 'dog',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('.getMapAsPromise()', () => {
|
||||
it('returns a promise of key-value map', () => {
|
||||
const registry = new Registry();
|
||||
registry.registerValue('a', 'test1');
|
||||
registry.registerLoader('b', () => 'test2');
|
||||
registry.registerLoader('c', () => Promise.resolve('test3'));
|
||||
return registry.getMapAsPromise().then((map) => {
|
||||
expect(map).toEqual({
|
||||
a: 'test1',
|
||||
b: 'test2',
|
||||
c: 'test3',
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('.keys()', () => {
|
||||
it('returns an array of keys', () => {
|
||||
const registry = new Registry();
|
||||
@@ -143,6 +185,34 @@ describe('Registry', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('.values()', () => {
|
||||
it('returns an array of values', () => {
|
||||
const registry = new Registry();
|
||||
registry.registerValue('a', 'test1');
|
||||
registry.registerLoader('b', () => 'test2');
|
||||
expect(registry.values()).toEqual([
|
||||
'test1',
|
||||
'test2',
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.valuesAsPromise()', () => {
|
||||
it('returns a Promise of an array { key, value }', () => {
|
||||
const registry = new Registry();
|
||||
registry.registerValue('a', 'test1');
|
||||
registry.registerLoader('b', () => 'test2');
|
||||
registry.registerLoader('c', () => Promise.resolve('test3'));
|
||||
return registry.valuesAsPromise().then((entries) => {
|
||||
expect(entries).toEqual([
|
||||
'test1',
|
||||
'test2',
|
||||
'test3',
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('.entries()', () => {
|
||||
it('returns an array of { key, value }', () => {
|
||||
const registry = new Registry();
|
||||
|
||||
Reference in New Issue
Block a user