@atlaskit/media-test-helpers 31.0.0 → 32.1.0

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 (72) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/cjs/authProvider.js +25 -27
  3. package/dist/cjs/await-error.js +17 -19
  4. package/dist/cjs/docs-content-tabs.js +1 -0
  5. package/dist/cjs/fakeMediaClient.js +0 -5
  6. package/dist/cjs/fileStateFactory/{createFileState.js → factory/createFileState.js} +8 -15
  7. package/dist/cjs/fileStateFactory/{factory.js → factory/factory.js} +34 -25
  8. package/dist/cjs/fileStateFactory/factory/index.js +38 -0
  9. package/dist/cjs/fileStateFactory/fileSimulation/fileSimulation.js +89 -0
  10. package/dist/cjs/fileStateFactory/fileSimulation/index.js +79 -0
  11. package/dist/cjs/fileStateFactory/fileSimulation/simulations.js +399 -0
  12. package/dist/cjs/fileStateFactory/index.js +76 -4
  13. package/dist/cjs/getAuthFromContextProvider.js +21 -23
  14. package/dist/cjs/index.js +72 -0
  15. package/dist/cjs/mediaPickerAuthProvider.js +22 -24
  16. package/dist/cjs/mocks/database/collection-item.js +5 -0
  17. package/dist/cjs/mocks/database/index.js +6 -0
  18. package/dist/cjs/mocks/routers/api-router.js +92 -98
  19. package/dist/cjs/story-list.js +1 -1
  20. package/dist/cjs/utils/logging.js +4 -4
  21. package/dist/cjs/version.json +1 -1
  22. package/dist/cjs/waitUntil.js +19 -21
  23. package/dist/es2019/fakeMediaClient.js +0 -5
  24. package/dist/es2019/fileStateFactory/{createFileState.js → factory/createFileState.js} +8 -17
  25. package/dist/es2019/fileStateFactory/{factory.js → factory/factory.js} +12 -2
  26. package/dist/es2019/fileStateFactory/factory/index.js +3 -0
  27. package/dist/es2019/fileStateFactory/fileSimulation/fileSimulation.js +63 -0
  28. package/dist/es2019/fileStateFactory/fileSimulation/index.js +2 -0
  29. package/dist/es2019/fileStateFactory/fileSimulation/simulations.js +148 -0
  30. package/dist/es2019/fileStateFactory/index.js +4 -2
  31. package/dist/es2019/index.js +5 -1
  32. package/dist/es2019/mocks/database/collection-item.js +1 -0
  33. package/dist/es2019/mocks/database/index.js +1 -1
  34. package/dist/es2019/mocks/routers/api-router.js +3 -3
  35. package/dist/es2019/utils/logging.js +3 -3
  36. package/dist/es2019/version.json +1 -1
  37. package/dist/esm/authProvider.js +25 -27
  38. package/dist/esm/await-error.js +17 -19
  39. package/dist/esm/fakeMediaClient.js +0 -5
  40. package/dist/esm/fileStateFactory/{createFileState.js → factory/createFileState.js} +8 -15
  41. package/dist/esm/fileStateFactory/{factory.js → factory/factory.js} +34 -25
  42. package/dist/esm/fileStateFactory/factory/index.js +3 -0
  43. package/dist/esm/fileStateFactory/fileSimulation/fileSimulation.js +81 -0
  44. package/dist/esm/fileStateFactory/fileSimulation/index.js +2 -0
  45. package/dist/esm/fileStateFactory/fileSimulation/simulations.js +382 -0
  46. package/dist/esm/fileStateFactory/index.js +4 -2
  47. package/dist/esm/getAuthFromContextProvider.js +21 -23
  48. package/dist/esm/index.js +5 -1
  49. package/dist/esm/mediaPickerAuthProvider.js +22 -24
  50. package/dist/esm/mocks/database/collection-item.js +3 -0
  51. package/dist/esm/mocks/database/index.js +1 -1
  52. package/dist/esm/mocks/routers/api-router.js +93 -99
  53. package/dist/esm/utils/logging.js +3 -3
  54. package/dist/esm/version.json +1 -1
  55. package/dist/esm/waitUntil.js +19 -21
  56. package/dist/types/fileStateFactory/{factory.d.ts → factory/factory.d.ts} +3 -0
  57. package/dist/types/fileStateFactory/factory/index.d.ts +4 -0
  58. package/dist/types/fileStateFactory/fileSimulation/fileSimulation.d.ts +18 -0
  59. package/dist/types/fileStateFactory/fileSimulation/index.d.ts +4 -0
  60. package/dist/types/fileStateFactory/fileSimulation/simulations.d.ts +35 -0
  61. package/dist/types/fileStateFactory/index.d.ts +7 -3
  62. package/dist/types/index.d.ts +2 -2
  63. package/dist/types/mocks/database/collection-item.d.ts +13 -1
  64. package/dist/types/mocks/database/collection.d.ts +4 -1
  65. package/dist/types/mocks/database/index.d.ts +2 -2
  66. package/package.json +4 -3
  67. package/report.api.md +90 -0
  68. /package/dist/cjs/fileStateFactory/{helpers.js → factory/helpers.js} +0 -0
  69. /package/dist/es2019/fileStateFactory/{helpers.js → factory/helpers.js} +0 -0
  70. /package/dist/esm/fileStateFactory/{helpers.js → factory/helpers.js} +0 -0
  71. /package/dist/types/fileStateFactory/{createFileState.d.ts → factory/createFileState.d.ts} +0 -0
  72. /package/dist/types/fileStateFactory/{helpers.d.ts → factory/helpers.d.ts} +0 -0
@@ -6,11 +6,16 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.createCollectionItem = createCollectionItem;
8
8
  exports.createEmptyCollectionItem = createEmptyCollectionItem;
9
+ exports.isMediaItemDetails = void 0;
9
10
  var uuid = _interopRequireWildcard(require("uuid"));
10
11
  var _mockData = require("../../utils/mockData");
11
12
  var _utils = require("../../utils");
12
13
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
14
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
+ var isMediaItemDetails = function isMediaItemDetails(mediaCollectionItem) {
16
+ return !!mediaCollectionItem['mediaType'] && !!mediaCollectionItem['mimeType'] && !!mediaCollectionItem['processingStatus'];
17
+ };
18
+ exports.isMediaItemDetails = isMediaItemDetails;
14
19
  function createEmptyCollectionItem(_ref) {
15
20
  var id = _ref.id,
16
21
  collectionName = _ref.collectionName,
@@ -23,6 +23,12 @@ Object.defineProperty(exports, "createEmptyCollectionItem", {
23
23
  return _collectionItem.createEmptyCollectionItem;
24
24
  }
25
25
  });
26
+ Object.defineProperty(exports, "isMediaItemDetails", {
27
+ enumerable: true,
28
+ get: function get() {
29
+ return _collectionItem.isMediaItemDetails;
30
+ }
31
+ });
26
32
  exports.userAuthProvider = exports.userAuth = exports.tenantAuthProvider = exports.tenantAuth = void 0;
27
33
  var _kakapo = require("kakapo");
28
34
  var _v = _interopRequireDefault(require("uuid/v4"));
@@ -28,7 +28,7 @@ var _utils = require("../../utils");
28
28
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
29
29
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
30
30
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
31
- 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; } }
31
+ 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; } } // eslint-disable-line no-console
32
32
  var RouterWithLogging = /*#__PURE__*/function (_Router) {
33
33
  (0, _inherits2.default)(RouterWithLogging, _Router);
34
34
  var _super = _createSuper(RouterWithLogging);
@@ -173,48 +173,46 @@ function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
173
173
  var _ref6 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(_ref5, database) {
174
174
  var params, fileId, record, defaultDimensions, dimensions;
175
175
  return _regenerator.default.wrap(function _callee$(_context) {
176
- while (1) {
177
- switch (_context.prev = _context.next) {
178
- case 0:
179
- params = _ref5.params;
180
- fileId = params.fileId;
181
- record = database.findOne('collectionItem', {
182
- id: fileId
176
+ while (1) switch (_context.prev = _context.next) {
177
+ case 0:
178
+ params = _ref5.params;
179
+ fileId = params.fileId;
180
+ record = database.findOne('collectionItem', {
181
+ id: fileId
182
+ });
183
+ defaultDimensions = {
184
+ height: 4096,
185
+ width: 4096
186
+ };
187
+ dimensions = Promise.resolve(defaultDimensions);
188
+ if (record && record.data.blob && !isSvgFile(record)) {
189
+ dimensions = new Promise(function (resolve) {
190
+ var image = new Image();
191
+ image.src = URL.createObjectURL(record.data.blob);
192
+ image.onload = function () {
193
+ return resolve({
194
+ height: image.height,
195
+ width: image.width
196
+ });
197
+ };
183
198
  });
184
- defaultDimensions = {
185
- height: 4096,
186
- width: 4096
187
- };
188
- dimensions = Promise.resolve(defaultDimensions);
189
- if (record && record.data.blob && !isSvgFile(record)) {
190
- dimensions = new Promise(function (resolve) {
191
- var image = new Image();
192
- image.src = URL.createObjectURL(record.data.blob);
193
- image.onload = function () {
194
- return resolve({
195
- height: image.height,
196
- width: image.width
197
- });
198
- };
199
- });
200
- }
201
- _context.t0 = {};
202
- _context.next = 9;
203
- return dimensions;
204
- case 9:
205
- _context.t1 = _context.sent;
206
- _context.t2 = {
207
- pending: false,
208
- preview: _context.t0,
209
- original: _context.t1
210
- };
211
- return _context.abrupt("return", {
212
- metadata: _context.t2
213
- });
214
- case 12:
215
- case "end":
216
- return _context.stop();
217
- }
199
+ }
200
+ _context.t0 = {};
201
+ _context.next = 9;
202
+ return dimensions;
203
+ case 9:
204
+ _context.t1 = _context.sent;
205
+ _context.t2 = {
206
+ pending: false,
207
+ preview: _context.t0,
208
+ original: _context.t1
209
+ };
210
+ return _context.abrupt("return", {
211
+ metadata: _context.t2
212
+ });
213
+ case 12:
214
+ case "end":
215
+ return _context.stop();
218
216
  }
219
217
  }, _callee);
220
218
  }));
@@ -257,25 +255,23 @@ function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
257
255
  function _awaitUpload() {
258
256
  _awaitUpload = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(resolver) {
259
257
  return _regenerator.default.wrap(function _callee3$(_context3) {
260
- while (1) {
261
- switch (_context3.prev = _context3.next) {
262
- case 0:
263
- return _context3.abrupt("return", new Promise(function (resolve) {
264
- if (window.mediaMockControlsBackdoor.shouldWaitUpload) {
265
- setTimeout(function () {
266
- return awaitUpload(resolver || resolve);
267
- }, 10);
268
- return;
269
- }
270
- if (resolver && !window.mediaMockControlsBackdoor.shouldWaitUpload) {
271
- resolver();
272
- }
273
- resolve();
274
- }));
275
- case 1:
276
- case "end":
277
- return _context3.stop();
278
- }
258
+ while (1) switch (_context3.prev = _context3.next) {
259
+ case 0:
260
+ return _context3.abrupt("return", new Promise(function (resolve) {
261
+ if (window.mediaMockControlsBackdoor.shouldWaitUpload) {
262
+ setTimeout(function () {
263
+ return awaitUpload(resolver || resolve);
264
+ }, 10);
265
+ return;
266
+ }
267
+ if (resolver && !window.mediaMockControlsBackdoor.shouldWaitUpload) {
268
+ resolver();
269
+ }
270
+ resolve();
271
+ }));
272
+ case 1:
273
+ case "end":
274
+ return _context3.stop();
279
275
  }
280
276
  }, _callee3);
281
277
  }));
@@ -285,42 +281,40 @@ function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
285
281
  var _ref10 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(_ref9, database) {
286
282
  var body, _JSON$parse2, chunks, allChunks, existingChunks, nonExistingChunks;
287
283
  return _regenerator.default.wrap(function _callee2$(_context2) {
288
- while (1) {
289
- switch (_context2.prev = _context2.next) {
290
- case 0:
291
- body = _ref9.body;
292
- _JSON$parse2 = JSON.parse(body), chunks = _JSON$parse2.chunks;
293
- allChunks = database.all('chunk');
294
- existingChunks = [];
295
- nonExistingChunks = [];
296
- allChunks.forEach(function (_ref11) {
297
- var id = _ref11.data.id;
298
- if (chunks.indexOf(id) > -1) {
299
- existingChunks.push(id);
300
- } else {
301
- nonExistingChunks.push(id);
302
- }
303
- });
304
- _context2.next = 8;
305
- return awaitUpload();
306
- case 8:
307
- return _context2.abrupt("return", {
308
- data: {
309
- results: [].concat((0, _toConsumableArray2.default)(existingChunks.map(function () {
310
- return {
311
- exists: true
312
- };
313
- })), (0, _toConsumableArray2.default)(nonExistingChunks.map(function () {
314
- return {
315
- exists: false
316
- };
317
- })))
318
- }
319
- });
320
- case 9:
321
- case "end":
322
- return _context2.stop();
323
- }
284
+ while (1) switch (_context2.prev = _context2.next) {
285
+ case 0:
286
+ body = _ref9.body;
287
+ _JSON$parse2 = JSON.parse(body), chunks = _JSON$parse2.chunks;
288
+ allChunks = database.all('chunk');
289
+ existingChunks = [];
290
+ nonExistingChunks = [];
291
+ allChunks.forEach(function (_ref11) {
292
+ var id = _ref11.data.id;
293
+ if (chunks.indexOf(id) > -1) {
294
+ existingChunks.push(id);
295
+ } else {
296
+ nonExistingChunks.push(id);
297
+ }
298
+ });
299
+ _context2.next = 8;
300
+ return awaitUpload();
301
+ case 8:
302
+ return _context2.abrupt("return", {
303
+ data: {
304
+ results: [].concat((0, _toConsumableArray2.default)(existingChunks.map(function () {
305
+ return {
306
+ exists: true
307
+ };
308
+ })), (0, _toConsumableArray2.default)(nonExistingChunks.map(function () {
309
+ return {
310
+ exists: false
311
+ };
312
+ })))
313
+ }
314
+ });
315
+ case 9:
316
+ case "end":
317
+ return _context2.stop();
324
318
  }
325
319
  }, _callee2);
326
320
  }));
@@ -516,7 +510,7 @@ function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
516
510
  id = _sourceRecord$data.id,
517
511
  details = _sourceRecord$data.details,
518
512
  blob = _sourceRecord$data.blob;
519
- var _ref19 = (0, _mediaClient.isMediaCollectionItemFullDetails)(details) ? details : {},
513
+ var _ref19 = (0, _database.isMediaItemDetails)(details) ? details : {},
520
514
  _ref19$name = _ref19.name,
521
515
  name = _ref19$name === void 0 ? (0, _mockData.getFakeFileName)(extension) : _ref19$name,
522
516
  _ref19$size = _ref19.size,
@@ -15,7 +15,7 @@ var _react = _interopRequireWildcard(require("react"));
15
15
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
16
16
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
17
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
18
- 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; } }
18
+ 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; } } // Simple component which wraps stories and creates a styled list out of it
19
19
  var styles = {
20
20
  column: {
21
21
  statesWrapper: {
@@ -6,12 +6,12 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.WsDirection = void 0;
7
7
  exports.logRequest = logRequest;
8
8
  exports.logWsMessage = logWsMessage;
9
- var WsDirection;
10
- exports.WsDirection = WsDirection;
11
- (function (WsDirection) {
9
+ var WsDirection = /*#__PURE__*/function (WsDirection) {
12
10
  WsDirection["Upstream"] = "UP";
13
11
  WsDirection["Downstream"] = "DOWN";
14
- })(WsDirection || (exports.WsDirection = WsDirection = {}));
12
+ return WsDirection;
13
+ }({});
14
+ exports.WsDirection = WsDirection;
15
15
  function logRequest(params) {
16
16
  var path = params.path,
17
17
  method = params.method,
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "@atlaskit/media-test-helpers",
3
- "version": "31.0.0"
3
+ "version": "32.1.0"
4
4
  }
@@ -17,29 +17,27 @@ function _waitUntil() {
17
17
  maxRetries,
18
18
  _args = arguments;
19
19
  return _regenerator.default.wrap(function _callee$(_context) {
20
- while (1) {
21
- switch (_context.prev = _context.next) {
22
- case 0:
23
- timeout = _args.length > 1 && _args[1] !== undefined ? _args[1] : 100;
24
- maxRetries = _args.length > 2 && _args[2] !== undefined ? _args[2] : 10;
25
- return _context.abrupt("return", new Promise(function (resolve, reject) {
26
- var check = function check(retry) {
27
- if (retry > 0) {
28
- if (predicate()) {
29
- resolve();
30
- } else {
31
- window.setTimeout(check, timeout, retry - 1);
32
- }
20
+ while (1) switch (_context.prev = _context.next) {
21
+ case 0:
22
+ timeout = _args.length > 1 && _args[1] !== undefined ? _args[1] : 100;
23
+ maxRetries = _args.length > 2 && _args[2] !== undefined ? _args[2] : 10;
24
+ return _context.abrupt("return", new Promise(function (resolve, reject) {
25
+ var check = function check(retry) {
26
+ if (retry > 0) {
27
+ if (predicate()) {
28
+ resolve();
33
29
  } else {
34
- reject('timed out');
30
+ window.setTimeout(check, timeout, retry - 1);
35
31
  }
36
- };
37
- check(maxRetries);
38
- }));
39
- case 3:
40
- case "end":
41
- return _context.stop();
42
- }
32
+ } else {
33
+ reject('timed out');
34
+ }
35
+ };
36
+ check(maxRetries);
37
+ }));
38
+ case 3:
39
+ case "end":
40
+ return _context.stop();
43
41
  }
44
42
  }, _callee);
45
43
  }));
@@ -1,4 +1,3 @@
1
- import { of } from 'rxjs/observable/of';
2
1
  import { MediaClient } from '@atlaskit/media-client';
3
2
  import { asMock } from './jestHelpers';
4
3
  import getJest from './getJest';
@@ -15,19 +14,16 @@ export const fakeMediaClient = (config = getDefaultMediaClientConfig()) => {
15
14
  const {
16
15
  MediaClient: MockMediaClient,
17
16
  FileFetcherImpl,
18
- CollectionFetcher,
19
17
  MediaStore: MockMediaStore,
20
18
  StargateClient
21
19
  } = jest.genMockFromModule('@atlaskit/media-client');
22
20
  const mediaClient = new MockMediaClient();
23
21
  const fileFetcher = new FileFetcherImpl();
24
- const collectionFetcher = new CollectionFetcher();
25
22
  const mockMediaStore = new MockMediaStore({
26
23
  authProvider: config.authProvider
27
24
  });
28
25
  const stargateClient = new StargateClient();
29
26
  mediaClient.file = fileFetcher;
30
- mediaClient.collection = collectionFetcher;
31
27
  mediaClient.stargate = stargateClient;
32
28
  mediaClient.config = config; // <- deprecated
33
29
  mediaClient.mediaClientConfig = config;
@@ -40,7 +36,6 @@ export const fakeMediaClient = (config = getDefaultMediaClientConfig()) => {
40
36
  asMock(mediaClient.getImageUrl).mockResolvedValue('some-image-url');
41
37
  asMock(mediaClient.getImageUrlSync).mockReturnValue('some-image-url');
42
38
  asMock(mediaClient.getImage).mockImplementation(mockMediaStore.getImage);
43
- asMock(mediaClient.collection.getItems).mockReturnValue(of([]));
44
39
  asMock(mediaClient.file.copyFile).mockReturnValue({
45
40
  id: 'copied-file-id'
46
41
  });
@@ -1,4 +1,4 @@
1
- import { tallImage } from '../';
1
+ import { tallImage } from '../..';
2
2
  const localPreview = {
3
3
  value: tallImage
4
4
  };
@@ -37,34 +37,25 @@ export const createFileState = (id, status, {
37
37
  id
38
38
  };
39
39
  switch (status) {
40
- case 'uploading':
41
- return {
42
- status: 'uploading',
43
- progress: 0,
44
- ...base
45
- };
46
40
  case 'processing':
47
- return {
48
- status: 'processing',
49
- ...base
50
- };
41
+ case 'failed-processing':
51
42
  case 'processed':
52
43
  return {
53
- status: 'processed',
54
- representations: remotePreview,
55
- artifacts: {},
44
+ status,
56
45
  ...base
57
46
  };
58
- case 'failed-processing':
47
+ case 'uploading':
59
48
  return {
60
- status: 'failed-processing',
49
+ status,
50
+ progress: 0,
61
51
  ...base
62
52
  };
63
53
  case 'error':
64
54
  default:
65
55
  return {
66
56
  id,
67
- status: 'error'
57
+ status: 'error',
58
+ message: 'This is a terrible error with a super long trace'
68
59
  };
69
60
  }
70
61
  };
@@ -1,19 +1,27 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import { tallImage, dataURItoBlob } from '..';
2
+ import { tallImage } from '../../images';
3
+ import { dataURItoBlob } from '../../mockData';
3
4
  import { MediaClient, createMediaSubject } from '@atlaskit/media-client';
4
5
  import { createFileState } from './createFileState';
5
6
  import { createFileDetails } from './helpers';
6
- import { sleep } from '../nextTick';
7
+ import { sleep } from '../../nextTick';
7
8
  export class MediaClientMock extends MediaClient {
8
9
  constructor(observable, mediaClientConfig, featureFlags, options = {}) {
9
10
  super(mediaClientConfig, featureFlags);
11
+ _defineProperty(this, "hasPreview", false);
10
12
  _defineProperty(this, "updateObserbable", newObservable => {
11
13
  this.observable = newObservable;
12
14
  });
15
+ _defineProperty(this, "setHasPreview", hasPreview => {
16
+ this.hasPreview = hasPreview;
17
+ });
13
18
  _defineProperty(this, "getImage", async () => {
14
19
  const {
15
20
  getImageDelay = 0
16
21
  } = this.options;
22
+ if (!this.hasPreview) {
23
+ throw new Error('some error');
24
+ }
17
25
  await sleep(getImageDelay);
18
26
  return dataURItoBlob(tallImage);
19
27
  });
@@ -23,6 +31,7 @@ export class MediaClientMock extends MediaClient {
23
31
  this.observable = observable;
24
32
  this.options = options;
25
33
  this.mockFileFetcher();
34
+ this.setHasPreview(!!options.hasPreview);
26
35
  }
27
36
  }
28
37
  const mockConfig = {
@@ -63,6 +72,7 @@ export class FileStateFactory {
63
72
  fileDetails: (options === null || options === void 0 ? void 0 : options.fileDetails) || this.fileDetails
64
73
  }));
65
74
  _defineProperty(this, "next", (status, options) => {
75
+ this.mediaClient.setHasPreview(!!(options !== null && options !== void 0 && options.withRemotePreview));
66
76
  this.subscription.next(this.createFileState(status, options));
67
77
  });
68
78
  _defineProperty(this, "error", error => {
@@ -0,0 +1,3 @@
1
+ export { FileStateFactory, MediaClientMock } from './factory';
2
+ export { createIdentifier, createFileDetails } from './helpers';
3
+ export { createFileState } from './createFileState';
@@ -0,0 +1,63 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { FileStateFactory, createIdentifier, createFileDetails } from '../factory';
3
+ const defaultDelay = 1500;
4
+ const useSimulationSettings = ({
5
+ mediaType,
6
+ mediaClientMockOptions = {}
7
+ } = {}) => {
8
+ const [identifier, setIdentifier] = useState(createIdentifier());
9
+ const [fileStateFactory] = useState(new FileStateFactory(identifier, {
10
+ fileDetails: createFileDetails(identifier.id, mediaType),
11
+ mediaClientMockOptions: {
12
+ // default options
13
+ getImageDelay: defaultDelay,
14
+ ...mediaClientMockOptions
15
+ }
16
+ }));
17
+ const [updateIdentifier] = useState(() => newMediaType => {
18
+ const newId = createIdentifier();
19
+ fileStateFactory.updateIdentifier(newId, createFileDetails(newId.id, newMediaType || mediaType));
20
+ setIdentifier(newId);
21
+ });
22
+ return {
23
+ fileStateFactory,
24
+ identifier,
25
+ updateIdentifier
26
+ };
27
+ };
28
+ export const useRunSimulation = (simulation, simulationSettings = {}) => {
29
+ const {
30
+ identifier,
31
+ fileStateFactory,
32
+ updateIdentifier
33
+ } = useSimulationSettings(simulationSettings);
34
+ const fileState = useSubscribeToFileState(identifier, fileStateFactory);
35
+ useEffect(() => {
36
+ simulation(fileStateFactory, {
37
+ updateIdentifier
38
+ });
39
+ }, [fileStateFactory, updateIdentifier, simulation]);
40
+ return {
41
+ identifier,
42
+ fileStateFactory,
43
+ fileState,
44
+ updateIdentifier
45
+ };
46
+ };
47
+ const useSubscribeToFileState = (identifier, fileStateFactory) => {
48
+ const [fileState, setFileState] = useState();
49
+ useEffect(() => {
50
+ const subscription = fileStateFactory.mediaClient.file.getFileState(identifier.id, {
51
+ ...identifier
52
+ }).subscribe({
53
+ next: filestate => setFileState(filestate),
54
+ error: () => setFileState({
55
+ status: 'subscription error'
56
+ })
57
+ });
58
+ return () => {
59
+ subscription.unsubscribe();
60
+ };
61
+ }, [fileStateFactory, identifier]);
62
+ return fileState;
63
+ };
@@ -0,0 +1,2 @@
1
+ export { useRunSimulation } from './fileSimulation';
2
+ export { simulateProcessed, simulateProcessing, simulateImmediateFailProcessing, simulateUpload, simulateError, simulateErrorState, simulateManyProcessed, simulateEmptyDetails, simulateUpdateFileId, simulateAlwaysLoading, simulateAlwaysProcessing } from './simulations';