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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/* eslint-disable react/no-children-prop */
import { FIRST_ARRAY_ELEMENT, SECOND_ARRAY_ELEMENT, THIRD_ARRAY_ELEMENT } from '@/constants/common';
import { DEFAULT_ERROR } from '@/constants/errors';
import { bioEntityContentFixture } from '@/models/fixtures/bioEntityContentsFixture';
import { MODELS_MOCK } from '@/models/mocks/modelsMock';
import { PUBLICATIONS_DEFAULT_SEARCH_FIRST_10_MOCK } from '@/models/mocks/publicationsResponseMock';
import { apiPath } from '@/redux/apiPath';
import { downloadFileFromBlob } from '@/redux/export/export.utils';
import { StoreType } from '@/redux/store';
import { BioEntityContent, Publication } from '@/types/models';
import { mockNetworkResponse } from '@/utils/mockNetworkResponse';
import {
InitialStoreState,
getReduxWrapperWithStore,
} from '@/utils/testing/getReduxWrapperWithStore';
import { render, screen, waitFor } from '@testing-library/react';
import { HttpStatusCode } from 'axios';
import { fetchElementData } from '../utils/fetchElementData';
import { PublicationsModalLayout } from './PublicationsModalLayout.component';
const FIRST_MODEL_ID = MODELS_MOCK[FIRST_ARRAY_ELEMENT].idObject;
const SECOND_MODEL_ID = MODELS_MOCK[SECOND_ARRAY_ELEMENT].idObject;
const THIRD_MODEL_ID = MODELS_MOCK[THIRD_ARRAY_ELEMENT].idObject;
const FIRST_ELEMENT_ID = 100;
const SECOND_ELEMENT_ID = 200;
const THIRD_ELEMENT_ID = 300;
const FOURTH_ELEMENT_ID = 400;
const BASE_PUBLICATION: Publication =
PUBLICATIONS_DEFAULT_SEARCH_FIRST_10_MOCK.data[FIRST_ARRAY_ELEMENT];
const BASE_ELEMENT = BASE_PUBLICATION.elements[FIRST_ARRAY_ELEMENT];
const PUBLICATION: Publication = {
...BASE_PUBLICATION,
elements: [
{
...BASE_ELEMENT,
id: FIRST_ELEMENT_ID,
modelId: FIRST_MODEL_ID,
},
{
...BASE_ELEMENT,
id: SECOND_ELEMENT_ID,
modelId: SECOND_MODEL_ID,
},
{
...BASE_ELEMENT,
id: THIRD_ELEMENT_ID,
modelId: THIRD_MODEL_ID, // model id duplicate
},
{
...BASE_ELEMENT,
id: FOURTH_ELEMENT_ID,
modelId: THIRD_MODEL_ID, // model id duplicate
},
],
};
const BIO_ENTITY_CONTENT = (id: number, elementId: string): BioEntityContent => ({
...bioEntityContentFixture,
bioEntity: {
...bioEntityContentFixture.bioEntity,
id,
elementId,
},
});
jest.mock('../../../../../redux/export/export.utils');
jest.mock('../utils/fetchElementData');
(fetchElementData as jest.Mock).mockImplementation(
(id: string): BioEntityContent =>
({
[`${FIRST_ELEMENT_ID}`]: BIO_ENTITY_CONTENT(FIRST_ELEMENT_ID, 'mi100'),
[`${SECOND_ELEMENT_ID}`]: BIO_ENTITY_CONTENT(SECOND_ELEMENT_ID, 'ne200'),
[`${THIRD_ELEMENT_ID}`]: BIO_ENTITY_CONTENT(THIRD_ELEMENT_ID, 'r300'),
[`${FOURTH_ELEMENT_ID}`]: BIO_ENTITY_CONTENT(FOURTH_ELEMENT_ID, 'va400'),
})[id] as BioEntityContent,
);
const mockedAxiosClient = mockNetworkResponse();
const renderComponent = (initialStore?: InitialStoreState): { store: StoreType } => {
const { Wrapper, store } = getReduxWrapperWithStore(initialStore);
return (
render(
<Wrapper>
<PublicationsModalLayout children={null} />
</Wrapper>,
),
{
store,
}
);
};
describe('PublicationsModalLayout - component', () => {
const length = 1;
mockedAxiosClient
.onGet(apiPath.getPublications({ params: { length } }))
.reply(HttpStatusCode.Ok, {
...PUBLICATIONS_DEFAULT_SEARCH_FIRST_10_MOCK,
data: [PUBLICATION],
});
it('should render download csv button', () => {
renderComponent();
expect(screen.getByTestId('download-csv-button')).toBeInTheDocument();
});
it('should run download file with valid content when download csv clicked', async () => {
renderComponent({
publications: {
data: {
...PUBLICATIONS_DEFAULT_SEARCH_FIRST_10_MOCK,
data: [PUBLICATION],
filteredSize: length,
},
loading: 'succeeded',
error: DEFAULT_ERROR,
sortColumn: '',
sortOrder: 'asc',
searchValue: '',
selectedModelId: undefined,
},
models: { data: MODELS_MOCK, loading: 'idle', error: DEFAULT_ERROR },
});
const downloadButton = screen.getByTestId('download-csv-button');
downloadButton.click();
await waitFor(() => {
expect(downloadFileFromBlob).toHaveBeenCalledWith(
'"10049997","The glutamate receptor ion channels.","Dingledine R, Borges K, Bowie D, Traynelis SF.","Pharmacological reviews","1999","mi100,ne200,r300,va400","Core PD map,Histamine signaling,PRKN substrates"',
'publications.csv',
);
});
});
});