Skip to content

Commit 1a94a71

Browse files
authored
Merge pull request #19 from oslabs-beta/action-testing
Action testing
2 parents 129bae3 + 727765e commit 1a94a71

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

src/app/__tests__/action.test.tsx

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
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';
6+
import { changeView, changeSlider } from '../actions/actions';
67

78
// @ts-ignore
89
Action.cleanTime = jest.fn().mockReturnValue();
@@ -58,5 +59,42 @@ describe('unit testing for Action.tsx', () => {
5859
render(<Action {...props} />);
5960
expect(screen.getAllByRole('button')[0]).toHaveTextContent('NO TIME');
6061
});
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+
});
6199
});
62100
});

0 commit comments

Comments
 (0)