Skip to content

Commit

Permalink
test: add tests with constant axes
Browse files Browse the repository at this point in the history
Refs: #437
  • Loading branch information
targos committed Nov 1, 2022
1 parent b42699e commit 6fbf8ec
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/components/Axis/Ticks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export function Ticks(props: Omit<TicksProps, 'children'>) {
style,
...otherProps
} = props;

// Primary Ticks
let elements: Array<JSX.Element | null> = primaryTicks.map((tick) => {
const { line, text } = getPositions(tick.position);
Expand Down
50 changes: 48 additions & 2 deletions tests/axis.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { test, expect } from '@playwright/experimental-ct-react';

import { Axis, ParallelAxis } from '../src';
import { Axis, LineSeries, ParallelAxis } from '../src';

import { InfraredPlotTest } from './utils';
import { DefaultPlotTest, InfraredPlotTest } from './utils';

test('all valid axes', async ({ mount }) => {
const plot = await mount(
Expand Down Expand Up @@ -76,3 +76,49 @@ test('axis scale', async ({ mount }) => {
const timeAxis = ['.500:01', '.500:02', '.500:03', '.500:04'].join('');
await expect(time.locator('_react=Axis[scale="time"]')).toHaveText(timeAxis);
});

test('constant x axis', async ({ mount }) => {
const plot = await mount(
<DefaultPlotTest>
<LineSeries
data={[
{ x: 0, y: 1 },
{ x: 0, y: 2 },
{ x: 0, y: 4 },
]}
/>
</DefaultPlotTest>,
);
await expect(plot.locator('_react=HorizontalAxis >> text=0')).toBeVisible();
});

test('constant y axis', async ({ mount }) => {
const plot = await mount(
<DefaultPlotTest>
<LineSeries
data={[
{ x: 1, y: 0 },
{ x: 2, y: 0 },
{ x: 4, y: 0 },
]}
/>
</DefaultPlotTest>,
);
await expect(plot.locator('_react=VerticalAxis >> text=0')).toBeVisible();
});

test('constant x and y axes', async ({ mount }) => {
const plot = await mount(
<DefaultPlotTest>
<LineSeries
data={[
{ x: 1, y: 2 },
{ x: 1, y: 2 },
{ x: 1, y: 2 },
]}
/>
</DefaultPlotTest>,
);
await expect(plot.locator('_react=HorizontalAxis >> text=1')).toBeVisible();
await expect(plot.locator('_react=VerticalAxis >> text=2')).toBeVisible();
});
18 changes: 11 additions & 7 deletions tests/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@ import { DirectedEllipse } from '../src/components/Annotations/DirectedEllipse';
import infrared from '../stories/data/infrared.json';
import { DEFAULT_PLOT_CONFIG } from '../stories/utils';

export function InfraredPlotTest({
children,
}: {
children?: ReactNode | ReactNode[];
}) {
interface ChildrenProps {
children?: ReactNode;
}

export function DefaultPlotTest({ children }: ChildrenProps) {
return <Plot {...DEFAULT_PLOT_CONFIG}>{children}</Plot>;
}

export function InfraredPlotTest({ children }: ChildrenProps) {
return (
<Plot {...DEFAULT_PLOT_CONFIG}>
<DefaultPlotTest>
<ScatterSeries data={infrared} />
{children}
</Plot>
</DefaultPlotTest>
);
}

Expand Down

0 comments on commit 6fbf8ec

Please sign in to comment.