Skip to content

Commit

Permalink
Added required chartTheme to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bmingles committed Oct 31, 2023
1 parent 2089a6d commit 9b97a3f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 28 deletions.
8 changes: 7 additions & 1 deletion packages/chart/src/ChartModelFactory.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import dh from '@deephaven/jsapi-shim';
import { TestUtils } from '@deephaven/utils';
import ChartModelFactory from './ChartModelFactory';
import type { ChartTheme } from './ChartTheme';
import FigureChartModel from './FigureChartModel';

const { createMockProxy } = TestUtils;

describe('creating model from metadata', () => {
it('handles loading a FigureChartModel from table settings', async () => {
const columns = [{ name: 'A' }, { name: 'B' }, { name: 'C' }];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const table = new (dh as any).Table({ columns });
const settings = { series: ['C'], xAxis: 'name', type: 'PIE' as const };
const chartTheme = createMockProxy<ChartTheme>();
const model = await ChartModelFactory.makeModelFromSettings(
dh,
settings,
table
table,
chartTheme
);

expect(model).toBeInstanceOf(FigureChartModel);
Expand Down
32 changes: 19 additions & 13 deletions packages/chart/src/ChartUtils.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import dh from '@deephaven/jsapi-shim';
import { Formatter } from '@deephaven/jsapi-utils';
import { TestUtils } from '@deephaven/utils';
import { Layout } from 'plotly.js';
import ChartUtils from './ChartUtils';
import ChartTestUtils from './ChartTestUtils';
import ChartTheme from './ChartTheme';
import type { ChartTheme } from './ChartTheme';

const chartUtils = new ChartUtils(dh);
const chartTestUtils = new ChartTestUtils(dh);

const { createMockProxy } = TestUtils;

function makeFormatter() {
return new Formatter(dh);
}

const chartTheme = createMockProxy<ChartTheme>();

it('groups the axes by type properly', () => {
const testAxes = (axes, expectedResult) => {
const chart = { axes };
Expand All @@ -37,8 +42,8 @@ it('groups the axes by type properly', () => {
});

it('returns a newly composed layout object each time', () => {
const layout1 = chartUtils.makeDefaultLayout(ChartTheme);
const layout2 = chartUtils.makeDefaultLayout(ChartTheme);
const layout1 = chartUtils.makeDefaultLayout(chartTheme);
const layout2 = chartUtils.makeDefaultLayout(chartTheme);

expect(layout1).not.toBe(layout2);
expect(layout1.xaxis).not.toBe(layout2.xaxis);
Expand Down Expand Up @@ -194,7 +199,7 @@ describe('updating layout axes', () => {
it('adds new axes', () => {
const layout = {};
const axes = makeTwinAxes();
chartUtils.updateLayoutAxes(layout, axes, axes);
chartUtils.updateLayoutAxes(layout, axes, axes, chartTheme);
expect(layout).toEqual(
expect.objectContaining({
xaxis: expect.objectContaining({
Expand All @@ -216,11 +221,11 @@ describe('updating layout axes', () => {
it('keeps the same axis objects, updates domain', () => {
const layout: Partial<Layout> = {};
const axes = makeTwinAxes();
chartUtils.updateLayoutAxes(layout, axes, axes, 10);
chartUtils.updateLayoutAxes(layout, axes, axes, chartTheme, 10);

const { xaxis } = layout;
const xDomain = [...(xaxis?.domain ?? [])];
chartUtils.updateLayoutAxes(layout, axes, axes, 1000);
chartUtils.updateLayoutAxes(layout, axes, axes, chartTheme, 1000);

expect(layout.xaxis).toBe(xaxis);
expect(xDomain).not.toBe(xaxis?.domain);
Expand All @@ -231,7 +236,7 @@ describe('updating layout axes', () => {
const axes = makeTwinAxes();
const chart = chartTestUtils.makeChart({ axes });
const figure = chartTestUtils.makeFigure({ charts: [chart] });
chartUtils.updateFigureAxes(layout, figure);
chartUtils.updateFigureAxes(layout, figure, chartTheme);
expect(layout).toEqual(
expect.objectContaining({
xaxis: expect.objectContaining({}),
Expand All @@ -241,7 +246,7 @@ describe('updating layout axes', () => {
);

axes.pop();
chartUtils.updateFigureAxes(layout, figure);
chartUtils.updateFigureAxes(layout, figure, chartTheme);
expect(layout).toEqual(
expect.objectContaining({
xaxis: expect.objectContaining({}),
Expand Down Expand Up @@ -300,6 +305,7 @@ describe('updating layout axes', () => {
layout,
axes,
figureAxes,
chartTheme,
width,
height,
bounds
Expand Down Expand Up @@ -416,21 +422,21 @@ describe('handles subplots and columns/rows correctly', () => {
describe('returns the axis layout ranges properly', () => {
function makeLayout(layout) {
return {
...chartUtils.makeDefaultLayout(ChartTheme),
...chartUtils.makeDefaultLayout(chartTheme),
...layout,
};
}
function testRange(layout, ranges) {
expect(ChartUtils.getLayoutRanges(makeLayout(layout))).toEqual(ranges);
}

const xaxis = chartUtils.makeLayoutAxis(dh.plot.AxisType.X);
const xaxis = chartUtils.makeLayoutAxis(dh.plot.AxisType.X, chartTheme);
xaxis.range = [0, 1];
const xaxis2 = chartUtils.makeLayoutAxis(dh.plot.AxisType.X);
const xaxis2 = chartUtils.makeLayoutAxis(dh.plot.AxisType.X, chartTheme);
xaxis2.range = [2, 3];
const yaxis = chartUtils.makeLayoutAxis(dh.plot.AxisType.Y);
const yaxis = chartUtils.makeLayoutAxis(dh.plot.AxisType.Y, chartTheme);
yaxis.range = [4, 5];
const yaxis2 = chartUtils.makeLayoutAxis(dh.plot.AxisType.Y);
const yaxis2 = chartUtils.makeLayoutAxis(dh.plot.AxisType.Y, chartTheme);
yaxis2.range = [6, 7];

it('handles empty', () => {
Expand Down
34 changes: 20 additions & 14 deletions packages/chart/src/FigureChartModel.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
import dh from '@deephaven/jsapi-shim';
import { TestUtils } from '@deephaven/utils';
import { PlotData } from 'plotly.js';
import ChartTestUtils from './ChartTestUtils';
import type { ChartTheme } from './ChartTheme';
import FigureChartModel from './FigureChartModel';

const { createMockProxy } = TestUtils;
const chartTestUtils = new ChartTestUtils(dh);

beforeEach(() => {
jest.clearAllMocks();
jest.useFakeTimers();
});

afterEach(() => {
jest.useRealTimers();
});

const chartTheme = createMockProxy<ChartTheme>();

it('populates the layout properly', () => {
const figure = chartTestUtils.makeFigure();
const model = new FigureChartModel(dh, figure);
const model = new FigureChartModel(dh, figure, chartTheme);

expect(model.getLayout()).toEqual(
expect.objectContaining({
Expand All @@ -38,7 +44,7 @@ it('populates the layout properly', () => {

it('populates series data properly', () => {
const figure = chartTestUtils.makeFigure();
const model = new FigureChartModel(dh, figure);
const model = new FigureChartModel(dh, figure, chartTheme);

expect(model.getData()).toEqual([
expect.objectContaining({
Expand All @@ -62,7 +68,7 @@ it('populates horizontal series properly', () => {
const chart = chartTestUtils.makeChart({ series: [series], axes });
const figure = chartTestUtils.makeFigure({ charts: [chart] });

const model = new FigureChartModel(dh, figure);
const model = new FigureChartModel(dh, figure, chartTheme);

expect(model.getData()).toEqual([
expect.objectContaining({ orientation: 'h' }),
Expand All @@ -75,7 +81,7 @@ it('converts histograms properly to bars', () => {
});
const chart = chartTestUtils.makeChart({ series: [series] });
const figure = chartTestUtils.makeFigure({ charts: [chart] });
const model = new FigureChartModel(dh, figure);
const model = new FigureChartModel(dh, figure, chartTheme);

expect(model.getData()).toEqual([
expect.objectContaining({
Expand All @@ -100,7 +106,7 @@ it('handles colors on line charts properly', () => {
});
const chart = chartTestUtils.makeChart({ series: [series] });
const figure = chartTestUtils.makeFigure({ charts: [chart] });
const model = new FigureChartModel(dh, figure);
const model = new FigureChartModel(dh, figure, chartTheme);

expect(model.getData()).toEqual([
expect.objectContaining({
Expand All @@ -122,7 +128,7 @@ it('handles colors on bar charts properly', () => {
});
const chart = chartTestUtils.makeChart({ series: [series] });
const figure = chartTestUtils.makeFigure({ charts: [chart] });
const model = new FigureChartModel(dh, figure);
const model = new FigureChartModel(dh, figure, chartTheme);

expect(model.getData()).toEqual([
expect.objectContaining({
Expand All @@ -149,7 +155,7 @@ describe('axis transform tests', () => {
const series = chartTestUtils.makeSeries({ sources });
const chart = chartTestUtils.makeChart({ series: [series], axes });
const figure = chartTestUtils.makeFigure({ charts: [chart] });
const model = new FigureChartModel(dh, figure);
const model = new FigureChartModel(dh, figure, chartTheme);

expect(model.getLayout().xaxis).toMatchObject({
type: 'log',
Expand All @@ -174,7 +180,7 @@ describe('axis transform tests', () => {
const series = chartTestUtils.makeSeries({ sources });
const chart = chartTestUtils.makeChart({ series: [series], axes });
const figure = chartTestUtils.makeFigure({ charts: [chart] });
const model = new FigureChartModel(dh, figure);
const model = new FigureChartModel(dh, figure, chartTheme);

expect(model.getLayout().xaxis).not.toMatchObject({
type: 'log',
Expand Down Expand Up @@ -208,7 +214,7 @@ describe('multiple axes', () => {

const chart = chartTestUtils.makeChart({ axes });
const figure = chartTestUtils.makeFigure({ charts: [chart] });
const model = new FigureChartModel(dh, figure);
const model = new FigureChartModel(dh, figure, chartTheme);

const layout = model.getLayout();

Expand Down Expand Up @@ -264,7 +270,7 @@ describe('multiple axes', () => {

const chart = chartTestUtils.makeChart({ axes });
const figure = chartTestUtils.makeFigure({ charts: [chart] });
const model = new FigureChartModel(dh, figure);
const model = new FigureChartModel(dh, figure, chartTheme);

const layout = model.getLayout();

Expand Down Expand Up @@ -326,7 +332,7 @@ describe('multiple axes', () => {

const chart = chartTestUtils.makeChart({ axes });
const figure = chartTestUtils.makeFigure({ charts: [chart] });
const model = new FigureChartModel(dh, figure);
const model = new FigureChartModel(dh, figure, chartTheme);

const layout = model.getLayout();

Expand Down Expand Up @@ -382,7 +388,7 @@ describe('multiple axes', () => {

const chart = chartTestUtils.makeChart({ axes });
const figure = chartTestUtils.makeFigure({ charts: [chart] });
const model = new FigureChartModel(dh, figure);
const model = new FigureChartModel(dh, figure, chartTheme);

const layout = model.getLayout();

Expand Down Expand Up @@ -429,7 +435,7 @@ it('adds new series', () => {
const figure = chartTestUtils.makeFigure({
charts: [chart],
});
const model = new FigureChartModel(dh, figure);
const model = new FigureChartModel(dh, figure, chartTheme);
model.subscribe(jest.fn());

expect(model.getData()).toEqual([
Expand Down Expand Up @@ -465,7 +471,7 @@ describe('legend visibility', () => {
const figure = chartTestUtils.makeFigure({
charts: [chart],
});
const model = new FigureChartModel(dh, figure);
const model = new FigureChartModel(dh, figure, chartTheme);
model.subscribe(jest.fn());

return model.getData();
Expand Down

0 comments on commit 9b97a3f

Please sign in to comment.