@atlaskit/media-test-helpers 30.1.1 → 30.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/I18nWrapper.js +8 -24
  3. package/dist/cjs/MockGlobalImage.js +0 -16
  4. package/dist/cjs/authProvider.js +0 -18
  5. package/dist/cjs/await-error.js +0 -10
  6. package/dist/cjs/clipboardEventMocks.js +6 -39
  7. package/dist/cjs/createMouseEvent.js +4 -8
  8. package/dist/cjs/createTouchEvent.js +0 -2
  9. package/dist/cjs/docs-content-tabs.js +1 -14
  10. package/dist/cjs/example-mediaFeatureFlags.js +0 -7
  11. package/dist/cjs/exampleMediaItems.js +6 -7
  12. package/dist/cjs/fakeI18n.js +2 -4
  13. package/dist/cjs/fakeMediaClient.js +5 -18
  14. package/dist/cjs/featureFlagsWrapper/dropdown.js +12 -46
  15. package/dist/cjs/featureFlagsWrapper/helpers.js +0 -14
  16. package/dist/cjs/featureFlagsWrapper/index.js +5 -19
  17. package/dist/cjs/fileReader.js +0 -28
  18. package/dist/cjs/fileStateFactory/createFileState.js +9 -27
  19. package/dist/cjs/fileStateFactory/factory.js +7 -44
  20. package/dist/cjs/fileStateFactory/helpers.js +10 -23
  21. package/dist/cjs/fileStateFactory/index.js +0 -3
  22. package/dist/cjs/flushPromises.js +0 -2
  23. package/dist/cjs/getAuthFromContextProvider.js +0 -9
  24. package/dist/cjs/getJest.js +3 -5
  25. package/dist/cjs/globalEventEmitterListeners.js +0 -8
  26. package/dist/cjs/images.js +0 -6
  27. package/dist/cjs/index.js +0 -42
  28. package/dist/cjs/jestHelpers.js +0 -20
  29. package/dist/cjs/keyboardEventWithKeyCode.js +0 -18
  30. package/dist/cjs/mediaClientErrors.js +0 -11
  31. package/dist/cjs/mediaClientProvider.js +1 -17
  32. package/dist/cjs/mediaPickerAuthProvider.js +5 -21
  33. package/dist/cjs/mockCanvas.js +0 -4
  34. package/dist/cjs/mockData/handlers/copyWithToken.js +0 -14
  35. package/dist/cjs/mockData/handlers/getFile.js +0 -8
  36. package/dist/cjs/mockData/handlers/getFileImage.js +0 -9
  37. package/dist/cjs/mockData/handlers/index.js +0 -5
  38. package/dist/cjs/mockData/handlers/tenantAuth.js +0 -6
  39. package/dist/cjs/mockData/handlers/userCollectionFetch.js +0 -11
  40. package/dist/cjs/mockData/index.js +0 -9
  41. package/dist/cjs/mockData/matchers.js +0 -11
  42. package/dist/cjs/mockData/utils.js +10 -10
  43. package/dist/cjs/mockLoadImage.js +2 -14
  44. package/dist/cjs/mocks/database/chunk.js +0 -3
  45. package/dist/cjs/mocks/database/collection-item.js +14 -23
  46. package/dist/cjs/mocks/database/collection.js +0 -2
  47. package/dist/cjs/mocks/database/index.js +5 -23
  48. package/dist/cjs/mocks/database/upload.js +0 -6
  49. package/dist/cjs/mocks/fileAndDirectoriesUtils.js +12 -20
  50. package/dist/cjs/mocks/media-mock.js +14 -45
  51. package/dist/cjs/mocks/routers/api-router.js +78 -162
  52. package/dist/cjs/mocks/routers/index.js +0 -2
  53. package/dist/cjs/mocks/routers/media-playground-router.js +0 -3
  54. package/dist/cjs/mocks/websockets/index.js +0 -1
  55. package/dist/cjs/mocks/websockets/messages.js +0 -9
  56. package/dist/cjs/mocks/websockets/remote-upload-server.js +19 -45
  57. package/dist/cjs/mountWithIntlContext.js +9 -27
  58. package/dist/cjs/nextTick.js +0 -4
  59. package/dist/cjs/renderWithIntl.js +0 -6
  60. package/dist/cjs/story-list.js +4 -22
  61. package/dist/cjs/story-styles.js +0 -6
  62. package/dist/cjs/styled.js +0 -6
  63. package/dist/cjs/timeoutPromise.js +0 -1
  64. package/dist/cjs/ufoLogger.js +0 -7
  65. package/dist/cjs/utils/index.js +2 -11
  66. package/dist/cjs/utils/logging.js +11 -12
  67. package/dist/cjs/utils/mockData.js +5 -19
  68. package/dist/cjs/version.json +1 -1
  69. package/dist/cjs/waitUntil.js +2 -10
  70. package/dist/es2019/I18nWrapper.js +2 -4
  71. package/dist/es2019/MockGlobalImage.js +0 -3
  72. package/dist/es2019/authProvider.js +2 -5
  73. package/dist/es2019/clipboardEventMocks.js +12 -26
  74. package/dist/es2019/createMouseEvent.js +0 -2
  75. package/dist/es2019/docs-content-tabs.js +1 -3
  76. package/dist/es2019/example-mediaFeatureFlags.js +3 -2
  77. package/dist/es2019/exampleMediaItems.js +8 -3
  78. package/dist/es2019/fakeI18n.js +2 -1
  79. package/dist/es2019/fakeMediaClient.js +0 -1
  80. package/dist/es2019/featureFlagsWrapper/dropdown.js +0 -10
  81. package/dist/es2019/featureFlagsWrapper/helpers.js +2 -1
  82. package/dist/es2019/featureFlagsWrapper/index.js +2 -7
  83. package/dist/es2019/fileReader.js +0 -17
  84. package/dist/es2019/fileStateFactory/createFileState.js +6 -14
  85. package/dist/es2019/fileStateFactory/factory.js +4 -15
  86. package/dist/es2019/fileStateFactory/helpers.js +2 -7
  87. package/dist/es2019/getJest.js +3 -6
  88. package/dist/es2019/globalEventEmitterListeners.js +0 -3
  89. package/dist/es2019/images.js +2 -1
  90. package/dist/es2019/keyboardEventWithKeyCode.js +0 -5
  91. package/dist/es2019/mediaClientErrors.js +2 -1
  92. package/dist/es2019/mediaClientProvider.js +1 -1
  93. package/dist/es2019/mediaPickerAuthProvider.js +2 -5
  94. package/dist/es2019/mockData/handlers/copyWithToken.js +0 -2
  95. package/dist/es2019/mockData/handlers/getFile.js +0 -3
  96. package/dist/es2019/mockData/handlers/getFileImage.js +0 -3
  97. package/dist/es2019/mockData/handlers/tenantAuth.js +0 -2
  98. package/dist/es2019/mockData/handlers/userCollectionFetch.js +0 -2
  99. package/dist/es2019/mockData/index.js +0 -2
  100. package/dist/es2019/mockData/utils.js +10 -6
  101. package/dist/es2019/mockLoadImage.js +4 -2
  102. package/dist/es2019/mocks/database/index.js +0 -2
  103. package/dist/es2019/mocks/fileAndDirectoriesUtils.js +20 -14
  104. package/dist/es2019/mocks/media-mock.js +4 -16
  105. package/dist/es2019/mocks/routers/api-router.js +13 -45
  106. package/dist/es2019/mocks/websockets/remote-upload-server.js +11 -14
  107. package/dist/es2019/mountWithIntlContext.js +4 -4
  108. package/dist/es2019/story-list.js +0 -1
  109. package/dist/es2019/ufoLogger.js +0 -1
  110. package/dist/es2019/utils/index.js +0 -2
  111. package/dist/es2019/utils/logging.js +4 -4
  112. package/dist/es2019/utils/mockData.js +5 -3
  113. package/dist/es2019/version.json +1 -1
  114. package/dist/es2019/waitUntil.js +0 -1
  115. package/dist/esm/I18nWrapper.js +8 -12
  116. package/dist/esm/MockGlobalImage.js +0 -10
  117. package/dist/esm/authProvider.js +0 -10
  118. package/dist/esm/await-error.js +0 -6
  119. package/dist/esm/clipboardEventMocks.js +15 -39
  120. package/dist/esm/createMouseEvent.js +4 -6
  121. package/dist/esm/docs-content-tabs.js +2 -5
  122. package/dist/esm/example-mediaFeatureFlags.js +0 -3
  123. package/dist/esm/exampleMediaItems.js +8 -3
  124. package/dist/esm/fakeI18n.js +2 -1
  125. package/dist/esm/fakeMediaClient.js +5 -8
  126. package/dist/esm/featureFlagsWrapper/dropdown.js +12 -30
  127. package/dist/esm/featureFlagsWrapper/helpers.js +0 -3
  128. package/dist/esm/featureFlagsWrapper/index.js +5 -12
  129. package/dist/esm/fileReader.js +0 -28
  130. package/dist/esm/fileStateFactory/createFileState.js +9 -22
  131. package/dist/esm/fileStateFactory/factory.js +7 -41
  132. package/dist/esm/fileStateFactory/helpers.js +10 -18
  133. package/dist/esm/getAuthFromContextProvider.js +0 -3
  134. package/dist/esm/getJest.js +3 -3
  135. package/dist/esm/globalEventEmitterListeners.js +0 -3
  136. package/dist/esm/images.js +2 -1
  137. package/dist/esm/jestHelpers.js +0 -2
  138. package/dist/esm/keyboardEventWithKeyCode.js +0 -10
  139. package/dist/esm/mediaClientErrors.js +0 -3
  140. package/dist/esm/mediaClientProvider.js +1 -1
  141. package/dist/esm/mediaPickerAuthProvider.js +5 -12
  142. package/dist/esm/mockData/handlers/copyWithToken.js +0 -4
  143. package/dist/esm/mockData/handlers/getFile.js +0 -3
  144. package/dist/esm/mockData/handlers/getFileImage.js +0 -3
  145. package/dist/esm/mockData/handlers/tenantAuth.js +0 -2
  146. package/dist/esm/mockData/handlers/userCollectionFetch.js +0 -5
  147. package/dist/esm/mockData/index.js +0 -2
  148. package/dist/esm/mockData/utils.js +10 -6
  149. package/dist/esm/mockLoadImage.js +2 -4
  150. package/dist/esm/mocks/database/collection-item.js +14 -15
  151. package/dist/esm/mocks/database/index.js +5 -7
  152. package/dist/esm/mocks/fileAndDirectoriesUtils.js +12 -13
  153. package/dist/esm/mocks/media-mock.js +14 -26
  154. package/dist/esm/mocks/routers/api-router.js +78 -144
  155. package/dist/esm/mocks/websockets/remote-upload-server.js +19 -24
  156. package/dist/esm/mountWithIntlContext.js +9 -17
  157. package/dist/esm/story-list.js +4 -12
  158. package/dist/esm/story-styles.js +0 -2
  159. package/dist/esm/styled.js +0 -2
  160. package/dist/esm/ufoLogger.js +0 -4
  161. package/dist/esm/utils/index.js +2 -5
  162. package/dist/esm/utils/logging.js +11 -11
  163. package/dist/esm/utils/mockData.js +5 -3
  164. package/dist/esm/version.json +1 -1
  165. package/dist/esm/waitUntil.js +2 -6
  166. package/package.json +4 -4
@@ -9,31 +9,27 @@ import { createUpload } from '../database/upload';
9
9
  import { logRequest } from '../../utils/logging';
10
10
  import { getTextFileType, getFakeFileName, mockDataUri } from '../../utils/mockData';
11
11
  import { mapDataUriToBlob } from '../../utils';
12
-
13
12
  class RouterWithLogging extends Router {
14
13
  register(method, path, originalHandler) {
15
14
  const handler = (request, database) => {
16
15
  let response;
17
16
  let requestWithBodyObject;
18
17
  let error;
19
-
20
18
  try {
21
19
  response = originalHandler(request, database);
22
20
  let body = request.body;
23
-
24
21
  try {
25
22
  body = JSON.parse(body);
26
23
  } catch (e) {}
27
-
28
24
  requestWithBodyObject = {
29
- request: { ...request,
25
+ request: {
26
+ ...request,
30
27
  body
31
28
  }
32
29
  };
33
30
  } catch (e) {
34
31
  error = e;
35
32
  }
36
-
37
33
  logRequest({
38
34
  path,
39
35
  method,
@@ -42,19 +38,15 @@ class RouterWithLogging extends Router {
42
38
  error,
43
39
  database
44
40
  });
45
-
46
41
  if (error) {
47
42
  throw error;
48
43
  } else {
49
44
  return response;
50
45
  }
51
46
  };
52
-
53
47
  return super.register(method, path, handler);
54
48
  }
55
-
56
49
  }
57
-
58
50
  export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
59
51
  const requestDelay = isSlowServer ? 200 : 10;
60
52
  const router = new RouterWithLogging({
@@ -74,7 +66,9 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
74
66
  return {
75
67
  data: collection
76
68
  };
77
- }); // TODO [EDM-1151]: Implement router.get('/file/binary') for videos
69
+ });
70
+
71
+ // TODO [EDM-1151]: Implement router.get('/file/binary') for videos
78
72
 
79
73
  router.post('/file/binary', ({
80
74
  headers,
@@ -128,11 +122,9 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
128
122
  }
129
123
  };
130
124
  });
131
-
132
125
  const isSvgFile = record => {
133
126
  return !!(record.data.blob && record.data.blob.type === 'image/svg+xml');
134
127
  };
135
-
136
128
  router.get('/file/:fileId/image', ({
137
129
  params,
138
130
  query
@@ -149,7 +141,6 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
149
141
  id: fileId
150
142
  });
151
143
  let blob;
152
-
153
144
  if (!record || !record.data.blob || isSvgFile(record)) {
154
145
  const dataUri = mockDataUri(width, height);
155
146
  blob = mapDataUriToBlob(dataUri);
@@ -158,7 +149,6 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
158
149
  } else {
159
150
  blob = record.data.blob;
160
151
  }
161
-
162
152
  return new KakapoResponse(200, blob, {
163
153
  'content-type': blob.type,
164
154
  'content-length': blob.size.toString(),
@@ -179,19 +169,16 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
179
169
  width: 4096
180
170
  };
181
171
  let dimensions = Promise.resolve(defaultDimensions);
182
-
183
172
  if (record && record.data.blob && !isSvgFile(record)) {
184
173
  dimensions = new Promise(resolve => {
185
174
  const image = new Image();
186
175
  image.src = URL.createObjectURL(record.data.blob);
187
-
188
176
  image.onload = () => resolve({
189
177
  height: image.height,
190
178
  width: image.width
191
179
  });
192
180
  });
193
181
  }
194
-
195
182
  return {
196
183
  metadata: {
197
184
  pending: false,
@@ -211,7 +198,6 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
211
198
  const {
212
199
  chunkId
213
200
  } = params;
214
-
215
201
  if (database.findOne('chunk', {
216
202
  id: chunkId
217
203
  })) {
@@ -233,24 +219,21 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
233
219
  });
234
220
  return new KakapoResponse(201, undefined, {});
235
221
  });
222
+
236
223
  /** This function waits for shouldWaitUpload to be false before it resolves the promise.
237
224
  * Otherwise it recursively calls itself with a 10ms timeout until it is false.*/
238
-
239
225
  async function awaitUpload(resolver) {
240
226
  return new Promise(resolve => {
241
227
  if (window.mediaMockControlsBackdoor.shouldWaitUpload) {
242
228
  setTimeout(() => awaitUpload(resolver || resolve), 10);
243
229
  return;
244
230
  }
245
-
246
231
  if (resolver && !window.mediaMockControlsBackdoor.shouldWaitUpload) {
247
232
  resolver();
248
233
  }
249
-
250
234
  resolve();
251
235
  });
252
236
  }
253
-
254
237
  router.post('/chunk/probe', async ({
255
238
  body
256
239
  }, database) => {
@@ -302,14 +285,11 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
302
285
  uploadId
303
286
  } = params;
304
287
  const {
305
- chunks
306
- /*, offset*/
307
-
288
+ chunks /*, offset*/
308
289
  } = JSON.parse(body);
309
290
  const record = database.findOne('upload', {
310
291
  id: uploadId
311
292
  });
312
-
313
293
  if (record) {
314
294
  database.update('upload', record.id, {
315
295
  chunks: [...record.data.chunks, ...chunks]
@@ -352,32 +332,26 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
352
332
  const uploadRecord = database.findOne('upload', {
353
333
  id: uploadId
354
334
  });
355
-
356
335
  if (!uploadRecord) {
357
336
  return new KakapoResponse(404, {
358
337
  message: `upload ${uploadId} is not found`
359
338
  }, {});
360
339
  }
361
-
362
340
  const fileRecord = database.findOne('collectionItem', {
363
341
  id: replaceFileId
364
342
  });
365
-
366
343
  if (fileRecord === undefined) {
367
344
  return new KakapoResponse(404, {
368
345
  message: `file ${replaceFileId} is not found`
369
346
  }, {});
370
347
  }
371
-
372
348
  const totalBlob = uploadRecord.data.chunks.reduce((memo, chunkId) => {
373
349
  const chunkRecord = database.findOne('chunk', {
374
350
  id: chunkId
375
351
  });
376
-
377
352
  if (!chunkRecord || !chunkRecord.data.blob) {
378
353
  return memo;
379
354
  }
380
-
381
355
  return new Blob([memo, chunkRecord.data.blob], {
382
356
  type: memo.type
383
357
  });
@@ -385,7 +359,8 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
385
359
  type: mimeType
386
360
  }));
387
361
  const mediaType = getMediaTypeFromMimeType(mimeType);
388
- const newDetails = { ...(fileRecord.data.details || {}),
362
+ const newDetails = {
363
+ ...(fileRecord.data.details || {}),
389
364
  name,
390
365
  mimeType,
391
366
  size: totalBlob.size,
@@ -403,7 +378,8 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
403
378
  details: newDetails
404
379
  });
405
380
  return {
406
- data: { ...newDetails,
381
+ data: {
382
+ ...newDetails,
407
383
  id: replaceFileId
408
384
  }
409
385
  };
@@ -422,7 +398,6 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
422
398
  id: fileId,
423
399
  collectionName: collection
424
400
  });
425
-
426
401
  if (record) {
427
402
  return {
428
403
  data: {
@@ -442,8 +417,8 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
442
417
  } = JSON.parse(body);
443
418
  const fileItems = descriptors.map(descriptor => {
444
419
  const record = database.findOne('collectionItem', {
445
- id: descriptor.id // TODO [MS-2249]: add collectionName: descriptor.collection check
446
-
420
+ id: descriptor.id
421
+ // TODO [MS-2249]: add collectionName: descriptor.collection check
447
422
  });
448
423
 
449
424
  if (record) {
@@ -454,7 +429,6 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
454
429
  details: record.data.details
455
430
  };
456
431
  }
457
-
458
432
  return null;
459
433
  }).filter(fileItem => fileItem !== null);
460
434
  return {
@@ -476,16 +450,13 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
476
450
  replaceFileId,
477
451
  occurrenceKey
478
452
  } = query;
479
-
480
453
  if (replaceFileId && !occurrenceKey || !replaceFileId && occurrenceKey) {
481
454
  return new KakapoResponse(404, undefined, {});
482
455
  }
483
-
484
456
  const sourceRecord = database.findOne('collectionItem', {
485
457
  id: sourceFile.id,
486
458
  collectionName: sourceFile.collection
487
459
  });
488
-
489
460
  if (!replaceFileId && !occurrenceKey) {
490
461
  replaceFileId = uuid();
491
462
  occurrenceKey = uuid();
@@ -495,13 +466,11 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
495
466
  occurrenceKey
496
467
  }));
497
468
  }
498
-
499
469
  const existingRecord = database.findOne('collectionItem', {
500
470
  id: replaceFileId,
501
471
  collectionName: destinationCollection,
502
472
  occurrenceKey
503
473
  });
504
-
505
474
  if (sourceRecord && existingRecord) {
506
475
  const extension = getTextFileType();
507
476
  const {
@@ -599,7 +568,6 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
599
568
  const return500 = () => new KakapoResponse(500, {
600
569
  message: 'As you wish, master!'
601
570
  });
602
-
603
571
  router.delete(url, return500);
604
572
  router.get(url, return500);
605
573
  router.post(url, return500);
@@ -20,7 +20,6 @@ import { getFakeFileSize } from '../../utils/mockData';
20
20
  const DELAY_MESSAGS_MS = 200;
21
21
  const DELAY_MESSAGES_SLOW_MS = 1000;
22
22
  const DELAY_MESSAGES_VARIATION = 500;
23
-
24
23
  /**
25
24
  * Returns an Observable emitting messages coming from a mocked websocket server.
26
25
  * Only listens to the latest connection and maps all non-empty messages to JSON.
@@ -29,16 +28,18 @@ const DELAY_MESSAGES_VARIATION = 500;
29
28
  * @returns Observable emitting websocket messages (referencing the currently active socket)
30
29
  */
31
30
  function getUpstreamMessages(wsServer) {
32
- return Observable.create(observer => wsServer.on('connection', socket => observer.next(socket))).pipe(switchMap(socket => Observable.create(observer => socket.on('message', data => observer.next(data))).pipe( // ignore empty messages
33
- filter(data => typeof data === 'string' && data.length > 0), // parse messages as JSON
31
+ return Observable.create(observer => wsServer.on('connection', socket => observer.next(socket))).pipe(switchMap(socket => Observable.create(observer => socket.on('message', data => observer.next(data))).pipe(
32
+ // ignore empty messages
33
+ filter(data => typeof data === 'string' && data.length > 0),
34
+ // parse messages as JSON
34
35
  map(data => ({
35
36
  socket,
36
37
  message: JSON.parse(data)
37
38
  })))));
38
39
  }
39
-
40
40
  function createUserFile(database, fileId, name, collection) {
41
- database.push('collectionItem', // backend initially creates cloud files
41
+ database.push('collectionItem',
42
+ // backend initially creates cloud files
42
43
  // having mediaType=unknown and mimeType=binary/octet-stream
43
44
  createCollectionItem({
44
45
  name,
@@ -50,13 +51,13 @@ function createUserFile(database, fileId, name, collection) {
50
51
  processingStatus: 'pending'
51
52
  }));
52
53
  }
53
-
54
54
  function sendDownstreamMessage(wsUrl, socket, database, message) {
55
55
  const {
56
56
  type,
57
57
  ...payload
58
- } = message; // logs every message in console
58
+ } = message;
59
59
 
60
+ // logs every message in console
60
61
  logWsMessage({
61
62
  url: wsUrl,
62
63
  dir: WsDirection.Downstream,
@@ -66,6 +67,7 @@ function sendDownstreamMessage(wsUrl, socket, database, message) {
66
67
  });
67
68
  socket.send(JSON.stringify(message));
68
69
  }
70
+
69
71
  /**
70
72
  * Given an Observable of websocket upstream messages, generates the corresponding downstream messages as follow:
71
73
  * 1. NotifyMetadata
@@ -79,8 +81,6 @@ function sendDownstreamMessage(wsUrl, socket, database, message) {
79
81
  * @param database Kakapo database
80
82
  * @param isSlowServer boolean to set to true to simulate a slower websocket server
81
83
  */
82
-
83
-
84
84
  function generateDownstreamMessages(wsUrl, database, isSlowServer) {
85
85
  const delayMessages = isSlowServer ? DELAY_MESSAGES_SLOW_MS : DELAY_MESSAGS_MS;
86
86
  return messages => messages.pipe(filter(({
@@ -99,13 +99,13 @@ function generateDownstreamMessages(wsUrl, database, isSlowServer) {
99
99
  }
100
100
  } = message;
101
101
  const userFileId = uuid();
102
- const fileSize = getFakeFileSize(); // create user file in database
102
+ const fileSize = getFakeFileSize();
103
103
 
104
+ // create user file in database
104
105
  createUserFile(database, userFileId, fileName, collection);
105
106
  return from([notifyMetadataPayload(tenantFileId, fileSize), remoteUploadStartPayload(tenantFileId), remoteUploadProgressPayload(tenantFileId, fileSize), remoteUploadEndPayload(tenantFileId, userFileId)]).pipe(concatMap(message => of(message).pipe(tap(message => sendDownstreamMessage(wsUrl, socket, database, message)), delay(delayMessages + Math.random() * DELAY_MESSAGES_VARIATION))));
106
107
  }));
107
108
  }
108
-
109
109
  export class RemoteUploadActivityServer {
110
110
  constructor(params) {
111
111
  const {
@@ -127,14 +127,11 @@ export class RemoteUploadActivityServer {
127
127
  database
128
128
  })), generateDownstreamMessages(wsUrl, database, isSlowServer)).subscribe();
129
129
  }
130
-
131
130
  start() {
132
131
  this.wsServer.start();
133
132
  }
134
-
135
133
  stop() {
136
134
  this.msgSubscription.unsubscribe();
137
135
  this.wsServer.stop();
138
136
  }
139
-
140
137
  }
@@ -4,10 +4,10 @@ import { mount, shallow } from 'enzyme';
4
4
  const mockIntl = createIntl({
5
5
  locale: 'en'
6
6
  });
7
+
7
8
  /**
8
9
  * When using React-Intl `injectIntl` on components, props.intl is required.
9
10
  */
10
-
11
11
  function nodeWithIntlProp(node) {
12
12
  const intl = !!node.props.intl ? node.props.intl : mockIntl;
13
13
  return /*#__PURE__*/React.createElement(RawIntlProvider, {
@@ -16,13 +16,12 @@ function nodeWithIntlProp(node) {
16
16
  intl
17
17
  }));
18
18
  }
19
+
19
20
  /* TODO: We are explicitly using the third arg of ReactWrapper to work around the following TS issue which prevents a d.ts from being generated
20
21
  * and therefore fails the build:
21
22
  * error TS2742: The inferred type of 'mountWithIntlContext' cannot be named without a reference to 'react-transition-group/node_modules/@types/react'. This is likely not portable. A type annotation is necessary.
22
23
  * TS is resolving enzyme's usage of react to react-transition-group???
23
24
  */
24
-
25
-
26
25
  export const mountWithIntlContext = (node, {
27
26
  context = {},
28
27
  childContextTypes = {},
@@ -53,6 +52,7 @@ export const shallowWithIntlContext = (node, {
53
52
  export const mountWithIntlWrapper = node => {
54
53
  return mount( /*#__PURE__*/React.createElement(props => /*#__PURE__*/React.createElement(IntlProvider, {
55
54
  locale: "en"
56
- }, /*#__PURE__*/React.cloneElement(node, { ...props
55
+ }, /*#__PURE__*/React.cloneElement(node, {
56
+ ...props
57
57
  }))));
58
58
  };
@@ -68,5 +68,4 @@ export class StoryList extends Component {
68
68
  style: listStyles.statesWrapper
69
69
  }, listContent);
70
70
  }
71
-
72
71
  }
@@ -2,7 +2,6 @@ export const enableMediaUfoLogger = (ufoPayloadPublisher, properties = {}) => {
2
2
  // Added try catch as Performance is not mocked properly in the Ufo packages.
3
3
  // By adding try catch test are successfully passing. Created ticket for the same - MEET-2652
4
4
  const MEDIA_UFO_OPERATIONAL_EVENT = 'Media::UFO::sendOperationalEvent:';
5
-
6
5
  try {
7
6
  ufoPayloadPublisher.setup({
8
7
  product: 'examples',
@@ -5,11 +5,9 @@ export function mapDataUriToBlob(dataUri) {
5
5
  const bstr = atob(arr[1]);
6
6
  let n = bstr.length;
7
7
  const u8arr = new Uint8Array(n);
8
-
9
8
  while (n--) {
10
9
  u8arr[n] = bstr.charCodeAt(n);
11
10
  }
12
-
13
11
  return new Blob([u8arr], {
14
12
  type: mime
15
13
  });
@@ -1,10 +1,8 @@
1
1
  export let WsDirection;
2
-
3
2
  (function (WsDirection) {
4
3
  WsDirection["Upstream"] = "UP";
5
4
  WsDirection["Downstream"] = "DOWN";
6
5
  })(WsDirection || (WsDirection = {}));
7
-
8
6
  export function logRequest(params) {
9
7
  const {
10
8
  path,
@@ -13,8 +11,9 @@ export function logRequest(params) {
13
11
  response,
14
12
  error,
15
13
  database
16
- } = params; // eslint-disable-next-line no-console
14
+ } = params;
17
15
 
16
+ // eslint-disable-next-line no-console
18
17
  console.log('MOCK', path, {
19
18
  method,
20
19
  request,
@@ -30,8 +29,9 @@ export function logWsMessage(params) {
30
29
  type,
31
30
  payload,
32
31
  database
33
- } = params; // eslint-disable-next-line no-console
32
+ } = params;
34
33
 
34
+ // eslint-disable-next-line no-console
35
35
  console.log(`MOCK WS:${dir}`, url, {
36
36
  type,
37
37
  payload,
@@ -5,9 +5,10 @@ export const imageFileTypes = ['.svgz', '.svg'];
5
5
  export const textFileTypes = ['.txt', '.in', '.ini', '.text', '.conf', '.list'];
6
6
  export const getTextFileType = () => textFileTypes[Math.floor(Math.random() * textFileTypes.length)];
7
7
  export const getFakeFileName = (ext = imageFileTypes[Math.round(Math.random())]) => `${commonFileName[Math.floor(Math.random() * commonFileName.length)]}${ext}`;
8
- export const getFakeFileSize = (maxSize = 1e7) => Math.round(Math.random() * maxSize); // This fake image was generated using faker. It never changes so we are just
9
- // using the output exact call Faker.image.dataUri(320, 240)
8
+ export const getFakeFileSize = (maxSize = 1e7) => Math.round(Math.random() * maxSize);
10
9
 
10
+ // This fake image was generated using faker. It never changes so we are just
11
+ // using the output exact call Faker.image.dataUri(320, 240)
11
12
  export const fakeImage = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZlcnNpb249IjEuMSIgYmFzZVByb2ZpbGU9ImZ1bGwiIHdpZHRoPSIzMjAiIGhlaWdodD0iMjQwIj4gPHJlY3Qgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0iZ3JleSIvPiAgPHRleHQgeD0iMCIgeT0iMjAiIGZvbnQtc2l6ZT0iMjAiIHRleHQtYW5jaG9yPSJzdGFydCIgZmlsbD0id2hpdGUiPjMyMHgyNDA8L3RleHQ+IDwvc3ZnPg==';
12
13
  export const getDateWithOffset = offset => {
13
14
  let time = new Date();
@@ -21,8 +22,9 @@ export const getPastDate = () => {
21
22
  export const getFutureDate = () => {
22
23
  let offset = 100000 + Math.round(Math.random() * 10000);
23
24
  return getDateWithOffset(offset);
24
- }; // This function is taken directly from Faker
25
+ };
25
26
 
27
+ // This function is taken directly from Faker
26
28
  export const mockDataUri = function (width, height) {
27
29
  const rawPrefix = 'data:image/svg+xml;base64,';
28
30
  const svgString = `<svg xmlns="http://www.w3.org/2000/svg" version="1.1" baseProfile="full" width="${width}" height="${height}"> <rect width="100%" height="100%" fill="grey"/> <text x="0" y="20" font-size="20" text-anchor="start" fill="white">${width}x${height}</text> </svg>`;
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "@atlaskit/media-test-helpers",
3
- "version": "30.1.1"
3
+ "version": "30.1.2"
4
4
  }
@@ -11,7 +11,6 @@ export async function waitUntil(predicate, timeout = 100, maxRetries = 10) {
11
11
  reject('timed out');
12
12
  }
13
13
  };
14
-
15
14
  check(maxRetries);
16
15
  });
17
16
  }
@@ -4,31 +4,26 @@ import React, { useState } from 'react';
4
4
  import { IntlProvider } from 'react-intl-next';
5
5
  import LocaleSelect, { defaultLocales } from '@atlaskit/locale/LocaleSelect';
6
6
  import { locales } from '@atlaskit/media-ui/locales';
7
-
8
7
  function getMessages(localeValue) {
9
8
  var lang = localeValue.substring(0, 2);
10
9
  var langWithRegion = localeValue.replace('-', '_');
11
10
  return locales[langWithRegion] || locales[lang];
12
11
  }
13
-
14
12
  var selectableLocales = defaultLocales.reduce(function (result, locale) {
15
13
  if (!getMessages(locale.value)) {
16
14
  return result;
17
15
  }
18
-
19
16
  return [].concat(_toConsumableArray(result), [locale]);
20
17
  }, []);
21
18
  export var I18NWrapper = function I18NWrapper(_ref) {
22
19
  var children = _ref.children;
23
-
24
20
  var _useState = useState({
25
- label: 'en',
26
- value: 'en'
27
- }),
28
- _useState2 = _slicedToArray(_useState, 2),
29
- locale = _useState2[0],
30
- setLocale = _useState2[1];
31
-
21
+ label: 'en',
22
+ value: 'en'
23
+ }),
24
+ _useState2 = _slicedToArray(_useState, 2),
25
+ locale = _useState2[0],
26
+ setLocale = _useState2[1];
32
27
  var lang = locale.value.substring(0, 2);
33
28
  var messages = getMessages(locale.value);
34
29
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
@@ -41,7 +36,8 @@ export var I18NWrapper = function I18NWrapper(_ref) {
41
36
  locales: selectableLocales
42
37
  })), /*#__PURE__*/React.createElement(IntlProvider, {
43
38
  locale: lang,
44
- messages: messages // We need to add this key to force a re-render and refresh translations
39
+ messages: messages
40
+ // We need to add this key to force a re-render and refresh translations
45
41
  // when selected language has changed
46
42
  ,
47
43
  key: locale.value
@@ -3,34 +3,24 @@ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
3
  import _inherits from "@babel/runtime/helpers/inherits";
4
4
  import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
5
5
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
-
7
6
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
8
-
9
7
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
10
-
11
8
  var globalImage = global.Image;
12
9
  var isErrorInsteadOfLoad;
13
-
14
10
  var MockImage = /*#__PURE__*/function (_global$Image) {
15
11
  _inherits(MockImage, _global$Image);
16
-
17
12
  var _super = _createSuper(MockImage);
18
-
19
13
  function MockImage() {
20
14
  var _this;
21
-
22
15
  _classCallCheck(this, MockImage);
23
-
24
16
  _this = _super.call(this);
25
17
  window.setTimeout(function () {
26
18
  return _this[isErrorInsteadOfLoad ? 'onerror' : 'onload']();
27
19
  });
28
20
  return _this;
29
21
  }
30
-
31
22
  return _createClass(MockImage);
32
23
  }(global.Image);
33
-
34
24
  export function enableMockGlobalImage() {
35
25
  var isError = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
36
26
  global.Image = MockImage;
@@ -9,7 +9,6 @@ export var StoryBookAuthProvider = /*#__PURE__*/function () {
9
9
  function StoryBookAuthProvider() {
10
10
  _classCallCheck(this, StoryBookAuthProvider);
11
11
  }
12
-
13
12
  _createClass(StoryBookAuthProvider, null, [{
14
13
  key: "create",
15
14
  value: function create(isAsapEnvironment, access) {
@@ -33,17 +32,13 @@ export var StoryBookAuthProvider = /*#__PURE__*/function () {
33
32
  };
34
33
  url = "".concat(authProviderBaseURL, "/token/tenant?collection=").concat(collectionName, "&environment=").concat(environment);
35
34
  response = fetch(url, config); // We leverage the fact, that our internal /toke/tenant API returns data in the same format as Auth
36
-
37
35
  _context.next = 9;
38
36
  return response;
39
-
40
37
  case 9:
41
38
  _context.next = 11;
42
39
  return _context.sent.json();
43
-
44
40
  case 11:
45
41
  return _context.abrupt("return", _context.sent);
46
-
47
42
  case 12:
48
43
  case "end":
49
44
  return _context.stop();
@@ -51,25 +46,20 @@ export var StoryBookAuthProvider = /*#__PURE__*/function () {
51
46
  }
52
47
  }, _callee);
53
48
  }));
54
-
55
49
  return function loadTenatAuth(_x) {
56
50
  return _ref.apply(this, arguments);
57
51
  };
58
52
  }();
59
-
60
53
  return function (authContext) {
61
54
  var collectionName = authContext && authContext.collectionName || defaultCollectionName;
62
55
  var accessStr = access ? JSON.stringify(access) : '';
63
56
  var cacheKey = "".concat(collectionName, "-").concat(accessStr, "-").concat(isAsapEnvironment);
64
-
65
57
  if (!cachedAuths[cacheKey]) {
66
58
  cachedAuths[cacheKey] = loadTenatAuth(collectionName);
67
59
  }
68
-
69
60
  return cachedAuths[cacheKey];
70
61
  };
71
62
  }
72
63
  }]);
73
-
74
64
  return StoryBookAuthProvider;
75
65
  }();
@@ -3,7 +3,6 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
3
3
  export function awaitError(_x, _x2) {
4
4
  return _awaitError.apply(this, arguments);
5
5
  }
6
-
7
6
  function _awaitError() {
8
7
  _awaitError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(response, expectedMessage) {
9
8
  return _regeneratorRuntime.wrap(function _callee$(_context) {
@@ -13,22 +12,17 @@ function _awaitError() {
13
12
  _context.prev = 0;
14
13
  _context.next = 3;
15
14
  return response;
16
-
17
15
  case 3:
18
16
  _context.next = 9;
19
17
  break;
20
-
21
18
  case 5:
22
19
  _context.prev = 5;
23
20
  _context.t0 = _context["catch"](0);
24
-
25
21
  if (!(_context.t0 instanceof Error && _context.t0.message !== expectedMessage)) {
26
22
  _context.next = 9;
27
23
  break;
28
24
  }
29
-
30
25
  throw _context.t0;
31
-
32
26
  case 9:
33
27
  case "end":
34
28
  return _context.stop();