From cc095a8b1bb0a9768a3312299525b203d7d107e9 Mon Sep 17 00:00:00 2001 From: Benjamin Langlotz Date: Tue, 21 May 2024 05:56:57 +0200 Subject: [PATCH] ref(KUI-1176): rename roundList to roundsBySemester --- public/js/app/components/DropdownRounds.jsx | 12 +++--- .../__tests__/useSemesterRoundState.test.js | 40 +++++++++---------- public/js/app/hooks/useSemesterRoundState.js | 16 ++++---- public/js/app/pages/CoursePage.jsx | 7 ++-- .../js/app/pages/__tests__/CoursePage.test.js | 2 +- server/apiCalls/getFilteredData.js | 16 +++----- .../controllers/__tests__/courseCtrl.test.js | 2 +- 7 files changed, 46 insertions(+), 49 deletions(-) diff --git a/public/js/app/components/DropdownRounds.jsx b/public/js/app/components/DropdownRounds.jsx index 3b67bc11..0ef341a6 100644 --- a/public/js/app/components/DropdownRounds.jsx +++ b/public/js/app/components/DropdownRounds.jsx @@ -5,10 +5,10 @@ import { useLanguage } from '../hooks/useLanguage' const DROPDOWN_ID = 'roundsDropdown' const EMPTY_OPTION = -1 -const RoundOptions = ({ courseRoundList }) => { +const RoundOptions = ({ roundsForSelectedSemester }) => { const { createRoundLabel } = useRoundUtils() - return courseRoundList.map((round, roundIndex) => { + return roundsForSelectedSemester.map((round, roundIndex) => { const optionLabel = createRoundLabel(round) const uniqueKey = `${optionLabel}${round.round_application_code}${round.round_start_date}` @@ -21,7 +21,7 @@ const RoundOptions = ({ courseRoundList }) => { }) } -const DropdownRounds = ({ courseRoundList, semesterRoundState }) => { +const DropdownRounds = ({ roundsForSelectedSemester, semesterRoundState }) => { const { setSelectedRoundIndex, resetSelectedRoundIndex } = semesterRoundState const { translation } = useLanguage() @@ -31,7 +31,7 @@ const DropdownRounds = ({ courseRoundList, semesterRoundState }) => { useEffect(() => { setSelectedOptionIndex(EMPTY_OPTION) - }, [courseRoundList]) + }, [roundsForSelectedSemester]) const handleDropdownSelect = React.useCallback( ({ target }) => { @@ -54,7 +54,7 @@ const DropdownRounds = ({ courseRoundList, semesterRoundState }) => { [setSelectedRoundIndex, resetSelectedRoundIndex, setSelectedOptionIndex] ) - if (!courseRoundList || courseRoundList.length < 2) { + if (!roundsForSelectedSemester || roundsForSelectedSemester.length < 2) { return null } @@ -74,7 +74,7 @@ const DropdownRounds = ({ courseRoundList, semesterRoundState }) => { > ( ) - + diff --git a/public/js/app/hooks/__tests__/useSemesterRoundState.test.js b/public/js/app/hooks/__tests__/useSemesterRoundState.test.js index 96c48a30..c919478f 100644 --- a/public/js/app/hooks/__tests__/useSemesterRoundState.test.js +++ b/public/js/app/hooks/__tests__/useSemesterRoundState.test.js @@ -1,4 +1,4 @@ -const roundList = { +const roundsBySemester = { 20222: [ { round_time_slots: 'No information inserted', @@ -222,7 +222,7 @@ describe('useSemesterRoundsLogic', () => { useSemesterRoundState({ initiallySelectedRoundIndex: undefined, initiallySelectedSemester: 20242, - roundList, + roundsBySemester, syllabusList, activeSemesters, }) @@ -233,7 +233,7 @@ describe('useSemesterRoundsLogic', () => { expect(result.current.selectedSemester).toBe(20242) expect(result.current.showRoundData).toBe(false) expect(result.current.activeSemesterOnlyHasOneRound).toBe(false) - expect(result.current.firstRoundInActiveSemester).toEqual(roundList[20242][0]) + expect(result.current.firstRoundInActiveSemester).toEqual(roundsBySemester[20242][0]) expect(result.current.hasActiveSemesters).toBe(true) expect(result.current.activeSyllabus).toBe(syllabusList[0]) expect(result.current.hasSyllabus).toBe(true) @@ -244,7 +244,7 @@ describe('useSemesterRoundsLogic', () => { useSemesterRoundState({ initiallySelectedRoundIndex: undefined, initiallySelectedSemester: 20242, - roundList, + roundsBySemester, syllabusList, activeSemesters, }) @@ -259,7 +259,7 @@ describe('useSemesterRoundsLogic', () => { await waitFor(() => expect(result.current.selectedRoundIndex).toBe(0)) await waitFor(() => expect(result.current.showRoundData).toBe(true)) - await waitFor(() => expect(result.current.activeRound).toEqual(roundList[20242][0])) + await waitFor(() => expect(result.current.activeRound).toEqual(roundsBySemester[20242][0])) }) test('updates selectedSemester, firstRoundInActiveSemester, when setSelectedSemester is called', async () => { @@ -267,7 +267,7 @@ describe('useSemesterRoundsLogic', () => { useSemesterRoundState({ initiallySelectedRoundIndex: undefined, initiallySelectedSemester: 20242, - roundList, + roundsBySemester, syllabusList, activeSemesters, }) @@ -278,7 +278,7 @@ describe('useSemesterRoundsLogic', () => { }) await waitFor(() => expect(result.current.selectedSemester).toBe(20232)) - await waitFor(() => expect(result.current.firstRoundInActiveSemester).toBe(roundList[20232][0])) + await waitFor(() => expect(result.current.firstRoundInActiveSemester).toBe(roundsBySemester[20232][0])) }) test('if selectedRoundIndex is set and setSelectedSemester is called, reset selectedRoundIndex, activeRound and showRoundData', async () => { @@ -286,7 +286,7 @@ describe('useSemesterRoundsLogic', () => { useSemesterRoundState({ initiallySelectedRoundIndex: undefined, initiallySelectedSemester: 20242, - roundList, + roundsBySemester, syllabusList, activeSemesters, }) @@ -301,7 +301,7 @@ describe('useSemesterRoundsLogic', () => { await waitFor(() => expect(result.current.selectedRoundIndex).toBe(0)) await waitFor(() => expect(result.current.showRoundData).toBe(true)) - await waitFor(() => expect(result.current.activeRound).toEqual(roundList[20242][0])) + await waitFor(() => expect(result.current.activeRound).toEqual(roundsBySemester[20242][0])) act(() => { result.current.setSelectedSemester(20232) @@ -316,7 +316,7 @@ describe('useSemesterRoundsLogic', () => { useSemesterRoundState({ initiallySelectedRoundIndex: undefined, initiallySelectedSemester: 20222, - roundList, + roundsBySemester, syllabusList, activeSemesters, }) @@ -324,7 +324,7 @@ describe('useSemesterRoundsLogic', () => { expect(result.current.activeSemesterOnlyHasOneRound).toBe(true) expect(result.current.showRoundData).toBe(true) - expect(result.current.activeRound).toEqual(roundList[20222][0]) + expect(result.current.activeRound).toEqual(roundsBySemester[20222][0]) }) test('if initiallySelectedSemester is a string, converts it to number', async () => { @@ -332,7 +332,7 @@ describe('useSemesterRoundsLogic', () => { useSemesterRoundState({ initiallySelectedRoundIndex: undefined, initiallySelectedSemester: '20222', - roundList, + roundsBySemester, syllabusList, activeSemesters, }) @@ -342,13 +342,13 @@ describe('useSemesterRoundsLogic', () => { }) test.each([[], undefined])( - 'if roundList is empty or undefined, returns values accordingly', - async invalidRoundList => { + 'if roundsBySemester is empty or undefined, returns values accordingly', + async invalidRoundsBySemester => { const { result } = renderHook(() => useSemesterRoundState({ initiallySelectedRoundIndex: undefined, initiallySelectedSemester: 20242, - roundList: invalidRoundList, + roundsBySemester: invalidRoundsBySemester, syllabusList, activeSemesters, }) @@ -368,7 +368,7 @@ describe('useSemesterRoundsLogic', () => { useSemesterRoundState({ initiallySelectedRoundIndex: undefined, initiallySelectedSemester: 20182, - roundList, + roundsBySemester, syllabusList, activeSemesters, }) @@ -383,7 +383,7 @@ describe('useSemesterRoundsLogic', () => { useSemesterRoundState({ initiallySelectedRoundIndex: undefined, initiallySelectedSemester: 20182, - roundList, + roundsBySemester, syllabusList: [], activeSemesters, }) @@ -398,7 +398,7 @@ describe('useSemesterRoundsLogic', () => { useSemesterRoundState({ initiallySelectedRoundIndex: undefined, initiallySelectedSemester: 20182, - roundList, + roundsBySemester, syllabusList: [{ course_valid_from: [], course_valid_to: [] }], activeSemesters, }) @@ -413,7 +413,7 @@ describe('useSemesterRoundsLogic', () => { useSemesterRoundState({ initiallySelectedRoundIndex: undefined, initiallySelectedSemester: 20242, - roundList, + roundsBySemester, syllabusList, activeSemesters, }) @@ -429,7 +429,7 @@ describe('useSemesterRoundsLogic', () => { await waitFor(() => expect(result.current.selectedRoundIndex).toBe(0)) await waitFor(() => expect(result.current.showRoundData).toBe(true)) - await waitFor(() => expect(result.current.activeRound).toEqual(roundList[20242][0])) + await waitFor(() => expect(result.current.activeRound).toEqual(roundsBySemester[20242][0])) act(() => { result.current.resetSelectedRoundIndex() diff --git a/public/js/app/hooks/useSemesterRoundState.js b/public/js/app/hooks/useSemesterRoundState.js index 7b2da659..037bb2e9 100644 --- a/public/js/app/hooks/useSemesterRoundState.js +++ b/public/js/app/hooks/useSemesterRoundState.js @@ -13,7 +13,7 @@ const getElementOrEmpty = (arr, index) => { const useSemesterRoundState = ({ initiallySelectedRoundIndex, initiallySelectedSemester, - roundList, + roundsBySemester, syllabusList, activeSemesters, }) => { @@ -31,8 +31,8 @@ const useSemesterRoundState = ({ rounds[semester].length === 1 const activeSemesterOnlyHasOneRound = useMemo( - () => determineSemesterOnlyHasOneRound(roundList, selectedSemester), - [roundList, selectedSemester] + () => determineSemesterOnlyHasOneRound(roundsBySemester, selectedSemester), + [roundsBySemester, selectedSemester] ) const showRoundData = useMemo(() => { @@ -44,12 +44,12 @@ const useSemesterRoundState = ({ }, [isSetSelectedRoundIndex, activeSemesterOnlyHasOneRound]) const roundsForActiveSemester = useMemo(() => { - if (!roundList) { + if (!roundsBySemester) { return [] } - return roundList[selectedSemester] - }, [roundList, selectedSemester]) + return roundsBySemester[selectedSemester] + }, [roundsBySemester, selectedSemester]) const firstRoundInActiveSemester = useMemo( () => getElementOrEmpty(roundsForActiveSemester, 0), @@ -77,13 +77,13 @@ const useSemesterRoundState = ({ const setSelectedSemesterAsNumber = useCallback( newActiveSemester => { setSelectedSemester(() => Number(newActiveSemester)) - if (determineSemesterOnlyHasOneRound(roundList, selectedSemester)) { + if (determineSemesterOnlyHasOneRound(roundsBySemester, selectedSemester)) { setSelectedRoundIndex(0) } else { resetSelectedRoundIndex() } }, - [resetSelectedRoundIndex, roundList, selectedSemester] + [resetSelectedRoundIndex, roundsBySemester, selectedSemester] ) return { diff --git a/public/js/app/pages/CoursePage.jsx b/public/js/app/pages/CoursePage.jsx index df847c3e..3b62f13b 100644 --- a/public/js/app/pages/CoursePage.jsx +++ b/public/js/app/pages/CoursePage.jsx @@ -44,7 +44,7 @@ function CoursePage() { const semesterRoundState = useSemesterRoundState({ initiallySelectedRoundIndex, initiallySelectedSemester, - roundList: courseData.roundList, + roundsBySemester: courseData.roundsBySemester, syllabusList: courseData.syllabusList, activeSemesters, }) @@ -178,9 +178,10 @@ function CoursePage() { {hasActiveSemesters && ( )} - {courseData.roundList[selectedSemester] && courseData.roundList[selectedSemester].length > 1 ? ( + {courseData.roundsBySemester[selectedSemester] && + courseData.roundsBySemester[selectedSemester].length > 1 ? ( ) : ( diff --git a/public/js/app/pages/__tests__/CoursePage.test.js b/public/js/app/pages/__tests__/CoursePage.test.js index caa20ca5..63759676 100644 --- a/public/js/app/pages/__tests__/CoursePage.test.js +++ b/public/js/app/pages/__tests__/CoursePage.test.js @@ -104,7 +104,7 @@ describe('Component ', () => { course_title: 'Basic Electrical Engineering', }, language: 'en', - roundList: { + roundsBySemester: { 20221: [ { has_round_published_memo: true, diff --git a/server/apiCalls/getFilteredData.js b/server/apiCalls/getFilteredData.js index a5900bdc..c6cea607 100644 --- a/server/apiCalls/getFilteredData.js +++ b/server/apiCalls/getFilteredData.js @@ -187,7 +187,7 @@ function _parseRounds({ roundInfos, courseCode, language, memoList }) { responsibles: [], } - const courseRoundList = {} + const roundsBySemester = {} for (const roundInfo of roundInfos) { const courseRound = _getRound(roundInfo, language) const { round_course_term: yearAndTermArr, round_application_code: applicationCode } = courseRound @@ -196,7 +196,7 @@ function _parseRounds({ roundInfos, courseCode, language, memoList }) { if (yearAndTermArr && tempList.indexOf(semester) < 0) { tempList.push(semester) activeSemesterArray.push([...yearAndTermArr, semester]) - courseRoundList[semester] = [] + roundsBySemester[semester] = [] } const hasMemoForThisRound = !!(memoList[semester] && memoList[semester][applicationCode]) @@ -210,7 +210,7 @@ function _parseRounds({ roundInfos, courseCode, language, memoList }) { } courseRound.has_round_published_memo = true } - courseRoundList[semester].push(courseRound) + roundsBySemester[semester].push(courseRound) // TODO: This will be removed. Because UG Rest Api is still using ladokRoundId. So once it get replaced by application code then this will be removed. const { round = {} } = roundInfo const { ladokRoundId } = round @@ -228,7 +228,7 @@ function _parseRounds({ roundInfos, courseCode, language, memoList }) { semester, })) - return { courseRoundList, activeSemesters, employees } + return { roundsBySemester, activeSemesters, employees } } const getFilteredData = async ({ courseCode, language, memoList }) => { @@ -260,11 +260,7 @@ const getFilteredData = async ({ courseCode, language, memoList }) => { const { syllabusList } = createSyllabusList(courseDetails, language) //* **** Get a list of rounds and a list of redis keys for using to get teachers and responsibles from UG Rest API *****// - const { - courseRoundList: roundList, - activeSemesters, - employees, - } = _parseRounds({ + const { roundsBySemester, activeSemesters, employees } = _parseRounds({ roundInfos: courseDetails.roundInfos, courseCode, language, @@ -274,7 +270,7 @@ const getFilteredData = async ({ courseCode, language, memoList }) => { const courseData = { syllabusList, courseInfo, - roundList, + roundsBySemester, courseTitleData, language, } diff --git a/server/controllers/__tests__/courseCtrl.test.js b/server/controllers/__tests__/courseCtrl.test.js index ab11ba92..c6310cd4 100644 --- a/server/controllers/__tests__/courseCtrl.test.js +++ b/server/controllers/__tests__/courseCtrl.test.js @@ -159,7 +159,7 @@ describe('Discontinued course to test', () => { "course_title": "Kolhydratteknik inom glykovetenskap", }, "language": "sv", - "roundList": {}, + "roundsBySemester": {}, "syllabusList": [ { "course_additional_regulations": "",