Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getHighchartsChart test helper #470

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions ember-highcharts/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default {
// up your addon's public API. Also make sure your package.json#exports
// is aligned to the config here.
// See https://github.com/embroider-build/embroider/blob/main/docs/v2-faq.md#how-can-i-define-the-public-exports-of-my-addon
addon.publicEntrypoints(["index.js", "**/*.js"]),
addon.publicEntrypoints(['index.js', '**/*.js']),

// These are the modules that should get reexported into the traditional
// "app" tree. Things in here should also be in publicEntrypoints above, but
Expand All @@ -30,7 +30,6 @@ export default {
'helpers/**/*.js',
'modifiers/**/*.js',
'services/**/*.js',
"modifiers/**/*.js"
]),

// Follow the V2 Addon rules about dependencies. Your code can import from
Expand Down
30 changes: 30 additions & 0 deletions ember-highcharts/src/test-support/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { find, waitFor, waitUntil } from '@ember/test-helpers';

import Highcharts from 'highcharts';

type ChartContainerElement = {
dataset: {
highchartsChart: string;
};
};

/**
* Finds the Highcharts chart container for a given chart and returns the Highcharts.Chart for it.
* This is useful for testing that the options for the chart are what you expect.
* @param selector The selector for your chart wrapper element
*/
export async function getHighchartsChart(selector: string) {
await waitFor(`${selector} .chart-container`);

const chartContainer = find(
`${selector} .chart-container`,
) as unknown as ChartContainerElement;

await waitUntil(
() => Highcharts.charts[Number(chartContainer.dataset.highchartsChart)],
);

return Highcharts.charts[
Number(chartContainer.dataset.highchartsChart)
] as Highcharts.Chart;
}
Loading