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
import { BASE_MAP_IMAGES_URL } from '@/constants';
import { DEFAULT_OVERVIEW_IMAGE_SIZE } from '@/constants/project';
import { projectFixture } from '@/models/fixtures/projectFixture';
import { MODAL_INITIAL_STATE_MOCK } from '@/redux/modal/modal.mock';
import { PROJECT_OVERVIEW_IMAGE_MOCK } from '@/redux/project/project.mock';
import { getReduxWrapperWithStore } from '@/utils/testing/getReduxWrapperWithStore';
import { renderHook } from '@testing-library/react';
import { useOverviewImage } from './useOverviewImage';
describe('useOverviewImage - hook', () => {
describe('when image data is invalid', () => {
const { Wrapper } = getReduxWrapperWithStore({
project: {
data: {
...projectFixture,
overviewImageViews: [],
topOverviewImage: PROJECT_OVERVIEW_IMAGE_MOCK,
},
loading: 'succeeded',
error: { message: '', name: '' },
},
modal: {
...MODAL_INITIAL_STATE_MOCK,
overviewImagesState: {
imageId: 0,
},
},
});
const { result } = renderHook(() => useOverviewImage({ containerRect: undefined }), {
wrapper: Wrapper,
});
it('should return default size of image and empty imageUrl', () => {
expect(result.current).toStrictEqual({
imageUrl: '',
size: DEFAULT_OVERVIEW_IMAGE_SIZE,
});
});
});
describe('when containerReact is undefined', () => {
const { Wrapper } = getReduxWrapperWithStore({
project: {
data: {
...projectFixture,
overviewImageViews: [PROJECT_OVERVIEW_IMAGE_MOCK],
topOverviewImage: PROJECT_OVERVIEW_IMAGE_MOCK,
},
loading: 'succeeded',
error: { message: '', name: '' },
},
modal: {
...MODAL_INITIAL_STATE_MOCK,
overviewImagesState: {
imageId: PROJECT_OVERVIEW_IMAGE_MOCK.idObject,
},
},
});
const { result } = renderHook(() => useOverviewImage({ containerRect: undefined }), {
wrapper: Wrapper,
});
it('should return default size of image and valid imageUrl', () => {
const imageUrl = `${BASE_MAP_IMAGES_URL}/map_images/${PROJECT_OVERVIEW_IMAGE_MOCK.filename}`;
expect(result.current).toMatchObject({
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
imageUrl,
size: DEFAULT_OVERVIEW_IMAGE_SIZE,
});
});
});
describe('when containerReact is valid', () => {
const { Wrapper } = getReduxWrapperWithStore({
project: {
data: {
...projectFixture,
overviewImageViews: [
{
...PROJECT_OVERVIEW_IMAGE_MOCK,
height: 500,
width: 500,
},
],
topOverviewImage: PROJECT_OVERVIEW_IMAGE_MOCK,
},
loading: 'succeeded',
error: { message: '', name: '' },
},
modal: {
...MODAL_INITIAL_STATE_MOCK,
overviewImagesState: {
imageId: PROJECT_OVERVIEW_IMAGE_MOCK.idObject,
},
},
});
const { result } = renderHook(
() => useOverviewImage({ containerRect: { width: 100, height: 200 } as DOMRect }),
{
wrapper: Wrapper,
},
);
it('should return size of image and valid imageUrl', () => {
const imageUrl = `${BASE_MAP_IMAGES_URL}/map_images/${PROJECT_OVERVIEW_IMAGE_MOCK.filename}`;
expect(result.current).toMatchObject({
imageUrl,
size: { height: 100, width: 100, sizeFactor: 0.2 },
});
});
});
});