diff --git a/package-lock.json b/package-lock.json index e79b5dd..221b66f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,6 +20,7 @@ "@tanstack/react-query": "^5.32.0", "@tanstack/react-query-devtools": "^5.32.0", "@testing-library/react": "^15.0.7", + "@testing-library/user-event": "^14.5.2", "axios": "^1.6.8", "connect-redis": "^7.1.1", "cors": "^2.8.5", @@ -2655,6 +2656,18 @@ } } }, + "node_modules/@testing-library/user-event": { + "version": "14.5.2", + "resolved": "https://registry.npmjs.org/@testing-library/user-event/-/user-event-14.5.2.tgz", + "integrity": "sha512-YAh82Wh4TIrxYLmfGcixwD18oIjyC1pFQC2Y01F2lzV2HTMiYrI0nze0FD0ocB//CKS/7jIUgae+adPqxK5yCQ==", + "engines": { + "node": ">=12", + "npm": ">=6" + }, + "peerDependencies": { + "@testing-library/dom": ">=7.21.4" + } + }, "node_modules/@tootallnate/once": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-2.0.0.tgz", diff --git a/package.json b/package.json index 95e30f8..e8b9776 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --testMatch '**/server/**/*.test.*' --setupFilesAfterEnv ./setupTests.ts", "test:watch": "node --experimental-vm-modules node_modules/jest/bin/jest.js --testMatch '**/server/**/*.test.*' --setupFilesAfterEnv ./setupTests.ts --watchAll", "test:front": "node --experimental-vm-modules node_modules/jest/bin/jest.js --testMatch '**/client/**/*.test.*' --setupFilesAfterEnv ./setupTests.ts", - "test:front:watch": "node --experimental-vm-modules node_modules/jest/bin/jest.js --testMatch '**/client/**/*.test.*' --setupFilesAfterEnv ./setupTests.ts --watchAll", + "test:front:watch": "DEBUG_PRINT_LIMIT=100000 node --experimental-vm-modules node_modules/jest/bin/jest.js --testMatch '**/client/**/*.test.*' --setupFilesAfterEnv ./setupTests.ts --watchAll", "test:integration": "concurrently \"docker run -e PGDATA=/test-data -e POSTGRES_PASSWORD=postgres -p 5433:5432 postgres:15.6\" \"sleep 3 && NODE_ENV=test REACT_APP_E2E=true PORT=8001 DATABASE_URL=postgres://postgres:postgres@localhost:5433/postgres node --experimental-vm-modules node_modules/jest/bin/jest.js --setupFilesAfterEnv ./setupIntegrationTests.ts --forceExit\" --kill-others --success command-1 --hide 0 --prefix none", "test:integration:watch": "concurrently \"docker run -e PGDATA=/test-data -e POSTGRES_PASSWORD=postgres -p 5433:5432 postgres:15.6\" \"NODE_ENV=test PORT=8001 DATABASE_URL=postgres://postgres:postgres@localhost:5433/postgres node --experimental-vm-modules node_modules/jest/bin/jest.js --watchAll --setupFilesAfterEnv ./setupIntegrationTests.ts\" --hide 0 --prefix none", "lint": "eslint 'src/**/*.{ts,tsx}'", @@ -44,6 +44,7 @@ "@tanstack/react-query": "^5.32.0", "@tanstack/react-query-devtools": "^5.32.0", "@testing-library/react": "^15.0.7", + "@testing-library/user-event": "^14.5.2", "axios": "^1.6.8", "connect-redis": "^7.1.1", "cors": "^2.8.5", diff --git a/src/client/components/ThesisPage/SupervisorSelect.test.jsx b/src/client/components/ThesisPage/SupervisorSelect.test.jsx index 606d5ae..97c7f6c 100644 --- a/src/client/components/ThesisPage/SupervisorSelect.test.jsx +++ b/src/client/components/ThesisPage/SupervisorSelect.test.jsx @@ -5,6 +5,7 @@ import React from 'react' import { render, screen } from '@testing-library/react' import SupervisorSelect from './SupervisorSelect' +import initializeI18n from '../../util/il18n' describe('SupervisorSelect', () => { const supervisors = [ @@ -16,6 +17,8 @@ describe('SupervisorSelect', () => { beforeEach(() => { setSupervisorSelections = jest.fn() + + initializeI18n() }) it('renders the SupervisorSelect component', () => { @@ -27,7 +30,7 @@ describe('SupervisorSelect', () => { /> ) - expect(screen.getByText('Add Supervisor')).toBeInTheDocument() + expect(screen.getByText('Lisää ohjaaja')).toBeInTheDocument() }) it('renders the SupervisorSelect component with a supervisor', () => { @@ -40,8 +43,11 @@ describe('SupervisorSelect', () => { setSupervisorSelections={setSupervisorSelections} /> ) + + expect(screen.getByText('Valitse ohjaaja')).toBeInTheDocument() + expect(screen.getByText('Osuus')).toBeInTheDocument() expect(screen.getByText('John Doe')).toBeInTheDocument() - expect(screen.getByText('Add Supervisor')).toBeInTheDocument() + expect(screen.getByText('Lisää ohjaaja')).toBeInTheDocument() }) it('renders the SupervisorSelect component with multiple supervisors', () => { @@ -57,7 +63,7 @@ describe('SupervisorSelect', () => { ) expect(screen.getByText('John Doe')).toBeInTheDocument() expect(screen.getByText('Jane Smith')).toBeInTheDocument() - expect(screen.getByText('Add Supervisor')).toBeInTheDocument() + expect(screen.getByText('Lisää ohjaaja')).toBeInTheDocument() }) describe('interactions', () => { @@ -70,7 +76,7 @@ describe('SupervisorSelect', () => { /> ) - const select = screen.getByText('Add Supervisor') + const select = screen.getByText('Lisää ohjaaja') select.click() expect(setSupervisorSelections).toHaveBeenCalledTimes(1) @@ -90,7 +96,7 @@ describe('SupervisorSelect', () => { /> ) - const removeButton = screen.getByText('Remove') + const removeButton = screen.getByText('Poista') removeButton.click() expect(setSupervisorSelections).toHaveBeenCalledTimes(1) diff --git a/src/client/components/ThesisPage/SupervisorSelect.tsx b/src/client/components/ThesisPage/SupervisorSelect.tsx index 108bcb1..e801781 100644 --- a/src/client/components/ThesisPage/SupervisorSelect.tsx +++ b/src/client/components/ThesisPage/SupervisorSelect.tsx @@ -10,12 +10,15 @@ import { } from '@mui/material' import { SupervisionData, User } from '@backend/types' import { SupervisorSelection } from '@frontend/types' +import { useTranslation } from 'react-i18next' const SupervisorSelect: React.FC<{ supervisors: User[] supervisorSelections: SupervisorSelection[] setSupervisorSelections: (newSupervisions: SupervisionData[]) => void }> = ({ supervisors, supervisorSelections, setSupervisorSelections }) => { + const { t } = useTranslation() + const handleSupervisorChange = (index: number, supervisorId: string) => { const updatedSelections = [...supervisorSelections] updatedSelections[index].userId = supervisorId @@ -59,14 +62,14 @@ const SupervisorSelect: React.FC<{ // eslint-disable-next-line react/no-array-index-key - - Select supervisor + + {t('thesisForm:selectSupervisor')} } > - Upload research plan + {t('thesisForm:uploadResearchPlanButton')} @@ -257,7 +257,7 @@ const ThesisEditForm: React.FC<{ tabIndex={-1} startIcon={} > - Upload ways of working + {t('thesisForm:uploadWaysOfWorkingButton')} @@ -340,12 +340,12 @@ const ThesisEditForm: React.FC<{ )} {!editedThesis.researchPlan && ( } severity="error"> - Make sure you upload a research plan PDF + {t('thesisForm:researchPlanMissingError')} )} {!editedThesis.waysOfWorking && ( } severity="error"> - Make sure you upload a ways of working PDF + {t('thesisForm:waysOfWorkingMissingError')} )} diff --git a/src/client/locales/en.json b/src/client/locales/en.json index bf65f4d..98c6486 100644 --- a/src/client/locales/en.json +++ b/src/client/locales/en.json @@ -1,6 +1,7 @@ { "common": { "appName": "Master theses progress tracking", + "author": "Author", "profileButton": "Profile", "programHeader": "Program", "topicHeader": "Topic", @@ -11,11 +12,18 @@ "deleteButton": "Delete", "cancelButton": "Cancel", "submitButton": "Submit", - "editThesisDialog": "Edit thesis", - "newThesisButton": "New thesis" + "newThesisButton": "New thesis", + "removeButton": "Remove" }, "thesisForm": { "supervisionPercentageError": "Make sure the total percentages of supervisors add up to 100", - "author": "Author" + "researchPlanMissingError": "Make sure you upload a research plan PDF", + "waysOfWorkingMissingError": "Make sure you upload a ways of working PDF", + "addSupervisor": "Add supervisor", + "editThesisDialog": "Edit thesis", + "uploadWaysOfWorkingButton": "Upload ways of working", + "uploadResearchPlanButton": "Upload research plan", + "selectSupervisor": "Select supervisor", + "selectSupervisorPercentage": "Percentage" } } diff --git a/src/client/locales/fi.json b/src/client/locales/fi.json index 9bfd8c8..64bac5b 100644 --- a/src/client/locales/fi.json +++ b/src/client/locales/fi.json @@ -1,6 +1,7 @@ { "common": { "appName": "GRAdut Pikaisesti Alkuun", + "author": "Tekijä", "profileButton": "Oma tiedot", "programHeader": "Ohjelma", "topicHeader": "Aihe", @@ -11,11 +12,18 @@ "deleteButton": "Poista", "cancelButton": "Peruuta", "submitButton": "Tallenna", - "editThesisDialog": "Muokkaa gradu", - "newThesisButton": "Uusi gradu" + "newThesisButton": "Uusi gradu", + "removeButton": "Poista" }, "thesisForm": { "supervisionPercentageError": " Varmista, että ohjaajien yhteisprosentti on 100", - "author": "Tekijä" + "researchPlanMissingError": "Tutkimussuunnitelma puuttuu", + "waysOfWorkingMissingError": "Työskentelysopimus puuttuu", + "addSupervisor": "Lisää ohjaaja", + "editThesisDialog": "Muokkaa gradu", + "uploadWaysOfWorkingButton": "Lataa työskentelysopimus", + "uploadResearchPlanButton": "Lataa tutkimussuunnitelma", + "selectSupervisor": "Valitse ohjaaja", + "selectSupervisorPercentage": "Osuus" } }