@contentful/field-editor-reference 5.11.0 → 5.12.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/dist/cjs/components/MissingEntityCard/MissingEntityCard.js +2 -1
- package/dist/cjs/components/ResourceEntityErrorCard/ResourceEntityErrorCard.js +67 -0
- package/dist/cjs/{resources/Cards → components/ResourceEntityErrorCard}/UnsupportedEntityCard.js +3 -2
- package/dist/cjs/components/index.js +4 -0
- package/dist/cjs/index.js +3 -0
- package/dist/cjs/resources/Cards/ResourceCard.js +3 -8
- package/dist/cjs/resources/Cards/ResourceCard.spec.js +149 -0
- package/dist/esm/components/MissingEntityCard/MissingEntityCard.js +2 -1
- package/dist/esm/components/ResourceEntityErrorCard/ResourceEntityErrorCard.js +18 -0
- package/dist/esm/{resources/Cards → components/ResourceEntityErrorCard}/UnsupportedEntityCard.js +3 -2
- package/dist/esm/components/index.js +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/resources/Cards/ResourceCard.js +5 -10
- package/dist/esm/resources/Cards/ResourceCard.spec.js +101 -0
- package/dist/types/components/MissingEntityCard/MissingEntityCard.d.ts +1 -0
- package/dist/types/components/ResourceEntityErrorCard/ResourceEntityErrorCard.d.ts +8 -0
- package/dist/types/{resources/Cards → components/ResourceEntityErrorCard}/UnsupportedEntityCard.d.ts +2 -1
- package/dist/types/components/index.d.ts +1 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/resources/Cards/ResourceCard.spec.d.ts +1 -0
- package/package.json +2 -2
|
@@ -54,7 +54,8 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
54
54
|
function MissingEntityCard(props) {
|
|
55
55
|
return _react.createElement(_f36components.Card, {
|
|
56
56
|
className: _styles.card,
|
|
57
|
-
testId: "cf-ui-missing-entry-card"
|
|
57
|
+
testId: "cf-ui-missing-entry-card",
|
|
58
|
+
isSelected: props.isSelected
|
|
58
59
|
}, _react.createElement(_f36components.Flex, {
|
|
59
60
|
alignItems: "center",
|
|
60
61
|
justifyContent: "space-between"
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "ResourceEntityErrorCard", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return ResourceEntityErrorCard;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = _interop_require_wildcard(require("react"));
|
|
12
|
+
const _EntityStore = require("../../common/EntityStore");
|
|
13
|
+
const _MissingEntityCard = require("../MissingEntityCard/MissingEntityCard");
|
|
14
|
+
const _UnsupportedEntityCard = require("./UnsupportedEntityCard");
|
|
15
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
16
|
+
if (typeof WeakMap !== "function") return null;
|
|
17
|
+
var cacheBabelInterop = new WeakMap();
|
|
18
|
+
var cacheNodeInterop = new WeakMap();
|
|
19
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
20
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
21
|
+
})(nodeInterop);
|
|
22
|
+
}
|
|
23
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
24
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
25
|
+
return obj;
|
|
26
|
+
}
|
|
27
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
28
|
+
return {
|
|
29
|
+
default: obj
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
33
|
+
if (cache && cache.has(obj)) {
|
|
34
|
+
return cache.get(obj);
|
|
35
|
+
}
|
|
36
|
+
var newObj = {};
|
|
37
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
38
|
+
for(var key in obj){
|
|
39
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
40
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
41
|
+
if (desc && (desc.get || desc.set)) {
|
|
42
|
+
Object.defineProperty(newObj, key, desc);
|
|
43
|
+
} else {
|
|
44
|
+
newObj[key] = obj[key];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
newObj.default = obj;
|
|
49
|
+
if (cache) {
|
|
50
|
+
cache.set(obj, newObj);
|
|
51
|
+
}
|
|
52
|
+
return newObj;
|
|
53
|
+
}
|
|
54
|
+
function ResourceEntityErrorCard(props) {
|
|
55
|
+
if ((0, _EntityStore.isUnsupportedError)(props.error)) {
|
|
56
|
+
return _react.createElement(_UnsupportedEntityCard.UnsupportedEntityCard, {
|
|
57
|
+
linkType: props.linkType,
|
|
58
|
+
isSelected: props.isSelected
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return _react.createElement(_MissingEntityCard.MissingEntityCard, {
|
|
62
|
+
entityType: "Entry",
|
|
63
|
+
isDisabled: props.isDisabled,
|
|
64
|
+
isSelected: props.isSelected,
|
|
65
|
+
onRemove: props.onRemove
|
|
66
|
+
});
|
|
67
|
+
}
|
package/dist/cjs/{resources/Cards → components/ResourceEntityErrorCard}/UnsupportedEntityCard.js
RENAMED
|
@@ -57,8 +57,9 @@ const styles = {
|
|
|
57
57
|
};
|
|
58
58
|
function UnsupportedEntityCard(props) {
|
|
59
59
|
return _react.createElement(_f36components.Card, {
|
|
60
|
-
className: styles.card
|
|
60
|
+
className: styles.card,
|
|
61
|
+
isSelected: props.isSelected
|
|
61
62
|
}, _react.createElement(_f36components.SectionHeading, {
|
|
62
63
|
marginBottom: "none"
|
|
63
|
-
}, "Resource type ", props.
|
|
64
|
+
}, "Resource type ", props.linkType, " is currently not supported"));
|
|
64
65
|
}
|
|
@@ -32,6 +32,9 @@ _export(exports, {
|
|
|
32
32
|
},
|
|
33
33
|
AssetThumbnail: function() {
|
|
34
34
|
return _AssetThumbnail.AssetThumbnail;
|
|
35
|
+
},
|
|
36
|
+
ResourceEntityErrorCard: function() {
|
|
37
|
+
return _ResourceEntityErrorCard.ResourceEntityErrorCard;
|
|
35
38
|
}
|
|
36
39
|
});
|
|
37
40
|
const _CombinedLinkActions = require("./LinkActions/CombinedLinkActions");
|
|
@@ -42,3 +45,4 @@ const _CreateEntryMenuTrigger = require("./CreateEntryLinkButton/CreateEntryMenu
|
|
|
42
45
|
const _ScheduledIconWithTooltip = require("./ScheduledIconWithTooltip/ScheduledIconWithTooltip");
|
|
43
46
|
const _ScheduleTooltip = require("./ScheduledIconWithTooltip/ScheduleTooltip");
|
|
44
47
|
const _AssetThumbnail = require("./AssetThumbnail/AssetThumbnail");
|
|
48
|
+
const _ResourceEntityErrorCard = require("./ResourceEntityErrorCard/ResourceEntityErrorCard");
|
package/dist/cjs/index.js
CHANGED
|
@@ -24,6 +24,9 @@ _export(exports, {
|
|
|
24
24
|
AssetThumbnail: function() {
|
|
25
25
|
return _components.AssetThumbnail;
|
|
26
26
|
},
|
|
27
|
+
ResourceEntityErrorCard: function() {
|
|
28
|
+
return _components.ResourceEntityErrorCard;
|
|
29
|
+
},
|
|
27
30
|
MissingEntityCard: function() {
|
|
28
31
|
return _components.MissingEntityCard;
|
|
29
32
|
},
|
|
@@ -14,7 +14,6 @@ const _f36components = require("@contentful/f36-components");
|
|
|
14
14
|
const _EntityStore = require("../../common/EntityStore");
|
|
15
15
|
const _components = require("../../components");
|
|
16
16
|
const _ContentfulEntryCard = require("./ContentfulEntryCard");
|
|
17
|
-
const _UnsupportedEntityCard = require("./UnsupportedEntityCard");
|
|
18
17
|
function _getRequireWildcardCache(nodeInterop) {
|
|
19
18
|
if (typeof WeakMap !== "function") return null;
|
|
20
19
|
var cacheBabelInterop = new WeakMap();
|
|
@@ -76,13 +75,9 @@ function ExistingResourceCard(props) {
|
|
|
76
75
|
...props
|
|
77
76
|
});
|
|
78
77
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
return _react.createElement(_components.MissingEntityCard, {
|
|
85
|
-
entityType: "Entry",
|
|
78
|
+
return _react.createElement(_components.ResourceEntityErrorCard, {
|
|
79
|
+
linkType: resourceLink.sys.linkType,
|
|
80
|
+
error: error,
|
|
86
81
|
isDisabled: props.isDisabled,
|
|
87
82
|
onRemove: props.onRemove
|
|
88
83
|
});
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
const _react = _interop_require_wildcard(require("react"));
|
|
6
|
+
require("@testing-library/jest-dom");
|
|
7
|
+
const _fieldeditortestutils = require("@contentful/field-editor-test-utils");
|
|
8
|
+
const _react1 = require("@testing-library/react");
|
|
9
|
+
const _published_content_typejson = _interop_require_default(require("../../__fixtures__/content-type/published_content_type.json"));
|
|
10
|
+
const _published_entryjson = _interop_require_default(require("../../__fixtures__/entry/published_entry.json"));
|
|
11
|
+
const _indifferent_spacejson = _interop_require_default(require("../../__fixtures__/space/indifferent_space.json"));
|
|
12
|
+
const _EntityStore = require("../../common/EntityStore");
|
|
13
|
+
const _ResourceCard = require("./ResourceCard");
|
|
14
|
+
function _interop_require_default(obj) {
|
|
15
|
+
return obj && obj.__esModule ? obj : {
|
|
16
|
+
default: obj
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
20
|
+
if (typeof WeakMap !== "function") return null;
|
|
21
|
+
var cacheBabelInterop = new WeakMap();
|
|
22
|
+
var cacheNodeInterop = new WeakMap();
|
|
23
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
24
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
25
|
+
})(nodeInterop);
|
|
26
|
+
}
|
|
27
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
28
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
29
|
+
return obj;
|
|
30
|
+
}
|
|
31
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
32
|
+
return {
|
|
33
|
+
default: obj
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
37
|
+
if (cache && cache.has(obj)) {
|
|
38
|
+
return cache.get(obj);
|
|
39
|
+
}
|
|
40
|
+
var newObj = {};
|
|
41
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
42
|
+
for(var key in obj){
|
|
43
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
44
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
45
|
+
if (desc && (desc.get || desc.set)) {
|
|
46
|
+
Object.defineProperty(newObj, key, desc);
|
|
47
|
+
} else {
|
|
48
|
+
newObj[key] = obj[key];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
newObj.default = obj;
|
|
53
|
+
if (cache) {
|
|
54
|
+
cache.set(obj, newObj);
|
|
55
|
+
}
|
|
56
|
+
return newObj;
|
|
57
|
+
}
|
|
58
|
+
(0, _react1.configure)({
|
|
59
|
+
testIdAttribute: 'data-test-id'
|
|
60
|
+
});
|
|
61
|
+
jest.mock('react-intersection-observer', ()=>({
|
|
62
|
+
useInView: jest.fn().mockReturnValue({})
|
|
63
|
+
}));
|
|
64
|
+
const resolvableEntryUrn = 'crn:contentful:::content:spaces/space-id/entries/linked-entry-urn';
|
|
65
|
+
const unknownEntryUrn = 'crn:contentful:::content:spaces/space-id/entries/unknown-entry-urn';
|
|
66
|
+
const sdk = {
|
|
67
|
+
locales: {
|
|
68
|
+
default: 'en-US'
|
|
69
|
+
},
|
|
70
|
+
cmaAdapter: (0, _fieldeditortestutils.createFakeCMAAdapter)({
|
|
71
|
+
ContentType: {
|
|
72
|
+
get: jest.fn().mockReturnValue(_published_content_typejson.default)
|
|
73
|
+
},
|
|
74
|
+
Entry: {
|
|
75
|
+
get: jest.fn().mockImplementation(({ entryId })=>{
|
|
76
|
+
if (entryId === 'linked-entry-urn') {
|
|
77
|
+
return Promise.resolve(_published_entryjson.default);
|
|
78
|
+
}
|
|
79
|
+
return Promise.reject(new Error());
|
|
80
|
+
})
|
|
81
|
+
},
|
|
82
|
+
Locale: {
|
|
83
|
+
getMany: jest.fn().mockResolvedValue({
|
|
84
|
+
items: [
|
|
85
|
+
{
|
|
86
|
+
default: true,
|
|
87
|
+
code: 'en'
|
|
88
|
+
}
|
|
89
|
+
]
|
|
90
|
+
})
|
|
91
|
+
},
|
|
92
|
+
ScheduledAction: {
|
|
93
|
+
getMany: jest.fn().mockResolvedValue({
|
|
94
|
+
items: [],
|
|
95
|
+
total: 0
|
|
96
|
+
})
|
|
97
|
+
},
|
|
98
|
+
Space: {
|
|
99
|
+
get: jest.fn().mockResolvedValue(_indifferent_spacejson.default)
|
|
100
|
+
}
|
|
101
|
+
}),
|
|
102
|
+
space: {
|
|
103
|
+
onEntityChanged: jest.fn()
|
|
104
|
+
},
|
|
105
|
+
navigator: {},
|
|
106
|
+
ids: {
|
|
107
|
+
space: 'space-id',
|
|
108
|
+
environment: 'environment-id'
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
function renderResourceCard({ linkType ='Contentful:Entry' , entryUrn =resolvableEntryUrn } = {}) {
|
|
112
|
+
return (0, _react1.render)(_react.createElement(_EntityStore.EntityProvider, {
|
|
113
|
+
sdk: sdk
|
|
114
|
+
}, _react.createElement(_ResourceCard.ResourceCard, {
|
|
115
|
+
isDisabled: false,
|
|
116
|
+
getEntryRouteHref: ()=>'',
|
|
117
|
+
resourceLink: {
|
|
118
|
+
sys: {
|
|
119
|
+
type: 'ResourceLink',
|
|
120
|
+
linkType: linkType,
|
|
121
|
+
urn: entryUrn
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
})));
|
|
125
|
+
}
|
|
126
|
+
describe('ResourceCard', ()=>{
|
|
127
|
+
it('renders entry card', async ()=>{
|
|
128
|
+
const { getByTestId , getByText } = renderResourceCard();
|
|
129
|
+
await (0, _react1.waitFor)(()=>expect(getByTestId('cf-ui-entry-card')).toBeDefined());
|
|
130
|
+
expect(getByText(_published_entryjson.default.fields.exField['en-US'])).toBeDefined();
|
|
131
|
+
expect(getByText(_indifferent_spacejson.default.name)).toBeDefined();
|
|
132
|
+
});
|
|
133
|
+
it('renders skeleton when no data is provided', ()=>{
|
|
134
|
+
const { getByTestId } = renderResourceCard();
|
|
135
|
+
expect(getByTestId('cf-ui-skeleton-form')).toBeDefined();
|
|
136
|
+
});
|
|
137
|
+
it('renders unsupported entity card when unsupported link is passed', async ()=>{
|
|
138
|
+
const { getByText } = renderResourceCard({
|
|
139
|
+
linkType: 'Contentful:UnsupportedLink'
|
|
140
|
+
});
|
|
141
|
+
await (0, _react1.waitFor)(()=>expect(getByText('Resource type Contentful:UnsupportedLink is currently not supported')).toBeDefined());
|
|
142
|
+
});
|
|
143
|
+
it('renders missing entity card when unknown error is returned', async ()=>{
|
|
144
|
+
const { getByTestId } = renderResourceCard({
|
|
145
|
+
entryUrn: unknownEntryUrn
|
|
146
|
+
});
|
|
147
|
+
await (0, _react1.waitFor)(()=>expect(getByTestId('cf-ui-missing-entry-card')).toBeDefined());
|
|
148
|
+
});
|
|
149
|
+
});
|
|
@@ -5,7 +5,8 @@ import * as styles from './styles';
|
|
|
5
5
|
export function MissingEntityCard(props) {
|
|
6
6
|
return React.createElement(Card, {
|
|
7
7
|
className: styles.card,
|
|
8
|
-
testId: "cf-ui-missing-entry-card"
|
|
8
|
+
testId: "cf-ui-missing-entry-card",
|
|
9
|
+
isSelected: props.isSelected
|
|
9
10
|
}, React.createElement(Flex, {
|
|
10
11
|
alignItems: "center",
|
|
11
12
|
justifyContent: "space-between"
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { isUnsupportedError } from '../../common/EntityStore';
|
|
3
|
+
import { MissingEntityCard } from '../MissingEntityCard/MissingEntityCard';
|
|
4
|
+
import { UnsupportedEntityCard } from './UnsupportedEntityCard';
|
|
5
|
+
export function ResourceEntityErrorCard(props) {
|
|
6
|
+
if (isUnsupportedError(props.error)) {
|
|
7
|
+
return React.createElement(UnsupportedEntityCard, {
|
|
8
|
+
linkType: props.linkType,
|
|
9
|
+
isSelected: props.isSelected
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
return React.createElement(MissingEntityCard, {
|
|
13
|
+
entityType: "Entry",
|
|
14
|
+
isDisabled: props.isDisabled,
|
|
15
|
+
isSelected: props.isSelected,
|
|
16
|
+
onRemove: props.onRemove
|
|
17
|
+
});
|
|
18
|
+
}
|
package/dist/esm/{resources/Cards → components/ResourceEntityErrorCard}/UnsupportedEntityCard.js
RENAMED
|
@@ -8,8 +8,9 @@ const styles = {
|
|
|
8
8
|
};
|
|
9
9
|
export function UnsupportedEntityCard(props) {
|
|
10
10
|
return React.createElement(Card, {
|
|
11
|
-
className: styles.card
|
|
11
|
+
className: styles.card,
|
|
12
|
+
isSelected: props.isSelected
|
|
12
13
|
}, React.createElement(SectionHeading, {
|
|
13
14
|
marginBottom: "none"
|
|
14
|
-
}, "Resource type ", props.
|
|
15
|
+
}, "Resource type ", props.linkType, " is currently not supported"));
|
|
15
16
|
}
|
|
@@ -6,3 +6,4 @@ export { CreateEntryMenuTrigger } from './CreateEntryLinkButton/CreateEntryMenuT
|
|
|
6
6
|
export { ScheduledIconWithTooltip } from './ScheduledIconWithTooltip/ScheduledIconWithTooltip';
|
|
7
7
|
export { getScheduleTooltipContent } from './ScheduledIconWithTooltip/ScheduleTooltip';
|
|
8
8
|
export { AssetThumbnail } from './AssetThumbnail/AssetThumbnail';
|
|
9
|
+
export { ResourceEntityErrorCard } from './ResourceEntityErrorCard/ResourceEntityErrorCard';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { CreateEntryMenuTrigger, CreateEntryLinkButton, getScheduleTooltipContent, ScheduledIconWithTooltip, AssetThumbnail, MissingEntityCard, CombinedLinkActions } from './components';
|
|
1
|
+
export { CreateEntryMenuTrigger, CreateEntryLinkButton, getScheduleTooltipContent, ScheduledIconWithTooltip, AssetThumbnail, ResourceEntityErrorCard, MissingEntityCard, CombinedLinkActions } from './components';
|
|
2
2
|
export { SingleEntryReferenceEditor, MultipleEntryReferenceEditor, WrappedEntryCard } from './entries';
|
|
3
3
|
export { SingleMediaEditor, MultipleMediaEditor, WrappedAssetCard } from './assets';
|
|
4
4
|
export { SortableLinkList } from './common/SortableLinkList';
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { useInView } from 'react-intersection-observer';
|
|
3
3
|
import { EntryCard } from '@contentful/f36-components';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { useResource } from '../../common/EntityStore';
|
|
5
|
+
import { ResourceEntityErrorCard } from '../../components';
|
|
6
6
|
import { ContentfulEntryCard } from './ContentfulEntryCard';
|
|
7
|
-
import { UnsupportedEntityCard } from './UnsupportedEntityCard';
|
|
8
7
|
function ResourceCardSkeleton() {
|
|
9
8
|
return React.createElement(EntryCard, {
|
|
10
9
|
size: "small",
|
|
@@ -27,13 +26,9 @@ function ExistingResourceCard(props) {
|
|
|
27
26
|
...props
|
|
28
27
|
});
|
|
29
28
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
return React.createElement(MissingEntityCard, {
|
|
36
|
-
entityType: "Entry",
|
|
29
|
+
return React.createElement(ResourceEntityErrorCard, {
|
|
30
|
+
linkType: resourceLink.sys.linkType,
|
|
31
|
+
error: error,
|
|
37
32
|
isDisabled: props.isDisabled,
|
|
38
33
|
onRemove: props.onRemove
|
|
39
34
|
});
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import '@testing-library/jest-dom';
|
|
3
|
+
import { createFakeCMAAdapter } from '@contentful/field-editor-test-utils';
|
|
4
|
+
import { configure, render, waitFor } from '@testing-library/react';
|
|
5
|
+
import publishedCT from '../../__fixtures__/content-type/published_content_type.json';
|
|
6
|
+
import publishedEntry from '../../__fixtures__/entry/published_entry.json';
|
|
7
|
+
import space from '../../__fixtures__/space/indifferent_space.json';
|
|
8
|
+
import { EntityProvider } from '../../common/EntityStore';
|
|
9
|
+
import { ResourceCard } from './ResourceCard';
|
|
10
|
+
configure({
|
|
11
|
+
testIdAttribute: 'data-test-id'
|
|
12
|
+
});
|
|
13
|
+
jest.mock('react-intersection-observer', ()=>({
|
|
14
|
+
useInView: jest.fn().mockReturnValue({})
|
|
15
|
+
}));
|
|
16
|
+
const resolvableEntryUrn = 'crn:contentful:::content:spaces/space-id/entries/linked-entry-urn';
|
|
17
|
+
const unknownEntryUrn = 'crn:contentful:::content:spaces/space-id/entries/unknown-entry-urn';
|
|
18
|
+
const sdk = {
|
|
19
|
+
locales: {
|
|
20
|
+
default: 'en-US'
|
|
21
|
+
},
|
|
22
|
+
cmaAdapter: createFakeCMAAdapter({
|
|
23
|
+
ContentType: {
|
|
24
|
+
get: jest.fn().mockReturnValue(publishedCT)
|
|
25
|
+
},
|
|
26
|
+
Entry: {
|
|
27
|
+
get: jest.fn().mockImplementation(({ entryId })=>{
|
|
28
|
+
if (entryId === 'linked-entry-urn') {
|
|
29
|
+
return Promise.resolve(publishedEntry);
|
|
30
|
+
}
|
|
31
|
+
return Promise.reject(new Error());
|
|
32
|
+
})
|
|
33
|
+
},
|
|
34
|
+
Locale: {
|
|
35
|
+
getMany: jest.fn().mockResolvedValue({
|
|
36
|
+
items: [
|
|
37
|
+
{
|
|
38
|
+
default: true,
|
|
39
|
+
code: 'en'
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
})
|
|
43
|
+
},
|
|
44
|
+
ScheduledAction: {
|
|
45
|
+
getMany: jest.fn().mockResolvedValue({
|
|
46
|
+
items: [],
|
|
47
|
+
total: 0
|
|
48
|
+
})
|
|
49
|
+
},
|
|
50
|
+
Space: {
|
|
51
|
+
get: jest.fn().mockResolvedValue(space)
|
|
52
|
+
}
|
|
53
|
+
}),
|
|
54
|
+
space: {
|
|
55
|
+
onEntityChanged: jest.fn()
|
|
56
|
+
},
|
|
57
|
+
navigator: {},
|
|
58
|
+
ids: {
|
|
59
|
+
space: 'space-id',
|
|
60
|
+
environment: 'environment-id'
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
function renderResourceCard({ linkType ='Contentful:Entry' , entryUrn =resolvableEntryUrn } = {}) {
|
|
64
|
+
return render(React.createElement(EntityProvider, {
|
|
65
|
+
sdk: sdk
|
|
66
|
+
}, React.createElement(ResourceCard, {
|
|
67
|
+
isDisabled: false,
|
|
68
|
+
getEntryRouteHref: ()=>'',
|
|
69
|
+
resourceLink: {
|
|
70
|
+
sys: {
|
|
71
|
+
type: 'ResourceLink',
|
|
72
|
+
linkType: linkType,
|
|
73
|
+
urn: entryUrn
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
})));
|
|
77
|
+
}
|
|
78
|
+
describe('ResourceCard', ()=>{
|
|
79
|
+
it('renders entry card', async ()=>{
|
|
80
|
+
const { getByTestId , getByText } = renderResourceCard();
|
|
81
|
+
await waitFor(()=>expect(getByTestId('cf-ui-entry-card')).toBeDefined());
|
|
82
|
+
expect(getByText(publishedEntry.fields.exField['en-US'])).toBeDefined();
|
|
83
|
+
expect(getByText(space.name)).toBeDefined();
|
|
84
|
+
});
|
|
85
|
+
it('renders skeleton when no data is provided', ()=>{
|
|
86
|
+
const { getByTestId } = renderResourceCard();
|
|
87
|
+
expect(getByTestId('cf-ui-skeleton-form')).toBeDefined();
|
|
88
|
+
});
|
|
89
|
+
it('renders unsupported entity card when unsupported link is passed', async ()=>{
|
|
90
|
+
const { getByText } = renderResourceCard({
|
|
91
|
+
linkType: 'Contentful:UnsupportedLink'
|
|
92
|
+
});
|
|
93
|
+
await waitFor(()=>expect(getByText('Resource type Contentful:UnsupportedLink is currently not supported')).toBeDefined());
|
|
94
|
+
});
|
|
95
|
+
it('renders missing entity card when unknown error is returned', async ()=>{
|
|
96
|
+
const { getByTestId } = renderResourceCard({
|
|
97
|
+
entryUrn: unknownEntryUrn
|
|
98
|
+
});
|
|
99
|
+
await waitFor(()=>expect(getByTestId('cf-ui-missing-entry-card')).toBeDefined());
|
|
100
|
+
});
|
|
101
|
+
});
|
|
@@ -7,3 +7,4 @@ export { CreateEntryMenuTrigger } from './CreateEntryLinkButton/CreateEntryMenuT
|
|
|
7
7
|
export { ScheduledIconWithTooltip } from './ScheduledIconWithTooltip/ScheduledIconWithTooltip';
|
|
8
8
|
export { getScheduleTooltipContent } from './ScheduledIconWithTooltip/ScheduleTooltip';
|
|
9
9
|
export { AssetThumbnail } from './AssetThumbnail/AssetThumbnail';
|
|
10
|
+
export { ResourceEntityErrorCard } from './ResourceEntityErrorCard/ResourceEntityErrorCard';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { CreateEntryMenuTrigger, CreateEntryLinkButton, getScheduleTooltipContent, ScheduledIconWithTooltip, AssetThumbnail, MissingEntityCard, CombinedLinkActions, } from './components';
|
|
1
|
+
export { CreateEntryMenuTrigger, CreateEntryLinkButton, getScheduleTooltipContent, ScheduledIconWithTooltip, AssetThumbnail, ResourceEntityErrorCard, MissingEntityCard, CombinedLinkActions, } from './components';
|
|
2
2
|
export { SingleEntryReferenceEditor, MultipleEntryReferenceEditor, WrappedEntryCard, } from './entries';
|
|
3
3
|
export { SingleMediaEditor, MultipleMediaEditor, WrappedAssetCard } from './assets';
|
|
4
4
|
export type { CustomActionProps } from './common/ReferenceEditor';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/field-editor-reference",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.12.0",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"@contentful/app-sdk": "^4.2.0",
|
|
65
65
|
"react": ">=16.8.0"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "667723f7f4c7fa168ad233f26e353108851fa4e0"
|
|
68
68
|
}
|