test: integration tests for plans creation - testing course#250
test: integration tests for plans creation - testing course#250simplyNoOne wants to merge 7 commits intoSolvro:mainfrom
Conversation
Rei-x
left a comment
There was a problem hiding this comment.
mega duma Ania, że dałaś radę z przetestowaniem planera i to przy użyciu RTLa - wiele osób przy tym poległo 😭
z takich rzeczy co można by było poprawić to mocniejsze skupienie się na testowaniu behawioralnym, a nie testowaniu implementacji - nasze testy powinny wytrzymać 90% refactorów kodu jeśli dla użytkownika nic się nie zmieniło. Testowanie czy jakiś element html'a jest labelem czy spanem trochę temu przeczy. Ta zasada odnosi się wszędzie do testowania - także nawet we flutterze się przyda
tutaj fajny artykuł jak nie czujesz się jeszcze pewna co już jest implementation detail a co jeszcze nie:
https://blog.photogrammer.net/why-the-scope-of-your-tests-matter/ - trochę nacechowany C# ale dobrze opisuje o co chodzi
| await act(async () => { | ||
| await user.click(regOption); | ||
| }); |
There was a problem hiding this comment.
z tego co kojarze react testing library automatycznie wszystkie userEventy w to wrappuje
There was a problem hiding this comment.
Niewykluczone, że to pozostałość z moich gimnastyk, aby w ogóle te testy przeszły i akurat ta była niepotrzebna
| const user = userEvent.setup(); | ||
| render( | ||
| <Providers user={generateMockUser()} queryClient={new QueryClient()}> | ||
| <CreateNewPlanPage planId="testplan1" /> |
There was a problem hiding this comment.
obstawiam, że losowe generowanie id planu byłoby trochę bardziej bulletproof - na wypadek jakby coś od tego zależalo
| const user = setup(); | ||
|
|
||
| const label = screen.getByText("Wydział"); | ||
| expect(label.tagName).toBe("LABEL"); |
There was a problem hiding this comment.
raczej to jest implementation detail
| export const mockFaculties: FacultyType = [ | ||
| { | ||
| id: "id1", | ||
| name: "faculty 1", | ||
| departmentId: "dep1", | ||
| }, | ||
| { | ||
| id: "id2", | ||
| name: "faculty 2", | ||
| departmentId: "dep2", | ||
| }, | ||
| { | ||
| id: "id3", | ||
| name: "faculty 3", | ||
| departmentId: "dep2", | ||
| }, | ||
| ]; | ||
|
|
||
| export const mockRegistrations: Registration[] = [ | ||
| { id: "reg1", name: "Registration 1" }, | ||
| { id: "reg2", name: "Registration 2" }, | ||
| ]; |
There was a problem hiding this comment.
ja akurat jestem fanem nadawania jak najprawdziszych nazw dla testowych danych - czyli np. zamiast faculty1 to Wydział Informatyki i Telekomunikacji
łatwiej mi się wtedy testuje i myśli (z tego samego powodu mamy deskryptywne nazwy zmiennych, a nie x,y,z jak matematycy)
| const span1 = regs1.find( | ||
| (element) => element.tagName.toLowerCase() === "span", | ||
| ); | ||
| const span2 = regs2.find( | ||
| (element) => element.tagName.toLowerCase() === "span", | ||
| ); |
There was a problem hiding this comment.
oj oj, co to właściwie testuje? czy istnieje span? to jest bardzo mocno testowanie implementation detail i nie powinno się tak robić - użytkownik nie patrzy na to czy dany element jest spanem
| newPlan, | ||
| } from "./mock-data"; | ||
|
|
||
| const NEXT_PUBLIC_API_URL = "http://localhost:3333"; |
There was a problem hiding this comment.
hmm, to nie powinno być jakoś wyciągane ze zmiennych środowiskowych? pytam bo nie jestem pewien
There was a problem hiding this comment.
Wiem że coś mi nie chciało działać jak było w .env i chyba musiałam tak to zrobić, ale możliwe że coś przeoczyłam
| export const mockCourses: CourseType = [ | ||
| { | ||
| id: "c1", | ||
| name: "Analizka", | ||
| registrationId: mockRegistrations[0].id, | ||
| groups: groupsForCourses1, | ||
| }, | ||
| { | ||
| id: "c2", | ||
| name: "Algebra", | ||
| registrationId: mockRegistrations[0].id, | ||
| groups: groupsForCourses2, | ||
| }, | ||
| ]; |
There was a problem hiding this comment.
| export const mockCourses: CourseType = [ | |
| { | |
| id: "c1", | |
| name: "Analizka", | |
| registrationId: mockRegistrations[0].id, | |
| groups: groupsForCourses1, | |
| }, | |
| { | |
| id: "c2", | |
| name: "Algebra", | |
| registrationId: mockRegistrations[0].id, | |
| groups: groupsForCourses2, | |
| }, | |
| ]; | |
| export const mockCourses = [ | |
| { | |
| id: "c1", | |
| name: "Analizka", | |
| registrationId: mockRegistrations[0].id, | |
| groups: groupsForCourses1, | |
| }, | |
| { | |
| id: "c2", | |
| name: "Algebra", | |
| registrationId: mockRegistrations[0].id, | |
| groups: groupsForCourses2, | |
| }, | |
| ] satisfies CourseType[]; |
satisfies jest troche bezpieczniejsze
| }, | ||
| })); | ||
|
|
||
| vi.mock("next/headers", () => ({ |
There was a problem hiding this comment.
nie mockowałaś już tego w frontend/src/tests/mocks/auth.ts?
ogólnie najlepiej trzymać wszystkie mocki w jednym miejscu według mnie, potem może się szybko pogubić co masz zamockowane a co nie
| }); | ||
| afterEach(() => { | ||
| server.resetHandlers(); | ||
| cleanup(); |
There was a problem hiding this comment.
szacun, że pamiętałaś o cleanupie z rtl'a - większość zapominała
| "code-test": "vitest", | ||
| "code-test:ui": "vitest --ui", |
There was a problem hiding this comment.
raczej konwencja jest taka, że to się nazywa po prostu "test" i "test:ui". To że @qamarq wymyślił sobie, że skrypt "test" będzie robił linting to inna kwestia - to jakiś jego wymyśł.
w swoich projektach nazywaj to po prostu "test"
Important
This PR adds a comprehensive testing setup using Vitest, including new test scripts, dependencies, mock data, and tests for plan-related components and pages.
vitestand related scriptscode-testandcode-test:uitopackage.json.vitest.config.tsfor Vitest configuration with plugins and setup files.setup.tsfor global test setup, including mock server initialization.@testing-library/react,@testing-library/jest-dom,@testing-library/user-event,msw,jsdom, andvitest.server.tsand handlers inhandlers.ts.Providers.tsxfor wrapping components in necessary context providers during tests.mock-data.ts,auth.ts,user.ts, andutils.tsx.editPlan.test.tsxfor testing plan editing functionality.planPage.test.tsxfor testing plan page interactions.app-sidebar.tsxandregistration-combobox.tsxto includedata-testidattributes for testing.This description was created by
for 5a4d5da. You can customize this summary. It will automatically update as commits are pushed.