forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: extract mock plugins into separate file (apache#172)
* test: extract mock plugins into separate file * fix: use constants * fix: test coverage
- Loading branch information
Showing
2 changed files
with
110 additions
and
68 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: ChartKeys.DILIGENT, | ||
thumbnail: '', | ||
}), | ||
Chart: TestComponent, | ||
transformProps: x => x, | ||
}); | ||
} | ||
} | ||
|
||
export class LazyChartPlugin extends ChartPlugin<ChartFormData> { | ||
constructor() { | ||
super({ | ||
metadata: new ChartMetadata({ | ||
name: ChartKeys.LAZY, | ||
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: ChartKeys.SLOW, | ||
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