Skip to content

Commit abfa9ee

Browse files
committed
Action.test.tsx
1 parent c4f7286 commit abfa9ee

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

src/app/__tests__jn/Action.test.tsx

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import React from 'react'
2+
import {render, screen, fireEvent} from '@testing-library/react'
3+
import user from '@testing-library/user-event'
4+
import '@testing-library/jest-dom/extend-expect' // needed this to extend the jest-dom assertions (ex toHaveTextContent)
5+
import Action from '../components/Action'
6+
7+
8+
// @ts-ignore
9+
Action.cleanTime = jest.fn().mockReturnValue();
10+
11+
describe('unit testing for Action.tsx', () => {
12+
const props = {
13+
key: 'actions2',
14+
selected: true,
15+
last: false,
16+
index: 2,
17+
sliderIndex: 2,
18+
isCurrIndex: false,
19+
routePath:"",
20+
dispatch: jest.fn(),
21+
displayName: '3.0',
22+
componentName: 'App',
23+
logChangedState: jest.fn(),
24+
componentData: {
25+
actualDuration: 3.5,
26+
},
27+
state: { test: 'test' },
28+
viewIndex: 2,
29+
handleOnkeyDown: jest.fn(),
30+
};
31+
32+
beforeEach(() => {
33+
props.isCurrIndex = false
34+
props.componentData = {actualDuration: 3.5}
35+
props.dispatch.mockClear();
36+
});
37+
38+
39+
describe('When a component is shown on the page', () => {
40+
test("Action snapshot should be shown as Snapshot: 3.0", () => {
41+
render(<Action {...props} />);
42+
expect(screen.getByPlaceholderText('Snapshot: 3.0')).toBeInTheDocument()
43+
});
44+
45+
test("two buttons time and Jump when at current snapshot", () => {
46+
render(<Action {...props} />);
47+
expect(screen.getAllByRole('button')).toHaveLength(2)
48+
expect(screen.getAllByRole('button')[0]).toHaveTextContent('+00:03.50')
49+
expect(screen.getAllByRole('button')[1]).toHaveTextContent('Jump')
50+
});
51+
52+
test("two buttons with time and Current when not at current snapshot", () => {
53+
props.isCurrIndex = true
54+
render(<Action {...props} />);
55+
expect(screen.getAllByRole('button')).toHaveLength(2)
56+
expect(screen.getAllByRole('button')[0]).toHaveTextContent('+00:03.50')
57+
expect(screen.getAllByRole('button')[1]).toHaveTextContent('Current')
58+
});
59+
60+
test("when there's no have no duration data", () => {
61+
props.componentData = undefined
62+
render(<Action {...props} />);
63+
expect(screen.getAllByRole('button')[0]).toHaveTextContent('NO TIME')
64+
});
65+
66+
});
67+
68+
});

0 commit comments

Comments
 (0)