This repository has been archived by the owner on Dec 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: refactor unit test for SuperChartKernel
- Loading branch information
Showing
2 changed files
with
102 additions
and
70 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
packages/superset-ui-chart/test/components/MockChartPlugins.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React from 'react'; | ||
import { ChartMetadata, ChartPlugin, ChartFormData } from '../../src'; | ||
|
||
export const TestComponent = ({ | ||
message, | ||
width, | ||
height, | ||
}: { | ||
message: string; | ||
width: number; | ||
height: number; | ||
}) => ( | ||
<div className="test-component"> | ||
<span className="message">{message || 'test-message'}</span> | ||
<span className="dimension">{[width, height].join('x')}</span> | ||
</div> | ||
); | ||
|
||
export const ChartKeys = { | ||
DILIGENT: 'diligent-chart', | ||
LAZY: 'lazy-chart', | ||
SLOW: 'slow-chart', | ||
}; | ||
|
||
export class DiligentChartPlugin extends ChartPlugin<ChartFormData> { | ||
constructor() { | ||
super({ | ||
metadata: new ChartMetadata({ | ||
name: 'diligent-chart', | ||
thumbnail: '', | ||
}), | ||
Chart: TestComponent, | ||
transformProps: x => x, | ||
}); | ||
} | ||
} | ||
|
||
export class LazyChartPlugin extends ChartPlugin<ChartFormData> { | ||
constructor() { | ||
super({ | ||
metadata: new ChartMetadata({ | ||
name: 'lazy-chart', | ||
thumbnail: '', | ||
}), | ||
// this mirrors `() => import(module)` syntax | ||
loadChart: () => Promise.resolve({ default: TestComponent }), | ||
// promise without .default | ||
loadTransformProps: () => Promise.resolve((x: any) => x), | ||
}); | ||
} | ||
} | ||
|
||
export class SlowChartPlugin extends ChartPlugin<ChartFormData> { | ||
constructor() { | ||
super({ | ||
metadata: new ChartMetadata({ | ||
name: 'slow-chart', | ||
thumbnail: '', | ||
}), | ||
loadChart: () => | ||
new Promise(resolve => { | ||
setTimeout(() => { | ||
resolve(TestComponent); | ||
}, 1000); | ||
}), | ||
transformProps: x => x, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters