Skip to content

Commit

Permalink
style: comment cleaned
Browse files Browse the repository at this point in the history
  • Loading branch information
nandodev-net committed Sep 11, 2024
1 parent 161a544 commit 951d946
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 32 deletions.
5 changes: 2 additions & 3 deletions src/core/tests/Main.test.jsx
Original file line number Diff line number Diff line change
@@ -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', () => () => <div>Mocked ClassRoster Component</div>);
jest.mock('../../views/LabSummary', () => () => <div>Mocked LabSummary Component</div>);
jest.mock('../../views/LabDetails', () => () => <div>Mocked LabDetails Component</div>);

// Mock constants
jest.mock('constants', () => ({
mfeBaseUrl: '/base-url',
}));
Expand Down
20 changes: 8 additions & 12 deletions src/helpers/tests/index.test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { eventManager, formatUnixTimestamp, formatTime } from '../index';

describe('Helper Functions', () => {

Check failure on line 3 in src/helpers/tests/index.test.js

View workflow job for this annotation

GitHub Actions / test (16)

Block must not be padded by blank lines
// 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',
Expand Down Expand Up @@ -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();
});

Expand All @@ -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 () => {
Expand All @@ -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',
Expand Down
4 changes: 0 additions & 4 deletions src/views/ClassRoster/tests/columns.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => (
Expand All @@ -13,7 +12,6 @@ jest.mock('@edx/paragon', () => ({
),
}));

// Mock the mfeBaseUrl constant
jest.mock('constants', () => ({
mfeBaseUrl: '/base-url/:courseId',
}));
Expand All @@ -40,15 +38,13 @@ describe('Columns Component', () => {
},
};

// Render the cell component
const CellComponent = columnDefinitions[0].Cell;
render(<CellComponent row={mockRow} />);

const hyperlink = screen.getByText('testuser');
expect(hyperlink).toBeInTheDocument();
fireEvent.click(hyperlink);

// Verify that handleUsernameClick is called correctly
expect(mockSetRosterStudent).toHaveBeenCalledWith({
user_id: 'anon_id_123',
username: 'testuser',
Expand Down
6 changes: 2 additions & 4 deletions src/views/LabDetails/tests/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => () => <div>Mocked AlertMessage</div>);
jest.mock('../../../shared/LabDetailsCard', () => () => <div>Mocked LabDetailsCard</div>);
jest.mock('../../../shared/LabDetailsChartCard', () => () => <div>Mocked LabDetailsChartCard</div>);
Expand Down Expand Up @@ -70,7 +70,6 @@ describe('LabDetails Component', () => {
</MemoryRouter>,
);

// Check for Redirect component being rendered
expect(container.innerHTML).toContain('');
});
});
Expand Down Expand Up @@ -152,7 +151,6 @@ describe('LabDetails Component', () => {
</Router>,
);

// Verify that the spinner is displayed
expect(screen.getByText('loading')).toBeInTheDocument();
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/views/LabSummary/tests/columns.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(<PassedCell row={mockRow} />);
Expand Down
13 changes: 5 additions & 8 deletions src/views/LabSummary/tests/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
});
Expand All @@ -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', () => {
Expand All @@ -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 () => {
Expand All @@ -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;

Expand All @@ -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);
});
});

0 comments on commit 951d946

Please sign in to comment.