-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP]: test(UI+model): implement test code from plans and more #139
Draft
kyubxy
wants to merge
6
commits into
main
Choose a base branch
from
tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
aeefa2f
chore(tests): install react-testing-library
kyubxy 0d5998c
implemented basic parampane tests
kyubxy 18fd644
did parameterbar tests
kyubxy 3284873
test height of parbar back button
kyubxy c5694be
attempting to test the tfjs service
kyubxy 2615c94
cleanup
kyubxy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
import { render, fireEvent } from '@testing-library/react' | ||
import ParametersBar from "../../src/components/ParametersBar" | ||
import { describe, it, expect, beforeAll, jest } from "@jest/globals" | ||
import '@testing-library/jest-dom/jest-globals' | ||
|
||
beforeAll(() => { | ||
Object.defineProperty(window, "matchMedia", { | ||
writable: true, | ||
value: jest.fn().mockImplementation(query => ({ | ||
matches: false, | ||
media: query, | ||
onchange: null, | ||
addListener: jest.fn(), // Deprecated | ||
removeListener: jest.fn(), // Deprecated | ||
addEventListener: jest.fn(), | ||
removeEventListener: jest.fn(), | ||
dispatchEvent: jest.fn(), | ||
})) | ||
}); | ||
}); | ||
|
||
describe('the parameter pane', () => { | ||
it('should change arrow direction on back button', async() => { | ||
const { getByTestId } = render(<ParametersBar params={null} setParams={null}/>) | ||
const backbutton = getByTestId('back') | ||
|
||
const left = getByTestId('leftarrow') | ||
expect(left).toBeInTheDocument() | ||
fireEvent.click(backbutton) | ||
const right = getByTestId('rightarrow') | ||
expect(right).toBeInTheDocument() | ||
}) | ||
|
||
it('should hide and show pane', async() => { | ||
const { getByTestId } = render(<ParametersBar params={null} setParams={null}/>) | ||
const backbutton = getByTestId('back') | ||
const pane = getByTestId('pane') | ||
|
||
expect(pane).toBeInTheDocument() | ||
fireEvent.click(backbutton) | ||
expect(pane).not.toBeInTheDocument() | ||
}) | ||
|
||
// TODO: there aren't any easy/expert mode specific parameters yet. once they are added | ||
// we should make sure to test them here | ||
}) | ||
|
||
|
||
describe('the back button', () => { | ||
it('back button should retain equal y position between states', async() => { | ||
const { getByTestId } = render(<ParametersBar params={null} setParams={null}/>) | ||
const backbutton = getByTestId('back') | ||
|
||
expect(backbutton).toBeInTheDocument() | ||
const openypos = backbutton.getBoundingClientRect().top | ||
fireEvent.click(backbutton) | ||
const closedypos = backbutton.getBoundingClientRect().top | ||
expect(openypos).toBe(closedypos) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import ONNXService from "../../../src/services/model/ONNXService" | ||
import { test, expect, beforeAll, beforeEach } from "@jest/globals" | ||
|
||
let service: ONNXService | ||
let initCond: number[][][][] | ||
|
||
beforeAll(async () => { | ||
// TODO | ||
}, 100000) | ||
|
||
beforeEach(() => { | ||
service.loadDataArray(initCond) | ||
}) | ||
|
||
test("Tfjs should be instantiable", async() => { | ||
expect(service).not.toBeUndefined() | ||
expect(service).not.toBeNull(); | ||
}) | ||
|
||
test("model should run callback", async() => { | ||
service.bindOutput((data) => { | ||
expect(data) | ||
}) | ||
service.startSimulation() | ||
service.pauseSimulation() | ||
}) | ||
|
||
test("model should conserve mass", async() => { | ||
const m1 = service.getMass() | ||
service.startSimulation() | ||
service.pauseSimulation() | ||
const m2 = service.getMass() | ||
expect(m1).toBeCloseTo(m2, 1) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import TfjsService from "../../../src/services/model/TfjsService" | ||
import { test, expect, beforeAll, beforeEach } from "@jest/globals" | ||
|
||
let service: TfjsService | ||
let initCond: number[][][][] | ||
|
||
beforeAll(async () => { | ||
service = await TfjsService.createService("https://github.com/techlauncher-mlai-edge-physics/CFlowSim/raw/main/public/model/bno_small_new_web/model.json") | ||
const resp = await fetch("https://github.com/techlauncher-mlai-edge-physics/CFlowSim/raw/main/public/initData/pvf_incomp_44_nonneg/pvf_incomp_44_nonneg_0.json") | ||
initCond = await resp.json() | ||
}, 100000) | ||
|
||
beforeEach(() => { | ||
service.loadDataArray(initCond) | ||
}) | ||
|
||
test("Tfjs should be instantiable", async() => { | ||
expect(service).not.toBeUndefined() | ||
expect(service).not.toBeNull(); | ||
}) | ||
|
||
test("model should run callback", async() => { | ||
service.bindOutput((data) => { | ||
expect(data) | ||
}) | ||
service.startSimulation() | ||
service.pauseSimulation() | ||
}) | ||
|
||
test("model should conserve mass", async() => { | ||
const m1 = service.getMass() | ||
service.startSimulation() | ||
service.pauseSimulation() | ||
const m2 = service.getMass() | ||
expect(m1).toBeCloseTo(m2, 1) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you mean by Hide/Show btn?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes i did. will change