-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathInputSelector.test.js
More file actions
98 lines (86 loc) · 2.36 KB
/
InputSelector.test.js
File metadata and controls
98 lines (86 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import React from "react";
import { render, screen } from "@testing-library/react";
import InputSelector from "./InputSelector";
import { AppContext } from "../contexts/GlobalContext";
jest.mock("antd", () => {
const Form = ({ children }) => <form>{children}</form>;
Form.Item = ({ label, children, help }) => (
<div>
{label}
{children}
{help ? <div>{help}</div> : null}
</div>
);
return {
Form,
Space: ({ children }) => <div>{children}</div>,
};
});
jest.mock("./UnifiedFileInput", () => (props) => (
<input
aria-label={props.placeholder}
data-selection-type={props.selectionType}
readOnly
value={typeof props.value === "string" ? props.value : ""}
/>
));
jest.mock("./InlineHelpChat", () => () => null);
beforeAll(() => {
Object.defineProperty(window, "matchMedia", {
writable: true,
value: jest.fn().mockImplementation((query) => ({
matches: false,
media: query,
onchange: null,
addListener: jest.fn(),
removeListener: jest.fn(),
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
})),
});
});
function renderWithContext(type) {
const contextValue = {
trainingState: {
inputImage: "",
inputLabel: "",
outputPath: "",
logPath: "",
checkpointPath: "",
setInputImage: jest.fn(),
setInputLabel: jest.fn(),
setOutputPath: jest.fn(),
setLogPath: jest.fn(),
setCheckpointPath: jest.fn(),
},
inferenceState: {
inputImage: "",
inputLabel: "/tmp/stale-label.tif",
outputPath: "",
logPath: "",
checkpointPath: "",
setInputImage: jest.fn(),
setInputLabel: jest.fn(),
setOutputPath: jest.fn(),
setLogPath: jest.fn(),
setCheckpointPath: jest.fn(),
},
};
return render(
<AppContext.Provider value={contextValue}>
<InputSelector type={type} />
</AppContext.Provider>,
);
}
describe("InputSelector", () => {
it("shows an input label field for training", () => {
renderWithContext("training");
expect(screen.getByText("Input Label")).toBeTruthy();
});
it("does not show an input label field for inference", () => {
renderWithContext("inference");
expect(screen.queryByText("Input Label")).toBeNull();
expect(screen.queryByText("Input Label (Optional)")).toBeNull();
});
});