sanity-plugin-media 4.3.6 → 5.0.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.
Files changed (162) hide show
  1. package/package.json +6 -15
  2. package/dist/index.cjs +0 -4721
  3. package/dist/index.cjs.map +0 -1
  4. package/dist/index.d.cts +0 -239
  5. package/dist/index.d.cts.map +0 -1
  6. package/sanity.json +0 -8
  7. package/src/__tests__/fixtures/createEpicTestStore.ts +0 -28
  8. package/src/__tests__/fixtures/listenMock.ts +0 -9
  9. package/src/__tests__/fixtures/mockSanityClient.ts +0 -84
  10. package/src/__tests__/fixtures/renderWithProviders.tsx +0 -55
  11. package/src/__tests__/fixtures/rootState.ts +0 -27
  12. package/src/__tests__/fixtures/withinDialog.ts +0 -28
  13. package/src/components/AssetGridVirtualized/index.tsx +0 -94
  14. package/src/components/AssetMetadata/index.tsx +0 -122
  15. package/src/components/AssetTableVirtualized/index.tsx +0 -73
  16. package/src/components/AutoTagInputWrapper/index.tsx +0 -85
  17. package/src/components/Browser/Browser.test.tsx +0 -45
  18. package/src/components/Browser/index.tsx +0 -90
  19. package/src/components/Browser/useBrowserInit.ts +0 -126
  20. package/src/components/ButtonAssetCopy/index.tsx +0 -65
  21. package/src/components/ButtonViewGroup/index.tsx +0 -39
  22. package/src/components/CardAsset/CardAsset.test.tsx +0 -323
  23. package/src/components/CardAsset/index.tsx +0 -290
  24. package/src/components/CardUpload/index.tsx +0 -161
  25. package/src/components/Controls/index.tsx +0 -136
  26. package/src/components/DebugControls/index.tsx +0 -80
  27. package/src/components/Dialog/index.tsx +0 -11
  28. package/src/components/DialogAssetEdit/Details.tsx +0 -181
  29. package/src/components/DialogAssetEdit/DialogAssetEdit.test.tsx +0 -216
  30. package/src/components/DialogAssetEdit/index.tsx +0 -493
  31. package/src/components/DialogConfirm/index.tsx +0 -90
  32. package/src/components/DialogSearchFacets/index.tsx +0 -42
  33. package/src/components/DialogTagCreate/DialogTagCreate.test.tsx +0 -121
  34. package/src/components/DialogTagCreate/index.tsx +0 -111
  35. package/src/components/DialogTagEdit/DialogTagEdit.test.tsx +0 -165
  36. package/src/components/DialogTagEdit/index.tsx +0 -201
  37. package/src/components/DialogTags/index.tsx +0 -45
  38. package/src/components/Dialogs/index.tsx +0 -76
  39. package/src/components/DocumentList/index.tsx +0 -62
  40. package/src/components/FileAssetPreview/index.tsx +0 -37
  41. package/src/components/FileIcon/index.tsx +0 -43
  42. package/src/components/FormBuilderTool/FormBuilderTool.test.tsx +0 -63
  43. package/src/components/FormBuilderTool/index.tsx +0 -69
  44. package/src/components/FormFieldInputLabel/index.tsx +0 -66
  45. package/src/components/FormFieldInputTags/index.tsx +0 -98
  46. package/src/components/FormFieldInputText/index.tsx +0 -41
  47. package/src/components/FormFieldInputTextarea/index.tsx +0 -43
  48. package/src/components/FormSubmitButton/index.tsx +0 -59
  49. package/src/components/Header/index.tsx +0 -80
  50. package/src/components/Image/index.tsx +0 -41
  51. package/src/components/Items/index.tsx +0 -68
  52. package/src/components/Notifications/index.tsx +0 -24
  53. package/src/components/OrderSelect/index.tsx +0 -66
  54. package/src/components/PickedBar/index.tsx +0 -77
  55. package/src/components/Progress/index.tsx +0 -38
  56. package/src/components/ReduxProvider/index.tsx +0 -96
  57. package/src/components/SearchFacet/index.tsx +0 -66
  58. package/src/components/SearchFacetNumber/index.tsx +0 -133
  59. package/src/components/SearchFacetSelect/index.tsx +0 -110
  60. package/src/components/SearchFacetString/index.tsx +0 -88
  61. package/src/components/SearchFacetTags/index.tsx +0 -121
  62. package/src/components/SearchFacets/index.tsx +0 -72
  63. package/src/components/SearchFacetsControl/index.tsx +0 -140
  64. package/src/components/TableHeader/index.tsx +0 -110
  65. package/src/components/TableHeaderItem/index.tsx +0 -61
  66. package/src/components/TableRowAsset/index.tsx +0 -419
  67. package/src/components/TableRowUpload/index.tsx +0 -164
  68. package/src/components/Tag/index.tsx +0 -200
  69. package/src/components/TagIcon/index.tsx +0 -22
  70. package/src/components/TagView/index.tsx +0 -39
  71. package/src/components/TagViewHeader/index.tsx +0 -70
  72. package/src/components/TagsPanel/index.tsx +0 -40
  73. package/src/components/TagsVirtualized/index.tsx +0 -160
  74. package/src/components/TextInputNumber/index.tsx +0 -32
  75. package/src/components/TextInputSearch/index.tsx +0 -60
  76. package/src/components/Tool/index.tsx +0 -13
  77. package/src/components/UploadDropzone/UploadDropzone.test.tsx +0 -40
  78. package/src/components/UploadDropzone/index.tsx +0 -173
  79. package/src/config/orders.ts +0 -28
  80. package/src/config/searchFacets.ts +0 -312
  81. package/src/constants.ts +0 -87
  82. package/src/contexts/AssetSourceDispatchContext.tsx +0 -38
  83. package/src/contexts/DropzoneDispatchContext.tsx +0 -32
  84. package/src/contexts/ToolOptionsContext.tsx +0 -66
  85. package/src/formSchema/index.test.ts +0 -56
  86. package/src/formSchema/index.ts +0 -39
  87. package/src/hooks/useBreakpointIndex.ts +0 -50
  88. package/src/hooks/useKeyPress.ts +0 -39
  89. package/src/hooks/usePortalPopoverProps.ts +0 -13
  90. package/src/hooks/useTypedSelector.ts +0 -7
  91. package/src/hooks/useVersionedClient.ts +0 -6
  92. package/src/index.ts +0 -5
  93. package/src/modules/assets/actions.ts +0 -42
  94. package/src/modules/assets/deleteAndUpdateEpics.test.ts +0 -87
  95. package/src/modules/assets/fetchEpic.test.ts +0 -73
  96. package/src/modules/assets/index.ts +0 -782
  97. package/src/modules/assets/reducer.test.ts +0 -91
  98. package/src/modules/assets/tagsAndListenerEpics.test.ts +0 -206
  99. package/src/modules/debug/index.ts +0 -28
  100. package/src/modules/dialog/actions.ts +0 -10
  101. package/src/modules/dialog/epics.test.ts +0 -168
  102. package/src/modules/dialog/index.ts +0 -238
  103. package/src/modules/dialog/reducer.test.ts +0 -185
  104. package/src/modules/index.ts +0 -117
  105. package/src/modules/notifications/epics.test.ts +0 -374
  106. package/src/modules/notifications/index.ts +0 -199
  107. package/src/modules/notifications/reducer.test.ts +0 -54
  108. package/src/modules/search/index.test.ts +0 -36
  109. package/src/modules/search/index.ts +0 -167
  110. package/src/modules/selected/index.ts +0 -22
  111. package/src/modules/selectors.test.ts +0 -21
  112. package/src/modules/selectors.ts +0 -17
  113. package/src/modules/tags/epics.test.ts +0 -96
  114. package/src/modules/tags/index.test.ts +0 -42
  115. package/src/modules/tags/index.ts +0 -540
  116. package/src/modules/types.ts +0 -3
  117. package/src/modules/uploads/actions.ts +0 -13
  118. package/src/modules/uploads/epics.test.ts +0 -109
  119. package/src/modules/uploads/index.test.ts +0 -59
  120. package/src/modules/uploads/index.ts +0 -272
  121. package/src/operators/checkTagName.test.ts +0 -29
  122. package/src/operators/checkTagName.ts +0 -33
  123. package/src/operators/debugThrottle.ts +0 -25
  124. package/src/plugin.tsx +0 -54
  125. package/src/schemas/tag.ts +0 -28
  126. package/src/styled/GlobalStyles/index.tsx +0 -40
  127. package/src/styled/react-select/creatable.tsx +0 -184
  128. package/src/styled/react-select/single.tsx +0 -184
  129. package/src/types/index.ts +0 -346
  130. package/src/types/sanity-ui.d.ts +0 -5
  131. package/src/utils/applyMediaTags.ts +0 -87
  132. package/src/utils/blocksToText.test.ts +0 -43
  133. package/src/utils/blocksToText.ts +0 -27
  134. package/src/utils/constructFilter.test.ts +0 -120
  135. package/src/utils/constructFilter.ts +0 -98
  136. package/src/utils/generatePreviewBlobUrl.test.ts +0 -68
  137. package/src/utils/generatePreviewBlobUrl.ts +0 -53
  138. package/src/utils/getAssetResolution.test.ts +0 -13
  139. package/src/utils/getAssetResolution.ts +0 -7
  140. package/src/utils/getDocumentAssetIds.test.ts +0 -50
  141. package/src/utils/getDocumentAssetIds.ts +0 -35
  142. package/src/utils/getSchemeColor.test.ts +0 -12
  143. package/src/utils/getSchemeColor.ts +0 -43
  144. package/src/utils/getTagSelectOptions.test.ts +0 -44
  145. package/src/utils/getTagSelectOptions.ts +0 -16
  146. package/src/utils/getUniqueDocuments.test.ts +0 -26
  147. package/src/utils/getUniqueDocuments.ts +0 -15
  148. package/src/utils/imageDprUrl.test.ts +0 -46
  149. package/src/utils/imageDprUrl.ts +0 -27
  150. package/src/utils/isSupportedAssetType.test.ts +0 -16
  151. package/src/utils/isSupportedAssetType.ts +0 -15
  152. package/src/utils/mediaField.ts +0 -73
  153. package/src/utils/sanitizeFormData.test.ts +0 -59
  154. package/src/utils/sanitizeFormData.ts +0 -26
  155. package/src/utils/typeGuards.test.ts +0 -18
  156. package/src/utils/typeGuards.ts +0 -9
  157. package/src/utils/uploadSanityAsset.test.ts +0 -29
  158. package/src/utils/uploadSanityAsset.ts +0 -97
  159. package/src/utils/withMaxConcurrency.test.ts +0 -43
  160. package/src/utils/withMaxConcurrency.ts +0 -55
  161. package/src/utils/zodFormResolver.ts +0 -17
  162. package/v2-incompatible.js +0 -11
@@ -1,91 +0,0 @@
1
- // @vitest-environment node
2
-
3
- import {describe, expect, it} from 'vitest'
4
-
5
- import type {AssetType, ImageAsset} from '../../types'
6
- import assetsReducer, {assetsActions, initialState, type AssetsReducerState} from './index'
7
-
8
- const minimalImage = {
9
- _id: 'img-1',
10
- _type: 'sanity.imageAsset',
11
- _createdAt: '2020-01-01',
12
- _updatedAt: '2020-01-01',
13
- _rev: 'r1',
14
- originalFilename: 'a.png',
15
- size: 1,
16
- mimeType: 'image/png',
17
- url: 'https://example.com/a.png',
18
- } as ImageAsset
19
-
20
- describe('assets slice', () => {
21
- function stateWithOneAsset(): AssetsReducerState {
22
- return {
23
- ...initialState,
24
- assetTypes: ['image'] as AssetType[],
25
- allIds: ['img-1'],
26
- byIds: {
27
- 'img-1': {
28
- _type: 'asset',
29
- asset: minimalImage,
30
- picked: false,
31
- updating: false,
32
- },
33
- },
34
- }
35
- }
36
-
37
- it('pick toggles picked flag', () => {
38
- let state = stateWithOneAsset()
39
- state = assetsReducer(state, assetsActions.pick({assetId: 'img-1', picked: true}))
40
- expect(state.byIds['img-1']!.picked).toBe(true)
41
- expect(state.lastPicked).toBe('img-1')
42
- })
43
-
44
- it('pickClear clears selection', () => {
45
- let state = stateWithOneAsset()
46
- state = assetsReducer(state, assetsActions.pick({assetId: 'img-1', picked: true}))
47
- state = assetsReducer(state, assetsActions.pickClear())
48
- expect(state.byIds['img-1']!.picked).toBe(false)
49
- expect(state.lastPicked).toBeUndefined()
50
- })
51
-
52
- it('fetchComplete merges assets', () => {
53
- let state = assetsReducer({...initialState, assetTypes: ['image'] as AssetType[]}, {
54
- type: '@@INIT',
55
- } as never)
56
- state = assetsReducer(state, assetsActions.fetchComplete({assets: [minimalImage]}))
57
- expect(state.allIds).toContain('img-1')
58
- expect(state.fetching).toBe(false)
59
- expect(state.fetchCount).toBe(1)
60
- })
61
-
62
- it('orderSet resets page index', () => {
63
- let state: AssetsReducerState = {
64
- ...initialState,
65
- assetTypes: ['image'] as AssetType[],
66
- pageIndex: 3,
67
- }
68
- state = assetsReducer(
69
- state,
70
- assetsActions.orderSet({
71
- order: {field: 'size', direction: 'asc'},
72
- }),
73
- )
74
- expect(state.pageIndex).toBe(0)
75
- expect(state.order.field).toBe('size')
76
- })
77
-
78
- it('listenerDeleteQueueComplete removes assets', () => {
79
- let state = stateWithOneAsset()
80
- state = assetsReducer(state, assetsActions.listenerDeleteQueueComplete({assetIds: ['img-1']}))
81
- expect(state.allIds).toHaveLength(0)
82
- expect(state.byIds['img-1']).toBeUndefined()
83
- })
84
-
85
- it('listenerUpdateQueueComplete updates asset document', () => {
86
- let state = stateWithOneAsset()
87
- const updated = {...minimalImage, title: 'New'}
88
- state = assetsReducer(state, assetsActions.listenerUpdateQueueComplete({assets: [updated]}))
89
- expect(state.byIds['img-1']!.asset.title).toBe('New')
90
- })
91
- })
@@ -1,206 +0,0 @@
1
- // @vitest-environment node
2
-
3
- import {describe, expect, it, vi, beforeEach, afterEach} from 'vitest'
4
-
5
- import {createEpicTestStore} from '../../__tests__/fixtures/createEpicTestStore'
6
- import {
7
- createMockSanityClient,
8
- mockTransactionCommit,
9
- } from '../../__tests__/fixtures/mockSanityClient'
10
- import type {ImageAsset, Tag} from '../../types'
11
- import {ASSETS_ACTIONS} from './actions'
12
- import {
13
- assetsActions,
14
- assetsListenerCreateQueueEpic,
15
- assetsListenerDeleteQueueEpic,
16
- assetsListenerUpdateQueueEpic,
17
- assetsTagsAddEpic,
18
- assetsTagsRemoveEpic,
19
- } from './index'
20
- import {initialState as assetsInitialState} from './index'
21
-
22
- const sampleAsset = {
23
- _id: 'a1',
24
- _type: 'sanity.imageAsset',
25
- _createdAt: '',
26
- _updatedAt: '',
27
- _rev: 'r1',
28
- originalFilename: 'x.png',
29
- size: 1,
30
- mimeType: 'image/png',
31
- url: '',
32
- } as ImageAsset
33
-
34
- const sampleTag: Tag = {
35
- _id: 't1',
36
- _type: 'media.tag',
37
- _createdAt: '',
38
- _updatedAt: '',
39
- _rev: 'tr',
40
- name: {_type: 'slug', current: 'tag-a'},
41
- }
42
-
43
- describe('assetsTagsAddEpic', () => {
44
- it('runs transaction.commit when adding tag to picked assets', async () => {
45
- const tx = mockTransactionCommit(undefined)
46
- const client = createMockSanityClient({
47
- transaction: vi.fn(() => tx),
48
- })
49
-
50
- const assetItem = {
51
- _type: 'asset' as const,
52
- asset: sampleAsset,
53
- picked: true,
54
- updating: false,
55
- }
56
-
57
- const store = createEpicTestStore(assetsTagsAddEpic, client, {
58
- assets: {
59
- ...assetsInitialState,
60
- assetTypes: ['image'],
61
- allIds: ['a1'],
62
- byIds: {a1: assetItem},
63
- },
64
- tags: {
65
- allIds: ['t1'],
66
- byIds: {
67
- t1: {_type: 'tag', tag: sampleTag, picked: false, updating: false},
68
- },
69
- creating: false,
70
- fetchCount: -1,
71
- fetching: false,
72
- panelVisible: true,
73
- },
74
- })
75
-
76
- store.dispatch(
77
- ASSETS_ACTIONS.tagsAddRequest({
78
- assets: [assetItem],
79
- tag: sampleTag,
80
- }),
81
- )
82
-
83
- await vi.waitFor(() => {
84
- expect(tx.commit).toHaveBeenCalled()
85
- })
86
- })
87
- })
88
-
89
- describe('assetsTagsRemoveEpic', () => {
90
- it('runs transaction.commit for tag removal', async () => {
91
- const tx = mockTransactionCommit(undefined)
92
- const client = createMockSanityClient({
93
- transaction: vi.fn(() => tx),
94
- })
95
-
96
- const assetItem = {
97
- _type: 'asset' as const,
98
- asset: sampleAsset,
99
- picked: true,
100
- updating: false,
101
- }
102
-
103
- const store = createEpicTestStore(assetsTagsRemoveEpic, client, {
104
- assets: {
105
- ...assetsInitialState,
106
- assetTypes: ['image'],
107
- allIds: ['a1'],
108
- byIds: {a1: assetItem},
109
- },
110
- tags: {
111
- allIds: ['t1'],
112
- byIds: {
113
- t1: {_type: 'tag', tag: sampleTag, picked: false, updating: false},
114
- },
115
- creating: false,
116
- fetchCount: -1,
117
- fetching: false,
118
- panelVisible: true,
119
- },
120
- })
121
-
122
- store.dispatch(
123
- ASSETS_ACTIONS.tagsRemoveRequest({
124
- assets: [assetItem],
125
- tag: sampleTag,
126
- }),
127
- )
128
-
129
- await vi.waitFor(() => {
130
- expect(tx.commit).toHaveBeenCalled()
131
- })
132
- })
133
- })
134
-
135
- describe('assets listener queue epics', () => {
136
- beforeEach(() => {
137
- vi.useFakeTimers()
138
- })
139
-
140
- afterEach(() => {
141
- vi.useRealTimers()
142
- })
143
-
144
- it('assetsListenerCreateQueueEpic batches creates after buffer window', async () => {
145
- const store = createEpicTestStore(assetsListenerCreateQueueEpic, createMockSanityClient(), {
146
- assets: {
147
- ...assetsInitialState,
148
- assetTypes: ['image'],
149
- allIds: ['a1'],
150
- byIds: {
151
- a1: {_type: 'asset', asset: sampleAsset, picked: false, updating: false},
152
- },
153
- },
154
- })
155
-
156
- const updated = {...sampleAsset, title: 'L'}
157
- store.dispatch(assetsActions.listenerCreateQueue({asset: updated}))
158
-
159
- await vi.advanceTimersByTimeAsync(2000)
160
-
161
- await vi.waitFor(() => {
162
- expect(store.getState().assets.byIds['a1']!.asset.title).toBe('L')
163
- })
164
- })
165
-
166
- it('assetsListenerDeleteQueueEpic batches deletes', async () => {
167
- const store = createEpicTestStore(assetsListenerDeleteQueueEpic, createMockSanityClient(), {
168
- assets: {
169
- ...assetsInitialState,
170
- assetTypes: ['image'],
171
- allIds: ['a1'],
172
- byIds: {
173
- a1: {_type: 'asset', asset: sampleAsset, picked: false, updating: false},
174
- },
175
- },
176
- })
177
-
178
- store.dispatch(assetsActions.listenerDeleteQueue({assetId: 'a1'}))
179
- await vi.advanceTimersByTimeAsync(2000)
180
-
181
- await vi.waitFor(() => {
182
- expect(store.getState().assets.byIds['a1']).toBeUndefined()
183
- })
184
- })
185
-
186
- it('assetsListenerUpdateQueueEpic batches updates', async () => {
187
- const store = createEpicTestStore(assetsListenerUpdateQueueEpic, createMockSanityClient(), {
188
- assets: {
189
- ...assetsInitialState,
190
- assetTypes: ['image'],
191
- allIds: ['a1'],
192
- byIds: {
193
- a1: {_type: 'asset', asset: sampleAsset, picked: false, updating: false},
194
- },
195
- },
196
- })
197
-
198
- const updated = {...sampleAsset, title: 'Buffered'}
199
- store.dispatch(assetsActions.listenerUpdateQueue({asset: updated}))
200
- await vi.advanceTimersByTimeAsync(2000)
201
-
202
- await vi.waitFor(() => {
203
- expect(store.getState().assets.byIds['a1']!.asset.title).toBe('Buffered')
204
- })
205
- })
206
- })
@@ -1,28 +0,0 @@
1
- import {type PayloadAction, createSlice} from '@reduxjs/toolkit'
2
-
3
- type DebugReducerState = {
4
- badConnection: boolean
5
- enabled: boolean
6
- }
7
-
8
- const initialState = {
9
- badConnection: false,
10
- enabled: false,
11
- } as DebugReducerState
12
-
13
- const debugSlice = createSlice({
14
- name: 'debug',
15
- initialState,
16
- reducers: {
17
- setBadConnection(state, action: PayloadAction<boolean>) {
18
- state.badConnection = action.payload
19
- },
20
- toggleEnabled(state) {
21
- state.enabled = !state.enabled
22
- },
23
- },
24
- })
25
-
26
- export const debugActions = {...debugSlice.actions}
27
-
28
- export default debugSlice.reducer
@@ -1,10 +0,0 @@
1
- import {createAction} from '@reduxjs/toolkit'
2
-
3
- export const DIALOG_ACTIONS = {
4
- showTagCreate: createAction('dialog/showTagCreate'),
5
- showTagEdit: createAction('dialog/showTagEdit', function prepare({tagId}: {tagId: string}) {
6
- return {
7
- payload: {tagId},
8
- }
9
- }),
10
- }
@@ -1,168 +0,0 @@
1
- // @vitest-environment node
2
-
3
- import {describe, expect, it, vi} from 'vitest'
4
-
5
- import {createEpicTestStore} from '../../__tests__/fixtures/createEpicTestStore'
6
- import {createMockSanityClient} from '../../__tests__/fixtures/mockSanityClient'
7
- import type {ImageAsset, Tag} from '../../types'
8
- import {assetsActions, initialState as assetsInitialState} from '../assets'
9
- import {tagsActions} from '../tags'
10
- import {dialogClearOnAssetUpdateEpic, dialogTagCreateEpic, dialogTagDeleteEpic} from './index'
11
-
12
- const sampleAsset = {
13
- _id: 'a1',
14
- _type: 'sanity.imageAsset',
15
- _createdAt: '',
16
- _updatedAt: '',
17
- _rev: 'r1',
18
- originalFilename: 'x.png',
19
- size: 1,
20
- mimeType: 'image/png',
21
- url: 'https://example.com/x.png',
22
- } as ImageAsset
23
-
24
- const sampleTag: Tag = {
25
- _id: 't1',
26
- _type: 'media.tag',
27
- _createdAt: '',
28
- _updatedAt: '',
29
- _rev: 'tr',
30
- name: {_type: 'slug', current: 'alpha'},
31
- }
32
-
33
- const tagWithId = (id: string): Tag => ({
34
- ...sampleTag,
35
- _id: id,
36
- })
37
-
38
- describe('dialogClearOnAssetUpdateEpic', () => {
39
- it('removes the dialog when assets.updateComplete carries closeDialogId', async () => {
40
- const store = createEpicTestStore(dialogClearOnAssetUpdateEpic, createMockSanityClient({}), {
41
- assets: {
42
- ...assetsInitialState,
43
- assetTypes: ['image'],
44
- allIds: ['a1'],
45
- byIds: {
46
- a1: {_type: 'asset', asset: sampleAsset, picked: false, updating: true},
47
- },
48
- },
49
- dialog: {
50
- items: [{id: 'a1', type: 'assetEdit', assetId: 'a1'}],
51
- },
52
- })
53
-
54
- store.dispatch(assetsActions.updateComplete({asset: sampleAsset, closeDialogId: 'a1'}))
55
-
56
- await vi.waitFor(() => {
57
- expect(store.getState().dialog.items).toHaveLength(0)
58
- })
59
- })
60
-
61
- it('removes the dialog when tags.updateComplete carries closeDialogId', async () => {
62
- const store = createEpicTestStore(dialogClearOnAssetUpdateEpic, createMockSanityClient({}), {
63
- tags: {
64
- allIds: ['t1'],
65
- byIds: {
66
- t1: {_type: 'tag', tag: sampleTag, picked: false, updating: true},
67
- },
68
- creating: false,
69
- fetchCount: -1,
70
- fetching: false,
71
- panelVisible: true,
72
- },
73
- dialog: {
74
- items: [{id: 't1', type: 'tagEdit', tagId: 't1'}],
75
- },
76
- })
77
-
78
- store.dispatch(tagsActions.updateComplete({tag: sampleTag, closeDialogId: 't1'}))
79
-
80
- await vi.waitFor(() => {
81
- expect(store.getState().dialog.items).toHaveLength(0)
82
- })
83
- })
84
-
85
- it('does not emit remove when closeDialogId is absent', async () => {
86
- const store = createEpicTestStore(dialogClearOnAssetUpdateEpic, createMockSanityClient({}), {
87
- assets: {
88
- ...assetsInitialState,
89
- assetTypes: ['image'],
90
- allIds: ['a1'],
91
- byIds: {
92
- a1: {_type: 'asset', asset: sampleAsset, picked: false, updating: true},
93
- },
94
- },
95
- dialog: {
96
- items: [{id: 'a1', type: 'assetEdit', assetId: 'a1'}],
97
- },
98
- })
99
-
100
- store.dispatch(assetsActions.updateComplete({asset: sampleAsset}))
101
-
102
- expect(store.getState().dialog.items).toHaveLength(1)
103
- })
104
- })
105
-
106
- describe('dialogTagCreateEpic', () => {
107
- it('dispatches inlineTagCreate when createComplete includes assetId', async () => {
108
- const store = createEpicTestStore(dialogTagCreateEpic, createMockSanityClient({}), {
109
- dialog: {
110
- items: [{id: 'a1', type: 'assetEdit', assetId: 'a1'}],
111
- },
112
- })
113
-
114
- store.dispatch(tagsActions.createComplete({assetId: 'a1', tag: sampleTag}))
115
-
116
- await vi.waitFor(() => {
117
- const item = store.getState().dialog.items[0]
118
- expect(item?.type).toBe('assetEdit')
119
- expect('lastCreatedTag' in item! && item.lastCreatedTag).toEqual({
120
- label: 'alpha',
121
- value: 't1',
122
- })
123
- })
124
- })
125
-
126
- it('removes tag create dialog when createComplete has no assetId', async () => {
127
- const store = createEpicTestStore(dialogTagCreateEpic, createMockSanityClient({}), {
128
- dialog: {
129
- items: [{id: 'tagCreate', type: 'tagCreate'}],
130
- },
131
- })
132
-
133
- store.dispatch(tagsActions.createComplete({tag: sampleTag}))
134
-
135
- await vi.waitFor(() => {
136
- expect(store.getState().dialog.items).toHaveLength(0)
137
- })
138
- })
139
- })
140
-
141
- describe('dialogTagDeleteEpic', () => {
142
- it('dispatches inlineTagRemove with listener tag ids', async () => {
143
- const store = createEpicTestStore(dialogTagDeleteEpic, createMockSanityClient({}), {
144
- tags: {
145
- allIds: ['t9'],
146
- byIds: {
147
- t9: {_type: 'tag', tag: tagWithId('t9'), picked: false, updating: false},
148
- },
149
- creating: false,
150
- fetchCount: -1,
151
- fetching: false,
152
- panelVisible: true,
153
- },
154
- dialog: {
155
- items: [{id: 'a1', type: 'assetEdit', assetId: 'a1'}],
156
- },
157
- })
158
-
159
- store.dispatch(tagsActions.listenerDeleteQueueComplete({tagIds: ['t9']}))
160
-
161
- await vi.waitFor(() => {
162
- expect(store.getState().dialog.items[0]).toMatchObject({
163
- type: 'assetEdit',
164
- lastRemovedTagIds: ['t9'],
165
- })
166
- })
167
- })
168
- })