Skip to content

Commit 387613b

Browse files
test(core): add more unit tests
1 parent e64dd9b commit 387613b

File tree

12 files changed

+379
-5
lines changed

12 files changed

+379
-5
lines changed

app/(main)/header/header.test.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from 'react';
2+
import { render, screen } from '@testing-library/react';
3+
import '@testing-library/jest-dom';
4+
import { Header } from './header';
5+
6+
describe('Header Component', () => {
7+
beforeEach(() => render(<Header />));
8+
9+
it('should render the header title', () => {
10+
const titleElement = screen.getByText(/Event loop explorer/i);
11+
expect(titleElement).toBeInTheDocument();
12+
});
13+
14+
it('should render the GitHub link', () => {
15+
const githubLink = screen.getByRole('link');
16+
expect(githubLink).toBeInTheDocument();
17+
expect(githubLink).toHaveAttribute(
18+
'href',
19+
'https://github.com/vault-developer/event-loop-explorer'
20+
);
21+
});
22+
23+
it('should render the ThemeToggle component', () => {
24+
const themeToggle = screen.getByTestId('theme-toggle');
25+
expect(themeToggle).toBeInTheDocument();
26+
});
27+
});

app/(main)/header/themeToggle.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ export function ThemeToggle() {
77
const onToggle = () => setTheme(theme === 'light' ? 'dark' : 'light');
88

99
return (
10-
<Button variant="ghost" size="iconBig" onClick={onToggle}>
10+
<Button
11+
variant="ghost"
12+
size="iconBig"
13+
onClick={onToggle}
14+
data-testid="theme-toggle"
15+
>
1116
<Sun
1217
className="absolute scale-100 dark:scale-0 rotate-0 dark:rotate-90 transition-all size-6"
1318
size={24}

app/(main)/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { Header } from './header/header';
44
import { Configurator } from '@/app/(main)/sections/configurator/configurator';
55
import { WebApi } from '@/app/(main)/sections/webApi';
6-
import { RequestAnimationFrame } from '@/app/(main)/sections/requestAnimaitionFrame';
6+
import { RequestAnimationFrame } from '@/app/(main)/sections/requestAnimationFrame';
77
import { Callstack } from '@/app/(main)/sections/callstack';
88
import { Console } from '@/app/(main)/sections/console';
99
import { TasksQueue } from '@/app/(main)/sections/tasksQueue';
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React from 'react';
2+
import { render, screen } from '@testing-library/react';
3+
import '@testing-library/jest-dom';
4+
import { Callstack } from '@/app/(main)/sections/callstack';
5+
6+
jest.mock('@/store/store', () => ({
7+
useQueueManagerStore: jest
8+
.fn()
9+
.mockImplementation(() => ['stack-1', 'stack-2']),
10+
}));
11+
12+
describe('Callstack Component', () => {
13+
beforeEach(() => render(<Callstack />));
14+
15+
it('should render the callstack title', () => {
16+
const titleElement = screen.getByText(/Callstack/i);
17+
expect(titleElement).toBeInTheDocument();
18+
});
19+
20+
it('should render callstacks', () => {
21+
const callstack1 = screen.getByText(/stack-1/i);
22+
const callstack2 = screen.getByText(/stack-2/i);
23+
expect(callstack1).toBeInTheDocument();
24+
expect(callstack2).toBeInTheDocument();
25+
});
26+
27+
it('should not render the modal by default', async () => {
28+
const descriptionElements = screen.queryAllByText(
29+
/A call stack is a mechanism for an interpreter to keep track of its place/i
30+
);
31+
expect(descriptionElements.length).toBe(0);
32+
});
33+
34+
it('should render the modal after icon click', async () => {
35+
const modalButton = screen.getByRole('button');
36+
await modalButton.click();
37+
const descriptionElement = screen.getByText(
38+
/A call stack is a mechanism for an interpreter to keep track of its place/i
39+
);
40+
expect(descriptionElement).toBeInTheDocument();
41+
});
42+
});
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React from 'react';
2+
import { render, screen } from '@testing-library/react';
3+
import '@testing-library/jest-dom';
4+
import { Console } from './console';
5+
6+
jest.mock('@/store/store', () => ({
7+
useQueueManagerStore: jest.fn().mockImplementation(() => ['log1', 'log2']),
8+
}));
9+
10+
describe('Console Component', () => {
11+
beforeEach(() => render(<Console />));
12+
13+
it('should render the console title', () => {
14+
const titleElement = screen.getByText(/Console/i);
15+
expect(titleElement).toBeInTheDocument();
16+
});
17+
18+
it('should render logs', () => {
19+
const log1 = screen.getByText(/log1/i);
20+
const log2 = screen.getByText(/log2/i);
21+
expect(log1).toBeInTheDocument();
22+
expect(log2).toBeInTheDocument();
23+
});
24+
25+
it('should not render the modal by default', async () => {
26+
const descriptionElements = screen.queryAllByText(
27+
/The browser console is a built-in tool/i
28+
);
29+
expect(descriptionElements.length).toBe(0);
30+
});
31+
32+
it('should render the modal after icon click', async () => {
33+
const modalButton = screen.getByRole('button');
34+
await modalButton.click();
35+
const descriptionElement = screen.getByText(
36+
/The browser console is a built-in tool/i
37+
);
38+
expect(descriptionElement).toBeInTheDocument();
39+
});
40+
});
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React from 'react';
2+
import { render, screen } from '@testing-library/react';
3+
import '@testing-library/jest-dom';
4+
import { MicrotasksQueue } from '@/app/(main)/sections/microtasksQueue';
5+
6+
jest.mock('@/store/store', () => ({
7+
useQueueManagerStore: jest.fn().mockImplementation(() => ['ms1', 'ms2']),
8+
}));
9+
10+
describe('Microtasks Queue Component', () => {
11+
beforeEach(() => render(<MicrotasksQueue />));
12+
13+
it('should render the microtask title', () => {
14+
const titleElement = screen.getByText(/Microtasks Queue/i);
15+
expect(titleElement).toBeInTheDocument();
16+
});
17+
18+
it('should render logs', () => {
19+
const ms1 = screen.getByText(/ms1/i);
20+
const ms2 = screen.getByText(/ms2/i);
21+
expect(ms1).toBeInTheDocument();
22+
expect(ms2).toBeInTheDocument();
23+
});
24+
25+
it('should not render the modal by default', async () => {
26+
const descriptionElements = screen.queryAllByText(
27+
/A microtask is a short function which is executed/i
28+
);
29+
expect(descriptionElements.length).toBe(0);
30+
});
31+
32+
it('should render the modal after icon click', async () => {
33+
const modalButton = screen.getByRole('button');
34+
await modalButton.click();
35+
const descriptionElement = screen.getByText(
36+
/A microtask is a short function which is executed/i
37+
);
38+
expect(descriptionElement).toBeInTheDocument();
39+
});
40+
});
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React from 'react';
2+
import { render, screen } from '@testing-library/react';
3+
import '@testing-library/jest-dom';
4+
import { RequestAnimationFrame } from '@/app/(main)/sections/requestAnimationFrame';
5+
6+
jest.mock('@/store/store', () => ({
7+
useQueueManagerStore: jest.fn().mockImplementation(() => ['raf1', 'raf2']),
8+
}));
9+
10+
describe('RequestAnimationFrame Callbacks Component', () => {
11+
beforeEach(() => render(<RequestAnimationFrame />));
12+
13+
it('should render the requestAnimationFrame title', () => {
14+
const titleElement = screen.getByText(/RequestAnimationFrame callbacks/i);
15+
expect(titleElement).toBeInTheDocument();
16+
});
17+
18+
it('should render elements', () => {
19+
const raf1 = screen.getByText(/raf1/i);
20+
const raf2 = screen.getByText(/raf2/i);
21+
expect(raf1).toBeInTheDocument();
22+
expect(raf2).toBeInTheDocument();
23+
});
24+
25+
it('should not render the modal by default', async () => {
26+
const descriptionElements = screen.queryAllByText(
27+
/The window.requestAnimationFrame\(\) method tells the browser/i
28+
);
29+
expect(descriptionElements.length).toBe(0);
30+
});
31+
32+
it('should render the modal after icon click', async () => {
33+
const modalButton = screen.getByRole('button');
34+
await modalButton.click();
35+
const descriptionElement = screen.getByText(
36+
/The window.requestAnimationFrame\(\) method tells the browser/i
37+
);
38+
expect(descriptionElement).toBeInTheDocument();
39+
});
40+
});
File renamed without changes.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React from 'react';
2+
import { render, screen } from '@testing-library/react';
3+
import '@testing-library/jest-dom';
4+
import { TasksQueue } from '@/app/(main)/sections/tasksQueue';
5+
6+
jest.mock('@/store/store', () => ({
7+
useQueueManagerStore: jest.fn().mockImplementation(() => ['task1', 'task2']),
8+
}));
9+
10+
describe('Tasks Queue Component', () => {
11+
beforeEach(() => render(<TasksQueue />));
12+
13+
it('should render the task title', () => {
14+
const titleElement = screen.getByText(/Tasks Queue/i);
15+
expect(titleElement).toBeInTheDocument();
16+
});
17+
18+
it('should render logs', () => {
19+
const task1 = screen.getByText(/task1/i);
20+
const task2 = screen.getByText(/task2/i);
21+
expect(task1).toBeInTheDocument();
22+
expect(task2).toBeInTheDocument();
23+
});
24+
25+
it('should not render the modal by default', async () => {
26+
const descriptionElements = screen.queryAllByText(
27+
/A task is anything which is scheduled to be run/i
28+
);
29+
expect(descriptionElements.length).toBe(0);
30+
});
31+
32+
it('should render the modal after icon click', async () => {
33+
const modalButton = screen.getByRole('button');
34+
await modalButton.click();
35+
const descriptionElement = screen.getByText(
36+
/A task is anything which is scheduled to be run/i
37+
);
38+
expect(descriptionElement).toBeInTheDocument();
39+
});
40+
});

components/infoContainer.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ export function InfoContainer({
2929
<div className="flex items-center justify-between gap-2">
3030
<h3>{title}</h3>
3131
<Modal title={title} description={description}>
32-
<Button variant="ghost" size="iconSmall">
32+
<Button
33+
variant="ghost"
34+
size="iconSmall"
35+
data-testid="info-container-button"
36+
>
3337
<Info className="size-5" />
3438
</Button>
3539
</Modal>

0 commit comments

Comments
 (0)