Skip to content

Commit b86ce47

Browse files
committed
Added missing tests
1 parent 06950b2 commit b86ce47

2 files changed

Lines changed: 53 additions & 1 deletion

File tree

‎front/src/pods/trainer/components/new-text.component.spec.tsx‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React from 'react';
2-
import { fireEvent, render, screen } from '@testing-library/react';
2+
import { render, screen } from '@testing-library/react';
33
import userEvent from '@testing-library/user-event';
44
import { NewTextComponent } from './new-text.component';
5+
import { act } from 'react-dom/test-utils';
56

67
describe('NewTextComponent unit tests', () => {
78
it('should handle the entered text when clicking on the send button', () => {
@@ -23,6 +24,23 @@ describe('NewTextComponent unit tests', () => {
2324
expect(handleAppendTrainerText).toHaveBeenCalledTimes(1);
2425
});
2526

27+
it('should handle the entered text when pressing ctrl + enter', async () => {
28+
// Arrange
29+
const handleAppendTrainerText = jest.fn();
30+
31+
// Act
32+
render(
33+
<NewTextComponent handleAppendTrainerText={handleAppendTrainerText} />
34+
);
35+
36+
const inputText = screen.getByRole('textbox');
37+
38+
await act(async () => userEvent.type(inputText, 'Test text{ctrl}{enter}{/ctrl}'));
39+
40+
// Assert
41+
expect(handleAppendTrainerText).toHaveBeenCalledTimes(1);
42+
});
43+
2644
it('should not handle any text when there is not entered text and clicking on the send button', () => {
2745
// Arrange
2846
const handleAppendTrainerText = jest.fn();
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React from 'react';
2+
import {render, screen } from '@testing-library/react';
3+
import { TrainerComponent } from './trainer.component';
4+
5+
describe('TrainerComponent tests', () => {
6+
it('should render all the expected sub components', () => {
7+
// Arrange
8+
const props = {
9+
handleAppendTrainerText: (trainerText: string) => {},
10+
handleSendFullContentLog: (fullContent: string) => {},
11+
currentTrainerUrl: 'http://current.trainer.url',
12+
currentStudentUrl: 'http://current.student.url',
13+
log: 'This is the log',
14+
};
15+
16+
// Act
17+
render(<TrainerComponent {...props} />);
18+
19+
const trainerLink = screen.getByRole('textbox', {name: 'Trainer Link'});
20+
const sendButton = screen.getByRole('button', {name: 'Send'});
21+
const sendFullContentButton = screen.getByRole('button', {name: 'Send Full Content'});
22+
23+
// Assert
24+
25+
// <HeaderComponent> rendered
26+
expect(trainerLink).toBeInTheDocument();
27+
28+
// <NewTextComponent> rendered
29+
expect(sendButton).toBeInTheDocument();
30+
31+
// <SessionComponent> rendered
32+
expect(sendFullContentButton).toBeInTheDocument();
33+
});
34+
});

0 commit comments

Comments
 (0)