-
Notifications
You must be signed in to change notification settings - Fork 0
/
EditableCard.test.tsx
61 lines (52 loc) · 2.51 KB
/
EditableCard.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
import '@testing-library/jest-dom/extend-expect';
import { describe, it } from 'vitest';
import { fireEvent, render } from '@testing-library/react';
import EditableCard from '.';
import KanbanListProvider from '../../Hooks/useList/Provider';
import columns from '../../data/columns';
import KanbanColumnProvider from '../../Hooks/useColumn/Provider';
import KanbanProvider from '../../Hooks/useKanban/Provider';
describe('EditableCard.tsx test', () => {
const mockedColumn = columns[0];
const mockedList = mockedColumn.lists[0];
const mockedCard = mockedList.cards[0];
const ContainerTest = () => (
<KanbanProvider>
<KanbanColumnProvider initialColumn={mockedColumn}>
<KanbanListProvider initialList={mockedList}>
<EditableCard card={mockedCard} />
</KanbanListProvider>
</KanbanColumnProvider>
</KanbanProvider>
);
it('Should finished tag not to be in component', () => {
const { getByText } = render(<ContainerTest />);
expect(getByText('Finished')).toBeInTheDocument();
});
it('Should it added finished when click in tag', () => {
const { getByTestId, getByText } = render(<ContainerTest />);
fireEvent.click(getByTestId(`tag-${mockedCard.id}`));
expect(() => getByText('Finished')).toThrow();
});
it('Should be possible edit the task', () => {
const { getByTestId, getByText } = render(<ContainerTest />);
fireEvent.focus(getByTestId(`editable-${mockedCard.id}`));
fireEvent.change(getByTestId(`input-${mockedCard.id}`), { target: { value: 'editingTask' } });
fireEvent.blur(getByTestId(`input-${mockedCard.id}`));
expect(getByText('editingTask')).toBeInTheDocument();
});
it('Should it set the task to (Edit task) when the entry is empty and the enter key is pressed', () => {
const { getByTestId, getByText } = render(<ContainerTest />);
fireEvent.click(getByTestId(`edit-icon-${mockedCard.id}`));
fireEvent.change(getByTestId(`input-${mockedCard.id}`), { target: { value: '' } });
fireEvent.click(getByTestId(`check-edit-icon-${mockedCard.id}`));
expect(getByText('Edit task')).toBeInTheDocument();
});
it('Should not be edited the card when click on (x) button', () => {
const { getByTestId, getByText } = render(<ContainerTest />);
fireEvent.click(getByTestId(`edit-icon-${mockedCard.id}`));
fireEvent.change(getByTestId(`input-${mockedCard.id}`), { target: { value: 'Click' } });
fireEvent.click(getByTestId(`close-edit-icon-${mockedCard.id}`));
expect(() => getByText('Click')).toThrow();
});
});