Skip to content

Commit c9e2311

Browse files
committed
Create test for handleOnKeyDown functionality
1 parent 415ca22 commit c9e2311

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/app/__tests__/action.test.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { render, screen } from '@testing-library/react';
2+
import { render, screen, fireEvent } from '@testing-library/react';
33
import user from '@testing-library/user-event';
44
import '@testing-library/jest-dom/extend-expect'; // needed this to extend the jest-dom assertions (ex toHaveTextContent)
55
import Action from '../components/Action';
@@ -58,13 +58,17 @@ describe('unit testing for Action.tsx', () => {
5858
render(<Action {...props} />);
5959
expect(screen.getAllByRole('button')[0]).toHaveTextContent('NO TIME');
6060
});
61-
});
6261

63-
describe('When actualDuration exceeds 60', () => {
64-
test('Time should be formatted correctly', () => {
62+
test('When actualDuration exceeds 60, time should be formatted correctly', () => {
6563
props.componentData.actualDuration = 75;
6664
render(<Action {...props} />);
6765
expect(screen.getAllByRole('button')[0]).toHaveTextContent('+01:15.00');
6866
});
67+
68+
test('Using the ArrowUp key on Action snapshot should trigger handleOnKeyDown', () => {
69+
render(<Action {...props} />);
70+
fireEvent.keyDown(screen.getByRole('presentation'), {key: 'ArrowUp', code: 'ArrowUp', charCode: 38});
71+
expect(props.handleOnkeyDown).toHaveBeenCalled();;
72+
});
6973
});
7074
});

0 commit comments

Comments
 (0)