From 2c53ece7983f3f95cf4649f1be57359757858cf9 Mon Sep 17 00:00:00 2001 From: Robbie Wagner Date: Fri, 26 Jul 2024 08:41:12 -0400 Subject: [PATCH] Add test helper --- ember-highcharts/rollup.config.mjs | 3 +- ember-highcharts/src/test-support/helpers.ts | 30 ++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 ember-highcharts/src/test-support/helpers.ts diff --git a/ember-highcharts/rollup.config.mjs b/ember-highcharts/rollup.config.mjs index 7a7496e..5fb4499 100644 --- a/ember-highcharts/rollup.config.mjs +++ b/ember-highcharts/rollup.config.mjs @@ -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 @@ -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 diff --git a/ember-highcharts/src/test-support/helpers.ts b/ember-highcharts/src/test-support/helpers.ts new file mode 100644 index 0000000..827a7cb --- /dev/null +++ b/ember-highcharts/src/test-support/helpers.ts @@ -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; +}