From 17e5c054142844cfe1076b609d48f61117530403 Mon Sep 17 00:00:00 2001 From: Jennings Zhang Date: Fri, 2 Feb 2024 20:48:39 -0500 Subject: [PATCH] Fix tests --- tests/playwright/NiivueCanvas.test.tsx | 21 ++++++++++++++++++--- tests/playwright/fixtures.ts | 3 ++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/tests/playwright/NiivueCanvas.test.tsx b/tests/playwright/NiivueCanvas.test.tsx index a017680..574e7b5 100644 --- a/tests/playwright/NiivueCanvas.test.tsx +++ b/tests/playwright/NiivueCanvas.test.tsx @@ -1,4 +1,4 @@ -import { test, expect } from "./fixtures.ts"; +import {expect, test} from "./fixtures.ts"; test.use({ viewport: { width: 500, height: 500 } }); @@ -49,6 +49,21 @@ test("can set and change colormap", async ({ page, nvt }) => { await expect.poll(getColormap).toBe("red"); }); -test("can set crosshairWidth", async ({ page, nvt }) => { - await nvt.setOptions({crosshairWidth: 1}); +// skipped until https://github.com/niivue/niivue/pull/864 gets merged +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.setVolumes([{ url: "/images/mean_func.nii.gz" }]); + 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 + const nvOpts = await nvt.getOpts(); + expect(nvOpts).toHaveProperty('crosshairColor', [0, 0.5, 0]); }); diff --git a/tests/playwright/fixtures.ts b/tests/playwright/fixtures.ts index 999084e..afca35b 100644 --- a/tests/playwright/fixtures.ts +++ b/tests/playwright/fixtures.ts @@ -36,7 +36,8 @@ export const test = base.extend({ }; const getOpts = async () => { - return await page.getByTestId('nv-opts').innerText(); + const text = await page.getByTestId('nv-opts').innerText(); + return JSON.parse(text); } const errors: Error[] = [];