From 951d946b29857703c9a139465bee6c3a1ceda74c Mon Sep 17 00:00:00 2001 From: Fernando Date: Wed, 11 Sep 2024 15:31:25 -0400 Subject: [PATCH] style: comment cleaned --- src/core/tests/Main.test.jsx | 5 ++--- src/helpers/tests/index.test.js | 20 ++++++++------------ src/views/ClassRoster/tests/columns.test.jsx | 4 ---- src/views/LabDetails/tests/index.test.jsx | 6 ++---- src/views/LabSummary/tests/columns.test.jsx | 2 +- src/views/LabSummary/tests/index.test.jsx | 13 +++++-------- 6 files changed, 18 insertions(+), 32 deletions(-) diff --git a/src/core/tests/Main.test.jsx b/src/core/tests/Main.test.jsx index 217191c..a925d2a 100644 --- a/src/core/tests/Main.test.jsx +++ b/src/core/tests/Main.test.jsx @@ -1,15 +1,14 @@ import React from 'react'; import { render, screen, act } from '@testing-library/react'; import { MemoryRouter } from 'react-router-dom'; -import Main from '../Main'; import '@testing-library/jest-dom'; -// Mock the child components +import Main from '../Main'; + jest.mock('../../views/ClassRoster', () => () =>
Mocked ClassRoster Component
); jest.mock('../../views/LabSummary', () => () =>
Mocked LabSummary Component
); jest.mock('../../views/LabDetails', () => () =>
Mocked LabDetails Component
); -// Mock constants jest.mock('constants', () => ({ mfeBaseUrl: '/base-url', })); diff --git a/src/helpers/tests/index.test.js b/src/helpers/tests/index.test.js index 0cba43f..8de3de3 100644 --- a/src/helpers/tests/index.test.js +++ b/src/helpers/tests/index.test.js @@ -1,14 +1,14 @@ import { eventManager, formatUnixTimestamp, formatTime } from '../index'; describe('Helper Functions', () => { - // Test 1: Check if formatUnixTimestamp correctly formats a valid timestamp + describe('formatUnixTimestamp', () => { it('formats a valid UNIX timestamp correctly', () => { const timestamp = 1672531199; // Corresponds to 12/31/2022 11:59 PM UTC const formatted = formatUnixTimestamp(timestamp); const expectedDate = new Date(timestamp * 1000).toLocaleString('en-US', { - timeZone: 'UTC', // Asegura que utilice la zona horaria UTC + timeZone: 'UTC', month: '2-digit', day: '2-digit', year: 'numeric', @@ -49,14 +49,12 @@ describe('Helper Functions', () => { }); }); - // Test 2: Check if eventManager manages the execution correctly describe('eventManager', () => { it('executes the callback function correctly', async () => { const mockCallback = jest.fn(); const managedEvent = eventManager(mockCallback); - await managedEvent(); // Call the managed event - + await managedEvent(); expect(mockCallback).toHaveBeenCalled(); }); @@ -65,15 +63,15 @@ describe('Helper Functions', () => { const mockCallback = jest.fn(); const managedEvent = eventManager(mockCallback); - await managedEvent(); // First call - await managedEvent(); // Second call (should be ignored due to the delay) + await managedEvent(); + await managedEvent(); expect(mockCallback).toHaveBeenCalledTimes(1); - jest.runAllTimers(); // Fast-forward the timers to complete the timeout - await managedEvent(); // Third call (after timeout) + jest.runAllTimers(); + await managedEvent(); - expect(mockCallback).toHaveBeenCalledTimes(2); // Should be called again after the delay + expect(mockCallback).toHaveBeenCalledTimes(2); }); it('executes the callback function correctly', async () => { @@ -89,13 +87,11 @@ describe('Helper Functions', () => { }); }); - // Test 3: Check if formatTime correctly formats a valid timestamp string describe('formatTime', () => { it('formats a valid timestamp string correctly', () => { const timeString = '/Date(1672531199000)/'; // Corresponds to 12/31/2022 11:59 PM UTC const formatted = formatTime(timeString); - // Adjust the expected output to match the local time zone const expectedDate = new Date(1672531199000).toLocaleDateString('en-US', { month: '2-digit', day: '2-digit', diff --git a/src/views/ClassRoster/tests/columns.test.jsx b/src/views/ClassRoster/tests/columns.test.jsx index d47099f..46be364 100644 --- a/src/views/ClassRoster/tests/columns.test.jsx +++ b/src/views/ClassRoster/tests/columns.test.jsx @@ -3,7 +3,6 @@ import { render, screen, fireEvent } from '@testing-library/react'; import { columns } from '../columns'; import '@testing-library/jest-dom'; -// Mock dependencies jest.mock('@edx/paragon', () => ({ // eslint-disable-next-line react/prop-types Hyperlink: ({ destination, onClick, children }) => ( @@ -13,7 +12,6 @@ jest.mock('@edx/paragon', () => ({ ), })); -// Mock the mfeBaseUrl constant jest.mock('constants', () => ({ mfeBaseUrl: '/base-url/:courseId', })); @@ -40,7 +38,6 @@ describe('Columns Component', () => { }, }; - // Render the cell component const CellComponent = columnDefinitions[0].Cell; render(); @@ -48,7 +45,6 @@ describe('Columns Component', () => { expect(hyperlink).toBeInTheDocument(); fireEvent.click(hyperlink); - // Verify that handleUsernameClick is called correctly expect(mockSetRosterStudent).toHaveBeenCalledWith({ user_id: 'anon_id_123', username: 'testuser', diff --git a/src/views/LabDetails/tests/index.test.jsx b/src/views/LabDetails/tests/index.test.jsx index d10915f..8e63fcb 100644 --- a/src/views/LabDetails/tests/index.test.jsx +++ b/src/views/LabDetails/tests/index.test.jsx @@ -12,10 +12,10 @@ import { BrowserRouter as Router, MemoryRouter, } from 'react-router-dom'; -import LabDetails from '../index'; import '@testing-library/jest-dom'; -// Mock necessary components +import LabDetails from '../index'; + jest.mock('../../../shared/AlertMessage', () => () =>
Mocked AlertMessage
); jest.mock('../../../shared/LabDetailsCard', () => () =>
Mocked LabDetailsCard
); jest.mock('../../../shared/LabDetailsChartCard', () => () =>
Mocked LabDetailsChartCard
); @@ -70,7 +70,6 @@ describe('LabDetails Component', () => { , ); - // Check for Redirect component being rendered expect(container.innerHTML).toContain(''); }); }); @@ -152,7 +151,6 @@ describe('LabDetails Component', () => { , ); - // Verify that the spinner is displayed expect(screen.getByText('loading')).toBeInTheDocument(); }); }); diff --git a/src/views/LabSummary/tests/columns.test.jsx b/src/views/LabSummary/tests/columns.test.jsx index e4c4e6a..b1bb2ee 100644 --- a/src/views/LabSummary/tests/columns.test.jsx +++ b/src/views/LabSummary/tests/columns.test.jsx @@ -108,7 +108,7 @@ describe('Columns Component for LabSummary', () => { const PassedCell = columnDefinitio[4].Cell; const mockRow = { original: { - exam_passed: '', // anything different from 'yes' or 'no' + exam_passed: '', }, }; render(); diff --git a/src/views/LabSummary/tests/index.test.jsx b/src/views/LabSummary/tests/index.test.jsx index 00940d3..a891df5 100644 --- a/src/views/LabSummary/tests/index.test.jsx +++ b/src/views/LabSummary/tests/index.test.jsx @@ -251,7 +251,7 @@ describe('LabSummary Component', () => { if (laboratory.exam_score !== null && laboratory.exam_max_possible_score !== null) { expect(examPercentage).toBe((laboratory.exam_score / laboratory.exam_max_possible_score) * 10); } else { - expect(examPercentage).toBeNaN(); // O se puede cambiar a otro tipo de validación si espera 'N/A' + expect(examPercentage).toBeNaN(); } }); }); @@ -264,7 +264,7 @@ describe('LabSummary Component', () => { }; const examPercentage = (laboratory.exam_score / laboratory.exam_max_possible_score) * 10; - expect(examPercentage).toBe(8); // Ejemplo de valor esperado + expect(examPercentage).toBe(8); }); it('returns "N/A" when exam_score or exam_max_possible_score is invalid', () => { @@ -275,7 +275,7 @@ describe('LabSummary Component', () => { }; const examPercentage = (laboratory.exam_score / laboratory.exam_max_possible_score) * 10; - expect(Number.isNaN(examPercentage)).toBe(true); // Cambia según el comportamiento esperado + expect(Number.isNaN(examPercentage)).toBe(true); }); it('handles pagination correctly and updates currentPage and isLoading', async () => { @@ -301,17 +301,15 @@ describe('LabSummary Component', () => { }); }); - // Test for passedValue and examPercentage it('calculates passedValue and examPercentage correctly', () => { const laboratory = { - exam_passed: true, // Case for 'Yes' + exam_passed: true, exam_score: 80, exam_max_possible_score: 100, }; const labsData = []; - // Manually call the calculation logic const passedValue = { true: 'Yes', false: 'No' }[laboratory.exam_passed] ?? 'N/A'; const examPercentage = (laboratory.exam_score / laboratory.exam_max_possible_score) * 10; @@ -326,8 +324,7 @@ describe('LabSummary Component', () => { end_time: formatUnixTimestamp(laboratory.end_time), }); - // Verifica que se calculen los valores correctos expect(passedValue).toBe('Yes'); - expect(examPercentage).toBe(8); // Asegúrate de que el valor de porcentaje sea el esperado + expect(examPercentage).toBe(8); }); });