Skip to content

Commit a88564e

Browse files
committed
simplify test store solution
1 parent 0f4e53e commit a88564e

File tree

12 files changed

+50
-41
lines changed

12 files changed

+50
-41
lines changed

jest.config.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module.exports = {
1111
'\\.svg': '<rootDir>/redisinsight/__mocks__/svg.js',
1212
'\\.(css|less|sass|scss)$': 'identity-obj-proxy',
1313
'\\.scss\\?inline$': '<rootDir>/redisinsight/__mocks__/scssRaw.js',
14+
'uiSrc/slices/store$': '<rootDir>/redisinsight/ui/src/utils/test-store.ts',
1415
'uiSrc/(.*)': '<rootDir>/redisinsight/ui/src/$1',
1516
'@redislabsdev/redis-ui-components': '@redis-ui/components',
1617
'@redislabsdev/redis-ui-styles': '@redis-ui/styles',

redisinsight/ui/src/services/apiService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { isNumber } from 'lodash'
77
import { sessionStorageService } from 'uiSrc/services'
88
import { BrowserStorageItem } from 'uiSrc/constants'
99
import { CLOUD_AUTH_API_ENDPOINTS, CustomHeaders } from 'uiSrc/constants/api'
10-
import { store } from 'uiSrc/slices/store-dynamic'
10+
import { store } from 'uiSrc/slices/store'
1111
import { logoutUserAction } from 'uiSrc/slices/oauth/cloud'
1212
import { setConnectivityError } from 'uiSrc/slices/app/connectivity'
1313
import { getConfig } from 'uiSrc/config'

redisinsight/ui/src/slices/store-dynamic.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.

redisinsight/ui/src/slices/store.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ import rdiStatisticsReducer from './rdi/statistics'
5656
import aiAssistantReducer from './panels/aiAssistant'
5757
import appDbSettingsReducer from './app/db-settings'
5858
import tagsReducer from './instances/tags'
59-
import { setStoreRef } from './store-dynamic'
6059

6160
const riConfig = getConfig()
6261

@@ -149,7 +148,6 @@ const store = configureStore({
149148
getDefaultMiddleware({ serializableCheck: false }),
150149
devTools: riConfig.app.env !== 'production',
151150
})
152-
setStoreRef(store)
153151

154152
export { store }
155153

redisinsight/ui/src/slices/tests/browser/keys.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import {
3131
setBrowserSelectedKey,
3232
} from 'uiSrc/slices/app/context'
3333
import { MOCK_TIMESTAMP } from 'uiSrc/mocks/data/dateNow'
34-
import { rootReducer } from 'uiSrc/slices/store'
3534
import {
3635
setEditorType,
3736
setIsWithinThreshold,
@@ -46,6 +45,7 @@ import { CreateRejsonRlWithExpireDto } from 'apiSrc/modules/browser/rejson-rl/dt
4645
import { CreateSetWithExpireDto } from 'apiSrc/modules/browser/set/dto'
4746
import { CreateZSetWithExpireDto } from 'apiSrc/modules/browser/z-set/dto'
4847
import { SetStringWithExpireDto } from 'apiSrc/modules/browser/string/dto'
48+
import { rootReducer } from '../../store'
4949
import { getString, getStringSuccess } from '../../browser/string'
5050
import reducer, {
5151
addHashKey,

redisinsight/ui/src/telemetry/checkAnalytics.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { get } from 'lodash'
2-
import { store } from 'uiSrc/slices/store-dynamic'
2+
import { store } from 'uiSrc/slices/store'
33

44
// Check is user give access to collect his events
55
export const checkIsAnalyticsGranted = (): boolean =>

redisinsight/ui/src/telemetry/telemetryUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
RedisModulesKeyType,
1515
} from 'uiSrc/telemetry/interfaces'
1616
import { apiService } from 'uiSrc/services'
17-
import { store } from 'uiSrc/slices/store-dynamic'
17+
import { store } from 'uiSrc/slices/store'
1818
import { getInstanceInfo } from 'uiSrc/services/database/instancesService'
1919
import { AdditionalRedisModule } from 'apiSrc/modules/database/models/additional.redis.module'
2020
import { IRedisModulesSummary, MatchType, RedisModules } from './interfaces'

redisinsight/ui/src/utils/capability.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { OAuthSocialSource, RedisDefaultModules } from 'uiSrc/slices/interfaces'
2-
import { store } from 'uiSrc/slices/store-dynamic'
2+
import { store } from 'uiSrc/slices/store'
33
import { Nullable } from 'uiSrc/utils'
44
import { findMarkdownPath } from 'uiSrc/utils/workbench'
55

redisinsight/ui/src/utils/formatters/valueFormatters.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { serialize, unserialize } from 'php-serialize'
66
import { getData } from 'rawproto'
77
import { Parser } from 'pickleparser'
88
import JSONBigInt from 'json-bigint'
9-
import { store } from 'uiSrc/slices/store-dynamic'
9+
import { store } from 'uiSrc/slices/store'
1010

1111
import JSONViewer from 'uiSrc/components/json-viewer/JSONViewer'
1212
import {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { createBrowserHistory } from 'history'
2+
3+
import type { RootState, AppDispatch, ReduxStore } from 'uiSrc/slices/store'
4+
5+
// Re-export all types and exports from the real store to avoid circular dependencies during tests
6+
7+
export type { RootState, AppDispatch, ReduxStore } from 'uiSrc/slices/store'
8+
export const history = createBrowserHistory()
9+
10+
// Lazy reference to avoid circular dependencies
11+
// The store will be set by the store module itself after it's created
12+
let storeRef: ReduxStore | null = null
13+
14+
// This function will be called by the store modules to set the reference
15+
export const setStoreRef = (store: ReduxStore) => {
16+
storeRef = store
17+
}
18+
19+
const getState = (): RootState => {
20+
if (!storeRef) {
21+
throw new Error(
22+
'Store not initialized. Make sure store-dynamic is imported after store creation.',
23+
)
24+
}
25+
return storeRef.getState()
26+
}
27+
28+
const dispatch: AppDispatch = (action: any) => {
29+
if (!storeRef) {
30+
throw new Error(
31+
'Store not initialized. Make sure store-dynamic is imported after store creation.',
32+
)
33+
}
34+
return storeRef.dispatch(action)
35+
}
36+
37+
// Export store object that matches the real store interface
38+
export const store = {
39+
getState,
40+
dispatch,
41+
}

0 commit comments

Comments
 (0)