-
Notifications
You must be signed in to change notification settings - Fork 346
Expand file tree
/
Copy pathContentSharingV2.test.tsx
More file actions
132 lines (118 loc) · 4.86 KB
/
ContentSharingV2.test.tsx
File metadata and controls
132 lines (118 loc) · 4.86 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
import React from 'react';
import { render, RenderResult, screen, waitFor } from '@testing-library/react';
import {
DEFAULT_ITEM_API_RESPONSE,
DEFAULT_USER_API_RESPONSE,
MOCK_ITEM,
MOCK_ITEM_API_RESPONSE_WITH_SHARED_LINK,
MOCK_ITEM_API_RESPONSE_WITH_CLASSIFICATION,
} from '../utils/__mocks__/ContentSharingV2Mocks';
import { CONTENT_SHARING_ITEM_FIELDS } from '../constants';
import ContentSharingV2 from '../ContentSharingV2';
const createAPIMock = (fileAPI, folderAPI, usersAPI) => ({
getFileAPI: jest.fn().mockReturnValue(fileAPI),
getFolderAPI: jest.fn().mockReturnValue(folderAPI),
getUsersAPI: jest.fn().mockReturnValue(usersAPI),
});
const createSuccessMock = responseFromAPI => (id, successFn) => {
return Promise.resolve(responseFromAPI).then(response => {
successFn(response);
});
};
const getDefaultUserMock = jest.fn().mockImplementation(createSuccessMock(DEFAULT_USER_API_RESPONSE));
const getDefaultFileMock = jest.fn().mockImplementation(createSuccessMock(DEFAULT_ITEM_API_RESPONSE));
const getFileMockWithSharedLink = jest
.fn()
.mockImplementation(createSuccessMock(MOCK_ITEM_API_RESPONSE_WITH_SHARED_LINK));
const getFileMockWithClassification = jest
.fn()
.mockImplementation(createSuccessMock(MOCK_ITEM_API_RESPONSE_WITH_CLASSIFICATION));
const getDefaultFolderMock = jest.fn().mockImplementation(createSuccessMock(DEFAULT_ITEM_API_RESPONSE));
const defaultAPIMock = createAPIMock(
{ getFile: getDefaultFileMock },
{ getFolderFields: getDefaultFolderMock },
{ getUser: getDefaultUserMock },
);
const getWrapper = (props): RenderResult =>
render(
<ContentSharingV2
api={defaultAPIMock}
itemID={MOCK_ITEM.id}
itemType={MOCK_ITEM.type}
hasProviders={true}
{...props}
/>,
);
describe('elements/content-sharing/ContentSharingV2', () => {
afterEach(() => {
jest.clearAllMocks();
});
test('should see the correct elements for files', async () => {
getWrapper({});
await waitFor(() => {
expect(getDefaultFileMock).toHaveBeenCalledWith(
MOCK_ITEM.id,
expect.any(Function),
{},
{
fields: CONTENT_SHARING_ITEM_FIELDS,
},
);
});
expect(screen.getByRole('heading', { name: 'Share ‘Box Development Guide.pdf’' })).toBeVisible();
expect(screen.getByRole('combobox', { name: 'Invite People' })).toBeVisible();
expect(screen.getByRole('switch', { name: 'Shared link' })).toBeVisible();
});
test('should see the correct elements for folders', async () => {
getWrapper({ itemType: 'folder' });
await waitFor(() => {
expect(getDefaultFolderMock).toHaveBeenCalledWith(
MOCK_ITEM.id,
expect.any(Function),
{},
{
fields: CONTENT_SHARING_ITEM_FIELDS,
},
);
});
expect(screen.getByRole('heading', { name: 'Share ‘Box Development Guide.pdf’' })).toBeVisible();
expect(screen.getByRole('combobox', { name: 'Invite People' })).toBeVisible();
expect(screen.getByRole('switch', { name: 'Shared link' })).toBeVisible();
});
test('should see the shared link elements if shared link is present', async () => {
getWrapper({
api: createAPIMock({ getFile: getFileMockWithSharedLink }, null, { getUser: getDefaultUserMock }),
});
await waitFor(() => {
expect(getFileMockWithSharedLink).toHaveBeenCalledWith(
MOCK_ITEM.id,
expect.any(Function),
{},
{
fields: CONTENT_SHARING_ITEM_FIELDS,
},
);
});
expect(await screen.findByLabelText('Shared link URL')).toBeVisible();
expect(await screen.findByRole('button', { name: 'People with the link' })).toBeVisible();
expect(await screen.findByRole('button', { name: 'Can view and download' })).toBeVisible();
expect(screen.getByRole('button', { name: 'Link Settings' })).toBeVisible();
expect(screen.getByRole('button', { name: 'Copy' })).toBeVisible();
});
test('should see the classification elements if classification is present', async () => {
getWrapper({
api: createAPIMock({ getFile: getFileMockWithClassification }, null, { getUser: getDefaultUserMock }),
});
await waitFor(() => {
expect(getFileMockWithClassification).toHaveBeenCalledWith(
MOCK_ITEM.id,
expect.any(Function),
{},
{
fields: CONTENT_SHARING_ITEM_FIELDS,
},
);
});
expect(screen.getByText('BLUE')).toBeVisible();
});
});