-
Notifications
You must be signed in to change notification settings - Fork 344
Expand file tree
/
Copy pathContentSharingV2Mocks.js
More file actions
195 lines (171 loc) · 5.01 KB
/
ContentSharingV2Mocks.js
File metadata and controls
195 lines (171 loc) · 5.01 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
export const MOCK_PERMISSIONS = {
can_download: true,
can_invite_collaborator: true,
can_set_share_access: true,
can_share: true,
};
export const MOCK_CLASSIFICATION = {
color: '#91c2fd',
definition: 'Blue classification',
name: 'Blue',
};
export const MOCK_ITEM = {
id: '123456789',
name: 'Box Development Guide.pdf',
type: 'file',
};
export const MOCK_SHARED_LINK = {
access: 'open',
effective_permission: 'can_download',
is_password_enabled: true,
unshared_at: 1704067200000,
url: 'https://example.com/shared-link',
vanity_name: 'vanity-name',
vanity_url: 'https://example.com/vanity-url',
};
export const mockAvatarURLMap = {
456: 'https://example.com/avatar.jpg',
};
export const mockOwnerEmail = 'aotter@example.com';
export const mockOwnerName = 'Astronaut Otter';
export const mockOwnerId = 789;
export const collabUser1 = {
id: 456,
login: 'dparrot@example.com',
name: 'Detective Parrot',
role: 'editor',
};
export const collabUser2 = {
id: 457,
login: 'rqueen@external.example.com',
name: 'Raccoon Queen',
};
export const collabUser3 = {
id: 458,
login: 'dpenguin@example.com',
name: 'Dancing Penguin',
};
export const mockOwner = {
id: mockOwnerId,
login: mockOwnerEmail,
name: mockOwnerName,
};
export const MOCK_COLLABORATORS = [collabUser1, collabUser2, collabUser3];
export const MOCK_COLLABORATIONS_RESPONSE = {
entries: MOCK_COLLABORATORS.map(user => ({
id: `record_${user.id}`,
accessible_by: user,
expires_at: user.expires_at,
created_by: {
id: mockOwnerId,
login: mockOwnerEmail,
name: mockOwnerName,
type: 'user',
},
role: user.id === mockOwnerId ? 'owner' : 'editor',
status: 'accepted',
type: user.type,
})),
};
export const EMPTY_COLLABORATIONS_RESPONSE = {
entries: [],
};
export const DEFAULT_USER_API_RESPONSE = {
id: '789',
enterprise: {
name: 'Otter Enterprise',
},
};
export const DEFAULT_ITEM_API_RESPONSE = {
allowed_invitee_roles: ['editor', 'viewer'],
allowed_shared_link_access_levels: ['open', 'company', 'collaborators'],
allowed_shared_link_access_levels_disabled_reasons: {
peopleInThisItem: 'access_policy',
},
classification: null,
id: MOCK_ITEM.id,
name: MOCK_ITEM.name,
owned_by: mockOwner,
permissions: MOCK_PERMISSIONS,
shared_link: null,
shared_link_features: { password: true },
type: MOCK_ITEM.type,
};
export const MOCK_ITEM_API_RESPONSE_WITH_SHARED_LINK = {
...DEFAULT_ITEM_API_RESPONSE,
shared_link: MOCK_SHARED_LINK,
};
export const MOCK_ITEM_API_RESPONSE_WITH_COLLABORATORS = {
...DEFAULT_ITEM_API_RESPONSE,
collaborators: MOCK_COLLABORATORS,
};
export const MOCK_ITEM_API_RESPONSE_WITH_CLASSIFICATION = {
...DEFAULT_ITEM_API_RESPONSE,
classification: MOCK_CLASSIFICATION,
};
// Mock API class for ContentSharingV2 storybook
export const createMockAPI = (
itemResponse = DEFAULT_ITEM_API_RESPONSE,
userResponse = DEFAULT_USER_API_RESPONSE,
collaboratorsResponse = MOCK_COLLABORATIONS_RESPONSE,
) => {
const mockFileAPI = {
getFile: (itemID, successCallback) => {
setTimeout(() => {
successCallback(itemResponse);
}, 100);
},
};
const mockFolderAPI = {
getFolderFields: (itemID, successCallback) => {
setTimeout(() => {
successCallback(itemResponse);
}, 100);
},
};
const mockUsersAPI = {
getUser: (itemID, successCallback) => {
setTimeout(() => {
successCallback(userResponse);
}, 100);
},
getAvatarUrlWithAccessToken: userID => mockAvatarURLMap[userID] ?? null,
};
const getFileCollaborationsAPI = () => ({
getCollaborations: (itemID, successCallback) => {
setTimeout(() => {
successCallback(collaboratorsResponse);
}, 100);
},
});
const getFolderCollaborationsAPI = () => ({
getCollaborations: (itemID, successCallback) => {
setTimeout(() => {
successCallback(collaboratorsResponse);
}, 100);
},
});
return {
getFileAPI: () => mockFileAPI,
getFolderAPI: () => mockFolderAPI,
getUsersAPI: () => mockUsersAPI,
getFileCollaborationsAPI,
getFolderCollaborationsAPI,
};
};
// Pre-configured mock APIs for different scenarios
export const mockAPIWithSharedLink = createMockAPI(
MOCK_ITEM_API_RESPONSE_WITH_SHARED_LINK,
DEFAULT_USER_API_RESPONSE,
EMPTY_COLLABORATIONS_RESPONSE,
);
export const mockAPIWithoutSharedLink = createMockAPI(
DEFAULT_ITEM_API_RESPONSE,
DEFAULT_USER_API_RESPONSE,
EMPTY_COLLABORATIONS_RESPONSE,
);
export const mockAPIWithCollaborators = createMockAPI(
MOCK_ITEM_API_RESPONSE_WITH_COLLABORATORS,
DEFAULT_USER_API_RESPONSE,
MOCK_COLLABORATIONS_RESPONSE,
);