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.
- package/package.json +6 -15
- package/dist/index.cjs +0 -4721
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -239
- package/dist/index.d.cts.map +0 -1
- package/sanity.json +0 -8
- package/src/__tests__/fixtures/createEpicTestStore.ts +0 -28
- package/src/__tests__/fixtures/listenMock.ts +0 -9
- package/src/__tests__/fixtures/mockSanityClient.ts +0 -84
- package/src/__tests__/fixtures/renderWithProviders.tsx +0 -55
- package/src/__tests__/fixtures/rootState.ts +0 -27
- package/src/__tests__/fixtures/withinDialog.ts +0 -28
- package/src/components/AssetGridVirtualized/index.tsx +0 -94
- package/src/components/AssetMetadata/index.tsx +0 -122
- package/src/components/AssetTableVirtualized/index.tsx +0 -73
- package/src/components/AutoTagInputWrapper/index.tsx +0 -85
- package/src/components/Browser/Browser.test.tsx +0 -45
- package/src/components/Browser/index.tsx +0 -90
- package/src/components/Browser/useBrowserInit.ts +0 -126
- package/src/components/ButtonAssetCopy/index.tsx +0 -65
- package/src/components/ButtonViewGroup/index.tsx +0 -39
- package/src/components/CardAsset/CardAsset.test.tsx +0 -323
- package/src/components/CardAsset/index.tsx +0 -290
- package/src/components/CardUpload/index.tsx +0 -161
- package/src/components/Controls/index.tsx +0 -136
- package/src/components/DebugControls/index.tsx +0 -80
- package/src/components/Dialog/index.tsx +0 -11
- package/src/components/DialogAssetEdit/Details.tsx +0 -181
- package/src/components/DialogAssetEdit/DialogAssetEdit.test.tsx +0 -216
- package/src/components/DialogAssetEdit/index.tsx +0 -493
- package/src/components/DialogConfirm/index.tsx +0 -90
- package/src/components/DialogSearchFacets/index.tsx +0 -42
- package/src/components/DialogTagCreate/DialogTagCreate.test.tsx +0 -121
- package/src/components/DialogTagCreate/index.tsx +0 -111
- package/src/components/DialogTagEdit/DialogTagEdit.test.tsx +0 -165
- package/src/components/DialogTagEdit/index.tsx +0 -201
- package/src/components/DialogTags/index.tsx +0 -45
- package/src/components/Dialogs/index.tsx +0 -76
- package/src/components/DocumentList/index.tsx +0 -62
- package/src/components/FileAssetPreview/index.tsx +0 -37
- package/src/components/FileIcon/index.tsx +0 -43
- package/src/components/FormBuilderTool/FormBuilderTool.test.tsx +0 -63
- package/src/components/FormBuilderTool/index.tsx +0 -69
- package/src/components/FormFieldInputLabel/index.tsx +0 -66
- package/src/components/FormFieldInputTags/index.tsx +0 -98
- package/src/components/FormFieldInputText/index.tsx +0 -41
- package/src/components/FormFieldInputTextarea/index.tsx +0 -43
- package/src/components/FormSubmitButton/index.tsx +0 -59
- package/src/components/Header/index.tsx +0 -80
- package/src/components/Image/index.tsx +0 -41
- package/src/components/Items/index.tsx +0 -68
- package/src/components/Notifications/index.tsx +0 -24
- package/src/components/OrderSelect/index.tsx +0 -66
- package/src/components/PickedBar/index.tsx +0 -77
- package/src/components/Progress/index.tsx +0 -38
- package/src/components/ReduxProvider/index.tsx +0 -96
- package/src/components/SearchFacet/index.tsx +0 -66
- package/src/components/SearchFacetNumber/index.tsx +0 -133
- package/src/components/SearchFacetSelect/index.tsx +0 -110
- package/src/components/SearchFacetString/index.tsx +0 -88
- package/src/components/SearchFacetTags/index.tsx +0 -121
- package/src/components/SearchFacets/index.tsx +0 -72
- package/src/components/SearchFacetsControl/index.tsx +0 -140
- package/src/components/TableHeader/index.tsx +0 -110
- package/src/components/TableHeaderItem/index.tsx +0 -61
- package/src/components/TableRowAsset/index.tsx +0 -419
- package/src/components/TableRowUpload/index.tsx +0 -164
- package/src/components/Tag/index.tsx +0 -200
- package/src/components/TagIcon/index.tsx +0 -22
- package/src/components/TagView/index.tsx +0 -39
- package/src/components/TagViewHeader/index.tsx +0 -70
- package/src/components/TagsPanel/index.tsx +0 -40
- package/src/components/TagsVirtualized/index.tsx +0 -160
- package/src/components/TextInputNumber/index.tsx +0 -32
- package/src/components/TextInputSearch/index.tsx +0 -60
- package/src/components/Tool/index.tsx +0 -13
- package/src/components/UploadDropzone/UploadDropzone.test.tsx +0 -40
- package/src/components/UploadDropzone/index.tsx +0 -173
- package/src/config/orders.ts +0 -28
- package/src/config/searchFacets.ts +0 -312
- package/src/constants.ts +0 -87
- package/src/contexts/AssetSourceDispatchContext.tsx +0 -38
- package/src/contexts/DropzoneDispatchContext.tsx +0 -32
- package/src/contexts/ToolOptionsContext.tsx +0 -66
- package/src/formSchema/index.test.ts +0 -56
- package/src/formSchema/index.ts +0 -39
- package/src/hooks/useBreakpointIndex.ts +0 -50
- package/src/hooks/useKeyPress.ts +0 -39
- package/src/hooks/usePortalPopoverProps.ts +0 -13
- package/src/hooks/useTypedSelector.ts +0 -7
- package/src/hooks/useVersionedClient.ts +0 -6
- package/src/index.ts +0 -5
- package/src/modules/assets/actions.ts +0 -42
- package/src/modules/assets/deleteAndUpdateEpics.test.ts +0 -87
- package/src/modules/assets/fetchEpic.test.ts +0 -73
- package/src/modules/assets/index.ts +0 -782
- package/src/modules/assets/reducer.test.ts +0 -91
- package/src/modules/assets/tagsAndListenerEpics.test.ts +0 -206
- package/src/modules/debug/index.ts +0 -28
- package/src/modules/dialog/actions.ts +0 -10
- package/src/modules/dialog/epics.test.ts +0 -168
- package/src/modules/dialog/index.ts +0 -238
- package/src/modules/dialog/reducer.test.ts +0 -185
- package/src/modules/index.ts +0 -117
- package/src/modules/notifications/epics.test.ts +0 -374
- package/src/modules/notifications/index.ts +0 -199
- package/src/modules/notifications/reducer.test.ts +0 -54
- package/src/modules/search/index.test.ts +0 -36
- package/src/modules/search/index.ts +0 -167
- package/src/modules/selected/index.ts +0 -22
- package/src/modules/selectors.test.ts +0 -21
- package/src/modules/selectors.ts +0 -17
- package/src/modules/tags/epics.test.ts +0 -96
- package/src/modules/tags/index.test.ts +0 -42
- package/src/modules/tags/index.ts +0 -540
- package/src/modules/types.ts +0 -3
- package/src/modules/uploads/actions.ts +0 -13
- package/src/modules/uploads/epics.test.ts +0 -109
- package/src/modules/uploads/index.test.ts +0 -59
- package/src/modules/uploads/index.ts +0 -272
- package/src/operators/checkTagName.test.ts +0 -29
- package/src/operators/checkTagName.ts +0 -33
- package/src/operators/debugThrottle.ts +0 -25
- package/src/plugin.tsx +0 -54
- package/src/schemas/tag.ts +0 -28
- package/src/styled/GlobalStyles/index.tsx +0 -40
- package/src/styled/react-select/creatable.tsx +0 -184
- package/src/styled/react-select/single.tsx +0 -184
- package/src/types/index.ts +0 -346
- package/src/types/sanity-ui.d.ts +0 -5
- package/src/utils/applyMediaTags.ts +0 -87
- package/src/utils/blocksToText.test.ts +0 -43
- package/src/utils/blocksToText.ts +0 -27
- package/src/utils/constructFilter.test.ts +0 -120
- package/src/utils/constructFilter.ts +0 -98
- package/src/utils/generatePreviewBlobUrl.test.ts +0 -68
- package/src/utils/generatePreviewBlobUrl.ts +0 -53
- package/src/utils/getAssetResolution.test.ts +0 -13
- package/src/utils/getAssetResolution.ts +0 -7
- package/src/utils/getDocumentAssetIds.test.ts +0 -50
- package/src/utils/getDocumentAssetIds.ts +0 -35
- package/src/utils/getSchemeColor.test.ts +0 -12
- package/src/utils/getSchemeColor.ts +0 -43
- package/src/utils/getTagSelectOptions.test.ts +0 -44
- package/src/utils/getTagSelectOptions.ts +0 -16
- package/src/utils/getUniqueDocuments.test.ts +0 -26
- package/src/utils/getUniqueDocuments.ts +0 -15
- package/src/utils/imageDprUrl.test.ts +0 -46
- package/src/utils/imageDprUrl.ts +0 -27
- package/src/utils/isSupportedAssetType.test.ts +0 -16
- package/src/utils/isSupportedAssetType.ts +0 -15
- package/src/utils/mediaField.ts +0 -73
- package/src/utils/sanitizeFormData.test.ts +0 -59
- package/src/utils/sanitizeFormData.ts +0 -26
- package/src/utils/typeGuards.test.ts +0 -18
- package/src/utils/typeGuards.ts +0 -9
- package/src/utils/uploadSanityAsset.test.ts +0 -29
- package/src/utils/uploadSanityAsset.ts +0 -97
- package/src/utils/withMaxConcurrency.test.ts +0 -43
- package/src/utils/withMaxConcurrency.ts +0 -55
- package/src/utils/zodFormResolver.ts +0 -17
- package/v2-incompatible.js +0 -11
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import {type PayloadAction, createSelector, createSlice} from '@reduxjs/toolkit'
|
|
2
|
-
import {uuid} from '@sanity/uuid'
|
|
3
|
-
import {EMPTY, of} from 'rxjs'
|
|
4
|
-
import {filter, mergeMap, withLatestFrom} from 'rxjs/operators'
|
|
5
|
-
|
|
6
|
-
import type {MyEpic, SearchFacetInputProps, SearchFacetOperatorType, WithId} from '../../types'
|
|
7
|
-
import {tagsActions} from '../tags'
|
|
8
|
-
import type {RootReducerState} from '../types'
|
|
9
|
-
|
|
10
|
-
// TODO: don't store non-serializable data in the search store
|
|
11
|
-
// (The main offender is `fieldModifier` which is currently a function)
|
|
12
|
-
|
|
13
|
-
type SearchState = {
|
|
14
|
-
facets: WithId<SearchFacetInputProps>[]
|
|
15
|
-
query: string
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const initialState = {
|
|
19
|
-
facets: [],
|
|
20
|
-
query: '',
|
|
21
|
-
} as SearchState
|
|
22
|
-
|
|
23
|
-
const searchSlice = createSlice({
|
|
24
|
-
name: 'search',
|
|
25
|
-
initialState,
|
|
26
|
-
reducers: {
|
|
27
|
-
// Add search facet
|
|
28
|
-
facetsAdd(state, action: PayloadAction<{facet: SearchFacetInputProps}>) {
|
|
29
|
-
state.facets.push({...action.payload.facet, id: uuid()})
|
|
30
|
-
},
|
|
31
|
-
// Clear all search facets
|
|
32
|
-
facetsClear(state) {
|
|
33
|
-
state.facets = []
|
|
34
|
-
},
|
|
35
|
-
// Remove search facet by name
|
|
36
|
-
facetsRemoveByName(state, action: PayloadAction<{facetName: string}>) {
|
|
37
|
-
state.facets = state.facets.filter((facet) => facet.name !== action.payload.facetName)
|
|
38
|
-
},
|
|
39
|
-
// Remove search facet by name
|
|
40
|
-
facetsRemoveByTag(state, action: PayloadAction<{tagId: string}>) {
|
|
41
|
-
state.facets = state.facets.filter(
|
|
42
|
-
(facet) =>
|
|
43
|
-
!(
|
|
44
|
-
facet.name === 'tag' &&
|
|
45
|
-
facet.type === 'searchable' &&
|
|
46
|
-
(facet.operatorType === 'references' || facet.operatorType === 'doesNotReference') &&
|
|
47
|
-
facet.value?.value === action.payload.tagId
|
|
48
|
-
),
|
|
49
|
-
)
|
|
50
|
-
},
|
|
51
|
-
// Remove search facet by name
|
|
52
|
-
facetsRemoveById(state, action: PayloadAction<{facetId: string}>) {
|
|
53
|
-
state.facets = state.facets.filter((facet) => facet.id !== action.payload.facetId)
|
|
54
|
-
},
|
|
55
|
-
// Update an existing search facet
|
|
56
|
-
facetsUpdate(
|
|
57
|
-
state,
|
|
58
|
-
action: PayloadAction<{
|
|
59
|
-
modifier?: string
|
|
60
|
-
name: string
|
|
61
|
-
operatorType?: SearchFacetOperatorType
|
|
62
|
-
value?: any // TODO: type correctly
|
|
63
|
-
}>,
|
|
64
|
-
) {
|
|
65
|
-
const {modifier, name, operatorType, value} = action.payload
|
|
66
|
-
|
|
67
|
-
const facet = state.facets.find((f) => f.name === name)
|
|
68
|
-
|
|
69
|
-
if (!facet) {
|
|
70
|
-
return
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (facet.type === 'number' && modifier) {
|
|
74
|
-
facet.modifier = modifier
|
|
75
|
-
}
|
|
76
|
-
if (operatorType) {
|
|
77
|
-
facet.operatorType = operatorType
|
|
78
|
-
}
|
|
79
|
-
if (typeof value !== 'undefined') {
|
|
80
|
-
facet.value = value
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
state.facets = state.facets.filter((f) => f.name !== facet.name || f.id === facet.id)
|
|
84
|
-
},
|
|
85
|
-
// Update an existing search facet
|
|
86
|
-
facetsUpdateById(
|
|
87
|
-
state,
|
|
88
|
-
action: PayloadAction<{
|
|
89
|
-
modifier?: string
|
|
90
|
-
id: string
|
|
91
|
-
operatorType?: SearchFacetOperatorType
|
|
92
|
-
value?: any // TODO: type correctly
|
|
93
|
-
}>,
|
|
94
|
-
) {
|
|
95
|
-
const {modifier, id, operatorType, value} = action.payload
|
|
96
|
-
|
|
97
|
-
state.facets.forEach((facet, index) => {
|
|
98
|
-
if (facet.id === id) {
|
|
99
|
-
if (facet.type === 'number' && modifier) {
|
|
100
|
-
facet.modifier = modifier
|
|
101
|
-
}
|
|
102
|
-
if (operatorType) {
|
|
103
|
-
facet.operatorType = operatorType
|
|
104
|
-
}
|
|
105
|
-
if (typeof value !== 'undefined') {
|
|
106
|
-
state.facets[index]!.value = value
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
})
|
|
110
|
-
},
|
|
111
|
-
// Update existing search query
|
|
112
|
-
querySet(state, action: PayloadAction<{searchQuery: string}>) {
|
|
113
|
-
state.query = action.payload?.searchQuery
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
// Epics
|
|
119
|
-
|
|
120
|
-
// On tag update success -> update existing tag search facet (if present)
|
|
121
|
-
export const searchFacetTagUpdateEpic: MyEpic = (action$, state$) =>
|
|
122
|
-
action$.pipe(
|
|
123
|
-
filter(tagsActions.updateComplete.match),
|
|
124
|
-
withLatestFrom(state$),
|
|
125
|
-
mergeMap(([action, state]) => {
|
|
126
|
-
const {tag} = action.payload
|
|
127
|
-
|
|
128
|
-
const currentSearchFacetTag = state.search.facets?.find((facet) => facet.name === 'tag')
|
|
129
|
-
const tagItem = state.tags.byIds[tag._id]
|
|
130
|
-
|
|
131
|
-
if (currentSearchFacetTag?.type === 'searchable') {
|
|
132
|
-
if (currentSearchFacetTag.value?.value === tag._id) {
|
|
133
|
-
return of(
|
|
134
|
-
searchSlice.actions.facetsUpdate({
|
|
135
|
-
name: 'tag',
|
|
136
|
-
value: {
|
|
137
|
-
label: tagItem?.tag?.name?.current,
|
|
138
|
-
value: tagItem?.tag?._id,
|
|
139
|
-
},
|
|
140
|
-
}),
|
|
141
|
-
)
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
return EMPTY
|
|
146
|
-
}),
|
|
147
|
-
)
|
|
148
|
-
|
|
149
|
-
// Selectors
|
|
150
|
-
export const selectIsSearchFacetTag = createSelector(
|
|
151
|
-
[
|
|
152
|
-
(state: RootReducerState) => state.search.facets,
|
|
153
|
-
(_state: RootReducerState, tagId: string) => tagId,
|
|
154
|
-
],
|
|
155
|
-
(searchFacets, tagId) =>
|
|
156
|
-
searchFacets.some(
|
|
157
|
-
(facet) =>
|
|
158
|
-
facet.name === 'tag' &&
|
|
159
|
-
facet.type === 'searchable' &&
|
|
160
|
-
(facet.operatorType === 'references' || facet.operatorType === 'doesNotReference') &&
|
|
161
|
-
facet.value?.value === tagId,
|
|
162
|
-
),
|
|
163
|
-
)
|
|
164
|
-
|
|
165
|
-
export const searchActions = {...searchSlice.actions}
|
|
166
|
-
|
|
167
|
-
export default searchSlice.reducer
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import {createSlice} from '@reduxjs/toolkit'
|
|
2
|
-
import type {SanityAssetDocument, SanityDocument, SanityImageAssetDocument} from '@sanity/client'
|
|
3
|
-
|
|
4
|
-
type SelectedReducerState = {
|
|
5
|
-
assets: (SanityAssetDocument | SanityImageAssetDocument)[]
|
|
6
|
-
document?: SanityDocument
|
|
7
|
-
documentAssetIds?: string[]
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const initialState = {
|
|
11
|
-
assets: [],
|
|
12
|
-
document: undefined,
|
|
13
|
-
documentAssetIds: [],
|
|
14
|
-
} as SelectedReducerState
|
|
15
|
-
|
|
16
|
-
const selectedSlice = createSlice({
|
|
17
|
-
name: 'selected',
|
|
18
|
-
initialState,
|
|
19
|
-
reducers: {},
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
export default selectedSlice.reducer
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// @vitest-environment node
|
|
2
|
-
|
|
3
|
-
import {describe, expect, it} from 'vitest'
|
|
4
|
-
|
|
5
|
-
import {selectCombinedItems} from './selectors'
|
|
6
|
-
import type {RootReducerState} from './types'
|
|
7
|
-
|
|
8
|
-
describe('selectCombinedItems', () => {
|
|
9
|
-
it('places upload items before asset items', () => {
|
|
10
|
-
const state = {
|
|
11
|
-
assets: {allIds: ['a1', 'a2']},
|
|
12
|
-
uploads: {allIds: ['u1']},
|
|
13
|
-
} as RootReducerState
|
|
14
|
-
|
|
15
|
-
expect(selectCombinedItems(state)).toEqual([
|
|
16
|
-
{id: 'u1', type: 'upload'},
|
|
17
|
-
{id: 'a1', type: 'asset'},
|
|
18
|
-
{id: 'a2', type: 'asset'},
|
|
19
|
-
])
|
|
20
|
-
})
|
|
21
|
-
})
|
package/src/modules/selectors.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import {createSelector} from '@reduxjs/toolkit'
|
|
2
|
-
|
|
3
|
-
import type {CardAssetData, CardUploadData} from '../types'
|
|
4
|
-
import type {RootReducerState} from './types'
|
|
5
|
-
|
|
6
|
-
export const selectCombinedItems = createSelector(
|
|
7
|
-
[
|
|
8
|
-
(state: RootReducerState) => state.assets.allIds,
|
|
9
|
-
(state: RootReducerState) => state.uploads.allIds,
|
|
10
|
-
],
|
|
11
|
-
(assetIds, uploadIds) => {
|
|
12
|
-
const assetItems = assetIds.map((id) => ({id, type: 'asset'}) as CardAssetData)
|
|
13
|
-
const uploadItems = uploadIds.map((id) => ({id, type: 'upload'}) as CardUploadData)
|
|
14
|
-
const combinedItems: (CardAssetData | CardUploadData)[] = [...uploadItems, ...assetItems]
|
|
15
|
-
return combinedItems
|
|
16
|
-
},
|
|
17
|
-
)
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
// @vitest-environment node
|
|
2
|
-
|
|
3
|
-
import {of} from 'rxjs'
|
|
4
|
-
import {describe, expect, it, vi} from 'vitest'
|
|
5
|
-
|
|
6
|
-
import {createEpicTestStore} from '../../__tests__/fixtures/createEpicTestStore'
|
|
7
|
-
import {
|
|
8
|
-
createMockSanityClient,
|
|
9
|
-
mockTransactionCommit,
|
|
10
|
-
} from '../../__tests__/fixtures/mockSanityClient'
|
|
11
|
-
import type {Tag} from '../../types'
|
|
12
|
-
import {tagsCreateEpic, tagsDeleteEpic, tagsActions} from './index'
|
|
13
|
-
|
|
14
|
-
const sampleTag: Tag = {
|
|
15
|
-
_id: 't1',
|
|
16
|
-
_type: 'media.tag',
|
|
17
|
-
_createdAt: '',
|
|
18
|
-
_updatedAt: '',
|
|
19
|
-
_rev: 'tr',
|
|
20
|
-
name: {_type: 'slug', current: 'alpha'},
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
describe('tagsCreateEpic', () => {
|
|
24
|
-
it('creates tag when checkTagName passes', async () => {
|
|
25
|
-
const client = createMockSanityClient({
|
|
26
|
-
fetch: vi.fn().mockResolvedValue(0),
|
|
27
|
-
observable: {
|
|
28
|
-
create: vi.fn(() => of(sampleTag)),
|
|
29
|
-
},
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
const store = createEpicTestStore(tagsCreateEpic, client)
|
|
33
|
-
store.dispatch(tagsActions.createRequest({name: 'alpha'}))
|
|
34
|
-
|
|
35
|
-
await vi.waitFor(() => {
|
|
36
|
-
expect(store.getState().tags.byIds['t1']?.tag).toEqual(sampleTag)
|
|
37
|
-
expect(client.observable.create).toHaveBeenCalled()
|
|
38
|
-
})
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
it('dispatches createError when tag exists', async () => {
|
|
42
|
-
const client = createMockSanityClient({
|
|
43
|
-
fetch: vi.fn().mockResolvedValue(1),
|
|
44
|
-
observable: {
|
|
45
|
-
create: vi.fn(() => of(sampleTag)),
|
|
46
|
-
},
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
const store = createEpicTestStore(tagsCreateEpic, client)
|
|
50
|
-
store.dispatch(tagsActions.createRequest({name: 'dup'}))
|
|
51
|
-
|
|
52
|
-
await vi.waitFor(() => {
|
|
53
|
-
expect(store.getState().tags.creatingError?.statusCode).toBe(409)
|
|
54
|
-
expect(client.observable.create).not.toHaveBeenCalled()
|
|
55
|
-
})
|
|
56
|
-
})
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
describe('tagsDeleteEpic', () => {
|
|
60
|
-
it('fetches referencing assets and commits transaction', async () => {
|
|
61
|
-
const tx = mockTransactionCommit(undefined)
|
|
62
|
-
const client = createMockSanityClient({
|
|
63
|
-
observable: {
|
|
64
|
-
fetch: vi.fn(() =>
|
|
65
|
-
of([
|
|
66
|
-
{_id: 'a1', _rev: 'r1', opt: {}},
|
|
67
|
-
{_id: 'a2', _rev: 'r2', opt: {}},
|
|
68
|
-
]),
|
|
69
|
-
),
|
|
70
|
-
},
|
|
71
|
-
transaction: vi.fn(() => tx),
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
const store = createEpicTestStore(tagsDeleteEpic, client, {
|
|
75
|
-
tags: {
|
|
76
|
-
allIds: ['t1'],
|
|
77
|
-
byIds: {
|
|
78
|
-
t1: {_type: 'tag', tag: sampleTag, picked: false, updating: false},
|
|
79
|
-
},
|
|
80
|
-
creating: false,
|
|
81
|
-
fetchCount: -1,
|
|
82
|
-
fetching: false,
|
|
83
|
-
panelVisible: true,
|
|
84
|
-
},
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
store.dispatch(tagsActions.deleteRequest({tag: sampleTag}))
|
|
88
|
-
|
|
89
|
-
await vi.waitFor(() => {
|
|
90
|
-
expect(tx.patch).toHaveBeenCalled()
|
|
91
|
-
expect(tx.delete).toHaveBeenCalledWith('t1')
|
|
92
|
-
expect(tx.commit).toHaveBeenCalled()
|
|
93
|
-
expect(store.getState().tags.byIds['t1']).toBeUndefined()
|
|
94
|
-
})
|
|
95
|
-
})
|
|
96
|
-
})
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
// @vitest-environment node
|
|
2
|
-
|
|
3
|
-
import {describe, expect, it} from 'vitest'
|
|
4
|
-
|
|
5
|
-
import type {Tag} from '../../types'
|
|
6
|
-
import tagsReducer, {tagsActions} from './index'
|
|
7
|
-
|
|
8
|
-
const sampleTag: Tag = {
|
|
9
|
-
_id: 'tag-1',
|
|
10
|
-
_type: 'media.tag',
|
|
11
|
-
_createdAt: '2020-01-01',
|
|
12
|
-
_updatedAt: '2020-01-01',
|
|
13
|
-
_rev: 'r1',
|
|
14
|
-
name: {_type: 'slug', current: 'alpha'},
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
describe('tags slice', () => {
|
|
18
|
-
it('createComplete adds tag', () => {
|
|
19
|
-
let state = tagsReducer(undefined, {type: '@@INIT'} as never)
|
|
20
|
-
state = tagsReducer(state, tagsActions.createComplete({tag: sampleTag}))
|
|
21
|
-
expect(state.allIds).toContain('tag-1')
|
|
22
|
-
expect(state.byIds['tag-1']!.tag).toEqual(sampleTag)
|
|
23
|
-
expect(state.creating).toBe(false)
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
it('deleteComplete removes tag', () => {
|
|
27
|
-
let state = tagsReducer(undefined, {type: '@@INIT'} as never)
|
|
28
|
-
state = tagsReducer(state, tagsActions.createComplete({tag: sampleTag}))
|
|
29
|
-
state = tagsReducer(state, tagsActions.deleteComplete({tagId: 'tag-1'}))
|
|
30
|
-
expect(state.allIds).not.toContain('tag-1')
|
|
31
|
-
expect(state.byIds['tag-1']).toBeUndefined()
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
it('fetchComplete hydrates tag list', () => {
|
|
35
|
-
let state = tagsReducer(undefined, {type: '@@INIT'} as never)
|
|
36
|
-
state = tagsReducer(state, tagsActions.fetchRequest())
|
|
37
|
-
expect(state.fetching).toBe(true)
|
|
38
|
-
state = tagsReducer(state, tagsActions.fetchComplete({tags: [sampleTag]}))
|
|
39
|
-
expect(state.fetching).toBe(false)
|
|
40
|
-
expect(state.byIds['tag-1']!.tag).toEqual(sampleTag)
|
|
41
|
-
})
|
|
42
|
-
})
|