|
1 | 1 | import React from 'react';
|
2 |
| -import { render, screen } from '@testing-library/react'; |
| 2 | +import { render, screen, fireEvent } from '@testing-library/react'; |
3 | 3 | import user from '@testing-library/user-event';
|
4 | 4 | import '@testing-library/jest-dom/extend-expect'; // needed this to extend the jest-dom assertions (ex toHaveTextContent)
|
5 | 5 | import Action from '../components/Action';
|
| 6 | +import { changeView, changeSlider } from '../actions/actions'; |
6 | 7 |
|
7 | 8 | // @ts-ignore
|
8 | 9 | Action.cleanTime = jest.fn().mockReturnValue();
|
@@ -58,5 +59,42 @@ describe('unit testing for Action.tsx', () => {
|
58 | 59 | render(<Action {...props} />);
|
59 | 60 | expect(screen.getAllByRole('button')[0]).toHaveTextContent('NO TIME');
|
60 | 61 | });
|
| 62 | + |
| 63 | + test('When actualDuration exceeds 60, time should be formatted correctly', () => { |
| 64 | + props.componentData.actualDuration = 75; |
| 65 | + render(<Action {...props} />); |
| 66 | + expect(screen.getAllByRole('button')[0]).toHaveTextContent('+01:15.00'); |
| 67 | + }); |
| 68 | + |
| 69 | + test('Using the ArrowUp key on Action snapshot should trigger handleOnKeyDown', () => { |
| 70 | + render(<Action {...props} />); |
| 71 | + fireEvent.keyDown(screen.getByRole('presentation'), {key: 'ArrowUp', code: 'ArrowUp', charCode: 38}); |
| 72 | + expect(props.handleOnkeyDown).toHaveBeenCalled(); |
| 73 | + }); |
| 74 | + |
| 75 | + test('Using the ArrowDown key on Action snapshot should trigger handleOnKeyDown', () => { |
| 76 | + render(<Action {...props} />); |
| 77 | + fireEvent.keyDown(screen.getByRole('presentation'), {key: 'ArrowDown', code: 'ArrowDown', charCode: 40}); |
| 78 | + expect(props.handleOnkeyDown).toHaveBeenCalled(); |
| 79 | + }); |
| 80 | + |
| 81 | + test('Using the Enter key on Action snapshot should trigger handleOnKeyDown', () => { |
| 82 | + render(<Action {...props} />); |
| 83 | + fireEvent.keyDown(screen.getByRole('presentation'), {key: 'Enter', code: 'Enter', charCode: 13}); |
| 84 | + expect(props.handleOnkeyDown).toHaveBeenCalled(); |
| 85 | + }); |
| 86 | + |
| 87 | + test('Clicking the snapshot should trigger onClick', () => { |
| 88 | + render(<Action {...props} />); |
| 89 | + fireEvent.click(screen.getByRole('presentation')); |
| 90 | + expect(props.dispatch).toHaveBeenCalledWith(changeView(2));; |
| 91 | + }); |
| 92 | + |
| 93 | + test('Clicking Jump button should trigger changeSlider and changeView', () => { |
| 94 | + render(<Action {...props} />); |
| 95 | + fireEvent.click(screen.getAllByRole('button')[1]); |
| 96 | + expect(props.dispatch).toHaveBeenCalledWith(changeSlider(2)); |
| 97 | + expect(props.dispatch).toHaveBeenCalledWith(changeView(2)); |
| 98 | + }); |
61 | 99 | });
|
62 | 100 | });
|
0 commit comments