Skip to content

Kurs z testowania - etap 8 - Testy promochatora#107

Open
jmorawiec wants to merge 7 commits into
mainfrom
kurs-testowania-etap-8-jakub-morawiec
Open

Kurs z testowania - etap 8 - Testy promochatora#107
jmorawiec wants to merge 7 commits into
mainfrom
kurs-testowania-etap-8-jakub-morawiec

Conversation

@jmorawiec

@jmorawiec jmorawiec commented Jul 25, 2025

Copy link
Copy Markdown
Member

Hej, jak zwykle byłem trochę w deficycie czasu przez Wakacyjne Wyzwanie, ale starałem się jak mogłem, by testy przyniosły wartość biznesową.

Btw wybaczcie autorzy repo za PR'kę :p


Important

This PR adds comprehensive tests for the Promochator chat component and API interactions, updates configurations for testing, and includes minor code adjustments for error handling and consistency.

  • Testing:
    • Added chat.test.tsx to test chat component interactions, including form submission and error handling.
    • Added failedData.test.ts to test API error handling for 500 responses.
    • Added fetchData-recommend.test.ts for integration tests on /recommend/invoke endpoint.
    • Added nonsenseSupervisor.test.ts to test handling of nonsense input in recommendations.
    • Added setup.ts for test environment setup.
  • Configuration:
    • Added vitest.config.ts for Vitest configuration with JSDOM environment and setup file.
    • Modified next.config.ts to ignore ESLint during builds.
    • Updated package.json to adjust scripts and dependencies for testing.
  • Code Adjustments:
    • Removed development-only API response handling in feedback/route.ts and recommend/route.ts.
    • Added error handling in PromptForm in prompt-form.tsx for chat submission errors.
    • Added React imports in chat.tsx, client-only.tsx, and prompt-form.tsx for consistency.
    • Adjusted Button component in button.tsx to use ref directly.

This description was created by Ellipsis for a24adf5. You can customize this summary. It will automatically update as commits are pushed.

Comment thread tests/nonsenseSupervisor.test.ts Outdated
});

expect(res.output.recommended_supervisors.length).toBe(0);
console.log("Response for nonsense input:", res);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the console.log used for debugging unless it's intended for persistent logging.

Suggested change
console.log("Response for nonsense input:", res);

@Solvro Solvro deleted a comment from ellipsis-dev Bot Jul 25, 2025

@Rei-x Rei-x left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no muszę Ci powiedzieć, że jestem dumny, bardzo solidne teściki, pokryłeś wszystko to co miałeś zrobić i jestem zadowolony (mam nadzieję, że ty )

tak jak Ci wcześniej mówiłem te testy czy promochator zwraca prawidłowego promotora raczej powinny być w repo backendu promochatora, bo tutaj jedyne co robisz właściwe to wykonujesz zapytanie do API, tam myślę, że byłoby dla nich odpowiedniejsze miejsce

poza tym jest spoczko, dużo dziwnych rzeczy też pozmieniałeś poza samymi testami 😭

Comment on lines -10 to -12
if (process.env.NODE_ENV === "development") {
return NextResponse.json(null, { status: 201 });
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

czemu to usunąłeś

Comment on lines -13 to -16
if (process.env.NODE_ENV === "development") {
const response = await mockFetch("/recommend/invoke");
return NextResponse.json(await response.json());
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to też?

}

const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
({ className, variant, size, asChild = false, ...props }, reference) => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?


return (
<Comp
ref={reference}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what 😭

Comment thread src/components/chat.tsx

import { ClientOnly } from "./client-only";
import { PromptForm } from "./prompt-form";
import React from "react";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zamiast dodawać importy reacta mogłeś dodać plugin do vite'a z obsługą reacta, nic byś nie musiał zmieniać

Comment thread tests/chat.test.tsx

await waitFor(() => {
expect(mockAddChat).toHaveBeenCalledWith({
uuid: "mock-uuid-1234",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trochę magic string, fajnie jakbyś wyciągnął to do stałej (albo w ogóle tego nie sprawdzał, przy użyciu expect.objectContaining({ }) - wtedy możesz podać tylko część pól)

Comment thread tests/chat.test.tsx

it("should return an error message in case of code 500", async () => {
const user = userEvent.setup();
mockAddChat.mockRejectedValueOnce(new Error("Błąd serwera"));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

czemu to zrobiłeś mockami a nie msw?

Comment thread tests/failedData.test.ts
Comment on lines +17 to +19
beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
afterAll(() => server.close());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to akurat mogło pójść do pliku z setupem

a jak byś potrzebował, żeby request dochodził do prawdziwego backendu to możesz użyć: https://mswjs.io/docs/api/passthrough

Comment thread next.config.ts
const nextConfig: NextConfig = {
/* config options here */
eslint: {
ignoreDuringBuilds: true,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😭😭

Comment thread package.json
"devDependencies": {
"@next/eslint-plugin-next": "^15.2.3",
"@solvro/config": "^1.13.1",
"@solvro/config": "^2.0.1",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

szacun za upgrade

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants