mirror of
https://github.com/apache/superset.git
synced 2024-09-19 20:19:37 -04:00
feat: 🎸 add .clone() function to ChartMetadata (#112)
* feat: 🎸 add .clone() function to ChartMetadata * test: 💍 add unit tests * fix: 🐛 lint
This commit is contained in:
parent
e14d6567a9
commit
9454aed59f
@ -4,6 +4,7 @@ interface LookupTable {
|
||||
|
||||
export default class ChartMetadata {
|
||||
name: string;
|
||||
canBeAnnotationTypes?: string[];
|
||||
canBeAnnotationTypesLookup: LookupTable;
|
||||
credits: string[];
|
||||
description: string;
|
||||
@ -37,6 +38,7 @@ export default class ChartMetadata {
|
||||
this.credits = credits;
|
||||
this.description = description;
|
||||
this.show = show;
|
||||
this.canBeAnnotationTypes = canBeAnnotationTypes;
|
||||
this.canBeAnnotationTypesLookup = canBeAnnotationTypes.reduce(
|
||||
(prev: LookupTable, type: string) => {
|
||||
const lookup = prev;
|
||||
@ -54,4 +56,17 @@ export default class ChartMetadata {
|
||||
canBeAnnotationType(type: string): boolean {
|
||||
return this.canBeAnnotationTypesLookup[type] || false;
|
||||
}
|
||||
|
||||
clone() {
|
||||
return new ChartMetadata({
|
||||
canBeAnnotationTypes: this.canBeAnnotationTypes,
|
||||
credits: this.credits,
|
||||
description: this.description,
|
||||
name: this.name,
|
||||
show: this.show,
|
||||
supportedAnnotationTypes: this.supportedAnnotationTypes,
|
||||
thumbnail: this.thumbnail,
|
||||
useLegacyApi: this.useLegacyApi,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -18,9 +18,9 @@ describe('ChartMetadata', () => {
|
||||
describe('.canBeAnnotationType(type)', () => {
|
||||
const metadata = new ChartMetadata({
|
||||
name: 'test chart',
|
||||
canBeAnnotationTypes: ['event'],
|
||||
credits: [],
|
||||
description: 'some kind of chart',
|
||||
canBeAnnotationTypes: ['event'],
|
||||
thumbnail: 'test.png',
|
||||
});
|
||||
it('returns true if can', () => {
|
||||
@ -30,4 +30,25 @@ describe('ChartMetadata', () => {
|
||||
expect(metadata.canBeAnnotationType('invalid-type')).toBeFalsy();
|
||||
});
|
||||
});
|
||||
describe('.clone()', () => {
|
||||
const metadata = new ChartMetadata({
|
||||
name: 'test chart',
|
||||
canBeAnnotationTypes: ['event'],
|
||||
credits: [],
|
||||
description: 'some kind of chart',
|
||||
thumbnail: 'test.png',
|
||||
});
|
||||
const clone = metadata.clone();
|
||||
|
||||
it('returns a new instance', () => {
|
||||
expect(metadata).not.toBe(clone);
|
||||
});
|
||||
it('returns a new instance with same field values', () => {
|
||||
expect(metadata.name).toEqual(clone.name);
|
||||
expect(metadata.credits).toEqual(clone.credits);
|
||||
expect(metadata.description).toEqual(clone.description);
|
||||
expect(metadata.canBeAnnotationTypes).toEqual(clone.canBeAnnotationTypes);
|
||||
expect(metadata.thumbnail).toEqual(clone.thumbnail);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user