@contentful/field-editor-rich-text 6.6.0 → 6.6.1-canary.1

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.
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ const _reacthooks = require("@testing-library/react-hooks");
6
+ const _vitest = require("vitest");
7
+ const _useEntityInfo = require("./useEntityInfo");
8
+ _vitest.vi.mock('./utils', ()=>({
9
+ getEntityInfo: _vitest.vi.fn()
10
+ }));
11
+ (0, _vitest.afterEach)(()=>_vitest.vi.restoreAllMocks());
12
+ _vitest.describe.each([
13
+ 'Entry',
14
+ 'Asset'
15
+ ])('%s hyperlink information', (linkType)=>{
16
+ _vitest.test.each([
17
+ undefined,
18
+ null,
19
+ {},
20
+ {
21
+ sys: undefined
22
+ },
23
+ {
24
+ sys: null
25
+ }
26
+ ])('shows an inaccessible state when fetched metadata is missing (%j)', async (entity)=>{
27
+ _vitest.vi.spyOn(console, 'log').mockImplementation(()=>undefined);
28
+ const get = _vitest.vi.fn().mockResolvedValue(entity);
29
+ const sdk = {
30
+ cma: {
31
+ entry: {
32
+ get
33
+ },
34
+ asset: {
35
+ get
36
+ }
37
+ },
38
+ field: {
39
+ locale: 'en-US'
40
+ },
41
+ locales: {
42
+ default: 'en-US'
43
+ }
44
+ };
45
+ const target = {
46
+ sys: {
47
+ type: 'Link',
48
+ id: 'linked-id',
49
+ linkType
50
+ }
51
+ };
52
+ const onEntityFetchComplete = _vitest.vi.fn();
53
+ const { result, waitFor } = (0, _reacthooks.renderHook)(()=>(0, _useEntityInfo.useEntityInfo)({
54
+ sdk,
55
+ target,
56
+ onEntityFetchComplete
57
+ }));
58
+ await waitFor(()=>{
59
+ (0, _vitest.expect)(result.current).toBe(`${linkType} missing or inaccessible`);
60
+ });
61
+ (0, _vitest.expect)(result.error).toBeUndefined();
62
+ (0, _vitest.expect)(onEntityFetchComplete).toHaveBeenCalledOnce();
63
+ });
64
+ });
@@ -116,7 +116,7 @@ function FetchingWrappedAssetCard(props) {
116
116
  isLoading: true
117
117
  });
118
118
  }
119
- if (status === 'error') {
119
+ if (status === 'error' || !asset?.sys?.id) {
120
120
  return /*#__PURE__*/ _react.createElement(_fieldeditorreference.MissingEntityCard, {
121
121
  isDisabled: props.isDisabled,
122
122
  onRemove: props.onRemove,
@@ -106,7 +106,7 @@ const InternalFetchingWrappedEntryCard = (props)=>{
106
106
  release: props.sdk.release,
107
107
  isReference: true
108
108
  });
109
- const contentTypeId = entry?.sys.contentType.sys.id;
109
+ const contentTypeId = entry?.sys?.contentType?.sys?.id;
110
110
  const { data: contentType } = (0, _reactquery.useContentType)(props.sdk, contentTypeId || '', {
111
111
  enabled: !!contentTypeId
112
112
  });
@@ -123,7 +123,7 @@ const InternalFetchingWrappedEntryCard = (props)=>{
123
123
  isLoading: true
124
124
  });
125
125
  }
126
- if (status === 'error') {
126
+ if (status === 'error' || !entry?.sys?.id) {
127
127
  return /*#__PURE__*/ _react.createElement(_fieldeditorreference.MissingEntityCard, {
128
128
  isDisabled: props.isDisabled,
129
129
  onRemove: props.onRemove,
@@ -0,0 +1,60 @@
1
+ import { renderHook } from '@testing-library/react-hooks';
2
+ import { afterEach, describe, expect, test, vi } from 'vitest';
3
+ import { useEntityInfo } from './useEntityInfo';
4
+ vi.mock('./utils', ()=>({
5
+ getEntityInfo: vi.fn()
6
+ }));
7
+ afterEach(()=>vi.restoreAllMocks());
8
+ describe.each([
9
+ 'Entry',
10
+ 'Asset'
11
+ ])('%s hyperlink information', (linkType)=>{
12
+ test.each([
13
+ undefined,
14
+ null,
15
+ {},
16
+ {
17
+ sys: undefined
18
+ },
19
+ {
20
+ sys: null
21
+ }
22
+ ])('shows an inaccessible state when fetched metadata is missing (%j)', async (entity)=>{
23
+ vi.spyOn(console, 'log').mockImplementation(()=>undefined);
24
+ const get = vi.fn().mockResolvedValue(entity);
25
+ const sdk = {
26
+ cma: {
27
+ entry: {
28
+ get
29
+ },
30
+ asset: {
31
+ get
32
+ }
33
+ },
34
+ field: {
35
+ locale: 'en-US'
36
+ },
37
+ locales: {
38
+ default: 'en-US'
39
+ }
40
+ };
41
+ const target = {
42
+ sys: {
43
+ type: 'Link',
44
+ id: 'linked-id',
45
+ linkType
46
+ }
47
+ };
48
+ const onEntityFetchComplete = vi.fn();
49
+ const { result, waitFor } = renderHook(()=>useEntityInfo({
50
+ sdk,
51
+ target,
52
+ onEntityFetchComplete
53
+ }));
54
+ await waitFor(()=>{
55
+ expect(result.current).toBe(`${linkType} missing or inaccessible`);
56
+ });
57
+ expect(result.error).toBeUndefined();
58
+ expect(onEntityFetchComplete).toHaveBeenCalledOnce();
59
+ });
60
+ });
@@ -60,7 +60,7 @@ export function FetchingWrappedAssetCard(props) {
60
60
  isLoading: true
61
61
  });
62
62
  }
63
- if (status === 'error') {
63
+ if (status === 'error' || !asset?.sys?.id) {
64
64
  return /*#__PURE__*/ React.createElement(MissingEntityCard, {
65
65
  isDisabled: props.isDisabled,
66
66
  onRemove: props.onRemove,
@@ -50,7 +50,7 @@ const InternalFetchingWrappedEntryCard = (props)=>{
50
50
  release: props.sdk.release,
51
51
  isReference: true
52
52
  });
53
- const contentTypeId = entry?.sys.contentType.sys.id;
53
+ const contentTypeId = entry?.sys?.contentType?.sys?.id;
54
54
  const { data: contentType } = useContentType(props.sdk, contentTypeId || '', {
55
55
  enabled: !!contentTypeId
56
56
  });
@@ -67,7 +67,7 @@ const InternalFetchingWrappedEntryCard = (props)=>{
67
67
  isLoading: true
68
68
  });
69
69
  }
70
- if (status === 'error') {
70
+ if (status === 'error' || !entry?.sys?.id) {
71
71
  return /*#__PURE__*/ React.createElement(MissingEntityCard, {
72
72
  isDisabled: props.isDisabled,
73
73
  onRemove: props.onRemove,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-rich-text",
3
- "version": "6.6.0",
3
+ "version": "6.6.1-canary.1+7c272f9d",
4
4
  "source": "./src/index.tsx",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -96,5 +96,5 @@
96
96
  "prettier --write"
97
97
  ]
98
98
  },
99
- "gitHead": "dac004ee83f052b9c06298cee482a049cbd78e4d"
99
+ "gitHead": "7c272f9d3fe6d53960257ed52443c66efa5ff838"
100
100
  }