-
Notifications
You must be signed in to change notification settings - Fork 14
/
App.test.tsx
72 lines (63 loc) · 1.67 KB
/
App.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import React from 'react';
import { render, screen, within } from '@testing-library/react';
import {
mockGetComputedStyle,
mockDndSpacing,
makeDnd,
DND_DIRECTION_UP,
DND_DIRECTION_DOWN,
DND_DRAGGABLE_DATA_ATTR
} from 'react-beautiful-dnd-test-utils';
import App from './App';
import initialData from './initial-data';
const verifyTaskOrderInColumn = (
columnTestId: string,
orderedTasks: string[]
): void => {
const texts = within(screen.getByTestId(columnTestId))
.getAllByTestId('task')
.map(x => x.textContent);
expect(texts).toEqual(orderedTasks);
};
const renderApp = (): void => {
const { container } = render(<App initialState={initialData} />);
mockDndSpacing(container);
};
describe('App', () => {
beforeEach(() => {
mockGetComputedStyle();
});
describe('dnd', () => {
test('moves a task up inside a column', async () => {
renderApp();
await makeDnd({
text: 'Cook dinner',
direction: DND_DIRECTION_UP,
positions: 1
});
verifyTaskOrderInColumn('to-do-column', [
'Take out the garbage',
'Watch my favorite show',
'Cook dinner',
'Charge my phone'
]);
});
test('moves a task down inside a column', async () => {
renderApp();
await makeDnd({
getDragElement: () =>
screen
.getByText('Take out the garbage')
.closest(DND_DRAGGABLE_DATA_ATTR),
direction: DND_DIRECTION_DOWN,
positions: 2
});
verifyTaskOrderInColumn('to-do-column', [
'Watch my favorite show',
'Charge my phone',
'Take out the garbage',
'Cook dinner'
]);
});
});
});