|
| 1 | +import * as React from 'react'; |
| 2 | +import { render, screen } from '@testing-library/react'; |
| 3 | +import { StudentComponent } from './student.component'; |
| 4 | + |
| 5 | +describe('StudentComponent tests', () => { |
| 6 | + it('It should show the session name and the text when passing valid parameters', () => { |
| 7 | + // Arrange |
| 8 | + const props = { |
| 9 | + room: 'Room I', |
| 10 | + log: 'This is test', |
| 11 | + }; |
| 12 | + |
| 13 | + const expectedSessionNameText = `Session name: ${props.room}`; |
| 14 | + |
| 15 | + // Act |
| 16 | + render(<StudentComponent {...props} />); |
| 17 | + |
| 18 | + // Assert |
| 19 | + const sessionName = screen.getByRole('heading'); |
| 20 | + const textArea = screen.getByRole('textbox'); |
| 21 | + |
| 22 | + expect(sessionName).toHaveTextContent(expectedSessionNameText); |
| 23 | + expect(textArea).toHaveValue(props.log); |
| 24 | + }); |
| 25 | + |
| 26 | + it('It should show an empty session name when passing an undefined room value', () => { |
| 27 | + // Arrange |
| 28 | + const props = { |
| 29 | + room: undefined, |
| 30 | + log: 'This is test', |
| 31 | + }; |
| 32 | + |
| 33 | + const expectedSessionNameText = `Session name:`; |
| 34 | + |
| 35 | + // Act |
| 36 | + render(<StudentComponent {...props} />); |
| 37 | + |
| 38 | + // Assert |
| 39 | + const sessionName = screen.getByRole('heading'); |
| 40 | + expect(sessionName).toHaveTextContent(expectedSessionNameText); |
| 41 | + }); |
| 42 | + |
| 43 | + it('It should show an empty session name when passing a null room value', () => { |
| 44 | + // Arrange |
| 45 | + const props = { |
| 46 | + room: null, |
| 47 | + log: 'This is test', |
| 48 | + }; |
| 49 | + |
| 50 | + const expectedSessionNameText = `Session name:`; |
| 51 | + |
| 52 | + // Act |
| 53 | + render(<StudentComponent {...props} />); |
| 54 | + |
| 55 | + // Assert |
| 56 | + const sessionName = screen.getByRole('heading'); |
| 57 | + |
| 58 | + expect(sessionName).toHaveTextContent(expectedSessionNameText); |
| 59 | + }); |
| 60 | + |
| 61 | + it('It should show an empty text when passing an undefined log value', () => { |
| 62 | + // Arrange |
| 63 | + const props = { |
| 64 | + room: 'Room I', |
| 65 | + log: undefined, |
| 66 | + }; |
| 67 | + |
| 68 | + // Act |
| 69 | + render(<StudentComponent {...props} />); |
| 70 | + |
| 71 | + // Assert |
| 72 | + const textArea = screen.getByRole('textbox'); |
| 73 | + expect(textArea).toHaveTextContent(''); |
| 74 | + }); |
| 75 | + |
| 76 | + it('It should show an empty text when passing a null log value', () => { |
| 77 | + // Arrange |
| 78 | + const props = { |
| 79 | + room: 'Room I', |
| 80 | + log: null, |
| 81 | + }; |
| 82 | + |
| 83 | + // Act |
| 84 | + render(<StudentComponent {...props} />); |
| 85 | + |
| 86 | + // Assert |
| 87 | + const textArea = screen.getByRole('textbox'); |
| 88 | + expect(textArea).toHaveTextContent(''); |
| 89 | + }); |
| 90 | +}); |
0 commit comments