@contentful/field-editor-reference 8.5.1-canary.4 → 8.5.1-canary.8
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/dist/cjs/assets/WrappedAssetCard/FetchingWrappedAssetCard.js +1 -1
- package/dist/cjs/assets/WrappedAssetCard/WrappedAssetCard.js +2 -9
- package/dist/cjs/assets/WrappedAssetCard/WrappedAssetLink.js +0 -6
- package/dist/cjs/components/EntityStatusBadge/EntityStatusBadge.js +0 -21
- package/dist/cjs/entries/WrappedEntryCard/FetchingWrappedEntryCard.js +1 -1
- package/dist/cjs/entries/WrappedEntryCard/WrappedEntryCard.js +2 -9
- package/dist/esm/assets/WrappedAssetCard/FetchingWrappedAssetCard.js +1 -1
- package/dist/esm/assets/WrappedAssetCard/WrappedAssetCard.js +2 -9
- package/dist/esm/assets/WrappedAssetCard/WrappedAssetLink.js +0 -6
- package/dist/esm/components/EntityStatusBadge/EntityStatusBadge.js +0 -21
- package/dist/esm/entries/WrappedEntryCard/FetchingWrappedEntryCard.js +1 -1
- package/dist/esm/entries/WrappedEntryCard/WrappedEntryCard.js +2 -9
- package/dist/types/components/EntityStatusBadge/EntityStatusBadge.d.ts +1 -1
- package/dist/types/components/ResourceEntityErrorCard/FunctionInvocationErrorCard.d.ts +1 -1
- package/package.json +3 -3
- package/dist/cjs/common/entityStatus.test.js +0 -87
- package/dist/cjs/common/fetchingEntityStatus.test.js +0 -101
- package/dist/cjs/components/EntityStatusBadge/EntityStatusBadge.test.js +0 -134
- package/dist/esm/common/entityStatus.test.js +0 -78
- package/dist/esm/common/fetchingEntityStatus.test.js +0 -92
- package/dist/esm/components/EntityStatusBadge/EntityStatusBadge.test.js +0 -125
- package/dist/types/common/entityStatus.test.d.ts +0 -1
- package/dist/types/common/fetchingEntityStatus.test.d.ts +0 -1
- package/dist/types/components/EntityStatusBadge/EntityStatusBadge.test.d.ts +0 -1
|
@@ -113,7 +113,7 @@ function FetchingWrappedAssetCard(props) {
|
|
|
113
113
|
});
|
|
114
114
|
};
|
|
115
115
|
return _react.useMemo(()=>{
|
|
116
|
-
if (status === 'error'
|
|
116
|
+
if (status === 'error') {
|
|
117
117
|
const card = /*#__PURE__*/ _react.createElement(_components.MissingAssetCard, {
|
|
118
118
|
asSquare: props.viewType !== 'link',
|
|
119
119
|
isDisabled: props.isDisabled,
|
|
@@ -88,7 +88,8 @@ function getFileType(file) {
|
|
|
88
88
|
}
|
|
89
89
|
const THUMBNAIL_SIZE = 150;
|
|
90
90
|
const WrappedAssetCard = ({ asset, className, size, localeCode, defaultLocaleCode, activeLocales, localesStatusMap, isDisabled, isSelected, isClickable, useLocalizedEntityStatus, renderDragHandle, getEntityScheduledActions, onEdit, getAssetUrl, onRemove, releaseEntityStatus, releaseStatusMap, release, onAddToRelease })=>{
|
|
91
|
-
const
|
|
91
|
+
const status = _fieldeditorshared.entityHelpers.getEntityStatus(asset.sys, useLocalizedEntityStatus ? localeCode : undefined);
|
|
92
|
+
const entityFile = asset.fields.file ? asset.fields.file[localeCode] || asset.fields.file[defaultLocaleCode] : undefined;
|
|
92
93
|
const imageUrl = _react.useMemo(()=>{
|
|
93
94
|
if (!entityFile?.url) return '';
|
|
94
95
|
if (size === 'small') {
|
|
@@ -105,14 +106,6 @@ const WrappedAssetCard = ({ asset, className, size, localeCode, defaultLocaleCod
|
|
|
105
106
|
entityFile?.url,
|
|
106
107
|
size
|
|
107
108
|
]);
|
|
108
|
-
if (!asset?.sys?.id) {
|
|
109
|
-
return /*#__PURE__*/ _react.createElement(_components.MissingAssetCard, {
|
|
110
|
-
asSquare: true,
|
|
111
|
-
isDisabled: isDisabled,
|
|
112
|
-
onRemove: onRemove
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
const status = _fieldeditorshared.entityHelpers.getEntityStatus(asset.sys, useLocalizedEntityStatus ? localeCode : undefined);
|
|
116
109
|
if (status === 'deleted') {
|
|
117
110
|
return /*#__PURE__*/ _react.createElement(_components.MissingAssetCard, {
|
|
118
111
|
asSquare: true,
|
|
@@ -56,12 +56,6 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
56
56
|
}
|
|
57
57
|
const WrappedAssetLink = (props)=>{
|
|
58
58
|
const { className, href, onEdit, onRemove, isDisabled, isClickable = true } = props;
|
|
59
|
-
if (!props.asset?.sys?.id) {
|
|
60
|
-
return /*#__PURE__*/ _react.createElement(_components.MissingAssetCard, {
|
|
61
|
-
isDisabled: isDisabled,
|
|
62
|
-
onRemove: onRemove
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
59
|
const status = _fieldeditorshared.entityHelpers.getEntityStatus(props.asset.sys, props.useLocalizedEntityStatus ? props.localeCode : undefined);
|
|
66
60
|
if (status === 'deleted') {
|
|
67
61
|
return /*#__PURE__*/ _react.createElement(_components.MissingAssetCard, {
|
|
@@ -19,27 +19,6 @@ function _interop_require_default(obj) {
|
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
function EntityStatusBadge({ entityType, getEntityScheduledActions, status, useLocalizedEntityStatus, localesStatusMap, activeLocales, entity, releaseStatusMap, releaseEntityStatus, release, ...props }) {
|
|
22
|
-
if (!entity?.sys?.id) {
|
|
23
|
-
return /*#__PURE__*/ _react.default.createElement(_f36components.EntityStatusBadge, {
|
|
24
|
-
...props,
|
|
25
|
-
entityStatus: status
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
return /*#__PURE__*/ _react.default.createElement(LoadedEntityStatusBadge, {
|
|
29
|
-
...props,
|
|
30
|
-
entityType: entityType,
|
|
31
|
-
getEntityScheduledActions: getEntityScheduledActions,
|
|
32
|
-
status: status,
|
|
33
|
-
useLocalizedEntityStatus: useLocalizedEntityStatus,
|
|
34
|
-
localesStatusMap: localesStatusMap,
|
|
35
|
-
activeLocales: activeLocales,
|
|
36
|
-
entity: entity,
|
|
37
|
-
releaseStatusMap: releaseStatusMap,
|
|
38
|
-
releaseEntityStatus: releaseEntityStatus,
|
|
39
|
-
release: release
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
function LoadedEntityStatusBadge({ entityType, getEntityScheduledActions, status, useLocalizedEntityStatus, localesStatusMap, activeLocales, entity, releaseStatusMap, releaseEntityStatus, release, ...props }) {
|
|
43
22
|
const { isError, isLoading, jobs } = (0, _ScheduledIconWithTooltip.useScheduledActions)({
|
|
44
23
|
entityId: entity.sys.id,
|
|
45
24
|
entityType,
|
|
@@ -134,7 +134,7 @@ function FetchingWrappedEntryCard(props) {
|
|
|
134
134
|
entry
|
|
135
135
|
]);
|
|
136
136
|
return _react.useMemo(()=>{
|
|
137
|
-
if (status === 'error'
|
|
137
|
+
if (status === 'error') {
|
|
138
138
|
const card = /*#__PURE__*/ _react.createElement(_components.MissingEntityCard, {
|
|
139
139
|
isDisabled: props.isDisabled,
|
|
140
140
|
onRemove: onRemoveEntry,
|
|
@@ -66,7 +66,7 @@ function WrappedEntryCard({ entry, entryUrl, contentType, activeLocales, localeC
|
|
|
66
66
|
const [file, setFile] = _react.useState(null);
|
|
67
67
|
_react.useEffect(()=>{
|
|
68
68
|
let mounted = true;
|
|
69
|
-
if (entry
|
|
69
|
+
if (entry) {
|
|
70
70
|
getEntryImage({
|
|
71
71
|
entry,
|
|
72
72
|
contentType,
|
|
@@ -92,14 +92,7 @@ function WrappedEntryCard({ entry, entryUrl, contentType, activeLocales, localeC
|
|
|
92
92
|
localeCode,
|
|
93
93
|
defaultLocaleCode
|
|
94
94
|
]);
|
|
95
|
-
|
|
96
|
-
return /*#__PURE__*/ _react.createElement(_components.MissingEntityCard, {
|
|
97
|
-
isDisabled: isDisabled,
|
|
98
|
-
onRemove: onRemove,
|
|
99
|
-
providerName: "Contentful"
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
const status = getEntityStatus(entry.sys, useLocalizedEntityStatus ? localeCode : undefined);
|
|
95
|
+
const status = getEntityStatus(entry?.sys, useLocalizedEntityStatus ? localeCode : undefined);
|
|
103
96
|
if (status === 'deleted') {
|
|
104
97
|
return /*#__PURE__*/ _react.createElement(_components.MissingEntityCard, {
|
|
105
98
|
isDisabled: isDisabled,
|
|
@@ -62,7 +62,7 @@ export function FetchingWrappedAssetCard(props) {
|
|
|
62
62
|
});
|
|
63
63
|
};
|
|
64
64
|
return React.useMemo(()=>{
|
|
65
|
-
if (status === 'error'
|
|
65
|
+
if (status === 'error') {
|
|
66
66
|
const card = /*#__PURE__*/ React.createElement(MissingAssetCard, {
|
|
67
67
|
asSquare: props.viewType !== 'link',
|
|
68
68
|
isDisabled: props.isDisabled,
|
|
@@ -32,7 +32,8 @@ function getFileType(file) {
|
|
|
32
32
|
}
|
|
33
33
|
const THUMBNAIL_SIZE = 150;
|
|
34
34
|
export const WrappedAssetCard = ({ asset, className, size, localeCode, defaultLocaleCode, activeLocales, localesStatusMap, isDisabled, isSelected, isClickable, useLocalizedEntityStatus, renderDragHandle, getEntityScheduledActions, onEdit, getAssetUrl, onRemove, releaseEntityStatus, releaseStatusMap, release, onAddToRelease })=>{
|
|
35
|
-
const
|
|
35
|
+
const status = entityHelpers.getEntityStatus(asset.sys, useLocalizedEntityStatus ? localeCode : undefined);
|
|
36
|
+
const entityFile = asset.fields.file ? asset.fields.file[localeCode] || asset.fields.file[defaultLocaleCode] : undefined;
|
|
36
37
|
const imageUrl = React.useMemo(()=>{
|
|
37
38
|
if (!entityFile?.url) return '';
|
|
38
39
|
if (size === 'small') {
|
|
@@ -49,14 +50,6 @@ export const WrappedAssetCard = ({ asset, className, size, localeCode, defaultLo
|
|
|
49
50
|
entityFile?.url,
|
|
50
51
|
size
|
|
51
52
|
]);
|
|
52
|
-
if (!asset?.sys?.id) {
|
|
53
|
-
return /*#__PURE__*/ React.createElement(MissingAssetCard, {
|
|
54
|
-
asSquare: true,
|
|
55
|
-
isDisabled: isDisabled,
|
|
56
|
-
onRemove: onRemove
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
const status = entityHelpers.getEntityStatus(asset.sys, useLocalizedEntityStatus ? localeCode : undefined);
|
|
60
53
|
if (status === 'deleted') {
|
|
61
54
|
return /*#__PURE__*/ React.createElement(MissingAssetCard, {
|
|
62
55
|
asSquare: true,
|
|
@@ -5,12 +5,6 @@ import { AssetThumbnail, EntityStatusBadge, MissingAssetCard } from '../../compo
|
|
|
5
5
|
import { renderActions, renderAssetInfo } from './AssetCardActions';
|
|
6
6
|
export const WrappedAssetLink = (props)=>{
|
|
7
7
|
const { className, href, onEdit, onRemove, isDisabled, isClickable = true } = props;
|
|
8
|
-
if (!props.asset?.sys?.id) {
|
|
9
|
-
return /*#__PURE__*/ React.createElement(MissingAssetCard, {
|
|
10
|
-
isDisabled: isDisabled,
|
|
11
|
-
onRemove: onRemove
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
8
|
const status = entityHelpers.getEntityStatus(props.asset.sys, props.useLocalizedEntityStatus ? props.localeCode : undefined);
|
|
15
9
|
if (status === 'deleted') {
|
|
16
10
|
return /*#__PURE__*/ React.createElement(MissingAssetCard, {
|
|
@@ -4,27 +4,6 @@ import { LocalePublishingPopover, ReleaseEntityStatusPopover, ReleaseEntityStatu
|
|
|
4
4
|
import { useScheduledActions } from '../ScheduledIconWithTooltip/ScheduledIconWithTooltip';
|
|
5
5
|
import { ScheduleTooltip } from '../ScheduledIconWithTooltip/ScheduleTooltip';
|
|
6
6
|
export function EntityStatusBadge({ entityType, getEntityScheduledActions, status, useLocalizedEntityStatus, localesStatusMap, activeLocales, entity, releaseStatusMap, releaseEntityStatus, release, ...props }) {
|
|
7
|
-
if (!entity?.sys?.id) {
|
|
8
|
-
return /*#__PURE__*/ React.createElement(StatusBadge, {
|
|
9
|
-
...props,
|
|
10
|
-
entityStatus: status
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
return /*#__PURE__*/ React.createElement(LoadedEntityStatusBadge, {
|
|
14
|
-
...props,
|
|
15
|
-
entityType: entityType,
|
|
16
|
-
getEntityScheduledActions: getEntityScheduledActions,
|
|
17
|
-
status: status,
|
|
18
|
-
useLocalizedEntityStatus: useLocalizedEntityStatus,
|
|
19
|
-
localesStatusMap: localesStatusMap,
|
|
20
|
-
activeLocales: activeLocales,
|
|
21
|
-
entity: entity,
|
|
22
|
-
releaseStatusMap: releaseStatusMap,
|
|
23
|
-
releaseEntityStatus: releaseEntityStatus,
|
|
24
|
-
release: release
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
function LoadedEntityStatusBadge({ entityType, getEntityScheduledActions, status, useLocalizedEntityStatus, localesStatusMap, activeLocales, entity, releaseStatusMap, releaseEntityStatus, release, ...props }) {
|
|
28
7
|
const { isError, isLoading, jobs } = useScheduledActions({
|
|
29
8
|
entityId: entity.sys.id,
|
|
30
9
|
entityType,
|
|
@@ -83,7 +83,7 @@ export function FetchingWrappedEntryCard(props) {
|
|
|
83
83
|
entry
|
|
84
84
|
]);
|
|
85
85
|
return React.useMemo(()=>{
|
|
86
|
-
if (status === 'error'
|
|
86
|
+
if (status === 'error') {
|
|
87
87
|
const card = /*#__PURE__*/ React.createElement(MissingEntityCard, {
|
|
88
88
|
isDisabled: props.isDisabled,
|
|
89
89
|
onRemove: onRemoveEntry,
|
|
@@ -15,7 +15,7 @@ export function WrappedEntryCard({ entry, entryUrl, contentType, activeLocales,
|
|
|
15
15
|
const [file, setFile] = React.useState(null);
|
|
16
16
|
React.useEffect(()=>{
|
|
17
17
|
let mounted = true;
|
|
18
|
-
if (entry
|
|
18
|
+
if (entry) {
|
|
19
19
|
getEntryImage({
|
|
20
20
|
entry,
|
|
21
21
|
contentType,
|
|
@@ -41,14 +41,7 @@ export function WrappedEntryCard({ entry, entryUrl, contentType, activeLocales,
|
|
|
41
41
|
localeCode,
|
|
42
42
|
defaultLocaleCode
|
|
43
43
|
]);
|
|
44
|
-
|
|
45
|
-
return /*#__PURE__*/ React.createElement(MissingEntityCard, {
|
|
46
|
-
isDisabled: isDisabled,
|
|
47
|
-
onRemove: onRemove,
|
|
48
|
-
providerName: "Contentful"
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
const status = getEntityStatus(entry.sys, useLocalizedEntityStatus ? localeCode : undefined);
|
|
44
|
+
const status = getEntityStatus(entry?.sys, useLocalizedEntityStatus ? localeCode : undefined);
|
|
52
45
|
if (status === 'deleted') {
|
|
53
46
|
return /*#__PURE__*/ React.createElement(MissingEntityCard, {
|
|
54
47
|
isDisabled: isDisabled,
|
|
@@ -5,7 +5,7 @@ import { EntryProps, LocaleProps, AssetProps } from 'contentful-management';
|
|
|
5
5
|
import { type UseScheduledActionsProps } from '../ScheduledIconWithTooltip/ScheduledIconWithTooltip';
|
|
6
6
|
type EntityStatusBadgeProps = Omit<UseScheduledActionsProps, 'entityId'> & {
|
|
7
7
|
status: EntityStatus;
|
|
8
|
-
entity
|
|
8
|
+
entity: EntryProps | AssetProps;
|
|
9
9
|
useLocalizedEntityStatus?: boolean;
|
|
10
10
|
localesStatusMap?: LocalePublishStatusMap;
|
|
11
11
|
activeLocales?: Pick<LocaleProps, 'code'>[];
|
|
@@ -7,5 +7,5 @@ type FunctionInvocationErrorCardProps = {
|
|
|
7
7
|
onRemove?: Function;
|
|
8
8
|
providerName?: string;
|
|
9
9
|
};
|
|
10
|
-
export declare function FunctionInvocationErrorCard({ providerName, organizationId, appDefinitionId, isDisabled, isSelected, onRemove }: FunctionInvocationErrorCardProps): React.JSX.Element;
|
|
10
|
+
export declare function FunctionInvocationErrorCard({ providerName, organizationId, appDefinitionId, isDisabled, isSelected, onRemove, }: FunctionInvocationErrorCardProps): React.JSX.Element;
|
|
11
11
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/field-editor-reference",
|
|
3
|
-
"version": "8.5.1-canary.
|
|
3
|
+
"version": "8.5.1-canary.8+6a2e7ea5",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@contentful/f36-components": "^6.7.1",
|
|
42
42
|
"@contentful/f36-icons": "^6.7.1",
|
|
43
43
|
"@contentful/f36-tokens": "^6.1.2",
|
|
44
|
-
"@contentful/field-editor-shared": "^4.6.
|
|
44
|
+
"@contentful/field-editor-shared": "^4.6.1-canary.8+6a2e7ea5",
|
|
45
45
|
"@contentful/mimetype": "^2.2.29",
|
|
46
46
|
"@dnd-kit/core": "^6.0.8",
|
|
47
47
|
"@dnd-kit/sortable": "^8.0.0",
|
|
@@ -78,5 +78,5 @@
|
|
|
78
78
|
"prettier --write"
|
|
79
79
|
]
|
|
80
80
|
},
|
|
81
|
-
"gitHead": "
|
|
81
|
+
"gitHead": "6a2e7ea577f3062298944fe57c6aea13010a545b"
|
|
82
82
|
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
const _react = /*#__PURE__*/ _interop_require_default(require("react"));
|
|
6
|
-
const _react1 = require("@testing-library/react");
|
|
7
|
-
const _vitest = require("vitest");
|
|
8
|
-
const _published_assetjson = /*#__PURE__*/ _interop_require_default(require("../__fixtures__/asset/published_asset.json"));
|
|
9
|
-
const _published_entryjson = /*#__PURE__*/ _interop_require_default(require("../__fixtures__/entry/published_entry.json"));
|
|
10
|
-
const _WrappedAssetCard = require("../assets/WrappedAssetCard/WrappedAssetCard");
|
|
11
|
-
const _WrappedAssetLink = require("../assets/WrappedAssetCard/WrappedAssetLink");
|
|
12
|
-
const _WrappedEntryCard = require("../entries/WrappedEntryCard/WrappedEntryCard");
|
|
13
|
-
function _interop_require_default(obj) {
|
|
14
|
-
return obj && obj.__esModule ? obj : {
|
|
15
|
-
default: obj
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
(0, _react1.configure)({
|
|
19
|
-
testIdAttribute: 'data-test-id'
|
|
20
|
-
});
|
|
21
|
-
const sharedProps = {
|
|
22
|
-
isDisabled: false,
|
|
23
|
-
localeCode: 'en-US',
|
|
24
|
-
defaultLocaleCode: 'en-US'
|
|
25
|
-
};
|
|
26
|
-
const cards = [
|
|
27
|
-
{
|
|
28
|
-
name: 'entry',
|
|
29
|
-
loadedEntity: _published_entryjson.default,
|
|
30
|
-
missingTestId: 'cf-ui-missing-entity-card',
|
|
31
|
-
renderEntity: (entity, getEntityScheduledActions)=>/*#__PURE__*/ _react.default.createElement(_WrappedEntryCard.WrappedEntryCard, {
|
|
32
|
-
...sharedProps,
|
|
33
|
-
entry: entity,
|
|
34
|
-
size: "small",
|
|
35
|
-
hasCardEditActions: false,
|
|
36
|
-
getAsset: _vitest.vi.fn().mockResolvedValue(undefined),
|
|
37
|
-
getEntityScheduledActions: getEntityScheduledActions
|
|
38
|
-
})
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
name: 'asset card',
|
|
42
|
-
loadedEntity: _published_assetjson.default,
|
|
43
|
-
missingTestId: 'cf-ui-missing-asset-card',
|
|
44
|
-
renderEntity: (entity, getEntityScheduledActions)=>/*#__PURE__*/ _react.default.createElement(_WrappedAssetCard.WrappedAssetCard, {
|
|
45
|
-
...sharedProps,
|
|
46
|
-
asset: entity,
|
|
47
|
-
size: "small",
|
|
48
|
-
getEntityScheduledActions: getEntityScheduledActions
|
|
49
|
-
})
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
name: 'asset link',
|
|
53
|
-
loadedEntity: _published_assetjson.default,
|
|
54
|
-
missingTestId: 'cf-ui-missing-asset-card',
|
|
55
|
-
renderEntity: (entity, getEntityScheduledActions)=>/*#__PURE__*/ _react.default.createElement(_WrappedAssetLink.WrappedAssetLink, {
|
|
56
|
-
...sharedProps,
|
|
57
|
-
asset: entity,
|
|
58
|
-
getEntityScheduledActions: getEntityScheduledActions
|
|
59
|
-
})
|
|
60
|
-
}
|
|
61
|
-
];
|
|
62
|
-
_vitest.describe.each(cards)('$name status', ({ renderEntity, missingTestId, loadedEntity })=>{
|
|
63
|
-
_vitest.test.each([
|
|
64
|
-
undefined,
|
|
65
|
-
{
|
|
66
|
-
sys: {}
|
|
67
|
-
}
|
|
68
|
-
])('shows a missing card instead of inferring a status for %j', (entity)=>{
|
|
69
|
-
const getEntityScheduledActions = _vitest.vi.fn().mockResolvedValue([]);
|
|
70
|
-
(0, _react1.render)(renderEntity(entity, getEntityScheduledActions));
|
|
71
|
-
(0, _vitest.expect)(_react1.screen.getByTestId(missingTestId)).toBeInTheDocument();
|
|
72
|
-
(0, _vitest.expect)(_react1.screen.queryByTestId('cf-ui-badge')).not.toBeInTheDocument();
|
|
73
|
-
(0, _vitest.expect)(getEntityScheduledActions).not.toHaveBeenCalled();
|
|
74
|
-
});
|
|
75
|
-
(0, _vitest.test)('handles missing-to-loaded-to-missing transitions', async ()=>{
|
|
76
|
-
const getEntityScheduledActions = _vitest.vi.fn().mockResolvedValue([]);
|
|
77
|
-
const { rerender } = (0, _react1.render)(renderEntity(undefined, getEntityScheduledActions));
|
|
78
|
-
await (0, _react1.act)(async ()=>{
|
|
79
|
-
rerender(renderEntity(loadedEntity, getEntityScheduledActions));
|
|
80
|
-
});
|
|
81
|
-
(0, _vitest.expect)(_react1.screen.getByText('published')).toBeInTheDocument();
|
|
82
|
-
(0, _vitest.expect)(_react1.screen.queryByTestId(missingTestId)).not.toBeInTheDocument();
|
|
83
|
-
rerender(renderEntity(undefined, getEntityScheduledActions));
|
|
84
|
-
(0, _vitest.expect)(_react1.screen.getByTestId(missingTestId)).toBeInTheDocument();
|
|
85
|
-
(0, _vitest.expect)(_react1.screen.queryByTestId('cf-ui-badge')).not.toBeInTheDocument();
|
|
86
|
-
});
|
|
87
|
-
});
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
const _react = /*#__PURE__*/ _interop_require_default(require("react"));
|
|
6
|
-
const _react1 = require("@testing-library/react");
|
|
7
|
-
const _vitest = require("vitest");
|
|
8
|
-
const _FetchingWrappedAssetCard = require("../assets/WrappedAssetCard/FetchingWrappedAssetCard");
|
|
9
|
-
const _FetchingWrappedEntryCard = require("../entries/WrappedEntryCard/FetchingWrappedEntryCard");
|
|
10
|
-
const _EntityStore = require("./EntityStore");
|
|
11
|
-
function _interop_require_default(obj) {
|
|
12
|
-
return obj && obj.__esModule ? obj : {
|
|
13
|
-
default: obj
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
_vitest.vi.mock('./EntityStore', async (importOriginal)=>({
|
|
17
|
-
...await importOriginal(),
|
|
18
|
-
useEntity: _vitest.vi.fn(),
|
|
19
|
-
useEntityLoader: _vitest.vi.fn()
|
|
20
|
-
}));
|
|
21
|
-
(0, _react1.configure)({
|
|
22
|
-
testIdAttribute: 'data-test-id'
|
|
23
|
-
});
|
|
24
|
-
const sdk = {
|
|
25
|
-
locales: {
|
|
26
|
-
available: [
|
|
27
|
-
'en-US'
|
|
28
|
-
],
|
|
29
|
-
default: 'en-US',
|
|
30
|
-
names: {
|
|
31
|
-
'en-US': 'English'
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
field: {
|
|
35
|
-
locale: 'en-US'
|
|
36
|
-
},
|
|
37
|
-
parameters: {
|
|
38
|
-
instance: {}
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
const props = {
|
|
42
|
-
sdk,
|
|
43
|
-
viewType: 'link',
|
|
44
|
-
isDisabled: false,
|
|
45
|
-
onRemove: _vitest.vi.fn()
|
|
46
|
-
};
|
|
47
|
-
const cards = [
|
|
48
|
-
{
|
|
49
|
-
name: 'entry',
|
|
50
|
-
missingTestId: 'cf-ui-missing-entity-card',
|
|
51
|
-
renderCard: ()=>/*#__PURE__*/ _react.default.createElement(_FetchingWrappedEntryCard.FetchingWrappedEntryCard, {
|
|
52
|
-
...props,
|
|
53
|
-
entryId: "linked-id",
|
|
54
|
-
allContentTypes: [],
|
|
55
|
-
isInitiallyDisabled: false,
|
|
56
|
-
hasCardEditActions: false,
|
|
57
|
-
parameters: {
|
|
58
|
-
instance: {}
|
|
59
|
-
}
|
|
60
|
-
})
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
name: 'asset',
|
|
64
|
-
missingTestId: 'cf-ui-missing-asset-card',
|
|
65
|
-
renderCard: ()=>/*#__PURE__*/ _react.default.createElement(_FetchingWrappedAssetCard.FetchingWrappedAssetCard, {
|
|
66
|
-
...props,
|
|
67
|
-
assetId: "linked-id"
|
|
68
|
-
})
|
|
69
|
-
}
|
|
70
|
-
];
|
|
71
|
-
(0, _vitest.beforeEach)(()=>{
|
|
72
|
-
_vitest.vi.mocked(_EntityStore.useEntityLoader).mockReturnValue({
|
|
73
|
-
getEntity: _vitest.vi.fn().mockResolvedValue(undefined),
|
|
74
|
-
getEntityScheduledActions: _vitest.vi.fn().mockResolvedValue([])
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
_vitest.describe.each(cards)('fetching $name status', ({ renderCard, missingTestId })=>{
|
|
78
|
-
_vitest.test.each([
|
|
79
|
-
undefined,
|
|
80
|
-
{
|
|
81
|
-
sys: {}
|
|
82
|
-
}
|
|
83
|
-
])('handles a completed fetch with missing metadata (%j)', (entity)=>{
|
|
84
|
-
_vitest.vi.mocked(_EntityStore.useEntity).mockReturnValue({
|
|
85
|
-
status: 'success',
|
|
86
|
-
data: entity,
|
|
87
|
-
currentEntity: undefined
|
|
88
|
-
});
|
|
89
|
-
(0, _react1.render)(renderCard());
|
|
90
|
-
(0, _vitest.expect)(_react1.screen.getByTestId(missingTestId)).toBeInTheDocument();
|
|
91
|
-
(0, _vitest.expect)(_react1.screen.queryByTestId('cf-ui-badge')).not.toBeInTheDocument();
|
|
92
|
-
});
|
|
93
|
-
(0, _vitest.test)('preserves the loading card while the entity is being fetched', ()=>{
|
|
94
|
-
_vitest.vi.mocked(_EntityStore.useEntity).mockReturnValue({
|
|
95
|
-
status: 'loading'
|
|
96
|
-
});
|
|
97
|
-
(0, _react1.render)(renderCard());
|
|
98
|
-
(0, _vitest.expect)(_react1.screen.getByTestId('cf-ui-skeleton-form')).toBeInTheDocument();
|
|
99
|
-
(0, _vitest.expect)(_react1.screen.queryByTestId(missingTestId)).not.toBeInTheDocument();
|
|
100
|
-
});
|
|
101
|
-
});
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
const _react = /*#__PURE__*/ _interop_require_default(require("react"));
|
|
6
|
-
const _react1 = require("@testing-library/react");
|
|
7
|
-
const _vitest = require("vitest");
|
|
8
|
-
const _EntityStatusBadge = require("./EntityStatusBadge");
|
|
9
|
-
function _interop_require_default(obj) {
|
|
10
|
-
return obj && obj.__esModule ? obj : {
|
|
11
|
-
default: obj
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
(0, _react1.configure)({
|
|
15
|
-
testIdAttribute: 'data-test-id'
|
|
16
|
-
});
|
|
17
|
-
const entity = {
|
|
18
|
-
sys: {
|
|
19
|
-
id: 'entry-id'
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
function createGetScheduledActions() {
|
|
23
|
-
return _vitest.vi.fn().mockResolvedValue([]);
|
|
24
|
-
}
|
|
25
|
-
(0, _vitest.describe)('EntityStatusBadge', ()=>{
|
|
26
|
-
_vitest.test.each([
|
|
27
|
-
[
|
|
28
|
-
'undefined',
|
|
29
|
-
undefined
|
|
30
|
-
],
|
|
31
|
-
[
|
|
32
|
-
'null',
|
|
33
|
-
null
|
|
34
|
-
],
|
|
35
|
-
[
|
|
36
|
-
'missing sys',
|
|
37
|
-
{}
|
|
38
|
-
],
|
|
39
|
-
[
|
|
40
|
-
'undefined sys',
|
|
41
|
-
{
|
|
42
|
-
sys: undefined
|
|
43
|
-
}
|
|
44
|
-
],
|
|
45
|
-
[
|
|
46
|
-
'null sys',
|
|
47
|
-
{
|
|
48
|
-
sys: null
|
|
49
|
-
}
|
|
50
|
-
],
|
|
51
|
-
[
|
|
52
|
-
'missing id',
|
|
53
|
-
{
|
|
54
|
-
sys: {}
|
|
55
|
-
}
|
|
56
|
-
]
|
|
57
|
-
])('renders the supplied status without fetching scheduled actions for %s', (_, entity)=>{
|
|
58
|
-
const getEntityScheduledActions = createGetScheduledActions();
|
|
59
|
-
(0, _react1.render)(/*#__PURE__*/ _react.default.createElement(_EntityStatusBadge.EntityStatusBadge, {
|
|
60
|
-
entity: entity,
|
|
61
|
-
status: "published",
|
|
62
|
-
entityType: "Entry",
|
|
63
|
-
getEntityScheduledActions: getEntityScheduledActions
|
|
64
|
-
}));
|
|
65
|
-
(0, _vitest.expect)(_react1.screen.getByText('published')).toBeInTheDocument();
|
|
66
|
-
(0, _vitest.expect)(getEntityScheduledActions).not.toHaveBeenCalled();
|
|
67
|
-
});
|
|
68
|
-
(0, _vitest.test)('handles an entity loading, disappearing and loading again', async ()=>{
|
|
69
|
-
const getEntityScheduledActions = createGetScheduledActions();
|
|
70
|
-
const props = {
|
|
71
|
-
status: 'draft',
|
|
72
|
-
entityType: 'Entry',
|
|
73
|
-
getEntityScheduledActions
|
|
74
|
-
};
|
|
75
|
-
const { rerender } = (0, _react1.render)(/*#__PURE__*/ _react.default.createElement(_EntityStatusBadge.EntityStatusBadge, props));
|
|
76
|
-
(0, _vitest.expect)(_react1.screen.getByText('draft')).toBeInTheDocument();
|
|
77
|
-
(0, _vitest.expect)(getEntityScheduledActions).not.toHaveBeenCalled();
|
|
78
|
-
await (0, _react1.act)(async ()=>{
|
|
79
|
-
rerender(/*#__PURE__*/ _react.default.createElement(_EntityStatusBadge.EntityStatusBadge, {
|
|
80
|
-
...props,
|
|
81
|
-
entity: entity
|
|
82
|
-
}));
|
|
83
|
-
});
|
|
84
|
-
(0, _vitest.expect)(getEntityScheduledActions).toHaveBeenCalledWith('Entry', 'entry-id');
|
|
85
|
-
rerender(/*#__PURE__*/ _react.default.createElement(_EntityStatusBadge.EntityStatusBadge, {
|
|
86
|
-
...props,
|
|
87
|
-
entity: null
|
|
88
|
-
}));
|
|
89
|
-
(0, _vitest.expect)(_react1.screen.getByText('draft')).toBeInTheDocument();
|
|
90
|
-
(0, _vitest.expect)(getEntityScheduledActions).toHaveBeenCalledTimes(1);
|
|
91
|
-
await (0, _react1.act)(async ()=>{
|
|
92
|
-
rerender(/*#__PURE__*/ _react.default.createElement(_EntityStatusBadge.EntityStatusBadge, {
|
|
93
|
-
...props,
|
|
94
|
-
entity: entity
|
|
95
|
-
}));
|
|
96
|
-
});
|
|
97
|
-
(0, _vitest.expect)(_react1.screen.getByText('draft')).toBeInTheDocument();
|
|
98
|
-
(0, _vitest.expect)(getEntityScheduledActions).toHaveBeenCalledTimes(2);
|
|
99
|
-
});
|
|
100
|
-
(0, _vitest.test)('still shows scheduled actions for a loaded entity', async ()=>{
|
|
101
|
-
const job = {
|
|
102
|
-
sys: {
|
|
103
|
-
id: 'scheduled-action-id'
|
|
104
|
-
},
|
|
105
|
-
action: 'publish',
|
|
106
|
-
scheduledFor: {
|
|
107
|
-
datetime: '2030-01-01T12:00:00.000Z'
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
const getEntityScheduledActions = createGetScheduledActions().mockResolvedValue([
|
|
111
|
-
job
|
|
112
|
-
]);
|
|
113
|
-
(0, _react1.render)(/*#__PURE__*/ _react.default.createElement(_EntityStatusBadge.EntityStatusBadge, {
|
|
114
|
-
entity: entity,
|
|
115
|
-
status: "draft",
|
|
116
|
-
entityType: "Entry",
|
|
117
|
-
getEntityScheduledActions: getEntityScheduledActions
|
|
118
|
-
}));
|
|
119
|
-
(0, _vitest.expect)(await _react1.screen.findByTestId('schedule-icon')).toBeInTheDocument();
|
|
120
|
-
(0, _vitest.expect)(_react1.screen.getByText('draft')).toBeInTheDocument();
|
|
121
|
-
(0, _vitest.expect)(getEntityScheduledActions).toHaveBeenCalledWith('Entry', 'entry-id');
|
|
122
|
-
});
|
|
123
|
-
(0, _vitest.test)('still shows the status when fetching scheduled actions fails', async ()=>{
|
|
124
|
-
const getEntityScheduledActions = createGetScheduledActions().mockRejectedValue(new Error('Unavailable'));
|
|
125
|
-
(0, _react1.render)(/*#__PURE__*/ _react.default.createElement(_EntityStatusBadge.EntityStatusBadge, {
|
|
126
|
-
entity: entity,
|
|
127
|
-
status: "archived",
|
|
128
|
-
entityType: "Entry",
|
|
129
|
-
getEntityScheduledActions: getEntityScheduledActions
|
|
130
|
-
}));
|
|
131
|
-
await (0, _react1.waitFor)(()=>(0, _vitest.expect)(getEntityScheduledActions).toHaveBeenCalledOnce());
|
|
132
|
-
(0, _vitest.expect)(_react1.screen.getByText('archived')).toBeInTheDocument();
|
|
133
|
-
});
|
|
134
|
-
});
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { act, configure, render, screen } from '@testing-library/react';
|
|
3
|
-
import { describe, expect, test, vi } from 'vitest';
|
|
4
|
-
import publishedAsset from '../__fixtures__/asset/published_asset.json';
|
|
5
|
-
import publishedEntry from '../__fixtures__/entry/published_entry.json';
|
|
6
|
-
import { WrappedAssetCard } from '../assets/WrappedAssetCard/WrappedAssetCard';
|
|
7
|
-
import { WrappedAssetLink } from '../assets/WrappedAssetCard/WrappedAssetLink';
|
|
8
|
-
import { WrappedEntryCard } from '../entries/WrappedEntryCard/WrappedEntryCard';
|
|
9
|
-
configure({
|
|
10
|
-
testIdAttribute: 'data-test-id'
|
|
11
|
-
});
|
|
12
|
-
const sharedProps = {
|
|
13
|
-
isDisabled: false,
|
|
14
|
-
localeCode: 'en-US',
|
|
15
|
-
defaultLocaleCode: 'en-US'
|
|
16
|
-
};
|
|
17
|
-
const cards = [
|
|
18
|
-
{
|
|
19
|
-
name: 'entry',
|
|
20
|
-
loadedEntity: publishedEntry,
|
|
21
|
-
missingTestId: 'cf-ui-missing-entity-card',
|
|
22
|
-
renderEntity: (entity, getEntityScheduledActions)=>/*#__PURE__*/ React.createElement(WrappedEntryCard, {
|
|
23
|
-
...sharedProps,
|
|
24
|
-
entry: entity,
|
|
25
|
-
size: "small",
|
|
26
|
-
hasCardEditActions: false,
|
|
27
|
-
getAsset: vi.fn().mockResolvedValue(undefined),
|
|
28
|
-
getEntityScheduledActions: getEntityScheduledActions
|
|
29
|
-
})
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
name: 'asset card',
|
|
33
|
-
loadedEntity: publishedAsset,
|
|
34
|
-
missingTestId: 'cf-ui-missing-asset-card',
|
|
35
|
-
renderEntity: (entity, getEntityScheduledActions)=>/*#__PURE__*/ React.createElement(WrappedAssetCard, {
|
|
36
|
-
...sharedProps,
|
|
37
|
-
asset: entity,
|
|
38
|
-
size: "small",
|
|
39
|
-
getEntityScheduledActions: getEntityScheduledActions
|
|
40
|
-
})
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
name: 'asset link',
|
|
44
|
-
loadedEntity: publishedAsset,
|
|
45
|
-
missingTestId: 'cf-ui-missing-asset-card',
|
|
46
|
-
renderEntity: (entity, getEntityScheduledActions)=>/*#__PURE__*/ React.createElement(WrappedAssetLink, {
|
|
47
|
-
...sharedProps,
|
|
48
|
-
asset: entity,
|
|
49
|
-
getEntityScheduledActions: getEntityScheduledActions
|
|
50
|
-
})
|
|
51
|
-
}
|
|
52
|
-
];
|
|
53
|
-
describe.each(cards)('$name status', ({ renderEntity, missingTestId, loadedEntity })=>{
|
|
54
|
-
test.each([
|
|
55
|
-
undefined,
|
|
56
|
-
{
|
|
57
|
-
sys: {}
|
|
58
|
-
}
|
|
59
|
-
])('shows a missing card instead of inferring a status for %j', (entity)=>{
|
|
60
|
-
const getEntityScheduledActions = vi.fn().mockResolvedValue([]);
|
|
61
|
-
render(renderEntity(entity, getEntityScheduledActions));
|
|
62
|
-
expect(screen.getByTestId(missingTestId)).toBeInTheDocument();
|
|
63
|
-
expect(screen.queryByTestId('cf-ui-badge')).not.toBeInTheDocument();
|
|
64
|
-
expect(getEntityScheduledActions).not.toHaveBeenCalled();
|
|
65
|
-
});
|
|
66
|
-
test('handles missing-to-loaded-to-missing transitions', async ()=>{
|
|
67
|
-
const getEntityScheduledActions = vi.fn().mockResolvedValue([]);
|
|
68
|
-
const { rerender } = render(renderEntity(undefined, getEntityScheduledActions));
|
|
69
|
-
await act(async ()=>{
|
|
70
|
-
rerender(renderEntity(loadedEntity, getEntityScheduledActions));
|
|
71
|
-
});
|
|
72
|
-
expect(screen.getByText('published')).toBeInTheDocument();
|
|
73
|
-
expect(screen.queryByTestId(missingTestId)).not.toBeInTheDocument();
|
|
74
|
-
rerender(renderEntity(undefined, getEntityScheduledActions));
|
|
75
|
-
expect(screen.getByTestId(missingTestId)).toBeInTheDocument();
|
|
76
|
-
expect(screen.queryByTestId('cf-ui-badge')).not.toBeInTheDocument();
|
|
77
|
-
});
|
|
78
|
-
});
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { configure, render, screen } from '@testing-library/react';
|
|
3
|
-
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
|
4
|
-
import { FetchingWrappedAssetCard } from '../assets/WrappedAssetCard/FetchingWrappedAssetCard';
|
|
5
|
-
import { FetchingWrappedEntryCard } from '../entries/WrappedEntryCard/FetchingWrappedEntryCard';
|
|
6
|
-
import { useEntity, useEntityLoader } from './EntityStore';
|
|
7
|
-
vi.mock('./EntityStore', async (importOriginal)=>({
|
|
8
|
-
...await importOriginal(),
|
|
9
|
-
useEntity: vi.fn(),
|
|
10
|
-
useEntityLoader: vi.fn()
|
|
11
|
-
}));
|
|
12
|
-
configure({
|
|
13
|
-
testIdAttribute: 'data-test-id'
|
|
14
|
-
});
|
|
15
|
-
const sdk = {
|
|
16
|
-
locales: {
|
|
17
|
-
available: [
|
|
18
|
-
'en-US'
|
|
19
|
-
],
|
|
20
|
-
default: 'en-US',
|
|
21
|
-
names: {
|
|
22
|
-
'en-US': 'English'
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
field: {
|
|
26
|
-
locale: 'en-US'
|
|
27
|
-
},
|
|
28
|
-
parameters: {
|
|
29
|
-
instance: {}
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
const props = {
|
|
33
|
-
sdk,
|
|
34
|
-
viewType: 'link',
|
|
35
|
-
isDisabled: false,
|
|
36
|
-
onRemove: vi.fn()
|
|
37
|
-
};
|
|
38
|
-
const cards = [
|
|
39
|
-
{
|
|
40
|
-
name: 'entry',
|
|
41
|
-
missingTestId: 'cf-ui-missing-entity-card',
|
|
42
|
-
renderCard: ()=>/*#__PURE__*/ React.createElement(FetchingWrappedEntryCard, {
|
|
43
|
-
...props,
|
|
44
|
-
entryId: "linked-id",
|
|
45
|
-
allContentTypes: [],
|
|
46
|
-
isInitiallyDisabled: false,
|
|
47
|
-
hasCardEditActions: false,
|
|
48
|
-
parameters: {
|
|
49
|
-
instance: {}
|
|
50
|
-
}
|
|
51
|
-
})
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
name: 'asset',
|
|
55
|
-
missingTestId: 'cf-ui-missing-asset-card',
|
|
56
|
-
renderCard: ()=>/*#__PURE__*/ React.createElement(FetchingWrappedAssetCard, {
|
|
57
|
-
...props,
|
|
58
|
-
assetId: "linked-id"
|
|
59
|
-
})
|
|
60
|
-
}
|
|
61
|
-
];
|
|
62
|
-
beforeEach(()=>{
|
|
63
|
-
vi.mocked(useEntityLoader).mockReturnValue({
|
|
64
|
-
getEntity: vi.fn().mockResolvedValue(undefined),
|
|
65
|
-
getEntityScheduledActions: vi.fn().mockResolvedValue([])
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
describe.each(cards)('fetching $name status', ({ renderCard, missingTestId })=>{
|
|
69
|
-
test.each([
|
|
70
|
-
undefined,
|
|
71
|
-
{
|
|
72
|
-
sys: {}
|
|
73
|
-
}
|
|
74
|
-
])('handles a completed fetch with missing metadata (%j)', (entity)=>{
|
|
75
|
-
vi.mocked(useEntity).mockReturnValue({
|
|
76
|
-
status: 'success',
|
|
77
|
-
data: entity,
|
|
78
|
-
currentEntity: undefined
|
|
79
|
-
});
|
|
80
|
-
render(renderCard());
|
|
81
|
-
expect(screen.getByTestId(missingTestId)).toBeInTheDocument();
|
|
82
|
-
expect(screen.queryByTestId('cf-ui-badge')).not.toBeInTheDocument();
|
|
83
|
-
});
|
|
84
|
-
test('preserves the loading card while the entity is being fetched', ()=>{
|
|
85
|
-
vi.mocked(useEntity).mockReturnValue({
|
|
86
|
-
status: 'loading'
|
|
87
|
-
});
|
|
88
|
-
render(renderCard());
|
|
89
|
-
expect(screen.getByTestId('cf-ui-skeleton-form')).toBeInTheDocument();
|
|
90
|
-
expect(screen.queryByTestId(missingTestId)).not.toBeInTheDocument();
|
|
91
|
-
});
|
|
92
|
-
});
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { act, configure, render, screen, waitFor } from '@testing-library/react';
|
|
3
|
-
import { describe, expect, test, vi } from 'vitest';
|
|
4
|
-
import { EntityStatusBadge } from './EntityStatusBadge';
|
|
5
|
-
configure({
|
|
6
|
-
testIdAttribute: 'data-test-id'
|
|
7
|
-
});
|
|
8
|
-
const entity = {
|
|
9
|
-
sys: {
|
|
10
|
-
id: 'entry-id'
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
function createGetScheduledActions() {
|
|
14
|
-
return vi.fn().mockResolvedValue([]);
|
|
15
|
-
}
|
|
16
|
-
describe('EntityStatusBadge', ()=>{
|
|
17
|
-
test.each([
|
|
18
|
-
[
|
|
19
|
-
'undefined',
|
|
20
|
-
undefined
|
|
21
|
-
],
|
|
22
|
-
[
|
|
23
|
-
'null',
|
|
24
|
-
null
|
|
25
|
-
],
|
|
26
|
-
[
|
|
27
|
-
'missing sys',
|
|
28
|
-
{}
|
|
29
|
-
],
|
|
30
|
-
[
|
|
31
|
-
'undefined sys',
|
|
32
|
-
{
|
|
33
|
-
sys: undefined
|
|
34
|
-
}
|
|
35
|
-
],
|
|
36
|
-
[
|
|
37
|
-
'null sys',
|
|
38
|
-
{
|
|
39
|
-
sys: null
|
|
40
|
-
}
|
|
41
|
-
],
|
|
42
|
-
[
|
|
43
|
-
'missing id',
|
|
44
|
-
{
|
|
45
|
-
sys: {}
|
|
46
|
-
}
|
|
47
|
-
]
|
|
48
|
-
])('renders the supplied status without fetching scheduled actions for %s', (_, entity)=>{
|
|
49
|
-
const getEntityScheduledActions = createGetScheduledActions();
|
|
50
|
-
render(/*#__PURE__*/ React.createElement(EntityStatusBadge, {
|
|
51
|
-
entity: entity,
|
|
52
|
-
status: "published",
|
|
53
|
-
entityType: "Entry",
|
|
54
|
-
getEntityScheduledActions: getEntityScheduledActions
|
|
55
|
-
}));
|
|
56
|
-
expect(screen.getByText('published')).toBeInTheDocument();
|
|
57
|
-
expect(getEntityScheduledActions).not.toHaveBeenCalled();
|
|
58
|
-
});
|
|
59
|
-
test('handles an entity loading, disappearing and loading again', async ()=>{
|
|
60
|
-
const getEntityScheduledActions = createGetScheduledActions();
|
|
61
|
-
const props = {
|
|
62
|
-
status: 'draft',
|
|
63
|
-
entityType: 'Entry',
|
|
64
|
-
getEntityScheduledActions
|
|
65
|
-
};
|
|
66
|
-
const { rerender } = render(/*#__PURE__*/ React.createElement(EntityStatusBadge, props));
|
|
67
|
-
expect(screen.getByText('draft')).toBeInTheDocument();
|
|
68
|
-
expect(getEntityScheduledActions).not.toHaveBeenCalled();
|
|
69
|
-
await act(async ()=>{
|
|
70
|
-
rerender(/*#__PURE__*/ React.createElement(EntityStatusBadge, {
|
|
71
|
-
...props,
|
|
72
|
-
entity: entity
|
|
73
|
-
}));
|
|
74
|
-
});
|
|
75
|
-
expect(getEntityScheduledActions).toHaveBeenCalledWith('Entry', 'entry-id');
|
|
76
|
-
rerender(/*#__PURE__*/ React.createElement(EntityStatusBadge, {
|
|
77
|
-
...props,
|
|
78
|
-
entity: null
|
|
79
|
-
}));
|
|
80
|
-
expect(screen.getByText('draft')).toBeInTheDocument();
|
|
81
|
-
expect(getEntityScheduledActions).toHaveBeenCalledTimes(1);
|
|
82
|
-
await act(async ()=>{
|
|
83
|
-
rerender(/*#__PURE__*/ React.createElement(EntityStatusBadge, {
|
|
84
|
-
...props,
|
|
85
|
-
entity: entity
|
|
86
|
-
}));
|
|
87
|
-
});
|
|
88
|
-
expect(screen.getByText('draft')).toBeInTheDocument();
|
|
89
|
-
expect(getEntityScheduledActions).toHaveBeenCalledTimes(2);
|
|
90
|
-
});
|
|
91
|
-
test('still shows scheduled actions for a loaded entity', async ()=>{
|
|
92
|
-
const job = {
|
|
93
|
-
sys: {
|
|
94
|
-
id: 'scheduled-action-id'
|
|
95
|
-
},
|
|
96
|
-
action: 'publish',
|
|
97
|
-
scheduledFor: {
|
|
98
|
-
datetime: '2030-01-01T12:00:00.000Z'
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
const getEntityScheduledActions = createGetScheduledActions().mockResolvedValue([
|
|
102
|
-
job
|
|
103
|
-
]);
|
|
104
|
-
render(/*#__PURE__*/ React.createElement(EntityStatusBadge, {
|
|
105
|
-
entity: entity,
|
|
106
|
-
status: "draft",
|
|
107
|
-
entityType: "Entry",
|
|
108
|
-
getEntityScheduledActions: getEntityScheduledActions
|
|
109
|
-
}));
|
|
110
|
-
expect(await screen.findByTestId('schedule-icon')).toBeInTheDocument();
|
|
111
|
-
expect(screen.getByText('draft')).toBeInTheDocument();
|
|
112
|
-
expect(getEntityScheduledActions).toHaveBeenCalledWith('Entry', 'entry-id');
|
|
113
|
-
});
|
|
114
|
-
test('still shows the status when fetching scheduled actions fails', async ()=>{
|
|
115
|
-
const getEntityScheduledActions = createGetScheduledActions().mockRejectedValue(new Error('Unavailable'));
|
|
116
|
-
render(/*#__PURE__*/ React.createElement(EntityStatusBadge, {
|
|
117
|
-
entity: entity,
|
|
118
|
-
status: "archived",
|
|
119
|
-
entityType: "Entry",
|
|
120
|
-
getEntityScheduledActions: getEntityScheduledActions
|
|
121
|
-
}));
|
|
122
|
-
await waitFor(()=>expect(getEntityScheduledActions).toHaveBeenCalledOnce());
|
|
123
|
-
expect(screen.getByText('archived')).toBeInTheDocument();
|
|
124
|
-
});
|
|
125
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|