-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSearchResultEntry.test.tsx
More file actions
102 lines (82 loc) · 3.19 KB
/
SearchResultEntry.test.tsx
File metadata and controls
102 lines (82 loc) · 3.19 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import { fireEvent, render, screen } from '@testing-library/react';
import { BrowserRouter } from 'react-router-dom';
import { setInitialGlobalState } from '@src/test/__mocks__/store';
import { useSearchStore, useUIStore } from '@src/store';
import { SearchResultEntry } from '@components/SearchResultEntry';
import { itemSearchMockData } from './ItemSearch.test';
jest.mock('@common/constants/build.constants', () => ({ IS_EMBEDDED_MODE: false }));
const mockedUsedNavigate = jest.fn();
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useNavigate: () => mockedUsedNavigate,
}));
const mockProps = itemSearchMockData.content[0];
describe('SearchResultEntry', () => {
describe('with instances', () => {
beforeEach(() =>
render(
<BrowserRouter>
<SearchResultEntry {...(mockProps as unknown as WorkAsSearchResultDTO)} />
</BrowserRouter>,
),
);
const { getByText, getByTestId, findByText } = screen;
test('renders instances as a table', () => {
const expectedTitle = [mockProps.instances[0].titles[0].value, mockProps.instances[0].titles[1].value].join(' ');
expect(getByText(expectedTitle)).toBeInTheDocument();
});
test('renders works as a table', () => {
const expectedTitle = [mockProps.titles[0].value, mockProps.titles[1].value].join(' ');
expect(getByText(expectedTitle)).toBeInTheDocument();
});
test('closes and renders closed card placeholder', async () => {
fireEvent.click(getByTestId('work-details-card-toggle'));
expect(await findByText('ld.instances')).toBeInTheDocument();
});
test('navigates to edit section for the relevant ID', () => {
fireEvent.click(getByTestId('edit-button__instanceId'));
expect(mockedUsedNavigate).toHaveBeenCalledWith('/resources/instanceId/edit', { state: {} });
});
});
describe('without instances', () => {
beforeEach(() =>
render(
<BrowserRouter>
<SearchResultEntry {...({ ...mockProps, instances: [] } as unknown as WorkAsSearchResultDTO)} />
</BrowserRouter>,
),
);
const { getByText } = screen;
test('shows placeholder when there are no instances', () => {
expect(getByText('ld.noInstancesAvailable')).toBeInTheDocument();
});
});
describe('component unmount', () => {
test('clears fullDisplayComponentType and selectedInstances on unmount', () => {
const mockResetFullDisplayComponentType = jest.fn();
const mockResetSelectedInstances = jest.fn();
setInitialGlobalState([
{
store: useUIStore,
state: {
resetFullDisplayComponentType: mockResetFullDisplayComponentType,
},
},
{
store: useSearchStore,
state: {
resetSelectedInstances: mockResetSelectedInstances,
},
},
]);
const { unmount } = render(
<BrowserRouter>
<SearchResultEntry {...(mockProps as unknown as WorkAsSearchResultDTO)} />
</BrowserRouter>,
);
unmount();
expect(mockResetFullDisplayComponentType).toHaveBeenCalled();
expect(mockResetSelectedInstances).toHaveBeenCalled();
});
});
});