@atlaskit/media-test-helpers 28.8.1 → 29.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 +77 -0
- package/dist/cjs/I18nWrapper.js +3 -17
- package/dist/cjs/MockGlobalImage.js +4 -2
- package/dist/cjs/clipboardEventMocks.js +2 -2
- package/dist/cjs/collectionNames.js +1 -1
- package/dist/cjs/example-mediaFeatureFlags.js +2 -2
- package/dist/cjs/exampleMediaItems.js +1 -1
- package/dist/cjs/fakeMediaClient.js +2 -1
- package/dist/cjs/featureFlagsWrapper/dropdown.js +5 -5
- package/dist/cjs/featureFlagsWrapper/helpers.js +3 -3
- package/dist/cjs/fileReader.js +6 -5
- package/dist/cjs/fileStateFactory/createFileState.js +93 -0
- package/dist/cjs/fileStateFactory/factory.js +174 -0
- package/dist/cjs/fileStateFactory/helpers.js +110 -0
- package/dist/cjs/fileStateFactory/index.js +41 -0
- package/dist/cjs/images.js +7 -7
- package/dist/cjs/index.js +309 -259
- package/dist/cjs/jestHelpers.js +1 -1
- package/dist/cjs/keyboardEventWithKeyCode.js +5 -3
- package/dist/cjs/mediaClientErrors.js +10 -4
- package/dist/cjs/mediaClientProvider.js +1 -1
- package/dist/cjs/mediaPickerAuthProvider.js +1 -1
- package/dist/cjs/mediaPickerMocks.js +3 -3
- package/dist/cjs/mockData/index.js +23 -22
- package/dist/cjs/mockData/matchers.js +1 -1
- package/dist/cjs/mockLoadImage.js +2 -2
- package/dist/cjs/mocks/database/collection-item.js +1 -1
- package/dist/cjs/mocks/database/index.js +2 -2
- package/dist/cjs/mocks/fileAndDirectoriesUtils.js +42 -36
- package/dist/cjs/mocks/media-mock.js +2 -1
- package/dist/cjs/mocks/routers/api-router.js +2 -2
- package/dist/cjs/mocks/websockets/messages.js +1 -1
- package/dist/cjs/mocks/websockets/remote-upload-server.js +4 -2
- package/dist/cjs/mountWithIntlContext.js +67 -17
- package/dist/cjs/renderWithIntl.js +22 -0
- package/dist/cjs/smart-card-state.js +108 -0
- package/dist/cjs/story-styles.js +2 -2
- package/dist/cjs/styled.js +2 -2
- package/dist/cjs/userAuthProvider.js +1 -1
- package/dist/cjs/utils/index.js +1 -1
- package/dist/cjs/utils/logging.js +1 -1
- package/dist/cjs/utils/mockData.js +1 -1
- package/dist/cjs/version.json +1 -1
- package/dist/cjs/waitUntil.js +1 -1
- package/dist/es2019/I18nWrapper.js +3 -16
- package/dist/es2019/fakeMediaClient.js +1 -0
- package/dist/es2019/featureFlagsWrapper/dropdown.js +2 -2
- package/dist/es2019/fileStateFactory/createFileState.js +78 -0
- package/dist/es2019/fileStateFactory/factory.js +87 -0
- package/dist/es2019/fileStateFactory/helpers.js +86 -0
- package/dist/es2019/fileStateFactory/index.js +3 -0
- package/dist/es2019/index.js +4 -3
- package/dist/es2019/mediaClientErrors.js +3 -2
- package/dist/es2019/mocks/fileAndDirectoriesUtils.js +6 -3
- package/dist/es2019/mountWithIntlContext.js +46 -13
- package/dist/es2019/renderWithIntl.js +8 -0
- package/dist/es2019/smart-card-state.js +100 -0
- package/dist/es2019/story-styles.js +1 -1
- package/dist/es2019/styled.js +1 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/I18nWrapper.js +3 -18
- package/dist/esm/MockGlobalImage.js +2 -1
- package/dist/esm/clipboardEventMocks.js +1 -1
- package/dist/esm/example-mediaFeatureFlags.js +2 -2
- package/dist/esm/fakeMediaClient.js +1 -0
- package/dist/esm/featureFlagsWrapper/dropdown.js +2 -2
- package/dist/esm/featureFlagsWrapper/helpers.js +2 -2
- package/dist/esm/fileReader.js +4 -3
- package/dist/esm/fileStateFactory/createFileState.js +80 -0
- package/dist/esm/fileStateFactory/factory.js +161 -0
- package/dist/esm/fileStateFactory/helpers.js +96 -0
- package/dist/esm/fileStateFactory/index.js +3 -0
- package/dist/esm/index.js +4 -3
- package/dist/esm/keyboardEventWithKeyCode.js +4 -3
- package/dist/esm/mediaClientErrors.js +6 -3
- package/dist/esm/mediaPickerMocks.js +2 -2
- package/dist/esm/mockData/index.js +3 -2
- package/dist/esm/mockLoadImage.js +2 -2
- package/dist/esm/mocks/fileAndDirectoriesUtils.js +41 -35
- package/dist/esm/mocks/routers/api-router.js +2 -2
- package/dist/esm/mocks/websockets/remote-upload-server.js +4 -2
- package/dist/esm/mountWithIntlContext.js +58 -16
- package/dist/esm/renderWithIntl.js +8 -0
- package/dist/esm/smart-card-state.js +100 -0
- package/dist/esm/story-styles.js +1 -1
- package/dist/esm/styled.js +1 -1
- package/dist/esm/version.json +1 -1
- package/dist/types/featureFlagsWrapper/dropdown.d.ts +1 -0
- package/dist/types/featureFlagsWrapper/helpers.d.ts +1 -1
- package/dist/types/fileStateFactory/createFileState.d.ts +10 -0
- package/dist/types/fileStateFactory/factory.d.ts +42 -0
- package/dist/types/fileStateFactory/helpers.d.ts +7 -0
- package/dist/types/fileStateFactory/index.d.ts +4 -0
- package/dist/types/index.d.ts +4 -2
- package/dist/types/mediaClientErrors.d.ts +2 -1
- package/dist/types/mountWithIntlContext.d.ts +12 -3
- package/dist/types/renderWithIntl.d.ts +3 -0
- package/dist/types/smart-card-state.d.ts +2 -0
- package/dist/types/story-styles.d.ts +2 -2
- package/dist/types/styled.d.ts +1 -1
- package/package.json +13 -11
- package/renderWithIntl/package.json +7 -0
- package/smart-card-state/package.json +7 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.url = exports.cardState = void 0;
|
|
7
|
+
var url = 'https://bitbucket.org/atlassian/incredible-monorepo/pull-requests/42';
|
|
8
|
+
exports.url = url;
|
|
9
|
+
var cardState = {
|
|
10
|
+
status: 'resolved',
|
|
11
|
+
lastUpdatedAt: 1624877833614,
|
|
12
|
+
details: {
|
|
13
|
+
meta: {
|
|
14
|
+
access: 'granted',
|
|
15
|
+
visibility: 'restricted',
|
|
16
|
+
auth: [{
|
|
17
|
+
key: 'bitbucket',
|
|
18
|
+
displayName: 'Atlassian Links - Bitbucket',
|
|
19
|
+
url: 'https://id.stg.internal.atlassian.com/outboundAuth/start?containerId=4d6a1ee9-20b3-492f-a0b6-3bab6c763a8e_3f823978-fbc9-4baa-95e2-1b4c89a73027&serviceKey=bitbucket'
|
|
20
|
+
}],
|
|
21
|
+
definitionId: 'a2d59c5a-952f-4996-8cf6-1d0ad318731a',
|
|
22
|
+
key: 'bitbucket-object-provider',
|
|
23
|
+
resourceType: 'pull',
|
|
24
|
+
version: '2.0.2'
|
|
25
|
+
},
|
|
26
|
+
data: {
|
|
27
|
+
'@id': url,
|
|
28
|
+
'@context': {
|
|
29
|
+
'@vocab': 'https://www.w3.org/ns/activitystreams#',
|
|
30
|
+
atlassian: 'https://schema.atlassian.com/ns/vocabulary#',
|
|
31
|
+
schema: 'http://schema.org/'
|
|
32
|
+
},
|
|
33
|
+
'@type': ['Object', 'atlassian:SourceCodePullRequest'],
|
|
34
|
+
url: url,
|
|
35
|
+
attributedTo: {
|
|
36
|
+
'@type': 'Person',
|
|
37
|
+
name: 'Matt Turner',
|
|
38
|
+
image: 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/initials/MT-4.png'
|
|
39
|
+
},
|
|
40
|
+
'schema:dateCreated': '2019-12-12T03:20:14.858Z',
|
|
41
|
+
generator: {
|
|
42
|
+
'@type': 'Application',
|
|
43
|
+
name: 'Bitbucket',
|
|
44
|
+
icon: {
|
|
45
|
+
'@type': 'Image',
|
|
46
|
+
url: 'https://wac-cdn.atlassian.com/assets/img/favicons/bitbucket/favicon-32x32.png'
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
icon: {
|
|
50
|
+
'@type': 'Image',
|
|
51
|
+
url: 'https://wac-cdn.atlassian.com/assets/img/favicons/bitbucket/favicon-32x32.png'
|
|
52
|
+
},
|
|
53
|
+
name: 'Normalise package config',
|
|
54
|
+
summary: '',
|
|
55
|
+
'atlassian:mergeSource': {
|
|
56
|
+
'@type': 'Link',
|
|
57
|
+
href: 'https://bitbucket.org/atlassian/incredible-monorepo/branch/normalise-package-config'
|
|
58
|
+
},
|
|
59
|
+
'atlassian:mergeDestination': {
|
|
60
|
+
'@type': 'Link',
|
|
61
|
+
href: 'https://bitbucket.org/atlassian/incredible-monorepo/branch/master'
|
|
62
|
+
},
|
|
63
|
+
updated: '2019-12-12T03:40:43.420Z',
|
|
64
|
+
'atlassian:mergeCommit': {
|
|
65
|
+
'@type': 'Link',
|
|
66
|
+
href: 'https://bitbucket.org/atlassian/incredible-monorepo/commits/56139bbc3793'
|
|
67
|
+
},
|
|
68
|
+
'atlassian:internalId': '42',
|
|
69
|
+
'atlassian:isMerged': true,
|
|
70
|
+
'atlassian:state': 'MERGED',
|
|
71
|
+
'atlassian:mergedBy': {
|
|
72
|
+
'@type': 'Person',
|
|
73
|
+
name: 'Matt Turner',
|
|
74
|
+
image: 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/initials/MT-4.png'
|
|
75
|
+
},
|
|
76
|
+
'atlassian:reviewer': [{
|
|
77
|
+
'@type': 'Person',
|
|
78
|
+
name: 'ᴄᴏsᴍᴏ',
|
|
79
|
+
image: 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/default-avatar-1.png'
|
|
80
|
+
}],
|
|
81
|
+
'atlassian:reviewedBy': [{
|
|
82
|
+
'@type': 'Person',
|
|
83
|
+
name: 'ᴄᴏsᴍᴏ',
|
|
84
|
+
image: 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/default-avatar-1.png'
|
|
85
|
+
}],
|
|
86
|
+
'atlassian:updatedBy': {
|
|
87
|
+
'@type': 'Person',
|
|
88
|
+
name: 'Matt Turner',
|
|
89
|
+
image: 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/initials/MT-4.png'
|
|
90
|
+
},
|
|
91
|
+
audience: [{
|
|
92
|
+
'@type': 'Person',
|
|
93
|
+
name: 'Matt Turner',
|
|
94
|
+
image: 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/initials/MT-4.png'
|
|
95
|
+
}, {
|
|
96
|
+
'@type': 'Person',
|
|
97
|
+
name: 'ᴄᴏsᴍᴏ',
|
|
98
|
+
image: 'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/default-avatar-1.png'
|
|
99
|
+
}],
|
|
100
|
+
context: {
|
|
101
|
+
'@type': 'atlassian:SourceCodeRepository',
|
|
102
|
+
name: 'incredible-monorepo',
|
|
103
|
+
url: 'https://bitbucket.org/atlassian/incredible-monorepo'
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
exports.cardState = cardState;
|
package/dist/cjs/story-styles.js
CHANGED
|
@@ -9,10 +9,10 @@ exports.Matrix = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _styled = _interopRequireDefault(require("@emotion/styled"));
|
|
13
13
|
|
|
14
14
|
var _templateObject;
|
|
15
15
|
|
|
16
|
-
var Matrix =
|
|
16
|
+
var Matrix = _styled.default.table(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n thead {\n td {\n text-align: center;\n font-weight: bold;\n font-size: 20px;\n }\n }\n\n tbody {\n td {\n padding: 25px 10px;\n }\n }\n\n td {\n margin: auto;\n text-align: center;\n vertical-align: middle;\n\n &:first-child {\n font-weight: bold;\n font-size: 20px;\n }\n\n > div {\n display: flex;\n justify-content: center;\n text-align: left;\n }\n }\n"])));
|
|
17
17
|
|
|
18
18
|
exports.Matrix = Matrix;
|
package/dist/cjs/styled.js
CHANGED
|
@@ -9,10 +9,10 @@ exports.LocaleSelectorWrapper = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _styled = _interopRequireDefault(require("@emotion/styled"));
|
|
13
13
|
|
|
14
14
|
var _templateObject;
|
|
15
15
|
|
|
16
|
-
var LocaleSelectorWrapper =
|
|
16
|
+
var LocaleSelectorWrapper = _styled.default.div(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n position: fixed;\n right: 20px;\n top: 20px;\n width: 200px;\n border: 1px solid #ccc;\n padding: 10px;\n border-radius: 3px;\n background-color: white;\n\n h2 {\n margin-bottom: 10px;\n }\n"])));
|
|
17
17
|
|
|
18
18
|
exports.LocaleSelectorWrapper = LocaleSelectorWrapper;
|
|
@@ -5,7 +5,7 @@ var _typeof = require("@babel/runtime/helpers/typeof");
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.
|
|
8
|
+
exports.userAuthProviderBaseURL = exports.userAuthProvider = exports.createUserMediaClient = void 0;
|
|
9
9
|
|
|
10
10
|
var exenv = _interopRequireWildcard(require("exenv"));
|
|
11
11
|
|
package/dist/cjs/utils/index.js
CHANGED
|
@@ -5,8 +5,8 @@ var _typeof = require("@babel/runtime/helpers/typeof");
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.mapDataUriToBlob = mapDataUriToBlob;
|
|
9
8
|
exports.getWsUrl = getWsUrl;
|
|
9
|
+
exports.mapDataUriToBlob = mapDataUriToBlob;
|
|
10
10
|
|
|
11
11
|
var url = _interopRequireWildcard(require("url"));
|
|
12
12
|
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.WsDirection = void 0;
|
|
6
7
|
exports.logRequest = logRequest;
|
|
7
8
|
exports.logWsMessage = logWsMessage;
|
|
8
|
-
exports.WsDirection = void 0;
|
|
9
9
|
var WsDirection;
|
|
10
10
|
exports.WsDirection = WsDirection;
|
|
11
11
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.textFileTypes = exports.mockDataUri = exports.imageFileTypes = exports.getTextFileType = exports.getPastDate = exports.getHackerNoun = exports.getFutureDate = exports.getFakeFileSize = exports.getFakeFileName = exports.getDateWithOffset = exports.fakeImage = void 0;
|
|
7
7
|
var hackerNouns = ['system', 'protocol', 'microchip', 'alarm', 'protocol', 'panel', 'pixel'];
|
|
8
8
|
|
|
9
9
|
var getHackerNoun = function getHackerNoun() {
|
package/dist/cjs/version.json
CHANGED
package/dist/cjs/waitUntil.js
CHANGED
|
@@ -5,8 +5,8 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.waitUntil = waitUntil;
|
|
9
8
|
exports.default = void 0;
|
|
9
|
+
exports.waitUntil = waitUntil;
|
|
10
10
|
|
|
11
11
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
12
12
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React, { useState
|
|
2
|
-
import { IntlProvider
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { IntlProvider } from 'react-intl-next';
|
|
3
3
|
import LocaleSelect, { defaultLocales } from '@atlaskit/locale/LocaleSelect';
|
|
4
4
|
import { locales } from '@atlaskit/media-ui/locales';
|
|
5
5
|
|
|
@@ -16,26 +16,13 @@ const selectableLocales = defaultLocales.reduce((result, locale) => {
|
|
|
16
16
|
|
|
17
17
|
return [...result, locale];
|
|
18
18
|
}, []);
|
|
19
|
-
|
|
20
|
-
function addAllLocaleData() {
|
|
21
|
-
Object.keys(locales).forEach(localeKey => {
|
|
22
|
-
const lang = localeKey.substring(0, 2);
|
|
23
|
-
|
|
24
|
-
const localeData = require(`react-intl/locale-data/${lang}`);
|
|
25
|
-
|
|
26
|
-
addLocaleData(localeData);
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
19
|
export const I18NWrapper = ({
|
|
31
20
|
children
|
|
32
21
|
}) => {
|
|
33
22
|
const [locale, setLocale] = useState({
|
|
34
23
|
label: 'en',
|
|
35
24
|
value: 'en'
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
useEffect(() => addAllLocaleData(), []);
|
|
25
|
+
});
|
|
39
26
|
const lang = locale.value.substring(0, 2);
|
|
40
27
|
const messages = getMessages(locale.value);
|
|
41
28
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
@@ -37,6 +37,7 @@ export const fakeMediaClient = (config = getDefaultMediaClientConfig()) => {
|
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
39
|
asMock(mediaClient.getImageUrl).mockResolvedValue('some-image-url');
|
|
40
|
+
asMock(mediaClient.getImageUrlSync).mockReturnValue('some-image-url');
|
|
40
41
|
asMock(mediaClient.getImage).mockImplementation(mockMediaStore.getImage);
|
|
41
42
|
asMock(mediaClient.collection.getItems).mockReturnValue(of([]));
|
|
42
43
|
asMock(mediaClient.file.copyFile).mockReturnValue({
|
|
@@ -4,9 +4,9 @@ import Textfield from '@atlaskit/textfield';
|
|
|
4
4
|
import { getMediaFeatureFlags, clearAllLocalFeatureFlags, setLocalFeatureFlag } from './helpers';
|
|
5
5
|
import SelectClearIcon from '@atlaskit/icon/glyph/select-clear';
|
|
6
6
|
import HipchatChevronDownIcon from '@atlaskit/icon/glyph/hipchat/chevron-down';
|
|
7
|
-
import Button from '@atlaskit/button';
|
|
7
|
+
import Button from '@atlaskit/button/standard-button';
|
|
8
8
|
import Tooltip from '@atlaskit/tooltip';
|
|
9
|
-
import styled from 'styled
|
|
9
|
+
import styled from '@emotion/styled';
|
|
10
10
|
import Popup from '@atlaskit/popup';
|
|
11
11
|
import { Checkbox } from '@atlaskit/checkbox';
|
|
12
12
|
import debounce from 'lodash/debounce';
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { tallImage } from '../';
|
|
2
|
+
const localPreview = {
|
|
3
|
+
value: tallImage
|
|
4
|
+
};
|
|
5
|
+
const brokenLocalPreview = {
|
|
6
|
+
value: 'broken-data-uri'
|
|
7
|
+
};
|
|
8
|
+
const remotePreview = {
|
|
9
|
+
image: {}
|
|
10
|
+
};
|
|
11
|
+
export const createFileState = (id, status, {
|
|
12
|
+
withRemotePreview,
|
|
13
|
+
withLocalPreview,
|
|
14
|
+
withBrokenLocalPreview,
|
|
15
|
+
uploadProgress,
|
|
16
|
+
fileDetails
|
|
17
|
+
} = {}) => {
|
|
18
|
+
const extendState = {};
|
|
19
|
+
|
|
20
|
+
if (uploadProgress) {
|
|
21
|
+
extendState.progress = uploadProgress;
|
|
22
|
+
} // REMOTE PREVIEW
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
if (withRemotePreview) {
|
|
26
|
+
extendState.representations = remotePreview;
|
|
27
|
+
} else if (withRemotePreview === false) {
|
|
28
|
+
extendState.representations = {};
|
|
29
|
+
} // LOCAL PREVIEW
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
if (withLocalPreview) {
|
|
33
|
+
extendState.preview = localPreview;
|
|
34
|
+
} else if (withBrokenLocalPreview) {
|
|
35
|
+
extendState.preview = brokenLocalPreview;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const base = { ...fileDetails,
|
|
39
|
+
...extendState,
|
|
40
|
+
id
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
switch (status) {
|
|
44
|
+
case 'uploading':
|
|
45
|
+
return {
|
|
46
|
+
status: 'uploading',
|
|
47
|
+
progress: 0,
|
|
48
|
+
...base
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
case 'processing':
|
|
52
|
+
return {
|
|
53
|
+
status: 'processing',
|
|
54
|
+
...base
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
case 'processed':
|
|
58
|
+
return {
|
|
59
|
+
status: 'processed',
|
|
60
|
+
representations: remotePreview,
|
|
61
|
+
artifacts: {},
|
|
62
|
+
...base
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
case 'failed-processing':
|
|
66
|
+
return {
|
|
67
|
+
status: 'failed-processing',
|
|
68
|
+
...base
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
case 'error':
|
|
72
|
+
default:
|
|
73
|
+
return {
|
|
74
|
+
id,
|
|
75
|
+
status: 'error'
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import { tallImage, dataURItoBlob } from '..';
|
|
3
|
+
import { MediaClient, createFileStateSubject } from '@atlaskit/media-client';
|
|
4
|
+
import { createFileState } from './createFileState';
|
|
5
|
+
import { createFileDetails } from './helpers';
|
|
6
|
+
import { sleep } from '../nextTick';
|
|
7
|
+
export class MediaClientMock extends MediaClient {
|
|
8
|
+
constructor(observable, mediaClientConfig, featureFlags, options = {}) {
|
|
9
|
+
super(mediaClientConfig, featureFlags);
|
|
10
|
+
|
|
11
|
+
_defineProperty(this, "updateObserbable", newObservable => {
|
|
12
|
+
this.observable = newObservable;
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
_defineProperty(this, "getImage", async () => {
|
|
16
|
+
const {
|
|
17
|
+
getImageDelay = 0
|
|
18
|
+
} = this.options;
|
|
19
|
+
await sleep(getImageDelay);
|
|
20
|
+
return dataURItoBlob(tallImage);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
_defineProperty(this, "mockFileFetcher", () => {
|
|
24
|
+
this.file.getFileState = () => this.observable;
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
this.observable = observable;
|
|
28
|
+
this.options = options;
|
|
29
|
+
this.mockFileFetcher();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
}
|
|
33
|
+
const mockConfig = {
|
|
34
|
+
authProvider: async () => ({
|
|
35
|
+
clientId: 'some-client',
|
|
36
|
+
token: 'some-token',
|
|
37
|
+
baseUrl: 'some-url'
|
|
38
|
+
})
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* A fake Media Client that provides a backdoor to inject
|
|
43
|
+
* simulated file states. With this class, we can test several scenarios
|
|
44
|
+
* without having to recreate them all in the backend.
|
|
45
|
+
*/
|
|
46
|
+
export class FileStateFactory {
|
|
47
|
+
constructor(identifier, {
|
|
48
|
+
fileDetails: _fileDetails,
|
|
49
|
+
mediaClientConfig = mockConfig,
|
|
50
|
+
featureFlags,
|
|
51
|
+
mediaClientMockOptions
|
|
52
|
+
} = {}) {
|
|
53
|
+
_defineProperty(this, "updateIdentifier", (identifier, fileDetails) => {
|
|
54
|
+
this.identifier = identifier;
|
|
55
|
+
this.fileDetails = fileDetails || createFileDetails(this.identifier.id);
|
|
56
|
+
this.observable = createFileStateSubject();
|
|
57
|
+
this.mediaClient.updateObserbable(this.observable);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
_defineProperty(this, "subscription", {
|
|
61
|
+
next: fileState => {
|
|
62
|
+
this.observable.next(fileState);
|
|
63
|
+
},
|
|
64
|
+
error: error => {
|
|
65
|
+
this.observable.error(error);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
_defineProperty(this, "createFileState", (status, options) => createFileState(this.identifier.id, status, { ...options,
|
|
70
|
+
fileDetails: (options === null || options === void 0 ? void 0 : options.fileDetails) || this.fileDetails
|
|
71
|
+
}));
|
|
72
|
+
|
|
73
|
+
_defineProperty(this, "next", (status, options) => {
|
|
74
|
+
this.subscription.next(this.createFileState(status, options));
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
_defineProperty(this, "error", error => {
|
|
78
|
+
this.subscription.error(error);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
this.identifier = identifier;
|
|
82
|
+
this.fileDetails = _fileDetails || createFileDetails(this.identifier.id);
|
|
83
|
+
this.observable = createFileStateSubject();
|
|
84
|
+
this.mediaClient = new MediaClientMock(this.observable, mediaClientConfig, featureFlags, mediaClientMockOptions);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
2
|
+
export const defaultFileDetails = {
|
|
3
|
+
createdAt: 1630986510989,
|
|
4
|
+
mediaType: 'image',
|
|
5
|
+
mimeType: 'image/png',
|
|
6
|
+
name: 'file-name.png',
|
|
7
|
+
size: 1
|
|
8
|
+
}; // min inclusive / max exclusive
|
|
9
|
+
|
|
10
|
+
function random(min = 0, max = 10000) {
|
|
11
|
+
min = Math.ceil(min);
|
|
12
|
+
max = Math.floor(max) - 1;
|
|
13
|
+
const result = Math.floor(Math.random() * (max - min + 1)) + min;
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const getRandomElem = arr => arr[Math.floor(Math.random() * arr.length)];
|
|
18
|
+
|
|
19
|
+
export const createIdentifier = ({
|
|
20
|
+
collectionName = `collection-${random()}`,
|
|
21
|
+
occurrenceKey = `occurrence-${random()}`
|
|
22
|
+
} = {}) => ({
|
|
23
|
+
mediaItemType: 'file',
|
|
24
|
+
id: uuidv4(),
|
|
25
|
+
collectionName,
|
|
26
|
+
occurrenceKey
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const generateFileName = extension => {
|
|
30
|
+
const fileNames = ['quick-and-dirty', 'quality-time', 'down-for-the-count', 'hard-pill-to-swallow', 'between-a-rock-and-a-hard-place', 'fish-out-of-water', 'top-drawer', 'like-father-like-son', 'mountain-out-of-a-molehill', 'under-your-nose', 'a-chip-on-your-shoulder', 'hit-below-the-belt'];
|
|
31
|
+
return `${getRandomElem(fileNames)}.${extension}`;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const mediaTypesDetails = {
|
|
35
|
+
image: {
|
|
36
|
+
ext: 'png',
|
|
37
|
+
mimeType: 'image/png'
|
|
38
|
+
},
|
|
39
|
+
video: {
|
|
40
|
+
ext: 'mp4',
|
|
41
|
+
mimeType: 'video/mp4'
|
|
42
|
+
},
|
|
43
|
+
doc: {
|
|
44
|
+
ext: 'pdf',
|
|
45
|
+
mimeType: 'application/pdf'
|
|
46
|
+
},
|
|
47
|
+
unknown: {
|
|
48
|
+
ext: 'unknown',
|
|
49
|
+
mimeType: 'unknown'
|
|
50
|
+
},
|
|
51
|
+
audio: {
|
|
52
|
+
ext: 'mp3',
|
|
53
|
+
mimeType: 'audio/mpeg'
|
|
54
|
+
},
|
|
55
|
+
archive: {
|
|
56
|
+
ext: 'zip',
|
|
57
|
+
mimeType: 'application/zip'
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const mediaTypes = Object.keys(mediaTypesDetails);
|
|
61
|
+
|
|
62
|
+
const generateMediaTypeDetails = mediaType => {
|
|
63
|
+
const {
|
|
64
|
+
mimeType,
|
|
65
|
+
ext
|
|
66
|
+
} = mediaTypesDetails[mediaType];
|
|
67
|
+
return {
|
|
68
|
+
mimeType,
|
|
69
|
+
name: generateFileName(ext)
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export const createFileDetails = (id, mediaType = getRandomElem(mediaTypes)) => {
|
|
74
|
+
const {
|
|
75
|
+
mimeType,
|
|
76
|
+
name
|
|
77
|
+
} = generateMediaTypeDetails(mediaType);
|
|
78
|
+
return {
|
|
79
|
+
id,
|
|
80
|
+
createdAt: random(),
|
|
81
|
+
size: random(),
|
|
82
|
+
name,
|
|
83
|
+
mediaType,
|
|
84
|
+
mimeType
|
|
85
|
+
};
|
|
86
|
+
};
|
package/dist/es2019/index.js
CHANGED
|
@@ -21,7 +21,7 @@ export { nextTick, sleep } from './nextTick';
|
|
|
21
21
|
export { timeoutPromise } from './timeoutPromise';
|
|
22
22
|
export { asMock, asMockFunction, asMockReturnValue, asMockFunctionReturnValue, asMockFunctionResolvedValue, expectConstructorToHaveBeenCalledWith, expectFunctionToHaveBeenCalledWith, expectToEqual } from './jestHelpers';
|
|
23
23
|
export { I18NWrapper } from './I18nWrapper';
|
|
24
|
-
export { mountWithIntlContext } from './mountWithIntlContext';
|
|
24
|
+
export { mountWithIntlContext, mountWithIntlWrapper, shallowWithIntlContext } from './mountWithIntlContext';
|
|
25
25
|
export { fakeIntl } from './fakeI18n';
|
|
26
26
|
export { mockCanvas } from './mockCanvas';
|
|
27
27
|
export { default as KeyboardEventWithKeyCode } from './keyboardEventWithKeyCode';
|
|
@@ -36,5 +36,6 @@ export { enableMockGlobalImage, disableMockGlobalImage } from './MockGlobalImage
|
|
|
36
36
|
export { exampleMediaFeatureFlags } from './example-mediaFeatureFlags';
|
|
37
37
|
export { dataURItoBlob } from './mockData/utils';
|
|
38
38
|
export { mapDataUriToBlob } from './utils/index';
|
|
39
|
-
export { createPollingMaxAttemptsError, createRateLimitedError } from './mediaClientErrors';
|
|
40
|
-
export { default as FeatureFlagsWrapper } from './featureFlagsWrapper';
|
|
39
|
+
export { createPollingMaxAttemptsError, createRateLimitedError, createMediaStoreError } from './mediaClientErrors';
|
|
40
|
+
export { default as FeatureFlagsWrapper } from './featureFlagsWrapper';
|
|
41
|
+
export { FileStateFactory, MediaClientMock, createIdentifier, createFileDetails, createFileState } from './fileStateFactory';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { RequestError, PollingError } from '@atlaskit/media-client';
|
|
1
|
+
import { RequestError, PollingError, MediaStoreError } from '@atlaskit/media-client';
|
|
2
2
|
export const createRateLimitedError = (metadata = {}) => new RequestError('serverRateLimited', { ...metadata,
|
|
3
3
|
statusCode: 429
|
|
4
4
|
});
|
|
5
|
-
export const createPollingMaxAttemptsError = (attempts = 1) => new PollingError('pollingMaxAttemptsExceeded', attempts);
|
|
5
|
+
export const createPollingMaxAttemptsError = (attempts = 1) => new PollingError('pollingMaxAttemptsExceeded', attempts);
|
|
6
|
+
export const createMediaStoreError = () => new MediaStoreError('missingInitialAuth');
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
// Based on https://developer.mozilla.org/en-US/docs/Web/API/FileSystemEntry
|
|
8
8
|
// Based on https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryEntry
|
|
9
9
|
// Represents https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryReader
|
|
10
|
-
const createDataTransferItem = webkitGetAsEntryResult => (
|
|
10
|
+
const createDataTransferItem = webkitGetAsEntryResult => ( // Using DataTransferItem constructor is illegal
|
|
11
|
+
{
|
|
11
12
|
getAsFile: () => null,
|
|
12
13
|
|
|
13
14
|
getAsString() {
|
|
@@ -19,12 +20,14 @@ const createDataTransferItem = webkitGetAsEntryResult => ({
|
|
|
19
20
|
webkitGetAsEntry: () => webkitGetAsEntryResult
|
|
20
21
|
});
|
|
21
22
|
|
|
22
|
-
const createFileList = filesArray => (
|
|
23
|
+
const createFileList = filesArray => ( // Using FileList constructor is illegal
|
|
24
|
+
{ ...filesArray,
|
|
23
25
|
length: filesArray.length,
|
|
24
26
|
item: index => filesArray[index]
|
|
25
27
|
});
|
|
26
28
|
|
|
27
|
-
const createDataTransferItemList = itemsArray => (
|
|
29
|
+
const createDataTransferItemList = itemsArray => ( // Using DataTransferItemList constructor is illegal
|
|
30
|
+
{ ...itemsArray,
|
|
28
31
|
length: itemsArray.length,
|
|
29
32
|
add: () => null,
|
|
30
33
|
clear: () => null,
|
|
@@ -1,25 +1,58 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { RawIntlProvider, createIntl, IntlProvider } from 'react-intl-next';
|
|
3
|
+
import { mount, shallow } from 'enzyme';
|
|
4
|
+
const mockIntl = createIntl({
|
|
5
|
+
locale: 'en'
|
|
6
|
+
});
|
|
7
|
+
/**
|
|
8
|
+
* When using React-Intl `injectIntl` on components, props.intl is required.
|
|
9
|
+
*/
|
|
3
10
|
|
|
11
|
+
function nodeWithIntlProp(node) {
|
|
12
|
+
const intl = !!node.props.intl ? node.props.intl : mockIntl;
|
|
13
|
+
return /*#__PURE__*/React.createElement(RawIntlProvider, {
|
|
14
|
+
value: intl
|
|
15
|
+
}, /*#__PURE__*/React.cloneElement(node, {
|
|
16
|
+
intl
|
|
17
|
+
}));
|
|
18
|
+
}
|
|
4
19
|
/* 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
|
|
5
20
|
* and therefore fails the build:
|
|
6
21
|
* 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.
|
|
7
22
|
* TS is resolving enzyme's usage of react to react-transition-group???
|
|
8
23
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
export const mountWithIntlContext = (node, {
|
|
27
|
+
context = {},
|
|
28
|
+
childContextTypes = {},
|
|
29
|
+
...additionalOptions
|
|
30
|
+
} = {}) => {
|
|
31
|
+
const intl = !!node.props.intl ? node.props.intl : mockIntl;
|
|
32
|
+
return mount(nodeWithIntlProp(node), {
|
|
33
|
+
context: {
|
|
34
|
+
intl,
|
|
35
|
+
...context
|
|
36
|
+
},
|
|
37
|
+
...additionalOptions
|
|
13
38
|
});
|
|
14
|
-
|
|
15
|
-
|
|
39
|
+
};
|
|
40
|
+
export const shallowWithIntlContext = (node, {
|
|
41
|
+
context = {},
|
|
42
|
+
...additionalOptions
|
|
43
|
+
} = {}) => {
|
|
44
|
+
const intl = !!node.props.intl ? node.props.intl : mockIntl;
|
|
45
|
+
return shallow(nodeWithIntlProp(node), {
|
|
16
46
|
context: {
|
|
17
47
|
intl,
|
|
18
|
-
...
|
|
48
|
+
...context
|
|
19
49
|
},
|
|
20
|
-
|
|
21
|
-
intl: intlShape,
|
|
22
|
-
...childContextTypes
|
|
23
|
-
}
|
|
50
|
+
...additionalOptions
|
|
24
51
|
});
|
|
52
|
+
};
|
|
53
|
+
export const mountWithIntlWrapper = node => {
|
|
54
|
+
return mount( /*#__PURE__*/React.createElement(props => /*#__PURE__*/React.createElement(IntlProvider, {
|
|
55
|
+
locale: "en"
|
|
56
|
+
}, /*#__PURE__*/React.cloneElement(node, { ...props
|
|
57
|
+
}))));
|
|
25
58
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { IntlProvider } from 'react-intl-next';
|
|
3
|
+
import { render } from '@testing-library/react';
|
|
4
|
+
export const renderWithIntl = component => {
|
|
5
|
+
return render( /*#__PURE__*/React.createElement(IntlProvider, {
|
|
6
|
+
locale: "en"
|
|
7
|
+
}, component));
|
|
8
|
+
};
|