Skip to content

Commit

Permalink
add tests for preset json files
Browse files Browse the repository at this point in the history
  • Loading branch information
tizayi committed Oct 30, 2023
1 parent bf04fda commit 4c98845
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
fetch-depth: 0

- name: Install
run: npm install
run: npm ci

- name: lint
run: npm run lint
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@ name: github-pages-deploy
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
workflow_dispatch:

jobs:
deploy:
runs-on: ubuntu-latest
concurrency: ci-${{github.ref}}

steps:
- name: Checkout Source
uses: actions/checkout@v3
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
[![dedi-web code CI](https://github.com/tizayi/dedi-web/actions/workflows/code.yml/badge.svg)](https://github.com/tizayi/dedi-web/actions/workflows/code.yml)
[![gh-pages](https://github.com/tizayi/dedi-web/actions/workflows/deploy.yml/badge.svg)](https://github.com/tizayi/dedi-web/actions/workflows/deploy.yml)

A client only Q-Range calculator. Based on dedi within dawn science. Built using react, typescript, mui, zustand, three.js, and h5web/lib.
A client only Q-Range calculator. Based on dedi within dawn science. Built using react, typescript, vite, mui, zustand, three.js, and h5web/lib.

https://tizayi.github.io/dedi-web/

## Start dev server

Start up
Start dev server

```bash
cd dedi-web
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@
"vite": "^4.4.5",
"vitest": "^0.34.1"
}
}
}
2 changes: 1 addition & 1 deletion src/calculations/qvalue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ export const getPointForQ = (
);
return ray.getPointAtDistance(
1.0e3 *
(calculateDistanceFromQValue(qValue, cameralength, wavelength) ?? 0),
(calculateDistanceFromQValue(qValue, cameralength, wavelength) ?? 0),
);
};
52 changes: 52 additions & 0 deletions src/presets/preset.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { expect, test } from "vitest";
import detectorData from "../presets/detectors.json";
import presetData from "../presets/presetConfigs.json";
import { Detector } from "../utils/types";
import { AppDataFormat } from "./presetManager";

const detectorList = detectorData as Record<string, Detector>;
const presetList = presetData as Record<string, AppDataFormat>;
const defaultConfig = presetList[Object.keys(presetList)[0]];

Check failure on line 9 in src/presets/preset.test.ts

View workflow job for this annotation

GitHub Actions / deploy

Unsafe assignment of an `any` value


// Also add some tests for input types



test("Test detectors exist and are valid", () => {
expect(detectorList).toBeTruthy()
for (const detector in detectorList) {
expect(detectorList[detector]).toHaveProperty("resolution.width")
expect(detectorList[detector]).toHaveProperty("resolution.height")
expect(detectorList[detector]).toHaveProperty("pixelSize.width")
expect(detectorList[detector]).toHaveProperty("pixelSize.height")
}
})

test("Test beamstop and camera tube are valid", () => {
for (const preset in presetList) {
expect(presetList[preset]).toHaveProperty("beamstop.diameter")
expect(presetList[preset]).toHaveProperty("beamstop.centre.x")
expect(presetList[preset]).toHaveProperty("beamstop.centre.y")
expect(presetList[preset]).toHaveProperty("beamstop.clearance")
expect(presetList[preset]).toHaveProperty("cameraTube.centre.x")
expect(presetList[preset]).toHaveProperty("cameraTube.centre.y")
expect(presetList[preset]).toHaveProperty("cameraTube.diameter")
}

})

test("Test presets exist and are valid", () => {
expect(presetList).toBeTruthy()
expect(defaultConfig).toBeTruthy()
for (const preset in presetList) {
expect(Object.keys(detectorList)).toContain(presetList[preset].detector)

Check failure on line 43 in src/presets/preset.test.ts

View workflow job for this annotation

GitHub Actions / deploy

Unsafe member access .detector on an `any` value
expect(presetList[preset]).toHaveProperty("angle")
expect(presetList[preset]).toHaveProperty("wavelength")
expect(presetList[preset]).toHaveProperty("cameraLength")
expect(presetList[preset]).toHaveProperty("minWavelength")
expect(presetList[preset]).toHaveProperty("maxWavelength")
expect(presetList[preset]).toHaveProperty("minCameraLength")
expect(presetList[preset]).toHaveProperty("maxCameraLength")
}
})

0 comments on commit 4c98845

Please sign in to comment.