@contentful/react-apps-toolkit 0.5.11 → 0.6.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.
@@ -1,6 +1,7 @@
1
+ import { SerializedJSONValue } from '@contentful/app-sdk';
1
2
  export declare type UseFieldValueReturnValue<Value = unknown> = [
2
3
  value: Value | undefined,
3
- setValue: (newValue: Value | undefined) => Promise<void>
4
+ setValue: (newValue: Value | undefined) => Promise<SerializedJSONValue | undefined>
4
5
  ];
5
6
  /**
6
7
  * Returns field value and a function to update it.
@@ -61,9 +61,7 @@ function useFieldValue(fieldId, locale) {
61
61
  case 0:
62
62
  setValue(newValue);
63
63
  return [4 /*yield*/, entryFieldApi.setValue(newValue, localeWithDefault)];
64
- case 1:
65
- _a.sent();
66
- return [2 /*return*/];
64
+ case 1: return [2 /*return*/, _a.sent()];
67
65
  }
68
66
  });
69
67
  }); }, [entryFieldApi, localeWithDefault]);
@@ -77,7 +77,11 @@ var useSDKMock = useSDK_1.useSDK;
77
77
  beforeEach(function () {
78
78
  jest.resetAllMocks();
79
79
  mockSDK.entry.fields.fieldId.onValueChanged.mockImplementation(function () { return function () { }; });
80
+ mockSDK.entry.fields.fieldId.setValue.mockImplementation(function () { return Promise.resolve('return value'); });
80
81
  mockSDK.entry.fields.otherFieldId.onValueChanged.mockImplementation(function () { return function () { }; });
82
+ mockSDK.entry.fields.otherFieldId.setValue.mockImplementation(function () {
83
+ return Promise.resolve('other return value');
84
+ });
81
85
  });
82
86
  describe('useFieldValue', function () {
83
87
  describe('throws error', function () {
@@ -120,7 +124,16 @@ describe('useFieldValue', function () {
120
124
  it('updates value', function () { return __awaiter(void 0, void 0, void 0, function () {
121
125
  return __generator(this, function (_a) {
122
126
  switch (_a.label) {
123
- case 0: return [4 /*yield*/, (0, react_hooks_1.act)(function () { return result.current[1]('new value'); })];
127
+ case 0: return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
128
+ return __generator(this, function (_a) {
129
+ switch (_a.label) {
130
+ case 0: return [4 /*yield*/, result.current[1]('new value')];
131
+ case 1:
132
+ _a.sent();
133
+ return [2 /*return*/];
134
+ }
135
+ });
136
+ }); })];
124
137
  case 1:
125
138
  _a.sent();
126
139
  expect(result.current[0]).toBe('new value');
@@ -135,6 +148,27 @@ describe('useFieldValue', function () {
135
148
  (0, react_hooks_1.act)(function () { return calls[0][1]('new value'); });
136
149
  expect(result.current[0]).toBe('new value');
137
150
  });
151
+ it('returns the updated value', function () { return __awaiter(void 0, void 0, void 0, function () {
152
+ var returnedValue;
153
+ return __generator(this, function (_a) {
154
+ switch (_a.label) {
155
+ case 0: return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
156
+ return __generator(this, function (_a) {
157
+ switch (_a.label) {
158
+ case 0: return [4 /*yield*/, result.current[1]('new value')];
159
+ case 1:
160
+ returnedValue = _a.sent();
161
+ return [2 /*return*/];
162
+ }
163
+ });
164
+ }); })];
165
+ case 1:
166
+ _a.sent();
167
+ expect(returnedValue).toBe('return value');
168
+ return [2 /*return*/];
169
+ }
170
+ });
171
+ }); });
138
172
  });
139
173
  describe('with `fieldId`', function () {
140
174
  var result;
@@ -149,7 +183,16 @@ describe('useFieldValue', function () {
149
183
  it('updates value', function () { return __awaiter(void 0, void 0, void 0, function () {
150
184
  return __generator(this, function (_a) {
151
185
  switch (_a.label) {
152
- case 0: return [4 /*yield*/, (0, react_hooks_1.act)(function () { return result.current[1]('new value'); })];
186
+ case 0: return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
187
+ return __generator(this, function (_a) {
188
+ switch (_a.label) {
189
+ case 0: return [4 /*yield*/, result.current[1]('new value')];
190
+ case 1:
191
+ _a.sent();
192
+ return [2 /*return*/];
193
+ }
194
+ });
195
+ }); })];
153
196
  case 1:
154
197
  _a.sent();
155
198
  expect(result.current[0]).toBe('new value');
@@ -178,7 +221,16 @@ describe('useFieldValue', function () {
178
221
  it('updates value', function () { return __awaiter(void 0, void 0, void 0, function () {
179
222
  return __generator(this, function (_a) {
180
223
  switch (_a.label) {
181
- case 0: return [4 /*yield*/, (0, react_hooks_1.act)(function () { return result.current[1]('new value'); })];
224
+ case 0: return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
225
+ return __generator(this, function (_a) {
226
+ switch (_a.label) {
227
+ case 0: return [4 /*yield*/, result.current[1]('new value')];
228
+ case 1:
229
+ _a.sent();
230
+ return [2 /*return*/];
231
+ }
232
+ });
233
+ }); })];
182
234
  case 1:
183
235
  _a.sent();
184
236
  expect(result.current[0]).toBe('new value');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/react-apps-toolkit",
3
- "version": "0.5.11",
3
+ "version": "0.6.0",
4
4
  "description": "Toolkit for building a Contentful app in React",
5
5
  "keywords": [],
6
6
  "author": "Contentful GmbH",
@@ -50,5 +50,5 @@
50
50
  "@contentful/app-sdk": "^4.0.0",
51
51
  "contentful-management": ">=7.30.0"
52
52
  },
53
- "gitHead": "61e3382ccad0a4bfb72625f5681271667e15acd6"
53
+ "gitHead": "a279a7b92f12e6792e4c76d86a3277006143bff0"
54
54
  }