-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathLibraryRow.spec.tsx
More file actions
123 lines (108 loc) · 3.92 KB
/
LibraryRow.spec.tsx
File metadata and controls
123 lines (108 loc) · 3.92 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import * as React from "react";
import { render as reactRender, screen } from "@testing-library/react";
import { createMethod } from "../../../../test/factories/model-editor/method-factories";
import { LibraryRow, LibraryRowProps } from "../LibraryRow";
import { InProgressMethods } from "../../../model-editor/shared/in-progress-methods";
import { createMockExtensionPack } from "../../../../test/factories/model-editor/extension-pack";
import { Mode } from "../../../model-editor/shared/mode";
import { ModelEditorViewState } from "../../../model-editor/shared/view-state";
import userEvent from "@testing-library/user-event";
describe(LibraryRow.name, () => {
const method = createMethod();
const onChange = jest.fn();
const onSaveModelClick = jest.fn();
const onGenerateFromLlmClick = jest.fn();
const onStopGenerateFromLlmClick = jest.fn();
const onModelDependencyClick = jest.fn();
const viewState: ModelEditorViewState = {
mode: Mode.Application,
showFlowGeneration: false,
showLlmButton: false,
showMultipleModels: false,
extensionPack: createMockExtensionPack(),
sourceArchiveAvailable: true,
};
const render = (props: Partial<LibraryRowProps> = {}) =>
reactRender(
<LibraryRow
title="sql2o"
libraryVersion="1.6.0"
methods={[method]}
modeledMethodsMap={{
[method.signature]: [
{
...method,
type: "sink",
input: "Argument[0]",
output: "",
kind: "jndi-injection",
provenance: "df-generated",
},
],
}}
modifiedSignatures={new Set([method.signature])}
inProgressMethods={new InProgressMethods()}
viewState={viewState}
hideModeledMethods={false}
revealedMethodSignature={null}
onChange={onChange}
onSaveModelClick={onSaveModelClick}
onGenerateFromLlmClick={onGenerateFromLlmClick}
onStopGenerateFromLlmClick={onStopGenerateFromLlmClick}
onGenerateFromSourceClick={jest.fn()}
onModelDependencyClick={onModelDependencyClick}
{...props}
/>,
);
it("renders the row", () => {
render();
expect(screen.queryByText("sql2o@1.6.0")).toBeInTheDocument();
expect(screen.queryByText("Model from source")).not.toBeInTheDocument();
expect(screen.queryByText("Model with AI")).not.toBeInTheDocument();
expect(screen.queryByText("Model dependency")).toBeInTheDocument();
});
it("renders the row when flow generation is enabled", () => {
render({
viewState: {
...viewState,
showFlowGeneration: true,
},
});
expect(screen.queryByText("Model from source")).toBeInTheDocument();
expect(screen.queryByText("Model with AI")).not.toBeInTheDocument();
expect(screen.queryByText("Model dependency")).toBeInTheDocument();
});
it("renders the row when LLM is enabled", () => {
render({
viewState: {
...viewState,
showLlmButton: true,
},
});
expect(screen.queryByText("Model from source")).not.toBeInTheDocument();
expect(screen.queryByText("Model with AI")).toBeInTheDocument();
expect(screen.queryByText("Model dependency")).toBeInTheDocument();
});
it("renders the row when flow generation and LLM are enabled", () => {
render({
viewState: {
...viewState,
showFlowGeneration: true,
showLlmButton: true,
},
});
expect(screen.queryByText("Model from source")).toBeInTheDocument();
expect(screen.queryByText("Model with AI")).toBeInTheDocument();
expect(screen.queryByText("Model dependency")).toBeInTheDocument();
});
it("can expand the row", async () => {
render();
expect(screen.queryByText("Save")).not.toBeInTheDocument();
await userEvent.click(
screen.getByRole("button", {
name: /sql2o@1.6.0/,
}),
);
expect(screen.getByText("Save")).toBeInTheDocument();
});
});