Newer
Older
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
103
104
105
106
107
import { FIRST_ARRAY_ELEMENT, SECOND_ARRAY_ELEMENT, THIRD_ARRAY_ELEMENT } from '@/constants/common';
import { bioEntityResponseFixture } from '@/models/fixtures/bioEntityContentsFixture';
import { apiPath } from '@/redux/apiPath';
import { INITIAL_STORE_STATE_MOCK } from '@/redux/root/root.fixtures';
import { AppDispatch, RootState } from '@/redux/store';
import { BioEntityContent, TargetElement } from '@/types/models';
import { mockNetworkNewAPIResponse } from '@/utils/mockNetworkResponse';
import {
InitialStoreState,
getReduxStoreWithActionsListener,
} from '@/utils/testing/getReduxStoreActionsListener';
import { render, screen, waitFor } from '@testing-library/react';
import { HttpStatusCode } from 'axios';
import { MockStoreEnhanced } from 'redux-mock-store';
import { ElementsOnMapCell } from './ElementsOnMapCell.component';
interface Props {
targets: TargetElement[];
}
const renderComponent = (
props: Props,
initialStoreState: InitialStoreState = {},
): { store: MockStoreEnhanced<Partial<RootState>, AppDispatch> } => {
const { Wrapper, store } = getReduxStoreWithActionsListener(initialStoreState);
return (
render(
<Wrapper>
<ElementsOnMapCell targets={props.targets} />
</Wrapper>,
),
{
store,
}
);
};
const mockedAxiosNewClient = mockNetworkNewAPIResponse();
const mockTargets = [
{ id: 1, modelId: 2, type: 'target-1' },
{ id: 2, modelId: 3, type: 'target-2' },
{ id: 3, modelId: 4, type: 'target-3' },
];
const getBioEntityContent = (elementId: string): BioEntityContent[] => [
{
...bioEntityResponseFixture.content[FIRST_ARRAY_ELEMENT],
bioEntity: {
...bioEntityResponseFixture.content[FIRST_ARRAY_ELEMENT].bioEntity,
elementId,
},
},
];
describe('ElementsOnMapCell - component', () => {
mockedAxiosNewClient
.onGet(
apiPath.getBioEntityContentsStringWithQuery({
searchQuery: mockTargets[FIRST_ARRAY_ELEMENT].id.toString(),
isPerfectMatch: true,
}),
)
.reply(HttpStatusCode.Ok, {
...bioEntityResponseFixture,
content: getBioEntityContent(mockTargets[FIRST_ARRAY_ELEMENT].type),
});
mockedAxiosNewClient
.onGet(
apiPath.getBioEntityContentsStringWithQuery({
searchQuery: mockTargets[SECOND_ARRAY_ELEMENT].id.toString(),
isPerfectMatch: true,
}),
)
.reply(HttpStatusCode.Ok, {
...bioEntityResponseFixture,
content: getBioEntityContent(mockTargets[SECOND_ARRAY_ELEMENT].type),
});
mockedAxiosNewClient
.onGet(
apiPath.getBioEntityContentsStringWithQuery({
searchQuery: mockTargets[THIRD_ARRAY_ELEMENT].id.toString(),
isPerfectMatch: true,
}),
)
.reply(HttpStatusCode.Ok, {
...bioEntityResponseFixture,
content: getBioEntityContent(mockTargets[THIRD_ARRAY_ELEMENT].type),
});
test.each(mockTargets)('should render correctly', async ({ type }) => {
renderComponent(
{
targets: mockTargets,
},
INITIAL_STORE_STATE_MOCK,
);
await waitFor(() => {
// type as elementId
expect(screen.getByText(type)).toBeInTheDocument();
});
});
});