From f635d8df5e7cc81cf8357bafb1e5a3484edb3ede Mon Sep 17 00:00:00 2001 From: juli-txt Date: Fri, 13 Sep 2024 00:50:07 +0200 Subject: [PATCH] Removed async from hook tests --- .../LearningElementRatingDashboard.test.tsx | 261 +++++++++--------- 1 file changed, 129 insertions(+), 132 deletions(-) diff --git a/src/components/Dashboards/Rating/LearningElementRatingDashboard/LearningElementRatingDashboard.test.tsx b/src/components/Dashboards/Rating/LearningElementRatingDashboard/LearningElementRatingDashboard.test.tsx index 0ed5ed08..9da091cd 100644 --- a/src/components/Dashboards/Rating/LearningElementRatingDashboard/LearningElementRatingDashboard.test.tsx +++ b/src/components/Dashboards/Rating/LearningElementRatingDashboard/LearningElementRatingDashboard.test.tsx @@ -22,43 +22,40 @@ describe('LearningElementRatingDashboard', () => { ) - console.log(container.innerHTML) - act(() => - waitFor(async () => { - const value = getByText('0.805') - fireEvent.mouseOver(value) + await waitFor(() => { + const value = getByText('0.805') + fireEvent.mouseOver(value) - const valueTrend = container.querySelectorAll('image.value-trend') - fireEvent.mouseOver(valueTrend[0]) + const valueTrend = container.querySelectorAll('image.value-trend') + fireEvent.mouseOver(valueTrend[0]) - const deviation = getByText('0.80') - fireEvent.mouseOver(deviation) + const deviation = getByText('0.80') + fireEvent.mouseOver(deviation) - const deviationTrend = container.querySelectorAll('image.deviation-trend') - fireEvent.mouseOver(deviationTrend[0]) + const deviationTrend = container.querySelectorAll('image.deviation-trend') + fireEvent.mouseOver(deviationTrend[0]) - const dataPoint = container.querySelectorAll('circle.data-point') - fireEvent.mouseOver(dataPoint[0]) + const dataPoint = container.querySelectorAll('circle.data-point') + fireEvent.mouseOver(dataPoint[0]) - const upperDeviation = container.querySelectorAll('circle.upper-deviation') - fireEvent.mouseOver(upperDeviation[0]) + const upperDeviation = container.querySelectorAll('circle.upper-deviation') + fireEvent.mouseOver(upperDeviation[0]) - const lowerDeviation = container.querySelectorAll('circle.lower-deviation') - fireEvent.mouseOver(lowerDeviation[0]) + const lowerDeviation = container.querySelectorAll('circle.lower-deviation') + fireEvent.mouseOver(lowerDeviation[0]) - const xAxis = container.querySelectorAll('g.x-axis') - fireEvent.mouseOver(xAxis[0]) + const xAxis = container.querySelectorAll('g.x-axis') + fireEvent.mouseOver(xAxis[0]) - const yAxis = container.querySelectorAll('g.y-axis') - fireEvent.mouseOver(yAxis[0]) + const yAxis = container.querySelectorAll('g.y-axis') + fireEvent.mouseOver(yAxis[0]) - const radioButton = getAllByRole('radio') - fireEvent.click(radioButton[1]) + const radioButton = getAllByRole('radio') + fireEvent.click(radioButton[1]) - const header = container.querySelectorAll('th') - fireEvent.mouseOver(header[0]) - }) - ) + const header = container.querySelectorAll('th') + fireEvent.mouseOver(header[0]) + }) }) it('rerenders the chart and checks the tooltip of the spider graph', async () => { @@ -77,7 +74,7 @@ describe('LearningElementRatingDashboard', () => { }) }) - test('Functionality of the hook', async () => { + test('Functionality of the hook', () => { const { result } = renderHook(() => useLearningElementRatingDashboard()) expect(result.current.ratingValue).toEqual(0) @@ -89,148 +86,148 @@ describe('LearningElementRatingDashboard', () => { expect(result.current.lineGraphData).toEqual([]) expect(result.current.topics).toEqual([]) - await waitFor(async () => { + waitFor(() => { expect(result.current.isLoading).toBe(false) - }) - expect(result.current.ratingValue).toEqual(0.8055555555555555) - expect(result.current.ratingDeviation).toEqual(0.8055555555555556) - expect(result.current.maxRatingDeviation).toEqual(1) - expect(result.current.ratingDeviationTrend).toEqual(0.5277777777777778) - expect(result.current.ratingValueTrend).toEqual(0.5277777777777777) - expect(result.current.spiderGraphData).toEqual({ '1': 1200, '2': 900, '99': 800 }) - expect(result.current.lineGraphData).toEqual([ - { - deviation: 196, - timestamp: new Date('2023-01-01T00:00:00.000Z'), - value: 1000 - }, - { - deviation: 182.9333333333333, - timestamp: new Date('2023-01-02T00:00:00.000Z'), - value: 933.3333333333334 - } - ]) - expect(result.current.topics).toEqual([ - { - contains_le: true, - created_at: 'string', - created_by: 'string', - id: 1, - is_topic: true, - last_updated: 'string', - lms_id: 1, - name: 'Wirtschaftsinformatik', - parent_id: 1, - student_topic: { - done: true, - done_at: 'string', + expect(result.current.ratingValue).toEqual(0.8055555555555555) + expect(result.current.ratingDeviation).toEqual(0.8055555555555556) + expect(result.current.maxRatingDeviation).toEqual(1) + expect(result.current.ratingDeviationTrend).toEqual(0.5277777777777778) + expect(result.current.ratingValueTrend).toEqual(0.5277777777777777) + expect(result.current.spiderGraphData).toEqual({ '1': 1200, '2': 900, '99': 800 }) + expect(result.current.lineGraphData).toEqual([ + { + deviation: 196, + timestamp: new Date('2023-01-01T00:00:00.000Z'), + value: 1000 + }, + { + deviation: 182.9333333333333, + timestamp: new Date('2023-01-02T00:00:00.000Z'), + value: 933.3333333333334 + } + ]) + expect(result.current.topics).toEqual([ + { + contains_le: true, + created_at: 'string', + created_by: 'string', id: 1, - student_id: 1, - topic_id: 1, - visits: ['string'] + is_topic: true, + last_updated: 'string', + lms_id: 1, + name: 'Wirtschaftsinformatik', + parent_id: 1, + student_topic: { + done: true, + done_at: 'string', + id: 1, + student_id: 1, + topic_id: 1, + visits: ['string'] + }, + university: 'HS-Kempten' }, - university: 'HS-Kempten' - }, - { - contains_le: true, - created_at: 'string', - created_by: 'string', - id: 2, - is_topic: true, - last_updated: 'string', - lms_id: 1, - name: 'Informatik', - parent_id: 1, - student_topic: { - done: true, - done_at: 'string', + { + contains_le: true, + created_at: 'string', + created_by: 'string', id: 2, - student_id: 1, - topic_id: 2, - visits: ['string'] + is_topic: true, + last_updated: 'string', + lms_id: 1, + name: 'Informatik', + parent_id: 1, + student_topic: { + done: true, + done_at: 'string', + id: 2, + student_id: 1, + topic_id: 2, + visits: ['string'] + }, + university: 'HS-Kempten' }, - university: 'HS-Kempten' - }, - { - contains_le: true, - created_at: 'string', - created_by: 'string', - id: 1, - is_topic: true, - last_updated: 'string', - lms_id: 1, - name: 'Wirtschaftsinformatik', - parent_id: 1, - student_topic: { - done: true, - done_at: 'string', + { + contains_le: true, + created_at: 'string', + created_by: 'string', id: 1, - student_id: 1, - topic_id: 1, - visits: ['string'] + is_topic: true, + last_updated: 'string', + lms_id: 1, + name: 'Wirtschaftsinformatik', + parent_id: 1, + student_topic: { + done: true, + done_at: 'string', + id: 1, + student_id: 1, + topic_id: 1, + visits: ['string'] + }, + university: 'HS-Kempten' }, - university: 'HS-Kempten' - }, - { - contains_le: true, - created_at: 'string', - created_by: 'string', - id: 2, - is_topic: true, - last_updated: 'string', - lms_id: 1, - name: 'Informatik', - parent_id: 1, - student_topic: { - done: true, - done_at: 'string', + { + contains_le: true, + created_at: 'string', + created_by: 'string', id: 2, - student_id: 1, - topic_id: 2, - visits: ['string'] - }, - university: 'HS-Kempten' - } - ]) + is_topic: true, + last_updated: 'string', + lms_id: 1, + name: 'Informatik', + parent_id: 1, + student_topic: { + done: true, + done_at: 'string', + id: 2, + student_id: 1, + topic_id: 2, + visits: ['string'] + }, + university: 'HS-Kempten' + } + ]) + }) }) - test('Functionality of the hook with getUser failing', async () => { + test('Functionality of the hook with getUser failing', () => { mockServices.fetchUser.mockImplementationOnce(() => Promise.reject(new Error('fetchUser error'))) + const { result } = renderHook(() => useLearningElementRatingDashboard()) - await waitFor(async () => { + waitFor(() => { expect(result.current.isLoading).toBe(true) }) }) - test('Functionality of the hook with getCourses failing', async () => { + test('Functionality of the hook with getCourses failing', () => { mockServices.fetchCourses.mockImplementationOnce(() => Promise.reject(new Error('fetchCourses error'))) const { result } = renderHook(() => useLearningElementRatingDashboard()) - await waitFor(async () => { + waitFor(() => { expect(result.current.isLoading).toBe(true) }) }) - test('Functionality of the hook with getLearningPathTopic failing', async () => { + test('Functionality of the hook with getLearningPathTopic failing', () => { mockServices.fetchLearningPathTopic.mockImplementationOnce(() => Promise.reject(new Error('fetchLearningPathTopic error')) ) const { result } = renderHook(() => useLearningElementRatingDashboard()) - await waitFor(async () => { + waitFor(() => { expect(result.current.isLoading).toBe(true) }) }) - test('Functionality of the hook with fetchLearningElementRatings failing', async () => { + test('Functionality of the hook with fetchLearningElementRatings failing', () => { mockServices.fetchLearningElementRatings.mockImplementationOnce(() => Promise.reject(new Error('fetchLearningElementRatings error')) ) const { result } = renderHook(() => useLearningElementRatingDashboard()) - - await waitFor(async () => { + waitFor(() => { expect(result.current.isLoading).toBe(true) }) })