Skip to content

Commit b877053

Browse files
authored
chore: test: Change import to import type, jsapi-shim to jsapi-types where possible (#1285)
- Change `import` to `import type`, `jsapi-shim` to `jsapi-types` where possible. - Move `jsapi-shim` to `devDependencies`. - Convert `ChartTestUtils` static methods to instance methods, fix unit tests.
1 parent 4b40e4b commit b877053

98 files changed

Lines changed: 440 additions & 341 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/app-utils/src/components/AppBootstrap.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import { AUTH_HANDLER_TYPE_ANONYMOUS } from '@deephaven/auth-plugins';
33
import { ApiContext } from '@deephaven/jsapi-bootstrap';
44
import { BROADCAST_LOGIN_MESSAGE } from '@deephaven/jsapi-utils';
5-
import {
5+
import type {
66
CoreClient,
77
IdeConnection,
88
dh as DhType,

packages/app-utils/src/utils/ConnectUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ConnectOptions } from '@deephaven/jsapi-types';
1+
import type { ConnectOptions } from '@deephaven/jsapi-types';
22

33
/**
44
* Get the base URL of the API

packages/auth-plugins/src/AuthPluginAnonymous.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import { act, render, screen } from '@testing-library/react';
33
import { ApiContext, ClientContext } from '@deephaven/jsapi-bootstrap';
44
import { dh } from '@deephaven/jsapi-shim';
5-
import { CoreClient } from '@deephaven/jsapi-types';
5+
import type { CoreClient } from '@deephaven/jsapi-types';
66
import AuthPluginAnonymous from './AuthPluginAnonymous';
77
import { AUTH_HANDLER_TYPE_ANONYMOUS as AUTH_TYPE } from './AuthHandlerTypes';
88
import { AuthConfigMap } from './AuthPlugin';

packages/auth-plugins/src/AuthPluginBase.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { act, render, screen } from '@testing-library/react';
33
import { ClientContext } from '@deephaven/jsapi-bootstrap';
4-
import { CoreClient } from '@deephaven/jsapi-types';
4+
import type { CoreClient } from '@deephaven/jsapi-types';
55
import { TestUtils } from '@deephaven/utils';
66
import AuthPluginBase from './AuthPluginBase';
77

packages/auth-plugins/src/AuthPluginBase.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react';
22
import { LoadingOverlay } from '@deephaven/components';
33
import { useClient } from '@deephaven/jsapi-bootstrap';
44
import Log from '@deephaven/log';
5-
import { LoginOptions } from '@deephaven/jsapi-types';
5+
import type { LoginOptions } from '@deephaven/jsapi-types';
66
import { CanceledPromiseError, getErrorMessage } from '@deephaven/utils';
77
import AuthenticationError from './AuthenticationError';
88

packages/auth-plugins/src/AuthPluginParent.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import { act, render, screen } from '@testing-library/react';
33
import { ApiContext, ClientContext } from '@deephaven/jsapi-bootstrap';
44
import { dh } from '@deephaven/jsapi-shim';
5-
import { CoreClient, LoginOptions } from '@deephaven/jsapi-types';
5+
import type { CoreClient, LoginOptions } from '@deephaven/jsapi-types';
66
import AuthPluginParent from './AuthPluginParent';
77
import { AuthConfigMap } from './AuthPlugin';
88

packages/auth-plugins/src/AuthPluginParent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { LoginOptions } from '@deephaven/jsapi-types';
2+
import type { LoginOptions } from '@deephaven/jsapi-types';
33
import {
44
LOGIN_OPTIONS_REQUEST,
55
requestParentResponse,

packages/auth-plugins/src/AuthPluginPsk.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { act, render, screen } from '@testing-library/react';
44
import userEvent from '@testing-library/user-event';
55
import { ApiContext, ClientContext } from '@deephaven/jsapi-bootstrap';
66
import { dh } from '@deephaven/jsapi-shim';
7-
import { CoreClient } from '@deephaven/jsapi-types';
7+
import type { CoreClient } from '@deephaven/jsapi-types';
88
import AuthPluginPsk from './AuthPluginPsk';
99
import { AUTH_HANDLER_TYPE_PSK as AUTH_TYPE } from './AuthHandlerTypes';
1010
import { AuthConfigMap } from './AuthPlugin';

packages/chart/src/ChartTestUtils.ts

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
import dh, {
1+
import type {
22
Axis,
3+
AxisFormatType,
4+
AxisPosition,
5+
AxisType,
36
Chart,
7+
dh as DhType,
48
Figure,
59
Series,
610
SeriesDataSource,
7-
} from '@deephaven/jsapi-shim';
11+
} from '@deephaven/jsapi-types';
812

913
class ChartTestUtils {
1014
static DEFAULT_CHART_TITLE = 'Chart Title';
@@ -15,73 +19,85 @@ class ChartTestUtils {
1519

1620
static DEFAULT_SERIES_NAME = 'MySeries';
1721

18-
static makeAxis({
22+
private dh: DhType;
23+
24+
constructor(dh: DhType) {
25+
this.dh = dh;
26+
}
27+
28+
makeAxis({
1929
label = 'Axis',
20-
type = dh.plot.AxisType.X,
21-
position = dh.plot.AxisPosition.BOTTOM,
22-
formatType = dh.Axis.FORMAT_TYPE_NUMBER,
30+
type = undefined,
31+
position = undefined,
32+
formatType = undefined,
2333
formatPattern = '###,###0.00',
2434
log = false,
35+
}: {
36+
label?: string;
37+
type?: AxisType;
38+
position?: AxisPosition;
39+
formatType?: AxisFormatType;
40+
formatPattern?: string;
41+
log?: boolean;
2542
} = {}): Axis {
43+
const { dh } = this;
2644
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2745
return new (dh as any).Axis({
2846
label,
29-
type,
30-
position,
31-
formatType,
47+
type: type ?? dh.plot.AxisType.X,
48+
position: position ?? dh.plot.AxisPosition.BOTTOM,
49+
formatType: formatType ?? dh.Axis.FORMAT_TYPE_NUMBER,
3250
formatPattern,
3351
log,
3452
});
3553
}
3654

37-
static makeDefaultAxes(): Axis[] {
55+
makeDefaultAxes(): Axis[] {
56+
const { dh } = this;
3857
return [
39-
ChartTestUtils.makeAxis({
58+
this.makeAxis({
4059
label: ChartTestUtils.DEFAULT_X_TITLE,
4160
type: dh.plot.AxisType.X,
4261
}),
43-
ChartTestUtils.makeAxis({
62+
this.makeAxis({
4463
label: ChartTestUtils.DEFAULT_Y_TITLE,
4564
type: dh.plot.AxisType.Y,
4665
}),
4766
];
4867
}
4968

50-
static makeSource({
51-
axis = ChartTestUtils.makeAxis(),
52-
}: {
53-
axis: Axis;
54-
}): SeriesDataSource {
69+
makeSource({ axis = this.makeAxis() }: { axis: Axis }): SeriesDataSource {
5570
// eslint-disable-next-line @typescript-eslint/no-explicit-any
56-
return new (dh as any).SeriesDataSource({ axis, type: axis.type });
71+
return new (this.dh as any).SeriesDataSource({ axis, type: axis.type });
5772
}
5873

59-
static makeDefaultSources(): SeriesDataSource[] {
60-
const axes = ChartTestUtils.makeDefaultAxes();
61-
return axes.map(axis => ChartTestUtils.makeSource({ axis }));
74+
makeDefaultSources(): SeriesDataSource[] {
75+
const axes = this.makeDefaultAxes();
76+
return axes.map(axis => this.makeSource({ axis }));
6277
}
6378

64-
static makeSeries({
79+
makeSeries({
6580
name = ChartTestUtils.DEFAULT_SERIES_NAME,
66-
plotStyle = dh.plot.SeriesPlotStyle.SCATTER,
67-
sources = ChartTestUtils.makeDefaultSources(),
81+
plotStyle = null,
82+
sources = this.makeDefaultSources(),
6883
lineColor = null,
6984
shapeColor = null,
7085
} = {}): Series {
86+
const { dh } = this;
7187
// eslint-disable-next-line @typescript-eslint/no-explicit-any
7288
return new (dh as any).Series(
7389
name,
74-
plotStyle,
90+
plotStyle ?? dh.plot.SeriesPlotStyle.SCATTER,
7591
sources,
7692
lineColor,
7793
shapeColor
7894
);
7995
}
8096

81-
static makeChart({
97+
makeChart({
8298
title = ChartTestUtils.DEFAULT_CHART_TITLE,
83-
series = [ChartTestUtils.makeSeries()],
84-
axes = ChartTestUtils.makeDefaultAxes(),
99+
series = [this.makeSeries()],
100+
axes = this.makeDefaultAxes(),
85101
showLegend = null,
86102
rowspan = 1,
87103
colspan = 1,
@@ -98,7 +114,7 @@ class ChartTestUtils {
98114
column?: number;
99115
} = {}): Chart {
100116
// eslint-disable-next-line @typescript-eslint/no-explicit-any
101-
return new (dh as any).Chart({
117+
return new (this.dh as any).Chart({
102118
title,
103119
series,
104120
axes,
@@ -110,14 +126,14 @@ class ChartTestUtils {
110126
});
111127
}
112128

113-
static makeFigure({
129+
makeFigure({
114130
title = 'Figure',
115-
charts = [ChartTestUtils.makeChart()],
131+
charts = [this.makeChart()],
116132
rows = 1,
117133
cols = 1,
118134
} = {}): Figure {
119135
// eslint-disable-next-line @typescript-eslint/no-explicit-any
120-
return new (dh as any).plot.Figure({ title, charts, rows, cols });
136+
return new (this.dh as any).plot.Figure({ title, charts, rows, cols });
121137
}
122138
}
123139

0 commit comments

Comments
 (0)