Skip to content

Commit

Permalink
test: react-plot on server side (#458)
Browse files Browse the repository at this point in the history
  • Loading branch information
wadjih-bencheikh18 authored Dec 29, 2022
1 parent 49ea616 commit 4b60443
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"@types/d3-shape": "^3.1.0",
"@types/point-in-polygon": "^1.1.1",
"@types/react": "^17.0.45",
"@types/react-dom": "^18.0.10",
"@zakodium/eslint-config": "^6.0.0",
"eslint": "^8.29.0",
"isotopic-distribution": "^1.4.15",
Expand Down
8 changes: 8 additions & 0 deletions tests/serverside.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { test, expect } from '@playwright/experimental-ct-react';
import { ServerSide } from './utils';

test('should render a plot in server-side mode', async ({ mount }) => {
const plot = await mount(<ServerSide />);
const html = await plot.innerHTML();
expect(html).toContain('svg');
});
6 changes: 5 additions & 1 deletion tests/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ReactNode, useState } from 'react';
import { renderToStaticMarkup } from 'react-dom/server';

import { Annotations, Plot, ScatterSeries } from '../src';
import { Arrow } from '../src/components/Annotations/Arrow';
Expand All @@ -13,7 +14,10 @@ interface ChildrenProps {
export function DefaultPlotTest({ children }: ChildrenProps) {
return <Plot {...DEFAULT_PLOT_CONFIG}>{children}</Plot>;
}

export function ServerSide() {
const html = renderToStaticMarkup(<InfraredPlotTest />);
return <div dangerouslySetInnerHTML={{ __html: html }} />;
}
export function InfraredPlotTest({ children }: ChildrenProps) {
return (
<DefaultPlotTest>
Expand Down

0 comments on commit 4b60443

Please sign in to comment.