Skip to content

Commit

Permalink
test: fix tests that where broken by objects being compared by refere…
Browse files Browse the repository at this point in the history
…nce rather than value
  • Loading branch information
MarcMcIntosh committed Mar 8, 2024
1 parent f906c2d commit 439ff98
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 44 deletions.
72 changes: 38 additions & 34 deletions src/components/ChatForm/ChatForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,44 +58,47 @@ const useControlsState = ({ activeFile, snippet }: useCheckboxStateProps) => {
return "```" + snippet.language + "\n" + snippet.code + "\n```\n";
}, [snippet.language, snippet.code]);

const defaultState = {
search_workspace: {
name: "search_workspace",
checked: false,
label: "Search workspace",
disabled: false,
},
file_upload: {
name: "file_upload",
checked: false,
label: "Attach",
value: fullPathWithLines,
disabled: !activeFile.name,
fileName: nameWithCursor,
},
lookup_symbols: {
name: "lookup_symbols",
checked: false,
label: "Lookup symbols at cursor",
value: fullPathWithCursor,
disabled: !activeFile.name,
// fileName: " at cursor",
// fileName: nameWithCursor,
},
selected_lines: {
name: "selected_lines",
checked: false,
label: "Selected N lines",
value: markdown,
disabled: !snippet.code,
// fileName: nameWithLines,
},
} as const;
const defaultState = useMemo(() => {
return {
search_workspace: {
name: "search_workspace",
checked: false,
label: "Search workspace",
disabled: false,
},
file_upload: {
name: "file_upload",
checked: false,
label: "Attach",
value: fullPathWithLines,
disabled: !activeFile.name,
fileName: nameWithCursor,
},
lookup_symbols: {
name: "lookup_symbols",
checked: false,
label: "Lookup symbols at cursor",
value: fullPathWithCursor,
disabled: !activeFile.name,
// fileName: " at cursor",
// fileName: nameWithCursor,
},
selected_lines: {
name: "selected_lines",
checked: false,
label: "Selected N lines",
value: markdown,
disabled: !snippet.code,
// fileName: nameWithLines,
},
} as const;
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const [checkboxes, setCheckboxes] =
React.useState<ChatControlsProps["checkboxes"]>(defaultState);

const reset = () => setCheckboxes(defaultState);
const reset = useCallback(() => setCheckboxes(defaultState), [defaultState]);

const toggleCheckbox = useCallback(
(name: string, value: boolean | string) => {
Expand Down Expand Up @@ -380,6 +383,7 @@ export const ChatForm: React.FC<ChatFormProps> = ({
}
render={(props) => (
<TextArea
data-testid="chat-form-textarea"
required={true}
disabled={isStreaming}
{...props}
Expand Down
19 changes: 9 additions & 10 deletions src/features/Chat.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe("Chat", () => {
vi.restoreAllMocks();
});

it.skip("should send and receive messages from the window", async () => {
it("should send and receive messages from the window", async () => {
vi.mock("uuid", () => ({ v4: () => "foo" }));

const postMessageSpy = vi.spyOn(window, "postMessage");
Expand All @@ -46,17 +46,16 @@ describe("Chat", () => {
setUpCapsForChat("foo");

const select = await app.findByTitle("chat model");
// app.debug(select.parentElement);

expect(select.textContent).toContain("gpt-3.5-turbo");

const textarea: HTMLTextAreaElement | null =
app.container.querySelector("textarea");
const textarea = app.getByTestId("chat-form-textarea");

expect(textarea).not.toBeNull();
if (textarea) {
await user.type(textarea, "hello");
await user.type(textarea, "{enter}");
}

await user.type(textarea, "hello");

await user.keyboard("{Enter}");

expect(postMessageSpy).toHaveBeenLastCalledWith(
{
Expand Down Expand Up @@ -139,7 +138,7 @@ describe("Chat", () => {
await waitFor(() => expect(app.queryByText(/Certainly!/)).not.toBeNull());
});

it.skip("when creating a new chat I can select which model to use", async () => {
it("when creating a new chat I can select which model to use", async () => {
vi.mock("uuid", () => ({ v4: () => "foo" }));

// Missing props in jsdom
Expand Down Expand Up @@ -220,7 +219,7 @@ describe("Chat", () => {
);
});

it.skip("retry chat", async () => {
it("retry chat", async () => {
const postMessageSpy = vi.spyOn(window, "postMessage");

const { user, ...app } = render(<Chat />);
Expand Down

0 comments on commit 439ff98

Please sign in to comment.