@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.
- package/CHANGELOG.md +21 -0
- package/dist/cjs/authProvider.js +25 -27
- package/dist/cjs/await-error.js +17 -19
- package/dist/cjs/docs-content-tabs.js +1 -0
- package/dist/cjs/fakeMediaClient.js +0 -5
- package/dist/cjs/fileStateFactory/{createFileState.js → factory/createFileState.js} +8 -15
- package/dist/cjs/fileStateFactory/{factory.js → factory/factory.js} +34 -25
- package/dist/cjs/fileStateFactory/factory/index.js +38 -0
- package/dist/cjs/fileStateFactory/fileSimulation/fileSimulation.js +89 -0
- package/dist/cjs/fileStateFactory/fileSimulation/index.js +79 -0
- package/dist/cjs/fileStateFactory/fileSimulation/simulations.js +399 -0
- package/dist/cjs/fileStateFactory/index.js +76 -4
- package/dist/cjs/getAuthFromContextProvider.js +21 -23
- package/dist/cjs/index.js +72 -0
- package/dist/cjs/mediaPickerAuthProvider.js +22 -24
- package/dist/cjs/mocks/database/collection-item.js +5 -0
- package/dist/cjs/mocks/database/index.js +6 -0
- package/dist/cjs/mocks/routers/api-router.js +92 -98
- package/dist/cjs/story-list.js +1 -1
- package/dist/cjs/utils/logging.js +4 -4
- package/dist/cjs/version.json +1 -1
- package/dist/cjs/waitUntil.js +19 -21
- package/dist/es2019/fakeMediaClient.js +0 -5
- package/dist/es2019/fileStateFactory/{createFileState.js → factory/createFileState.js} +8 -17
- package/dist/es2019/fileStateFactory/{factory.js → factory/factory.js} +12 -2
- package/dist/es2019/fileStateFactory/factory/index.js +3 -0
- package/dist/es2019/fileStateFactory/fileSimulation/fileSimulation.js +63 -0
- package/dist/es2019/fileStateFactory/fileSimulation/index.js +2 -0
- package/dist/es2019/fileStateFactory/fileSimulation/simulations.js +148 -0
- package/dist/es2019/fileStateFactory/index.js +4 -2
- package/dist/es2019/index.js +5 -1
- package/dist/es2019/mocks/database/collection-item.js +1 -0
- package/dist/es2019/mocks/database/index.js +1 -1
- package/dist/es2019/mocks/routers/api-router.js +3 -3
- package/dist/es2019/utils/logging.js +3 -3
- package/dist/es2019/version.json +1 -1
- package/dist/esm/authProvider.js +25 -27
- package/dist/esm/await-error.js +17 -19
- package/dist/esm/fakeMediaClient.js +0 -5
- package/dist/esm/fileStateFactory/{createFileState.js → factory/createFileState.js} +8 -15
- package/dist/esm/fileStateFactory/{factory.js → factory/factory.js} +34 -25
- package/dist/esm/fileStateFactory/factory/index.js +3 -0
- package/dist/esm/fileStateFactory/fileSimulation/fileSimulation.js +81 -0
- package/dist/esm/fileStateFactory/fileSimulation/index.js +2 -0
- package/dist/esm/fileStateFactory/fileSimulation/simulations.js +382 -0
- package/dist/esm/fileStateFactory/index.js +4 -2
- package/dist/esm/getAuthFromContextProvider.js +21 -23
- package/dist/esm/index.js +5 -1
- package/dist/esm/mediaPickerAuthProvider.js +22 -24
- package/dist/esm/mocks/database/collection-item.js +3 -0
- package/dist/esm/mocks/database/index.js +1 -1
- package/dist/esm/mocks/routers/api-router.js +93 -99
- package/dist/esm/utils/logging.js +3 -3
- package/dist/esm/version.json +1 -1
- package/dist/esm/waitUntil.js +19 -21
- package/dist/types/fileStateFactory/{factory.d.ts → factory/factory.d.ts} +3 -0
- package/dist/types/fileStateFactory/factory/index.d.ts +4 -0
- package/dist/types/fileStateFactory/fileSimulation/fileSimulation.d.ts +18 -0
- package/dist/types/fileStateFactory/fileSimulation/index.d.ts +4 -0
- package/dist/types/fileStateFactory/fileSimulation/simulations.d.ts +35 -0
- package/dist/types/fileStateFactory/index.d.ts +7 -3
- package/dist/types/index.d.ts +2 -2
- package/dist/types/mocks/database/collection-item.d.ts +13 -1
- package/dist/types/mocks/database/collection.d.ts +4 -1
- package/dist/types/mocks/database/index.d.ts +2 -2
- package/package.json +4 -3
- package/report.api.md +90 -0
- /package/dist/cjs/fileStateFactory/{helpers.js → factory/helpers.js} +0 -0
- /package/dist/es2019/fileStateFactory/{helpers.js → factory/helpers.js} +0 -0
- /package/dist/esm/fileStateFactory/{helpers.js → factory/helpers.js} +0 -0
- /package/dist/types/fileStateFactory/{createFileState.d.ts → factory/createFileState.d.ts} +0 -0
- /package/dist/types/fileStateFactory/{helpers.d.ts → factory/helpers.d.ts} +0 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { sleep } from '../../nextTick';
|
|
2
|
+
const speed = 1500;
|
|
3
|
+
/**
|
|
4
|
+
* Normal File Flow
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export const simulateProcessed = (withRemotePreview = false) => ({
|
|
8
|
+
simulation: async factory => {
|
|
9
|
+
await sleep(speed);
|
|
10
|
+
factory.next('processed', {
|
|
11
|
+
withRemotePreview
|
|
12
|
+
});
|
|
13
|
+
},
|
|
14
|
+
description: `File state is processed ${withRemotePreview ? 'with' : 'without'} remote preview`
|
|
15
|
+
});
|
|
16
|
+
export const simulateProcessing = (suceeded = true, withRemotePreview = true) => ({
|
|
17
|
+
description: `File is processing, then ${suceeded ? 'succeeds' : 'fails'} ${withRemotePreview ? 'with' : 'without'} remote preview`,
|
|
18
|
+
simulation: async factory => {
|
|
19
|
+
await sleep(speed);
|
|
20
|
+
factory.next('processing');
|
|
21
|
+
await sleep(speed);
|
|
22
|
+
factory.next('processing');
|
|
23
|
+
await sleep(speed * 0.5);
|
|
24
|
+
if (!suceeded) {
|
|
25
|
+
factory.next('failed-processing', {
|
|
26
|
+
withRemotePreview
|
|
27
|
+
});
|
|
28
|
+
} else {
|
|
29
|
+
factory.next('processed', {
|
|
30
|
+
withRemotePreview
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
export const simulateImmediateFailProcessing = () => ({
|
|
36
|
+
description: 'The first sate is failed-processing with no preview',
|
|
37
|
+
simulation: async factory => {
|
|
38
|
+
await sleep(speed);
|
|
39
|
+
factory.next('failed-processing');
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
export const simulateUpload = (withLocalPreview, suceeded = true) => ({
|
|
43
|
+
description: '',
|
|
44
|
+
simulation: async factory => {
|
|
45
|
+
const chunks = 3;
|
|
46
|
+
const chunkUploadDelay = 500;
|
|
47
|
+
const processingTime = speed;
|
|
48
|
+
await sleep(speed);
|
|
49
|
+
factory.next('uploading', {
|
|
50
|
+
withLocalPreview
|
|
51
|
+
});
|
|
52
|
+
const uploadUpTo = !suceeded ? chunks / 2 : chunks;
|
|
53
|
+
for (let index = 0; index <= uploadUpTo; index++) {
|
|
54
|
+
factory.next('uploading', {
|
|
55
|
+
uploadProgress: index / chunks,
|
|
56
|
+
withLocalPreview
|
|
57
|
+
});
|
|
58
|
+
await sleep(chunkUploadDelay);
|
|
59
|
+
}
|
|
60
|
+
if (!suceeded) {
|
|
61
|
+
factory.error(new Error('some-error'));
|
|
62
|
+
}
|
|
63
|
+
factory.next('processing', {
|
|
64
|
+
withLocalPreview
|
|
65
|
+
});
|
|
66
|
+
await sleep(processingTime);
|
|
67
|
+
factory.next('processed', {
|
|
68
|
+
withLocalPreview
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
export const simulateErrorState = () => ({
|
|
73
|
+
description: 'File state is error',
|
|
74
|
+
simulation: async factory => {
|
|
75
|
+
await sleep(speed);
|
|
76
|
+
factory.next('error');
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
export const simulateError = () => ({
|
|
80
|
+
description: 'Subscription throws an error through the observer',
|
|
81
|
+
simulation: async factory => {
|
|
82
|
+
await sleep(speed);
|
|
83
|
+
factory.error(new Error('error thrown from client'));
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Rare Cases
|
|
89
|
+
*/
|
|
90
|
+
|
|
91
|
+
export const simulateManyProcessed = (withRemotePreview = false) => ({
|
|
92
|
+
description: '',
|
|
93
|
+
simulation: async factory => {
|
|
94
|
+
await sleep(speed);
|
|
95
|
+
factory.next('processed', {
|
|
96
|
+
withRemotePreview
|
|
97
|
+
});
|
|
98
|
+
await sleep(speed);
|
|
99
|
+
factory.next('processed', {
|
|
100
|
+
withRemotePreview
|
|
101
|
+
});
|
|
102
|
+
await sleep(speed);
|
|
103
|
+
factory.next('processed', {
|
|
104
|
+
withRemotePreview
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
export const simulateEmptyDetails = () => ({
|
|
109
|
+
description: 'Incomplete uploads return empty file details and a processing status pending',
|
|
110
|
+
simulation: async factory => {
|
|
111
|
+
const emptyDetails = {
|
|
112
|
+
createdAt: 1630986510989
|
|
113
|
+
};
|
|
114
|
+
await sleep(speed);
|
|
115
|
+
factory.next('processing', {
|
|
116
|
+
fileDetails: emptyDetails
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
export const simulateUpdateFileId = () => ({
|
|
121
|
+
description: 'First File Id: video with processing issue. Next File Id: PDF sucessfully processed',
|
|
122
|
+
simulation: async (factory, {
|
|
123
|
+
updateIdentifier
|
|
124
|
+
}) => {
|
|
125
|
+
await sleep(speed);
|
|
126
|
+
factory.next('failed-processing');
|
|
127
|
+
await sleep(speed);
|
|
128
|
+
updateIdentifier('doc');
|
|
129
|
+
await sleep(speed);
|
|
130
|
+
factory.next('processing');
|
|
131
|
+
await sleep(speed);
|
|
132
|
+
factory.next('processed');
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
export const simulateAlwaysLoading = () => ({
|
|
136
|
+
description: 'File state never fetched',
|
|
137
|
+
simulation: async () => {}
|
|
138
|
+
});
|
|
139
|
+
export const simulateAlwaysProcessing = () => ({
|
|
140
|
+
description: 'File state is permanently processing',
|
|
141
|
+
simulation: async factory => {
|
|
142
|
+
await sleep(speed);
|
|
143
|
+
factory.next('processing');
|
|
144
|
+
await sleep(speed);
|
|
145
|
+
factory.next('processing');
|
|
146
|
+
await sleep(speed * 0.5);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { FileStateFactory, MediaClientMock } from './factory';
|
|
2
|
-
export { createIdentifier, createFileDetails } from './
|
|
3
|
-
export { createFileState } from './createFileState';
|
|
2
|
+
export { createIdentifier, createFileDetails } from './factory';
|
|
3
|
+
export { createFileState } from './factory/createFileState';
|
|
4
|
+
export { useRunSimulation } from './fileSimulation';
|
|
5
|
+
export { simulateProcessed, simulateProcessing, simulateImmediateFailProcessing, simulateUpload, simulateError, simulateErrorState, simulateManyProcessed, simulateEmptyDetails, simulateUpdateFileId, simulateAlwaysLoading, simulateAlwaysProcessing } from './fileSimulation';
|
package/dist/es2019/index.js
CHANGED
|
@@ -37,5 +37,9 @@ export { dataURItoBlob } from './mockData/utils';
|
|
|
37
37
|
export { mapDataUriToBlob } from './utils/index';
|
|
38
38
|
export { createPollingMaxAttemptsError, createRateLimitedError, createMediaStoreError } from './mediaClientErrors';
|
|
39
39
|
export { default as FeatureFlagsWrapper } from './featureFlagsWrapper';
|
|
40
|
-
export {
|
|
40
|
+
export {
|
|
41
|
+
// Simulation tools
|
|
42
|
+
FileStateFactory, MediaClientMock, createIdentifier, createFileDetails, createFileState, useRunSimulation,
|
|
43
|
+
// Predefined simulations
|
|
44
|
+
simulateProcessed, simulateProcessing, simulateImmediateFailProcessing, simulateUpload, simulateError, simulateErrorState, simulateManyProcessed, simulateEmptyDetails, simulateUpdateFileId, simulateAlwaysLoading, simulateAlwaysProcessing } from './fileStateFactory';
|
|
41
45
|
export { DocsContentTabs } from './docs-content-tabs';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as uuid from 'uuid';
|
|
2
2
|
import { getHackerNoun, getPastDate, fakeImage, getFakeFileName, getTextFileType } from '../../utils/mockData';
|
|
3
3
|
import { mapDataUriToBlob } from '../../utils';
|
|
4
|
+
export const isMediaItemDetails = mediaCollectionItem => !!mediaCollectionItem['mediaType'] && !!mediaCollectionItem['mimeType'] && !!mediaCollectionItem['processingStatus'];
|
|
4
5
|
export function createEmptyCollectionItem({
|
|
5
6
|
id,
|
|
6
7
|
collectionName,
|
|
@@ -8,7 +8,7 @@ import { defaultBaseUrl } from '../../mediaClientProvider';
|
|
|
8
8
|
import { defaultCollectionName } from '../../collectionNames';
|
|
9
9
|
import { RECENTS_COLLECTION } from '@atlaskit/media-client/constants';
|
|
10
10
|
export { createCollection } from './collection';
|
|
11
|
-
export { createCollectionItem, createEmptyCollectionItem } from './collection-item';
|
|
11
|
+
export { createCollectionItem, createEmptyCollectionItem, isMediaItemDetails } from './collection-item';
|
|
12
12
|
export const tenantAuth = {
|
|
13
13
|
clientId: uuidV4(),
|
|
14
14
|
token: 'some-tenant-token',
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// eslint-disable-line no-console
|
|
2
2
|
import { Router, KakapoResponse } from 'kakapo';
|
|
3
3
|
import uuid from 'uuid/v4';
|
|
4
|
-
import { getMediaTypeFromMimeType
|
|
5
|
-
import { createCollection, createCollectionItem, createEmptyCollectionItem } from '../database';
|
|
4
|
+
import { getMediaTypeFromMimeType } from '@atlaskit/media-client';
|
|
5
|
+
import { createCollection, createCollectionItem, createEmptyCollectionItem, isMediaItemDetails } from '../database';
|
|
6
6
|
import { vrVideoDetails } from '../../exampleMediaItems';
|
|
7
7
|
import { defaultBaseUrl } from '../../mediaClientProvider';
|
|
8
8
|
import { createUpload } from '../database/upload';
|
|
@@ -514,7 +514,7 @@ export function createApiRouter(isSlowServer, urlsReturnErrorsTo) {
|
|
|
514
514
|
image: {}
|
|
515
515
|
},
|
|
516
516
|
createdAt = -1
|
|
517
|
-
} =
|
|
517
|
+
} = isMediaItemDetails(details) ? details : {};
|
|
518
518
|
database.update('collectionItem', existingRecord.id, {
|
|
519
519
|
id: replaceFileId,
|
|
520
520
|
insertedAt: sourceRecord.data.insertedAt,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export let WsDirection
|
|
2
|
-
(function (WsDirection) {
|
|
1
|
+
export let WsDirection = /*#__PURE__*/function (WsDirection) {
|
|
3
2
|
WsDirection["Upstream"] = "UP";
|
|
4
3
|
WsDirection["Downstream"] = "DOWN";
|
|
5
|
-
|
|
4
|
+
return WsDirection;
|
|
5
|
+
}({});
|
|
6
6
|
export function logRequest(params) {
|
|
7
7
|
const {
|
|
8
8
|
path,
|
package/dist/es2019/version.json
CHANGED
package/dist/esm/authProvider.js
CHANGED
|
@@ -16,33 +16,31 @@ export var StoryBookAuthProvider = /*#__PURE__*/function () {
|
|
|
16
16
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(collectionName) {
|
|
17
17
|
var environment, headers, config, url, response;
|
|
18
18
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
19
|
-
while (1) {
|
|
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
|
-
return _context.stop();
|
|
45
|
-
}
|
|
19
|
+
while (1) switch (_context.prev = _context.next) {
|
|
20
|
+
case 0:
|
|
21
|
+
environment = isAsapEnvironment ? 'asap' : '';
|
|
22
|
+
headers = new Headers();
|
|
23
|
+
headers.append('Content-Type', 'application/json; charset=utf-8');
|
|
24
|
+
headers.append('Accept', 'text/plain, */*; q=0.01');
|
|
25
|
+
config = {
|
|
26
|
+
method: 'POST',
|
|
27
|
+
headers: headers,
|
|
28
|
+
body: access ? JSON.stringify({
|
|
29
|
+
access: access
|
|
30
|
+
}) : undefined
|
|
31
|
+
};
|
|
32
|
+
url = "".concat(authProviderBaseURL, "/token/tenant?collection=").concat(collectionName, "&environment=").concat(environment);
|
|
33
|
+
response = fetch(url, config); // We leverage the fact, that our internal /toke/tenant API returns data in the same format as Auth
|
|
34
|
+
_context.next = 9;
|
|
35
|
+
return response;
|
|
36
|
+
case 9:
|
|
37
|
+
_context.next = 11;
|
|
38
|
+
return _context.sent.json();
|
|
39
|
+
case 11:
|
|
40
|
+
return _context.abrupt("return", _context.sent);
|
|
41
|
+
case 12:
|
|
42
|
+
case "end":
|
|
43
|
+
return _context.stop();
|
|
46
44
|
}
|
|
47
45
|
}, _callee);
|
|
48
46
|
}));
|
package/dist/esm/await-error.js
CHANGED
|
@@ -6,27 +6,25 @@ export function awaitError(_x, _x2) {
|
|
|
6
6
|
function _awaitError() {
|
|
7
7
|
_awaitError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(response, expectedMessage) {
|
|
8
8
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
9
|
-
while (1) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
while (1) switch (_context.prev = _context.next) {
|
|
10
|
+
case 0:
|
|
11
|
+
_context.prev = 0;
|
|
12
|
+
_context.next = 3;
|
|
13
|
+
return response;
|
|
14
|
+
case 3:
|
|
15
|
+
_context.next = 9;
|
|
16
|
+
break;
|
|
17
|
+
case 5:
|
|
18
|
+
_context.prev = 5;
|
|
19
|
+
_context.t0 = _context["catch"](0);
|
|
20
|
+
if (!(_context.t0 instanceof Error && _context.t0.message !== expectedMessage)) {
|
|
16
21
|
_context.next = 9;
|
|
17
22
|
break;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
break;
|
|
24
|
-
}
|
|
25
|
-
throw _context.t0;
|
|
26
|
-
case 9:
|
|
27
|
-
case "end":
|
|
28
|
-
return _context.stop();
|
|
29
|
-
}
|
|
23
|
+
}
|
|
24
|
+
throw _context.t0;
|
|
25
|
+
case 9:
|
|
26
|
+
case "end":
|
|
27
|
+
return _context.stop();
|
|
30
28
|
}
|
|
31
29
|
}, _callee, null, [[0, 5]]);
|
|
32
30
|
}));
|
|
@@ -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';
|
|
@@ -18,18 +17,15 @@ export var fakeMediaClient = function fakeMediaClient() {
|
|
|
18
17
|
var _jest$genMockFromModu = jest.genMockFromModule('@atlaskit/media-client'),
|
|
19
18
|
MockMediaClient = _jest$genMockFromModu.MediaClient,
|
|
20
19
|
FileFetcherImpl = _jest$genMockFromModu.FileFetcherImpl,
|
|
21
|
-
CollectionFetcher = _jest$genMockFromModu.CollectionFetcher,
|
|
22
20
|
MockMediaStore = _jest$genMockFromModu.MediaStore,
|
|
23
21
|
StargateClient = _jest$genMockFromModu.StargateClient;
|
|
24
22
|
var mediaClient = new MockMediaClient();
|
|
25
23
|
var fileFetcher = new FileFetcherImpl();
|
|
26
|
-
var collectionFetcher = new CollectionFetcher();
|
|
27
24
|
var mockMediaStore = new MockMediaStore({
|
|
28
25
|
authProvider: config.authProvider
|
|
29
26
|
});
|
|
30
27
|
var stargateClient = new StargateClient();
|
|
31
28
|
mediaClient.file = fileFetcher;
|
|
32
|
-
mediaClient.collection = collectionFetcher;
|
|
33
29
|
mediaClient.stargate = stargateClient;
|
|
34
30
|
mediaClient.config = config; // <- deprecated
|
|
35
31
|
mediaClient.mediaClientConfig = config;
|
|
@@ -42,7 +38,6 @@ export var fakeMediaClient = function fakeMediaClient() {
|
|
|
42
38
|
asMock(mediaClient.getImageUrl).mockResolvedValue('some-image-url');
|
|
43
39
|
asMock(mediaClient.getImageUrlSync).mockReturnValue('some-image-url');
|
|
44
40
|
asMock(mediaClient.getImage).mockImplementation(mockMediaStore.getImage);
|
|
45
|
-
asMock(mediaClient.collection.getItems).mockReturnValue(of([]));
|
|
46
41
|
asMock(mediaClient.file.copyFile).mockReturnValue({
|
|
47
42
|
id: 'copied-file-id'
|
|
48
43
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
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; }
|
|
3
3
|
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) { _defineProperty(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; }
|
|
4
|
-
import { tallImage } from '
|
|
4
|
+
import { tallImage } from '../..';
|
|
5
5
|
var localPreview = {
|
|
6
6
|
value: tallImage
|
|
7
7
|
};
|
|
@@ -38,30 +38,23 @@ export var createFileState = function createFileState(id, status) {
|
|
|
38
38
|
id: id
|
|
39
39
|
});
|
|
40
40
|
switch (status) {
|
|
41
|
-
case 'uploading':
|
|
42
|
-
return _objectSpread({
|
|
43
|
-
status: 'uploading',
|
|
44
|
-
progress: 0
|
|
45
|
-
}, base);
|
|
46
41
|
case 'processing':
|
|
47
|
-
|
|
48
|
-
status: 'processing'
|
|
49
|
-
}, base);
|
|
42
|
+
case 'failed-processing':
|
|
50
43
|
case 'processed':
|
|
51
44
|
return _objectSpread({
|
|
52
|
-
status:
|
|
53
|
-
representations: remotePreview,
|
|
54
|
-
artifacts: {}
|
|
45
|
+
status: status
|
|
55
46
|
}, base);
|
|
56
|
-
case '
|
|
47
|
+
case 'uploading':
|
|
57
48
|
return _objectSpread({
|
|
58
|
-
status:
|
|
49
|
+
status: status,
|
|
50
|
+
progress: 0
|
|
59
51
|
}, base);
|
|
60
52
|
case 'error':
|
|
61
53
|
default:
|
|
62
54
|
return {
|
|
63
55
|
id: id,
|
|
64
|
-
status: 'error'
|
|
56
|
+
status: 'error',
|
|
57
|
+
message: 'This is a terrible error with a super long trace'
|
|
65
58
|
};
|
|
66
59
|
}
|
|
67
60
|
};
|
|
@@ -11,11 +11,12 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
11
11
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
12
12
|
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); }; }
|
|
13
13
|
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; } }
|
|
14
|
-
import { tallImage
|
|
14
|
+
import { tallImage } from '../../images';
|
|
15
|
+
import { dataURItoBlob } from '../../mockData';
|
|
15
16
|
import { MediaClient, createMediaSubject } from '@atlaskit/media-client';
|
|
16
17
|
import { createFileState } from './createFileState';
|
|
17
18
|
import { createFileDetails } from './helpers';
|
|
18
|
-
import { sleep } from '
|
|
19
|
+
import { sleep } from '../../nextTick';
|
|
19
20
|
export var MediaClientMock = /*#__PURE__*/function (_MediaClient) {
|
|
20
21
|
_inherits(MediaClientMock, _MediaClient);
|
|
21
22
|
var _super = _createSuper(MediaClientMock);
|
|
@@ -24,24 +25,32 @@ export var MediaClientMock = /*#__PURE__*/function (_MediaClient) {
|
|
|
24
25
|
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
25
26
|
_classCallCheck(this, MediaClientMock);
|
|
26
27
|
_this = _super.call(this, mediaClientConfig, featureFlags);
|
|
28
|
+
_defineProperty(_assertThisInitialized(_this), "hasPreview", false);
|
|
27
29
|
_defineProperty(_assertThisInitialized(_this), "updateObserbable", function (newObservable) {
|
|
28
30
|
_this.observable = newObservable;
|
|
29
31
|
});
|
|
32
|
+
_defineProperty(_assertThisInitialized(_this), "setHasPreview", function (hasPreview) {
|
|
33
|
+
_this.hasPreview = hasPreview;
|
|
34
|
+
});
|
|
30
35
|
_defineProperty(_assertThisInitialized(_this), "getImage", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
31
36
|
var _this$options$getImag, getImageDelay;
|
|
32
37
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
33
|
-
while (1) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
while (1) switch (_context.prev = _context.next) {
|
|
39
|
+
case 0:
|
|
40
|
+
_this$options$getImag = _this.options.getImageDelay, getImageDelay = _this$options$getImag === void 0 ? 0 : _this$options$getImag;
|
|
41
|
+
if (_this.hasPreview) {
|
|
37
42
|
_context.next = 3;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
throw new Error('some error');
|
|
46
|
+
case 3:
|
|
47
|
+
_context.next = 5;
|
|
48
|
+
return sleep(getImageDelay);
|
|
49
|
+
case 5:
|
|
50
|
+
return _context.abrupt("return", dataURItoBlob(tallImage));
|
|
51
|
+
case 6:
|
|
52
|
+
case "end":
|
|
53
|
+
return _context.stop();
|
|
45
54
|
}
|
|
46
55
|
}, _callee);
|
|
47
56
|
})));
|
|
@@ -53,6 +62,7 @@ export var MediaClientMock = /*#__PURE__*/function (_MediaClient) {
|
|
|
53
62
|
_this.observable = observable;
|
|
54
63
|
_this.options = options;
|
|
55
64
|
_this.mockFileFetcher();
|
|
65
|
+
_this.setHasPreview(!!options.hasPreview);
|
|
56
66
|
return _this;
|
|
57
67
|
}
|
|
58
68
|
return _createClass(MediaClientMock);
|
|
@@ -61,18 +71,16 @@ var mockConfig = {
|
|
|
61
71
|
authProvider: function () {
|
|
62
72
|
var _authProvider = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
63
73
|
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
64
|
-
while (1) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return _context2.stop();
|
|
75
|
-
}
|
|
74
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
75
|
+
case 0:
|
|
76
|
+
return _context2.abrupt("return", {
|
|
77
|
+
clientId: 'some-client',
|
|
78
|
+
token: 'some-token',
|
|
79
|
+
baseUrl: 'some-url'
|
|
80
|
+
});
|
|
81
|
+
case 1:
|
|
82
|
+
case "end":
|
|
83
|
+
return _context2.stop();
|
|
76
84
|
}
|
|
77
85
|
}, _callee2);
|
|
78
86
|
}));
|
|
@@ -116,6 +124,7 @@ export var FileStateFactory = /*#__PURE__*/_createClass(function FileStateFactor
|
|
|
116
124
|
}));
|
|
117
125
|
});
|
|
118
126
|
_defineProperty(this, "next", function (status, options) {
|
|
127
|
+
_this2.mediaClient.setHasPreview(!!(options !== null && options !== void 0 && options.withRemotePreview));
|
|
119
128
|
_this2.subscription.next(_this2.createFileState(status, options));
|
|
120
129
|
});
|
|
121
130
|
_defineProperty(this, "error", function (error) {
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
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; }
|
|
4
|
+
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) { _defineProperty(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; }
|
|
5
|
+
import { useEffect, useState } from 'react';
|
|
6
|
+
import { FileStateFactory, createIdentifier, createFileDetails } from '../factory';
|
|
7
|
+
var defaultDelay = 1500;
|
|
8
|
+
var useSimulationSettings = function useSimulationSettings() {
|
|
9
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
10
|
+
mediaType = _ref.mediaType,
|
|
11
|
+
_ref$mediaClientMockO = _ref.mediaClientMockOptions,
|
|
12
|
+
mediaClientMockOptions = _ref$mediaClientMockO === void 0 ? {} : _ref$mediaClientMockO;
|
|
13
|
+
var _useState = useState(createIdentifier()),
|
|
14
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
15
|
+
identifier = _useState2[0],
|
|
16
|
+
setIdentifier = _useState2[1];
|
|
17
|
+
var _useState3 = useState(new FileStateFactory(identifier, {
|
|
18
|
+
fileDetails: createFileDetails(identifier.id, mediaType),
|
|
19
|
+
mediaClientMockOptions: _objectSpread({
|
|
20
|
+
// default options
|
|
21
|
+
getImageDelay: defaultDelay
|
|
22
|
+
}, mediaClientMockOptions)
|
|
23
|
+
})),
|
|
24
|
+
_useState4 = _slicedToArray(_useState3, 1),
|
|
25
|
+
fileStateFactory = _useState4[0];
|
|
26
|
+
var _useState5 = useState(function () {
|
|
27
|
+
return function (newMediaType) {
|
|
28
|
+
var newId = createIdentifier();
|
|
29
|
+
fileStateFactory.updateIdentifier(newId, createFileDetails(newId.id, newMediaType || mediaType));
|
|
30
|
+
setIdentifier(newId);
|
|
31
|
+
};
|
|
32
|
+
}),
|
|
33
|
+
_useState6 = _slicedToArray(_useState5, 1),
|
|
34
|
+
updateIdentifier = _useState6[0];
|
|
35
|
+
return {
|
|
36
|
+
fileStateFactory: fileStateFactory,
|
|
37
|
+
identifier: identifier,
|
|
38
|
+
updateIdentifier: updateIdentifier
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
export var useRunSimulation = function useRunSimulation(simulation) {
|
|
42
|
+
var simulationSettings = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
43
|
+
var _useSimulationSetting = useSimulationSettings(simulationSettings),
|
|
44
|
+
identifier = _useSimulationSetting.identifier,
|
|
45
|
+
fileStateFactory = _useSimulationSetting.fileStateFactory,
|
|
46
|
+
updateIdentifier = _useSimulationSetting.updateIdentifier;
|
|
47
|
+
var fileState = useSubscribeToFileState(identifier, fileStateFactory);
|
|
48
|
+
useEffect(function () {
|
|
49
|
+
simulation(fileStateFactory, {
|
|
50
|
+
updateIdentifier: updateIdentifier
|
|
51
|
+
});
|
|
52
|
+
}, [fileStateFactory, updateIdentifier, simulation]);
|
|
53
|
+
return {
|
|
54
|
+
identifier: identifier,
|
|
55
|
+
fileStateFactory: fileStateFactory,
|
|
56
|
+
fileState: fileState,
|
|
57
|
+
updateIdentifier: updateIdentifier
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
var useSubscribeToFileState = function useSubscribeToFileState(identifier, fileStateFactory) {
|
|
61
|
+
var _useState7 = useState(),
|
|
62
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
63
|
+
fileState = _useState8[0],
|
|
64
|
+
setFileState = _useState8[1];
|
|
65
|
+
useEffect(function () {
|
|
66
|
+
var subscription = fileStateFactory.mediaClient.file.getFileState(identifier.id, _objectSpread({}, identifier)).subscribe({
|
|
67
|
+
next: function next(filestate) {
|
|
68
|
+
return setFileState(filestate);
|
|
69
|
+
},
|
|
70
|
+
error: function error() {
|
|
71
|
+
return setFileState({
|
|
72
|
+
status: 'subscription error'
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
return function () {
|
|
77
|
+
subscription.unsubscribe();
|
|
78
|
+
};
|
|
79
|
+
}, [fileStateFactory, identifier]);
|
|
80
|
+
return fileState;
|
|
81
|
+
};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { useRunSimulation } from './fileSimulation';
|
|
2
|
+
export { simulateProcessed, simulateProcessing, simulateImmediateFailProcessing, simulateUpload, simulateError, simulateErrorState, simulateManyProcessed, simulateEmptyDetails, simulateUpdateFileId, simulateAlwaysLoading, simulateAlwaysProcessing } from './simulations';
|