-
Notifications
You must be signed in to change notification settings - Fork 345
Expand file tree
/
Copy pathContent.test.tsx
More file actions
153 lines (134 loc) · 5.75 KB
/
Content.test.tsx
File metadata and controls
153 lines (134 loc) · 5.75 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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
import * as React from 'react';
import { render, screen } from '../../../test-utils/testing-library';
import Content, { ContentProps } from '../Content';
import {
VIEW_ERROR,
VIEW_METADATA,
VIEW_MODE_LIST,
VIEW_MODE_GRID,
VIEW_FOLDER,
VIEW_RECENTS,
} from '../../../constants';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import { Collection } from '../../common/types/core';
const mockProps: ContentProps = {
canDelete: true,
canDownload: true,
canPreview: true,
canRename: true,
canShare: true,
currentCollection: { items: [], percentLoaded: 100 } as Collection,
isMedium: false,
isSmall: false,
isTouch: false,
onItemClick: jest.fn(),
onItemDelete: jest.fn(),
onItemDownload: jest.fn(),
onItemPreview: jest.fn(),
onItemRename: jest.fn(),
onItemSelect: jest.fn(),
onItemShare: jest.fn(),
onMetadataFilter: jest.fn(),
onMetadataUpdate: jest.fn(),
onSortChange: jest.fn(),
portalElement: null,
view: VIEW_RECENTS,
viewMode: VIEW_MODE_LIST,
};
jest.mock('../MetadataViewContainer', () => ({
__esModule: true,
default: () => <div>MetadataViewContainer</div>,
}));
describe('Content Component', () => {
const renderComponent = (props: Partial<ContentProps> = {}) => {
return render(<Content {...mockProps} {...props} />);
};
test('renders ProgressBar when view is not VIEW_ERROR or VIEW_SELECTED', () => {
renderComponent({ view: VIEW_FOLDER });
expect(screen.getByRole('progressbar')).toBeInTheDocument();
});
test('renders error message in empty view when there is an error', () => {
renderComponent({ view: VIEW_ERROR });
expect(screen.getByText('A network error has occurred while trying to load.')).toBeInTheDocument();
});
test('renders MetadataBasedItemList when view is VIEW_METADATA', () => {
const collection = { boxItem: {}, id: '0', items: [{ id: 1 }], name: 'name' };
renderComponent({ view: VIEW_METADATA, fieldsToShow: ['id'], currentCollection: collection });
expect(screen.getByTestId('metadata-based-item-list')).toBeInTheDocument();
});
test('renders ItemList when viewMode is VIEW_MODE_LIST', () => {
const collection = {
boxItem: {},
id: '0',
items: [{ id: 1, name: 'Item 1', size: 1000, modified_at: '2023-10-10T10:00:00Z', type: 'file' }],
name: 'name',
percentLoaded: 100,
};
renderComponent({ viewMode: VIEW_MODE_LIST, currentCollection: collection });
expect(screen.getByText('Item 1')).toBeInTheDocument();
expect(screen.getByText('1000 Bytes')).toBeInTheDocument();
expect(screen.getByText('Viewed Oct 10, 2023')).toBeInTheDocument();
expect(screen.getByLabelText('File')).toBeInTheDocument();
});
test('renders ItemGrid when viewMode is VIEW_MODE_GRID', () => {
const item1 = { id: 1, name: 'Item 1', size: 1000, modified_at: '2023-10-10T10:00:00Z', type: 'file' };
const collection = { boxItem: {}, id: '0', items: [item1], name: 'name', percentLoaded: 100 };
render(<Content {...mockProps} viewMode={VIEW_MODE_GRID} currentCollection={collection} />);
expect(screen.getByText('Item 1')).toBeInTheDocument();
expect(screen.getByText('Viewed Oct 10, 2023')).toBeInTheDocument();
expect(screen.getByLabelText('File')).toBeInTheDocument();
});
describe('MetadataView V2 feature', () => {
const features = {
contentExplorer: { metadataViewV2: true },
};
const collection = {
percentLoaded: 100,
boxItem: {},
id: '0',
items: [{ id: 1 }],
name: 'name',
};
test('does not render MetadataBasedItemList when contentExplorer.metadataViewV2 is enabled', () => {
renderComponent({
currentCollection: collection,
features,
fieldsToShow: ['id'],
view: VIEW_METADATA,
});
expect(screen.queryByTestId('metadata-based-item-list')).not.toBeInTheDocument();
});
test('renders new metadata view when contentExplorer.metadataViewV2 is enabled', () => {
renderComponent({
currentCollection: collection,
features,
fieldsToShow: ['id'],
view: VIEW_METADATA,
});
expect(screen.getByText('MetadataViewContainer')).toBeInTheDocument();
});
describe('EmptyView rendering for VIEW_ERROR with metadataViewV2 feature', () => {
test('renders EmptyView with isLoading=false when metadataViewV2 feature is enabled and view is VIEW_ERROR', () => {
// This test verifies that the EmptyView receives isLoading={false}
// We can verify this by checking that the loading message is not shown
renderComponent({
features,
view: VIEW_ERROR,
});
// Should show error message, not loading message
expect(screen.getByText('A network error has occurred while trying to load.')).toBeInTheDocument();
expect(screen.queryByText('Please wait while the items load...')).not.toBeInTheDocument();
});
test('does not render EmptyView when metadataViewV2 feature is enabled but view is not VIEW_ERROR', () => {
renderComponent({
features,
view: VIEW_FOLDER,
});
expect(
screen.queryByText('A network error has occurred while trying to load.'),
).not.toBeInTheDocument();
});
});
});
});