Skip to content

Commit 7c79fef

Browse files
committed
clean up test cases
1 parent 39e6f92 commit 7c79fef

File tree

4 files changed

+32
-122
lines changed

4 files changed

+32
-122
lines changed

packages/field-plugin/src/createFieldPlugin/createPluginActions/createPluginActions.test.ts

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
ModalChangeMessage,
66
ValueChangeMessage,
77
} from '../../messaging'
8+
import { emptyAsset } from '../../messaging/pluginMessage/containerToPluginMessage/Asset.test'
89

910
// INFO: The methods like `setContent` is not being resolved in this file because `pushCallback` doesn't resolve.
1011
// We can also mock `callbackQueue` and make it resolve, and resolve this `no-floating-promises` issue.
@@ -231,33 +232,10 @@ describe('createPluginActions', () => {
231232
field: 'dummy',
232233
callbackId: TEST_CALLBACK_ID,
233234
filename,
234-
asset: {
235-
id: 0,
236-
fieldtype: 'asset',
237-
name: '',
238-
filename: '',
239-
meta_data: {},
240-
title: '',
241-
copyright: '',
242-
focus: '',
243-
alt: '',
244-
source: '',
245-
is_private: false,
246-
},
235+
asset: emptyAsset,
247236
})
248237
const result = await promise
249-
expect(result).toEqual({
250-
filename,
251-
fieldtype: 'asset',
252-
name: '',
253-
meta_data: {},
254-
title: '',
255-
copyright: '',
256-
focus: '',
257-
alt: '',
258-
source: '',
259-
is_private: false,
260-
})
238+
expect(result).toEqual(emptyAsset)
261239
})
262240
it('does not call the callack function when callbackId does not match', async () => {
263241
const WRONG_CALLBACK_ID = TEST_CALLBACK_ID + '_wrong'
@@ -279,19 +257,7 @@ describe('createPluginActions', () => {
279257
field: 'dummy',
280258
callbackId: WRONG_CALLBACK_ID,
281259
filename,
282-
asset: {
283-
id: 0,
284-
fieldtype: 'asset',
285-
name: '',
286-
filename: '',
287-
meta_data: {},
288-
title: '',
289-
copyright: '',
290-
focus: '',
291-
alt: '',
292-
source: '',
293-
is_private: false,
294-
},
260+
asset: emptyAsset,
295261
})
296262
const resolvedFn = jest.fn()
297263
const rejectedFn = jest.fn()

packages/field-plugin/src/createFieldPlugin/createPluginActions/createPluginMessageListener/handlePluginMessage.test.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
LoadedMessage,
77
MessageToPlugin,
88
} from '../../../messaging'
9+
import { emptyAsset } from '../../../messaging/pluginMessage/containerToPluginMessage/Asset.test'
910

1011
const uid = 'abc123'
1112
const mockCallbacks = (): PluginMessageCallbacks => ({
@@ -95,19 +96,7 @@ describe('handlePluginMessage', () => {
9596
filename: '/my-file.jpg',
9697
field: 'callback-uid',
9798
callbackId: 'test-callback-id',
98-
asset: {
99-
id: 0,
100-
fieldtype: 'asset',
101-
name: '',
102-
filename: '',
103-
meta_data: {},
104-
title: '',
105-
copyright: '',
106-
focus: '',
107-
alt: '',
108-
source: '',
109-
is_private: false,
110-
},
99+
asset: emptyAsset,
111100
}
112101
const callbacks = mockCallbacks()
113102
handlePluginMessage(data, uid, callbacks)

packages/field-plugin/src/messaging/pluginMessage/containerToPluginMessage/Asset.test.ts

Lines changed: 22 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
1-
import { AssetWrapper, assetFromAssetSelectedMessage, isAsset } from './Asset'
1+
import {
2+
Asset,
3+
AssetWrapper,
4+
assetFromAssetSelectedMessage,
5+
isAsset,
6+
} from './Asset'
27
import { AssetSelectedMessage } from './AssetSelectedMessage'
38

9+
export const emptyAsset: Asset = {
10+
id: 0,
11+
fieldtype: 'asset',
12+
name: '',
13+
filename: '',
14+
meta_data: {},
15+
title: '',
16+
copyright: '',
17+
focus: '',
18+
alt: '',
19+
source: '',
20+
is_private: false,
21+
}
22+
423
const stub: AssetWrapper = {
524
filename: 'https://somthing.com/myimage.jpg',
6-
asset: {
7-
id: 0,
8-
fieldtype: 'asset',
9-
name: '',
10-
filename: '',
11-
meta_data: {},
12-
title: '',
13-
copyright: '',
14-
focus: '',
15-
alt: '',
16-
source: '',
17-
is_private: false,
18-
},
25+
asset: emptyAsset,
1926
}
2027

2128
const assetSelectedMessage: AssetSelectedMessage = {
@@ -24,19 +31,7 @@ const assetSelectedMessage: AssetSelectedMessage = {
2431
callbackId: 'test-callback-id',
2532
action: 'asset-selected',
2633
filename: 'https://somthing.com/myimage.jpg',
27-
asset: {
28-
id: 0,
29-
fieldtype: 'asset',
30-
name: '',
31-
filename: '',
32-
meta_data: {},
33-
title: '',
34-
copyright: '',
35-
focus: '',
36-
alt: '',
37-
source: '',
38-
is_private: false,
39-
},
34+
asset: emptyAsset,
4035
}
4136

4237
describe('Asset', function () {
@@ -61,24 +56,8 @@ describe('Asset', function () {
6156
assetFromAssetSelectedMessage(assetSelectedMessage),
6257
).toHaveProperty('filename')
6358
})
64-
it('keeps unknown properties', () => {
65-
expect(
66-
assetFromAssetSelectedMessage({
67-
...assetSelectedMessage,
68-
unknownProperty: 'any-value',
69-
}),
70-
).toHaveProperty('unknownProperty', 'any-value')
71-
})
7259
})
7360
describe('validation', () => {
74-
it('allows unknown properties', () => {
75-
expect(
76-
isAsset({
77-
...stub,
78-
anUnknownProperty: 'something',
79-
}),
80-
).toEqual(true)
81-
})
8261
describe('the filename property', () => {
8362
it('is required', () => {
8463
expect(

packages/field-plugin/src/messaging/pluginMessage/containerToPluginMessage/AssetSelectedMessage.test.ts

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,15 @@ import {
33
isAssetSelectedMessage,
44
} from './AssetSelectedMessage'
55
import { isAsset } from './Asset'
6+
import { emptyAsset } from './Asset.test'
67

78
const stub: AssetSelectedMessage = {
89
action: 'asset-selected',
910
uid: '-preview',
1011
field: 'dummy-field',
1112
callbackId: 'test-callback-id',
1213
filename: 'https://somthing.com/myimage.jpg',
13-
asset: {
14-
id: 0,
15-
fieldtype: 'asset',
16-
name: '',
17-
filename: '',
18-
meta_data: {},
19-
title: '',
20-
copyright: '',
21-
focus: '',
22-
alt: '',
23-
source: '',
24-
is_private: false,
25-
},
14+
asset: emptyAsset,
2615
}
2716

2817
describe('AssetSelectedMessage', function () {
@@ -32,14 +21,6 @@ describe('AssetSelectedMessage', function () {
3221
it('is an Asset', () => {
3322
expect(isAsset(stub)).toEqual(true)
3423
})
35-
it('allows unknown properties', () => {
36-
expect(
37-
isAssetSelectedMessage({
38-
...stub,
39-
anUnknownProperty: 'something',
40-
}),
41-
).toEqual(true)
42-
})
4324
describe('the action property', () => {
4425
it('equals "asset-selected"', () => {
4526
expect(
@@ -58,13 +39,8 @@ describe('AssetSelectedMessage', function () {
5839
})
5940
describe('the field property', () => {
6041
it('is optional', () => {
61-
expect(
62-
isAssetSelectedMessage({
63-
action: 'asset-selected',
64-
uid: '-preview',
65-
filename: 'https://somthing.com/myimage.jpg',
66-
}),
67-
).toEqual(true)
42+
const { field: _field, ...withoutField } = stub
43+
expect(isAssetSelectedMessage(withoutField)).toEqual(true)
6844
})
6945
it('can be undefined', () => {
7046
expect(

0 commit comments

Comments
 (0)