Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
jennydaman committed Feb 7, 2024
1 parent 7712dad commit f008b4e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
8 changes: 5 additions & 3 deletions examples/NiivueCanvasForPlaywrightTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ const NiivueCanvasForTest: React.FC<NiivueCanvasForTestProps> = ({
</button>
<div>
optionsChangeCounter=
<span data-testid="options-change-counter">{optionsChangeCounter}</span>
<span data-testid="options-change-counter">
{optionsChangeCounter}
</span>
</div>

{nv && (
Expand Down Expand Up @@ -127,5 +129,5 @@ const NiivueCanvasForTest: React.FC<NiivueCanvasForTestProps> = ({
);
};

export type {NiivueCanvasForTestProps};
export {NiivueCanvasForTest};
export type { NiivueCanvasForTestProps };
export { NiivueCanvasForTest };
18 changes: 11 additions & 7 deletions tests/playwright/NiivueCanvas.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {expect, test} from "./fixtures.ts";
import { expect, test } from "./fixtures.ts";

test.use({ viewport: { width: 500, height: 500 } });

Expand Down Expand Up @@ -53,17 +53,21 @@ test("can set and change colormap", async ({ page, nvt }) => {
test.skip("can set crosshairWidth", async ({ nvt }) => {
// regression test: having the option crosshairWidth without the 3D render being shown can cause an exception
// if nv.setCrosshairWidth is called.
await nvt.setOptions({crosshairWidth: 10, sliceType: 0 }); // axial
expect(await nvt.getOpts()).toHaveProperty('crosshairWidth', 10);
await nvt.setOptions({ crosshairWidth: 10, sliceType: 0 }); // axial
expect(await nvt.getOpts()).toHaveProperty("crosshairWidth", 10);
await nvt.setVolumes([{ url: "/images/mean_func.nii.gz" }]);
await nvt.setOptions({crosshairWidth: 10, multiplanarForceRender: true, sliceType: 3}); // multiplanar
expect(await nvt.getOpts()).toHaveProperty('crosshairWidth', 10);
await nvt.setOptions({
crosshairWidth: 10,
multiplanarForceRender: true,
sliceType: 3,
}); // multiplanar
expect(await nvt.getOpts()).toHaveProperty("crosshairWidth", 10);
});

test("can set crosshairColor", async ({ nvt }) => {
// regression test: having the option crosshairWidth without the 3D render being shown can cause an exception
// if nv.setCrosshairWidth is called.
await nvt.setOptions({crosshairColor: [0, 0.5, 0], sliceType: 0 }); // axial
await nvt.setOptions({ crosshairColor: [0, 0.5, 0], sliceType: 0 }); // axial
const nvOpts = await nvt.getOpts();
expect(nvOpts).toHaveProperty('crosshairColor', [0, 0.5, 0]);
expect(nvOpts).toHaveProperty("crosshairColor", [0, 0.5, 0]);
});
14 changes: 9 additions & 5 deletions tests/playwright/fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test as base, expect } from "playwright-test-coverage-native";
import { NVImage } from "@niivue/niivue";
import {NVROptions, NVRVolume} from "../../src";
import { NVROptions, NVRVolume } from "../../src";

type NiivueCanvasTest = {
getVolume: (name: string) => Promise<NVImage>;
Expand Down Expand Up @@ -28,17 +28,21 @@ export const test = base.extend<MyFixtures>({
return JSON.parse(await getText());
};
const setOptions = async (options: NVROptions) => {
const counterString = await page.getByTestId('options-change-counter').innerText();
const counterString = await page
.getByTestId("options-change-counter")
.innerText();
const counterValue = parseInt(counterString);
await page.getByTestId("options-string").fill(JSON.stringify(options));
await page.getByTestId("set-options").click();
await expect(page.getByTestId('options-change-counter')).toHaveText(`${counterValue + 1}`);
await expect(page.getByTestId("options-change-counter")).toHaveText(
`${counterValue + 1}`,
);
};

const getOpts = async () => {
const text = await page.getByTestId('nv-opts').innerText();
const text = await page.getByTestId("nv-opts").innerText();
return JSON.parse(text);
}
};

const errors: Error[] = [];
page.on("pageerror", (error) => errors.push(error));
Expand Down

0 comments on commit f008b4e

Please sign in to comment.