diff --git a/.eslintignore b/.eslintignore index 699437a49e..0f5f5970d1 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,6 +1,6 @@ # Ignores folders covered with custom linters configs redisinsight/api -tests +tests/e2e # Logs logs diff --git a/redisinsight/ui/src/packages/redisearch/src/utils/tests/parseResponse.spec.ts b/redisinsight/ui/src/packages/redisearch/src/utils/tests/parseResponse.spec.ts index ab86946d03..35ed6b734c 100644 --- a/redisinsight/ui/src/packages/redisearch/src/utils/tests/parseResponse.spec.ts +++ b/redisinsight/ui/src/packages/redisearch/src/utils/tests/parseResponse.spec.ts @@ -1,4 +1,4 @@ -import { parseSearchRawResponse, parseInfoRawResponse, parseAggregateRawResponse } from '../'; +import { parseSearchRawResponse, parseInfoRawResponse, parseAggregateRawResponse } from '..' const resultFTSearch: any[] = [ 'red:2', @@ -23,27 +23,27 @@ const resultFTSearch: any[] = [ 'visits', '108', ], -]; +] -const resultFTSearchNoContent: any[] = ['red:2', 'red:3', 'red:4', 'red:5', 'red:6']; +const resultFTSearchNoContent: any[] = ['red:2', 'red:3', 'red:4', 'red:5', 'red:6'] describe('parseSearchRawResponse', () => { it('command "get" should return result is not modified 1', () => { - const command = 'get'; - const result: any[] = []; + const command = 'get' + const result: any[] = [] - expect(parseSearchRawResponse(command, result)).toEqual(result); - }); + expect(parseSearchRawResponse(command, result)).toEqual(result) + }) it('command "get" should return result is not modified 2', () => { - const command = 'get'; + const command = 'get' const result: any = [] - expect(parseSearchRawResponse(command, result)).toEqual(result); - }); + expect(parseSearchRawResponse(command, result)).toEqual(result) + }) it('command "ft.search" should return array with parsed object', () => { - const command = 'ft.search'; + const command = 'ft.search' const parsedResultFTSearch = [ { Doc: 'red:2', @@ -59,13 +59,13 @@ describe('parseSearchRawResponse', () => { url: '', visits: '108', }, - ]; + ] - expect(parseSearchRawResponse(command, resultFTSearch)).toEqual(parsedResultFTSearch); - }); + expect(parseSearchRawResponse(command, resultFTSearch)).toEqual(parsedResultFTSearch) + }) it('command "ft.search" with attr NOCONTENT should return array of doc names', () => { - const command = 'ft.search NOCONTENT'; + const command = 'ft.search NOCONTENT' const parsedResultFTSearch = [ { Doc: 'red:2', @@ -82,19 +82,17 @@ describe('parseSearchRawResponse', () => { { Doc: 'red:6', }, - ]; + ] - expect(parseSearchRawResponse(command, resultFTSearchNoContent)).toEqual(parsedResultFTSearch); - }); - - -}); + expect(parseSearchRawResponse(command, resultFTSearchNoContent)).toEqual(parsedResultFTSearch) + }) +}) describe('parseAggregateRawResponse', () => { it('command "ft.aggregate" should return array of array with objects count of docs ', () => { - const command = 'ft.aggregate'; - const resultFTAggregate = [[], [], [], [], []]; + const command = 'ft.aggregate' + const resultFTAggregate = [[], [], [], [], []] - expect(parseAggregateRawResponse(resultFTAggregate)).toEqual(resultFTAggregate); - }); -}); + expect(parseAggregateRawResponse(resultFTAggregate)).toEqual(resultFTAggregate) + }) +}) diff --git a/redisinsight/ui/src/slices/tests/app/info.spec.ts b/redisinsight/ui/src/slices/tests/app/info.spec.ts index b0d63665bd..02398eef32 100644 --- a/redisinsight/ui/src/slices/tests/app/info.spec.ts +++ b/redisinsight/ui/src/slices/tests/app/info.spec.ts @@ -1,11 +1,12 @@ -import { cloneDeep } from 'lodash'; +import { cloneDeep } from 'lodash' import { cleanup, initialStateDefault, mockedStore, -} from 'uiSrc/utils/test-utils'; +} from 'uiSrc/utils/test-utils' +import { apiService } from 'uiSrc/services' import reducer, { initialState, setAnalyticsIdentified, @@ -15,55 +16,54 @@ import reducer, { getServerInfoSuccess, getServerInfoFailure, appInfoSelector, fetchServerInfo, -} from '../../app/info'; -import { apiService } from 'uiSrc/services'; +} from '../../app/info' -jest.mock('uiSrc/services'); +jest.mock('uiSrc/services') -let store: typeof mockedStore; +let store: typeof mockedStore beforeEach(() => { - cleanup(); - store = cloneDeep(mockedStore); - store.clearActions(); -}); + cleanup() + store = cloneDeep(mockedStore) + store.clearActions() +}) describe('slices', () => { describe('reducer, actions and selectors', () => { it('should return the initial state on first run', () => { // Arrange - const nextState = initialState; + const nextState = initialState // Act - const result = reducer(undefined, {}); + const result = reducer(undefined, {}) // Assert - expect(result).toEqual(nextState); - }); - }); + expect(result).toEqual(nextState) + }) + }) describe('setAnalyticsIdentified', () => { it('should properly set analytics identified', () => { // Arrange - const identified = true; + const identified = true const state = { ...initialState, analytics: { ...initialState.analytics, identified } - }; + } // Act - const nextState = reducer(initialState, setAnalyticsIdentified(identified)); + const nextState = reducer(initialState, setAnalyticsIdentified(identified)) // Assert const rootState = Object.assign(initialStateDefault, { app: { info: nextState }, - }); + }) - expect(appInfoSelector(rootState)).toEqual(state); - }); - }); + expect(appInfoSelector(rootState)).toEqual(state) + }) + }) describe('setElectronInfo', () => { it('should properly set electron info', () => { @@ -71,38 +71,38 @@ describe('slices', () => { const data = { isUpdateAvailable: true, updateDownloadedVersion: '1.2.0' - }; + } const state = { ...initialState, electron: { ...initialState.electron, ...data } - }; + } // Act - const nextState = reducer(initialState, setElectronInfo(data)); + const nextState = reducer(initialState, setElectronInfo(data)) // Assert const rootState = Object.assign(initialStateDefault, { app: { info: nextState }, - }); + }) - expect(appInfoSelector(rootState)).toEqual(state); - }); - }); + expect(appInfoSelector(rootState)).toEqual(state) + }) + }) describe('setReleaseNotesViewed', () => { it('should properly set state', () => { // Arrange - const isReleaseNotesViewed = true; + const isReleaseNotesViewed = true const state = { ...initialState, electron: { ...initialState.electron, isReleaseNotesViewed } - }; + } // Act const nextState = reducer(initialState, setReleaseNotesViewed(isReleaseNotesViewed)) @@ -110,32 +110,32 @@ describe('slices', () => { // Assert const rootState = Object.assign(initialStateDefault, { app: { info: nextState }, - }); + }) - expect(appInfoSelector(rootState)).toEqual(state); - }); - }); + expect(appInfoSelector(rootState)).toEqual(state) + }) + }) describe('getServerInfo', () => { it('should properly set loading', () => { // Arrange - const loading = true; + const loading = true const state = { ...initialState, loading - }; + } // Act - const nextState = reducer(initialState, getServerInfo()); + const nextState = reducer(initialState, getServerInfo()) // Assert const rootState = Object.assign(initialStateDefault, { app: { info: nextState }, - }); + }) - expect(appInfoSelector(rootState)).toEqual(state); - }); - }); + expect(appInfoSelector(rootState)).toEqual(state) + }) + }) describe('getServerInfoSuccess', () => { it('should properly set state after success', () => { @@ -146,45 +146,45 @@ describe('slices', () => { appVersion: '2.0.0', osPlatform: 'win32', buildType: 'ELECTRON' - }; + } const state = { ...initialState, server: data - }; + } // Act - const nextState = reducer(initialState, getServerInfoSuccess(data)); + const nextState = reducer(initialState, getServerInfoSuccess(data)) // Assert const rootState = Object.assign(initialStateDefault, { app: { info: nextState }, - }); + }) - expect(appInfoSelector(rootState)).toEqual(state); - }); - }); + expect(appInfoSelector(rootState)).toEqual(state) + }) + }) describe('getServerInfoFailure', () => { it('should properly set error', () => { // Arrange - const error = 'error'; + const error = 'error' const state = { ...initialState, loading: false, error - }; + } // Act - const nextState = reducer(initialState, getServerInfoFailure(error)); + const nextState = reducer(initialState, getServerInfoFailure(error)) // Assert const rootState = Object.assign(initialStateDefault, { app: { info: nextState }, - }); + }) - expect(appInfoSelector(rootState)).toEqual(state); - }); - }); + expect(appInfoSelector(rootState)).toEqual(state) + }) + }) // thunks describe('fetchServerInfo', () => { @@ -196,44 +196,44 @@ describe('slices', () => { appVersion: '2.0.0', osPlatform: 'win32', buildType: 'ELECTRON' - }; - const responsePayload = { status: 200, data }; + } + const responsePayload = { status: 200, data } - apiService.get = jest.fn().mockResolvedValue(responsePayload); + apiService.get = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(fetchServerInfo(jest.fn())); + await store.dispatch(fetchServerInfo(jest.fn())) // Assert const expectedActions = [ getServerInfo(), getServerInfoSuccess(data), - ]; + ] - expect(mockedStore.getActions()).toEqual(expectedActions); - }); + expect(mockedStore.getActions()).toEqual(expectedActions) + }) it('failed to fetch server info', async () => { // Arrange - const errorMessage = 'Something was wrong!'; + const errorMessage = 'Something was wrong!' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; - apiService.get = jest.fn().mockRejectedValue(responsePayload); + } + apiService.get = jest.fn().mockRejectedValue(responsePayload) // Act - await store.dispatch(fetchServerInfo(jest.fn(), jest.fn())); + await store.dispatch(fetchServerInfo(jest.fn(), jest.fn())) // Assert const expectedActions = [ getServerInfo(), getServerInfoFailure(errorMessage), - ]; + ] - expect(mockedStore.getActions()).toEqual(expectedActions); - }); - }); -}); + expect(mockedStore.getActions()).toEqual(expectedActions) + }) + }) +}) diff --git a/redisinsight/ui/src/slices/tests/app/notifications.spec.ts b/redisinsight/ui/src/slices/tests/app/notifications.spec.ts index 64da654bc3..387b86e1bf 100644 --- a/redisinsight/ui/src/slices/tests/app/notifications.spec.ts +++ b/redisinsight/ui/src/slices/tests/app/notifications.spec.ts @@ -1,11 +1,12 @@ -import { cloneDeep } from 'lodash'; +import { cloneDeep } from 'lodash' import { cleanup, initialStateDefault, mockedStore, -} from 'uiSrc/utils/test-utils'; +} from 'uiSrc/utils/test-utils' +import { IError, IMessage } from 'uiSrc/slices/interfaces' import reducer, { initialState, removeError, @@ -17,36 +18,35 @@ import reducer, { errorsSelector, messagesSelector, IAddInstanceErrorPayload -} from '../../app/notifications'; -import { IError, IMessage } from 'uiSrc/slices/interfaces'; +} from '../../app/notifications' -jest.mock('uiSrc/services'); +jest.mock('uiSrc/services') -let store: typeof mockedStore; +let store: typeof mockedStore beforeEach(() => { - cleanup(); - store = cloneDeep(mockedStore); - store.clearActions(); -}); + cleanup() + store = cloneDeep(mockedStore) + store.clearActions() +}) describe('slices', () => { describe('reducer, actions and selectors', () => { it('should return the initial state on first run', () => { // Arrange - const nextState = initialState; + const nextState = initialState // Act - const result = reducer(undefined, {}); + const result = reducer(undefined, {}) // Assert - expect(result).toEqual(nextState); - }); - }); + expect(result).toEqual(nextState) + }) + }) describe('addErrorNotification', () => { it('should properly set the state', () => { // Arrange - const errorMessage = 'some error'; + const errorMessage = 'some error' const responsePayload = { instanceId: undefined, name: 'Error', @@ -54,15 +54,15 @@ describe('slices', () => { status: 500, data: { message: errorMessage }, }, - }; + } // Act - const nextState = reducer(initialState, addErrorNotification(responsePayload as IAddInstanceErrorPayload)); + const nextState = reducer(initialState, addErrorNotification(responsePayload as IAddInstanceErrorPayload)) // Assert const rootState = Object.assign(initialStateDefault, { app: { notifications: nextState }, - }); + }) const state = { ...initialState, @@ -71,18 +71,18 @@ describe('slices', () => { id: errorsSelector(rootState)[0].id, message: responsePayload.response.data.message, }] - }; + } - expect(errorsSelector(rootState)).toEqual(state.errors); + expect(errorsSelector(rootState)).toEqual(state.errors) }) - }); + }) describe('removeError', () => { it('should properly remove the error', () => { // Arrange const stateWithErrors: IError[] = [ // @ts-ignore - { id: '1', message: ''}, + { id: '1', message: '' }, // @ts-ignore { id: '2', message: '' } ] @@ -93,28 +93,29 @@ describe('slices', () => { ...initialState, errors: stateWithErrors }, - removeError('1')); + removeError('1') + ) // Assert const rootState = Object.assign(initialStateDefault, { app: { notifications: nextState }, - }); + }) const state = { ...initialState, errors: [{ id: '2', message: '' }] - }; + } - expect(errorsSelector(rootState)).toEqual(state.errors); - }); - }); + expect(errorsSelector(rootState)).toEqual(state.errors) + }) + }) describe('resetErrors', () => { it('should properly reset errors', () => { // Arrange const stateWithErrors: IError[] = [ // @ts-ignore - { id: '1', message: ''}, + { id: '1', message: '' }, // @ts-ignore { id: '2', message: '' } ] @@ -125,40 +126,41 @@ describe('slices', () => { ...initialState, errors: stateWithErrors }, - resetErrors()); + resetErrors() + ) // Assert const rootState = Object.assign(initialStateDefault, { app: { notifications: nextState }, - }); + }) const state = { ...initialState, errors: [] - }; + } - expect(errorsSelector(rootState)).toEqual(state.errors); - }); - }); + expect(errorsSelector(rootState)).toEqual(state.errors) + }) + }) describe('addMessageNotification', () => { it('should properly set the state', () => { // Arrange - const message = 'some message'; + const message = 'some message' const responsePayload = { response: { status: 200, - data: { message: message }, + data: { message }, }, - }; + } // Act - const nextState = reducer(initialState, addMessageNotification(responsePayload)); + const nextState = reducer(initialState, addMessageNotification(responsePayload)) // Assert const rootState = Object.assign(initialStateDefault, { app: { notifications: nextState }, - }); + }) const state = { ...initialState, @@ -166,18 +168,18 @@ describe('slices', () => { ...responsePayload, id: messagesSelector(rootState)[0].id }] - }; + } - expect(messagesSelector(rootState)).toEqual(state.messages); + expect(messagesSelector(rootState)).toEqual(state.messages) }) - }); + }) describe('removeMessage', () => { it('should properly remove the message', () => { // Arrange const stateWithMessages: IMessage[] = [ - { id: '1', message: '', title: ''}, - { id: '2', message: '', title: ''}, + { id: '1', message: '', title: '' }, + { id: '2', message: '', title: '' }, ] // Act @@ -186,28 +188,29 @@ describe('slices', () => { ...initialState, messages: stateWithMessages }, - removeMessage('1')); + removeMessage('1') + ) // Assert const rootState = Object.assign(initialStateDefault, { app: { notifications: nextState }, - }); + }) const state = { ...initialState, - messages: [{ id: '2', message: '', title: ''}] - }; + messages: [{ id: '2', message: '', title: '' }] + } - expect(messagesSelector(rootState)).toEqual(state.messages); - }); - }); + expect(messagesSelector(rootState)).toEqual(state.messages) + }) + }) describe('resetMessages', () => { it('should properly reset errors', () => { // Arrange const stateWithMessages: IMessage[] = [ - { id: '1', message: '', title: ''}, - { id: '2', message: '', title: ''}, + { id: '1', message: '', title: '' }, + { id: '2', message: '', title: '' }, ] // Act @@ -216,19 +219,20 @@ describe('slices', () => { ...initialState, messages: stateWithMessages }, - resetMessages()); + resetMessages() + ) // Assert const rootState = Object.assign(initialStateDefault, { app: { notifications: nextState }, - }); + }) const state = { ...initialState, messages: [] - }; + } - expect(messagesSelector(rootState)).toEqual(state.messages); - }); - }); + expect(messagesSelector(rootState)).toEqual(state.messages) + }) + }) }) diff --git a/redisinsight/ui/src/slices/tests/caCerts.spec.ts b/redisinsight/ui/src/slices/tests/caCerts.spec.ts index fe11af179e..b35da87961 100644 --- a/redisinsight/ui/src/slices/tests/caCerts.spec.ts +++ b/redisinsight/ui/src/slices/tests/caCerts.spec.ts @@ -1,11 +1,11 @@ -import { AxiosError } from 'axios'; -import { cloneDeep } from 'lodash'; -import { apiService } from 'uiSrc/services'; +import { AxiosError } from 'axios' +import { cloneDeep } from 'lodash' +import { apiService } from 'uiSrc/services' import { cleanup, initialStateDefault, mockedStore, -} from 'uiSrc/utils/test-utils'; +} from 'uiSrc/utils/test-utils' import reducer, { initialState, loadCaCerts, @@ -13,31 +13,31 @@ import reducer, { loadCaCertsFailure, caCertsSelector, fetchCaCerts, -} from '../caCerts'; -import { addErrorNotification } from '../app/notifications'; +} from '../caCerts' +import { addErrorNotification } from '../app/notifications' -jest.mock('uiSrc/services'); +jest.mock('uiSrc/services') -let store: typeof mockedStore; +let store: typeof mockedStore beforeEach(() => { - cleanup(); - store = cloneDeep(mockedStore); - store.clearActions(); -}); + cleanup() + store = cloneDeep(mockedStore) + store.clearActions() +}) describe('caCerts slice', () => { describe('reducer, actions and selectors', () => { it('should return the initial state on first run', () => { // Arrange - const nextState = initialState; + const nextState = initialState // Act - const result = reducer(undefined, {}); + const result = reducer(undefined, {}) // Assert - expect(result).toEqual(nextState); - }); - }); + expect(result).toEqual(nextState) + }) + }) describe('loadCaCerts', () => { it('should properly set loading = true', () => { @@ -45,20 +45,20 @@ describe('caCerts slice', () => { const state = { ...initialState, loading: true, - }; + } // Act - const nextState = reducer(initialState, loadCaCerts()); + const nextState = reducer(initialState, loadCaCerts()) // Assert const rootState = Object.assign(initialStateDefault, { connections: { caCerts: nextState, }, - }); - expect(caCertsSelector(rootState)).toEqual(state); - }); - }); + }) + expect(caCertsSelector(rootState)).toEqual(state) + }) + }) describe('loadCaCertsSuccess', () => { it('should properly set the state with fetched data', () => { @@ -66,116 +66,115 @@ describe('caCerts slice', () => { const data = [ { id: '70b95d32-c19d-4311-bb24-e684af12cf15', name: 'ca cert' }, - ]; + ] const state = { ...initialState, loading: false, data, - }; + } // Act - const nextState = reducer(initialState, loadCaCertsSuccess(data)); + const nextState = reducer(initialState, loadCaCertsSuccess(data)) // Assert const rootState = Object.assign(initialStateDefault, { connections: { caCerts: nextState, }, - }); - expect(caCertsSelector(rootState)).toEqual(state); - }); + }) + expect(caCertsSelector(rootState)).toEqual(state) + }) it('should properly set the state with empty data', () => { // Arrange - const data: any = []; + const data: any = [] const state = { ...initialState, loading: false, data, - }; + } // Act - const nextState = reducer(initialState, loadCaCertsSuccess(data)); + const nextState = reducer(initialState, loadCaCertsSuccess(data)) // Assert const rootState = Object.assign(initialStateDefault, { connections: { caCerts: nextState, }, - }); - expect(caCertsSelector(rootState)).toEqual(state); - }); - }); + }) + expect(caCertsSelector(rootState)).toEqual(state) + }) + }) describe('loadCaCertsFailure', () => { it('should properly set the error', () => { // Arrange - const data = 'some error'; + const data = 'some error' const state = { ...initialState, loading: false, error: data, data: [], - }; + } // Act - const nextState = reducer(initialState, loadCaCertsFailure(data)); + const nextState = reducer(initialState, loadCaCertsFailure(data)) // Assert const rootState = Object.assign(initialStateDefault, { connections: { caCerts: nextState, }, - }); - expect(caCertsSelector(rootState)).toEqual(state); - }); - }); + }) + expect(caCertsSelector(rootState)).toEqual(state) + }) + }) describe('thunks', () => { it('call both fetchCaCerts and loadCaCertsSuccess when fetch is successed', async () => { // Arrange const data = [ { id: '70b95d32-c19d-4311-bb24-e684af12cf15', name: 'ca cert' }, - ]; - const responsePayload = { data, status: 200 }; + ] + const responsePayload = { data, status: 200 } - apiService.get = jest.fn().mockResolvedValue(responsePayload); + apiService.get = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(fetchCaCerts()); + await store.dispatch(fetchCaCerts()) // Assert const expectedActions = [ loadCaCerts(), loadCaCertsSuccess(responsePayload.data), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) it('call both fetchCaCerts and loadCaCertsFailure when fetch is fail', async () => { // Arrange - const errorMessage = - 'Could not connect to aoeu:123, please check the connection details.'; + const errorMessage = 'Could not connect to aoeu:123, please check the connection details.' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; + } - apiService.get = jest.fn().mockRejectedValueOnce(responsePayload); + apiService.get = jest.fn().mockRejectedValueOnce(responsePayload) // Act - await store.dispatch(fetchCaCerts()); + await store.dispatch(fetchCaCerts()) // Assert const expectedActions = [ loadCaCerts(), addErrorNotification(responsePayload as AxiosError), loadCaCertsFailure(responsePayload.response.data.message), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); - }); -}); + ] + expect(store.getActions()).toEqual(expectedActions) + }) + }) +}) diff --git a/redisinsight/ui/src/slices/tests/cli/cli-output.spec.ts b/redisinsight/ui/src/slices/tests/cli/cli-output.spec.ts index 893bb38e71..9d485122e8 100644 --- a/redisinsight/ui/src/slices/tests/cli/cli-output.spec.ts +++ b/redisinsight/ui/src/slices/tests/cli/cli-output.spec.ts @@ -1,5 +1,5 @@ -import { SendClusterCommandDto, SendClusterCommandResponse } from 'apiSrc/modules/cli/dto/cli.dto'; -import { cloneDeep, first } from 'lodash'; +import { SendClusterCommandDto, SendClusterCommandResponse } from 'apiSrc/modules/cli/dto/cli.dto' +import { cloneDeep, first } from 'lodash' import { cleanup, @@ -7,11 +7,11 @@ import { initialStateDefault, clearStoreActions, mockStore, -} from 'uiSrc/utils/test-utils'; -import { ClusterNodeRole, CommandExecutionStatus } from 'uiSrc/slices/interfaces/cli'; -import { apiService } from 'uiSrc/services'; -import { cliTexts } from 'uiSrc/constants/cliOutput'; -import { cliCommandOutput, cliParseTextResponseWithOffset } from 'uiSrc/utils/cli'; +} from 'uiSrc/utils/test-utils' +import { ClusterNodeRole, CommandExecutionStatus } from 'uiSrc/slices/interfaces/cli' +import { apiService } from 'uiSrc/services' +import { cliTexts } from 'uiSrc/constants/cliOutput' +import { cliCommandOutput, cliParseTextResponseWithOffset } from 'uiSrc/utils/cli' import reducer, { initialState, concatToOutput, @@ -23,61 +23,61 @@ import reducer, { outputSelector, processUnsupportedCommand, updateCliCommandHistory, -} from '../../cli/cli-output'; +} from '../../cli/cli-output' -jest.mock('uiSrc/services'); +jest.mock('uiSrc/services') -let store: typeof mockedStore; +let store: typeof mockedStore beforeEach(() => { - cleanup(); - store = cloneDeep(mockedStore); - store.clearActions(); -}); + cleanup() + store = cloneDeep(mockedStore) + store.clearActions() +}) describe('cliOutput slice', () => { describe('concatToOutput', () => { it('should properly concat a new array to existed output', () => { - const data = ['\n\n', 'tatata']; + const data = ['\n\n', 'tatata'] // Arrange const state: typeof initialState = { ...initialState, data, - }; + } // Act - const nextState = reducer(initialState, concatToOutput(data)); + const nextState = reducer(initialState, concatToOutput(data)) // Assert const rootState = Object.assign(initialStateDefault, { cli: { output: nextState, }, - }); - expect(outputSelector(rootState)).toEqual(state); - }); - }); + }) + expect(outputSelector(rootState)).toEqual(state) + }) + }) describe('updateCliCommandHistory', () => { it('should properly updated cli history output', () => { - const data = ['lalal', 'tatata']; + const data = ['lalal', 'tatata'] // Arrange const state: typeof initialState = { ...initialState, commandHistory: data, - }; + } // Act - const nextState = reducer(initialState, updateCliCommandHistory(data)); + const nextState = reducer(initialState, updateCliCommandHistory(data)) // Assert const rootState = Object.assign(initialStateDefault, { cli: { output: nextState, }, - }); - expect(outputSelector(rootState)).toEqual(state); - }); - }); + }) + expect(outputSelector(rootState)).toEqual(state) + }) + }) describe('sendCliCommand', () => { it('should properly set loading = true', () => { @@ -85,20 +85,20 @@ describe('cliOutput slice', () => { const state = { ...initialState, loading: true, - }; + } // Act - const nextState = reducer(initialState, sendCliCommand()); + const nextState = reducer(initialState, sendCliCommand()) // Assert const rootState = Object.assign(initialStateDefault, { cli: { output: nextState, }, - }); - expect(outputSelector(rootState)).toEqual(state); - }); - }); + }) + expect(outputSelector(rootState)).toEqual(state) + }) + }) describe('sendCliCommandSuccess', () => { it('should properly set the state with fetched data', () => { @@ -107,69 +107,69 @@ describe('cliOutput slice', () => { const state = { ...initialState, loading: false, - }; + } // Act - const nextState = reducer(initialState, sendCliCommandSuccess()); + const nextState = reducer(initialState, sendCliCommandSuccess()) // Assert const rootState = Object.assign(initialStateDefault, { cli: { output: nextState, }, - }); - expect(outputSelector(rootState)).toEqual(state); - }); - }); + }) + expect(outputSelector(rootState)).toEqual(state) + }) + }) describe('sendCliCommandFailure', () => { it('should properly set the error', () => { // Arrange - const data = 'some error'; + const data = 'some error' const state = { ...initialState, loading: false, error: data, - }; + } // Act - const nextState = reducer(initialState, sendCliCommandFailure(data)); + const nextState = reducer(initialState, sendCliCommandFailure(data)) // Assert const rootState = Object.assign(initialStateDefault, { cli: { output: nextState, }, - }); - expect(outputSelector(rootState)).toEqual(state); - }); - }); + }) + expect(outputSelector(rootState)).toEqual(state) + }) + }) describe('processUnsupportedCommand', () => { it('should properly concat to output "unsupported text"', async () => { // Arrange - const onSuccessActionMock = jest.fn(); - const unsupportedCommands: string[] = ['sync', 'subscription']; - const command = first(unsupportedCommands) ?? ''; + const onSuccessActionMock = jest.fn() + const unsupportedCommands: string[] = ['sync', 'subscription'] + const command = first(unsupportedCommands) ?? '' const nextState = { ...initialStateDefault.cli.settings, unsupportedCommands, - }; + } // Assert const rootState = Object.assign(initialStateDefault, { cli: { settings: nextState, }, - }); + }) - const tempStore = mockStore(rootState); + const tempStore = mockStore(rootState) // Act await tempStore.dispatch( processUnsupportedCommand(command, first(unsupportedCommands), onSuccessActionMock) - ); + ) // Assert const expectedActions = [ @@ -180,28 +180,28 @@ describe('cliOutput slice', () => { CommandExecutionStatus.Fail ) ), - ]; + ] - expect(onSuccessActionMock).toBeCalled(); - expect(clearStoreActions(tempStore.getActions())).toEqual(clearStoreActions(expectedActions)); - }); - }); + expect(onSuccessActionMock).toBeCalled() + expect(clearStoreActions(tempStore.getActions())).toEqual(clearStoreActions(expectedActions)) + }) + }) describe('thunks', () => { describe('Standalone Cli command', () => { it('call both sendCliStandaloneCommandAction and sendCliCommandSuccess when response status is successed', async () => { // Arrange - const command = 'keys *'; + const command = 'keys *' const data = { response: 'tatata', status: CommandExecutionStatus.Success, - }; - const responsePayload = { data, status: 200 }; + } + const responsePayload = { data, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(sendCliCommandAction(command)); + await store.dispatch(sendCliCommandAction(command)) // Assert const expectedActions = [ @@ -209,23 +209,23 @@ describe('cliOutput slice', () => { sendCliCommand(), sendCliCommandSuccess(), concatToOutput(cliParseTextResponseWithOffset(data.response, data.status)), - ]; - expect(clearStoreActions(store.getActions())).toEqual(clearStoreActions(expectedActions)); - }); + ] + expect(clearStoreActions(store.getActions())).toEqual(clearStoreActions(expectedActions)) + }) it('call both sendCliStandaloneCommandAction and sendCliCommandSuccess when response status is fail', async () => { // Arrange - const command = 'keys *'; + const command = 'keys *' const data = { response: '(err) tatata', status: CommandExecutionStatus.Fail, - }; - const responsePayload = { data, status: 200 }; + } + const responsePayload = { data, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(sendCliCommandAction(command)); + await store.dispatch(sendCliCommandAction(command)) // Assert const expectedActions = [ @@ -233,26 +233,26 @@ describe('cliOutput slice', () => { sendCliCommand(), sendCliCommandSuccess(), concatToOutput(cliParseTextResponseWithOffset(data.response, data.status)), - ]; + ] - expect(clearStoreActions(store.getActions())).toEqual(clearStoreActions(expectedActions)); - }); + expect(clearStoreActions(store.getActions())).toEqual(clearStoreActions(expectedActions)) + }) it('call both sendCliStandaloneCommandAction and sendCliCommandFailure when fetch is fail', async () => { // Arrange - const command = 'keys *'; - const errorMessage = 'Could not connect to aoeu:123, please check the connection details.'; + const command = 'keys *' + const errorMessage = 'Could not connect to aoeu:123, please check the connection details.' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; + } - apiService.post = jest.fn().mockRejectedValueOnce(responsePayload); + apiService.post = jest.fn().mockRejectedValueOnce(responsePayload) // Act - await store.dispatch(sendCliCommandAction(command)); + await store.dispatch(sendCliCommandAction(command)) // Assert const expectedActions = [ @@ -260,10 +260,10 @@ describe('cliOutput slice', () => { sendCliCommand(), sendCliCommandFailure(responsePayload.response.data.message), concatToOutput(cliParseTextResponseWithOffset(errorMessage, CommandExecutionStatus.Fail)), - ]; - expect(clearStoreActions(store.getActions())).toEqual(clearStoreActions(expectedActions)); - }); - }); + ] + expect(clearStoreActions(store.getActions())).toEqual(clearStoreActions(expectedActions)) + }) + }) describe('Single Node Cluster Cli command', () => { const options: SendClusterCommandDto = { @@ -274,24 +274,24 @@ describe('cliOutput slice', () => { enableRedirection: true, }, role: ClusterNodeRole.All, - }; + } it('call both sendCliClusterCommandAction and sendCliCommandSuccess when response status is successed', async () => { // Arrange - const command = 'keys *'; + const command = 'keys *' const data: SendClusterCommandResponse[] = [ { response: '-> Redirected to slot [6918] located at 127.0.0.1:7002\n(nil)', status: 'success', node: { host: '127.0.0.1', port: 7002 }, }, - ]; - const responsePayload = { data, status: 200 }; + ] + const responsePayload = { data, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(sendCliClusterCommandAction(command, options)); + await store.dispatch(sendCliClusterCommandAction(command, options)) // Assert const expectedActions = [ @@ -301,26 +301,26 @@ describe('cliOutput slice', () => { concatToOutput( cliParseTextResponseWithOffset(first(data)?.response, first(data)?.status) ), - ]; - expect(clearStoreActions(store.getActions())).toEqual(clearStoreActions(expectedActions)); - }); + ] + expect(clearStoreActions(store.getActions())).toEqual(clearStoreActions(expectedActions)) + }) it('call both sendCliClusterCommandAction and sendCliCommandSuccess when response status is fail', async () => { // Arrange - const command = 'keys *'; + const command = 'keys *' const data: SendClusterCommandResponse[] = [ { response: '-> Redirected to slot [6918] located at 127.0.0.1:7002\n(nil)', status: 'success', node: { host: '127.0.0.1', port: 7002 }, }, - ]; - const responsePayload = { data, status: 200 }; + ] + const responsePayload = { data, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(sendCliClusterCommandAction(command, options)); + await store.dispatch(sendCliClusterCommandAction(command, options)) // Assert const expectedActions = [ @@ -330,25 +330,25 @@ describe('cliOutput slice', () => { concatToOutput( cliParseTextResponseWithOffset(first(data)?.response, first(data)?.status) ), - ]; - expect(clearStoreActions(store.getActions())).toEqual(clearStoreActions(expectedActions)); - }); + ] + expect(clearStoreActions(store.getActions())).toEqual(clearStoreActions(expectedActions)) + }) it('call both sendCliClusterCommandAction and sendCliCommandFailure when fetch is fail', async () => { // Arrange - const command = 'keys *'; - const errorMessage = 'Could not connect to aoeu:123, please check the connection details.'; + const command = 'keys *' + const errorMessage = 'Could not connect to aoeu:123, please check the connection details.' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; + } - apiService.post = jest.fn().mockRejectedValueOnce(responsePayload); + apiService.post = jest.fn().mockRejectedValueOnce(responsePayload) // Act - await store.dispatch(sendCliClusterCommandAction(command, options)); + await store.dispatch(sendCliClusterCommandAction(command, options)) // Assert const expectedActions = [ @@ -356,9 +356,9 @@ describe('cliOutput slice', () => { sendCliCommand(), sendCliCommandFailure(responsePayload.response.data.message), concatToOutput(cliParseTextResponseWithOffset(errorMessage, CommandExecutionStatus.Fail)), - ]; - expect(clearStoreActions(store.getActions())).toEqual(clearStoreActions(expectedActions)); - }); - }); - }); -}); + ] + expect(clearStoreActions(store.getActions())).toEqual(clearStoreActions(expectedActions)) + }) + }) + }) +}) diff --git a/redisinsight/ui/src/slices/tests/cli/cli-settings.spec.ts b/redisinsight/ui/src/slices/tests/cli/cli-settings.spec.ts index ff20165d5b..404095a7a7 100644 --- a/redisinsight/ui/src/slices/tests/cli/cli-settings.spec.ts +++ b/redisinsight/ui/src/slices/tests/cli/cli-settings.spec.ts @@ -1,7 +1,7 @@ -import { cloneDeep } from 'lodash'; -import { BrowserStorageItem } from 'uiSrc/constants'; -import { apiService, localStorageService } from 'uiSrc/services'; -import { cleanup, mockedStore, initialStateDefault } from 'uiSrc/utils/test-utils'; +import { cloneDeep } from 'lodash' +import { BrowserStorageItem } from 'uiSrc/constants' +import { apiService, localStorageService } from 'uiSrc/services' +import { cleanup, mockedStore, initialStateDefault } from 'uiSrc/utils/test-utils' import reducer, { initialState, toggleCli, @@ -23,24 +23,22 @@ import reducer, { setSearchingCommandFilter, setSearchingCommand, clearSearchingCommand, -} from '../../cli/cli-settings'; +} from '../../cli/cli-settings' -let store: typeof mockedStore; +let store: typeof mockedStore beforeEach(() => { - cleanup(); - store = cloneDeep(mockedStore); - store.clearActions(); -}); - -jest.mock('uiSrc/services', () => { - return { - ...jest.requireActual('uiSrc/services'), - localStorageService: { - set: jest.fn(), - get: jest.fn(), - }, - }; -}); + cleanup() + store = cloneDeep(mockedStore) + store.clearActions() +}) + +jest.mock('uiSrc/services', () => ({ + ...jest.requireActual('uiSrc/services'), + localStorageService: { + set: jest.fn(), + get: jest.fn(), + }, +})) describe('cliSettings slice', () => { describe('toggleCliHelper', () => { @@ -49,47 +47,47 @@ describe('cliSettings slice', () => { const state: typeof initialState = { ...initialState, isShowHelper: true, - }; + } - expect(cliSettingsSelector(initialStateDefault)).toEqual(state); - }); + expect(cliSettingsSelector(initialStateDefault)).toEqual(state) + }) it('should properly set !isShowHelper', () => { // Arrange const state: typeof initialState = { ...initialState, isShowHelper: false, - }; + } // Act - const nextState = reducer(initialState, toggleCliHelper()); + const nextState = reducer(initialState, toggleCliHelper()) // Assert const rootState = Object.assign(initialStateDefault, { cli: { settings: nextState, }, - }); - expect(cliSettingsSelector(rootState)).toEqual(state); - }); + }) + expect(cliSettingsSelector(rootState)).toEqual(state) + }) it('should properly set to localStorageService', () => { // Arrange - localStorageService.set = jest.fn(); + localStorageService.set = jest.fn() const state: typeof initialState = { ...initialState, isShowHelper: false, - }; + } // Act - reducer(initialState, toggleCliHelper()); + reducer(initialState, toggleCliHelper()) expect(localStorageService.set).toBeCalledWith( BrowserStorageItem.cliIsShowHelper, state.isShowHelper - ); - }); - }); + ) + }) + }) describe('toggleCli', () => { it('should properly set !isShowCli', () => { @@ -97,42 +95,42 @@ describe('cliSettings slice', () => { const state: typeof initialState = { ...initialState, isShowCli: true, - }; + } // Act - const nextState = reducer(initialState, toggleCli()); + const nextState = reducer(initialState, toggleCli()) // Assert const rootState = Object.assign(initialStateDefault, { cli: { settings: nextState, }, - }); - expect(cliSettingsSelector(rootState)).toEqual(state); - }); - }); + }) + expect(cliSettingsSelector(rootState)).toEqual(state) + }) + }) describe('setMatchedCommand', () => { it('should properly set !isShowCli', () => { // Arrange - const matchedCommand = 'get'; + const matchedCommand = 'get' const state: typeof initialState = { ...initialState, matchedCommand, - }; + } // Act - const nextState = reducer(initialState, setMatchedCommand(matchedCommand)); + const nextState = reducer(initialState, setMatchedCommand(matchedCommand)) // Assert const rootState = Object.assign(initialStateDefault, { cli: { settings: nextState, }, - }); - expect(cliSettingsSelector(rootState)).toEqual(state); - }); - }); + }) + expect(cliSettingsSelector(rootState)).toEqual(state) + }) + }) describe('setCliEnteringCommand', () => { it('should properly set !isShowCli', () => { @@ -140,91 +138,91 @@ describe('cliSettings slice', () => { const state: typeof initialState = { ...initialState, isEnteringCommand: true, - }; + } // Act - const nextState = reducer(initialState, setCliEnteringCommand()); + const nextState = reducer(initialState, setCliEnteringCommand()) // Assert const rootState = Object.assign(initialStateDefault, { cli: { settings: nextState, }, - }); - expect(cliSettingsSelector(rootState)).toEqual(state); - }); - }); + }) + expect(cliSettingsSelector(rootState)).toEqual(state) + }) + }) describe('setSearchedCommand', () => { it('should properly set searched command', () => { // Arrange - const searchedCommand = 'SET'; + const searchedCommand = 'SET' const state: typeof initialState = { ...initialState, searchedCommand, isSearching: false - }; + } // Act - const nextState = reducer(initialState, setSearchedCommand(searchedCommand)); + const nextState = reducer(initialState, setSearchedCommand(searchedCommand)) // Assert const rootState = Object.assign(initialStateDefault, { cli: { settings: nextState, }, - }); - expect(cliSettingsSelector(rootState)).toEqual(state); - }); - }); + }) + expect(cliSettingsSelector(rootState)).toEqual(state) + }) + }) describe('setSearchingCommand', () => { it('should properly set searching command', () => { // Arrange - const searchingCommand = 'se'; + const searchingCommand = 'se' const state: typeof initialState = { ...initialState, searchingCommand, isEnteringCommand: false, isSearching: true - }; + } // Act - const nextState = reducer(initialState, setSearchingCommand(searchingCommand)); + const nextState = reducer(initialState, setSearchingCommand(searchingCommand)) // Assert const rootState = Object.assign(initialStateDefault, { cli: { settings: nextState, }, - }); - expect(cliSettingsSelector(rootState)).toEqual(state); - }); - }); + }) + expect(cliSettingsSelector(rootState)).toEqual(state) + }) + }) describe('setSearchingCommandFilter', () => { it('should properly set searching command filter', () => { // Arrange - const searchingCommandFilter = 'server'; + const searchingCommandFilter = 'server' const state: typeof initialState = { ...initialState, searchingCommandFilter, isEnteringCommand: false, isSearching: true - }; + } // Act - const nextState = reducer(initialState, setSearchingCommandFilter(searchingCommandFilter)); + const nextState = reducer(initialState, setSearchingCommandFilter(searchingCommandFilter)) // Assert const rootState = Object.assign(initialStateDefault, { cli: { settings: nextState, }, - }); - expect(cliSettingsSelector(rootState)).toEqual(state); - }); - }); + }) + expect(cliSettingsSelector(rootState)).toEqual(state) + }) + }) describe('clearSearchingCommand', () => { it('should properly clear search', () => { @@ -235,20 +233,20 @@ describe('cliSettings slice', () => { searchedCommand: '', searchingCommandFilter: '', isSearching: false - }; + } // Act - const nextState = reducer(initialState, clearSearchingCommand()); + const nextState = reducer(initialState, clearSearchingCommand()) // Assert const rootState = Object.assign(initialStateDefault, { cli: { settings: nextState, }, - }); - expect(cliSettingsSelector(rootState)).toEqual(state); - }); - }); + }) + expect(cliSettingsSelector(rootState)).toEqual(state) + }) + }) describe('resetIsShowCli', () => { it('should properly set isShowCli = false', () => { @@ -256,20 +254,20 @@ describe('cliSettings slice', () => { const state: typeof initialState = { ...initialState, isShowCli: false, - }; + } // Act - const nextState = reducer(initialState, resetIsShowCli()); + const nextState = reducer(initialState, resetIsShowCli()) // Assert const rootState = Object.assign(initialStateDefault, { cli: { settings: nextState, }, - }); - expect(cliSettingsSelector(rootState)).toEqual(state); - }); - }); + }) + expect(cliSettingsSelector(rootState)).toEqual(state) + }) + }) describe('processCliClient', () => { it('should properly set loading = true', () => { @@ -277,251 +275,251 @@ describe('cliSettings slice', () => { const state = { ...initialState, loading: true, - }; + } // Act - const nextState = reducer(initialState, processCliClient()); + const nextState = reducer(initialState, processCliClient()) // Assert const rootState = Object.assign(initialStateDefault, { cli: { settings: nextState, }, - }); - expect(cliSettingsSelector(rootState)).toEqual(state); - }); - }); + }) + expect(cliSettingsSelector(rootState)).toEqual(state) + }) + }) describe('processCliClientSuccess', () => { it('should properly set the state with fetched data', () => { // Arrange - const data = { uuid: '70b95d32-c19d-4311-bb24-e684af12cf15' }; + const data = { uuid: '70b95d32-c19d-4311-bb24-e684af12cf15' } const state = { ...initialState, loading: false, cliClientUuid: data.uuid, - }; + } // Act - const nextState = reducer(initialState, processCliClientSuccess(data?.uuid)); + const nextState = reducer(initialState, processCliClientSuccess(data?.uuid)) // Assert const rootState = Object.assign(initialStateDefault, { cli: { settings: nextState, }, - }); - expect(cliSettingsSelector(rootState)).toEqual(state); - }); + }) + expect(cliSettingsSelector(rootState)).toEqual(state) + }) it('should properly set the state with empty data', () => { // Arrange - const data = { uuid: '' }; + const data = { uuid: '' } const state = { ...initialState, loading: false, cliClientUuid: data.uuid, - }; + } // Act - const nextState = reducer(initialState, processCliClientSuccess(data?.uuid)); + const nextState = reducer(initialState, processCliClientSuccess(data?.uuid)) // Assert const rootState = Object.assign(initialStateDefault, { cli: { settings: nextState, }, - }); - expect(cliSettingsSelector(rootState)).toEqual(state); - }); - }); + }) + expect(cliSettingsSelector(rootState)).toEqual(state) + }) + }) describe('processCliClientFailure', () => { it('should properly set the error', () => { // Arrange - const data = 'some error'; + const data = 'some error' const state = { ...initialState, loading: false, errorClient: data, - }; + } // Act - const nextState = reducer(initialState, processCliClientFailure(data)); + const nextState = reducer(initialState, processCliClientFailure(data)) // Assert const rootState = Object.assign(initialStateDefault, { cli: { settings: nextState, }, - }); - expect(cliSettingsSelector(rootState)).toEqual(state); - }); - }); + }) + expect(cliSettingsSelector(rootState)).toEqual(state) + }) + }) describe('getUnsupportedCommandsSuccess', () => { it('should properly set unsupportedCommands', () => { // Arrange - const data = ['sync', 'subscribe']; + const data = ['sync', 'subscribe'] const state = { ...initialState, loading: false, unsupportedCommands: data, - }; + } // Act - const nextState = reducer(initialState, getUnsupportedCommandsSuccess(data)); + const nextState = reducer(initialState, getUnsupportedCommandsSuccess(data)) // Assert const rootState = Object.assign(initialStateDefault, { cli: { settings: nextState, }, - }); - expect(cliSettingsSelector(rootState)).toEqual(state); - }); - }); + }) + expect(cliSettingsSelector(rootState)).toEqual(state) + }) + }) describe('thunks', () => { it('call both createCliClientAction and processCliClientSuccess when fetch is successed', async () => { // Arrange - const data = { uuid: '70b95d32-c19d-4311-bb24-e684af12cf15' }; - const responsePayload = { data, status: 200 }; + const data = { uuid: '70b95d32-c19d-4311-bb24-e684af12cf15' } + const responsePayload = { data, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(createCliClientAction()); + await store.dispatch(createCliClientAction()) // Assert const expectedActions = [ processCliClient(), processCliClientSuccess(responsePayload.data?.uuid), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) it('call both createCliClientAction and processCliClientFailure when fetch is fail', async () => { // Arrange - const errorMessage = 'Could not connect to aoeu:123, please check the connection details.'; + const errorMessage = 'Could not connect to aoeu:123, please check the connection details.' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; + } - apiService.post = jest.fn().mockRejectedValueOnce(responsePayload); + apiService.post = jest.fn().mockRejectedValueOnce(responsePayload) // Act - await store.dispatch(createCliClientAction()); + await store.dispatch(createCliClientAction()) // Assert const expectedActions = [ processCliClient(), processCliClientFailure(responsePayload.response.data.message), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) it('call both updateCliClientAction and processCliClientSuccess when fetch is successed', async () => { // Arrange - const uuid = '70b95d32-c19d-4311-bb24-e684af12cf15'; - const data = { uuid }; - const responsePayload = { data, status: 200 }; + const uuid = '70b95d32-c19d-4311-bb24-e684af12cf15' + const data = { uuid } + const responsePayload = { data, status: 200 } - apiService.patch = jest.fn().mockResolvedValue(responsePayload); + apiService.patch = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(updateCliClientAction(uuid)); + await store.dispatch(updateCliClientAction(uuid)) // Assert const expectedActions = [ processCliClient(), processCliClientSuccess(responsePayload.data?.uuid), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) it('call both updateCliClientAction and processCliClientFailure when fetch is fail', async () => { // Arrange - const uuid = '70b95d32-c19d-4311-bb24-e684af12cf15'; - const errorMessage = 'Could not connect to aoeu:123, please check the connection details.'; + const uuid = '70b95d32-c19d-4311-bb24-e684af12cf15' + const errorMessage = 'Could not connect to aoeu:123, please check the connection details.' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; + } - apiService.patch = jest.fn().mockRejectedValueOnce(responsePayload); + apiService.patch = jest.fn().mockRejectedValueOnce(responsePayload) // Act - await store.dispatch(updateCliClientAction(uuid)); + await store.dispatch(updateCliClientAction(uuid)) // Assert const expectedActions = [ processCliClient(), processCliClientFailure(responsePayload.response.data.message), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) it('call both deleteCliClientAction and deleteCliClientSuccess when fetch is successed', async () => { // Arrange - const uuid = '70b95d32-c19d-4311-bb24-e684af12cf15'; - const data = { uuid }; - const responsePayload = { data, status: 200 }; + const uuid = '70b95d32-c19d-4311-bb24-e684af12cf15' + const data = { uuid } + const responsePayload = { data, status: 200 } - apiService.delete = jest.fn().mockResolvedValue(responsePayload); + apiService.delete = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(deleteCliClientAction(uuid)); + await store.dispatch(deleteCliClientAction(uuid)) // Assert - const expectedActions = [processCliClient(), deleteCliClientSuccess()]; - expect(store.getActions()).toEqual(expectedActions); - }); + const expectedActions = [processCliClient(), deleteCliClientSuccess()] + expect(store.getActions()).toEqual(expectedActions) + }) it('call both deleteCliClientAction and processCliClientFailure when fetch is fail', async () => { // Arrange - const uuid = '70b95d32-c19d-4311-bb24-e684af12cf15'; - const errorMessage = 'Could not connect to aoeu:123, please check the connection details.'; + const uuid = '70b95d32-c19d-4311-bb24-e684af12cf15' + const errorMessage = 'Could not connect to aoeu:123, please check the connection details.' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; + } - apiService.delete = jest.fn().mockRejectedValueOnce(responsePayload); + apiService.delete = jest.fn().mockRejectedValueOnce(responsePayload) // Act - await store.dispatch(deleteCliClientAction(uuid)); + await store.dispatch(deleteCliClientAction(uuid)) // Assert const expectedActions = [ processCliClient(), processCliClientFailure(responsePayload.response.data.message), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) it('call both fetchUnsupportedCliCommandsAction and getUnsupportedCommandsSuccess when fetch is successed', async () => { // Arrange - const data = ['sync', 'subscribe']; - const responsePayload = { data, status: 200 }; + const data = ['sync', 'subscribe'] + const responsePayload = { data, status: 200 } - apiService.get = jest.fn().mockResolvedValue(responsePayload); + apiService.get = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(fetchUnsupportedCliCommandsAction()); + await store.dispatch(fetchUnsupportedCliCommandsAction()) // Assert - const expectedActions = [processCliClient(), getUnsupportedCommandsSuccess(data)]; - expect(store.getActions()).toEqual(expectedActions); - }); - }); -}); + const expectedActions = [processCliClient(), getUnsupportedCommandsSuccess(data)] + expect(store.getActions()).toEqual(expectedActions) + }) + }) +}) diff --git a/redisinsight/ui/src/slices/tests/clientCerts.spec.ts b/redisinsight/ui/src/slices/tests/clientCerts.spec.ts index a2ca3243c1..e58624271f 100644 --- a/redisinsight/ui/src/slices/tests/clientCerts.spec.ts +++ b/redisinsight/ui/src/slices/tests/clientCerts.spec.ts @@ -1,6 +1,6 @@ -import { cloneDeep } from 'lodash'; -import { apiService } from 'uiSrc/services'; -import { initialStateDefault, mockedStore } from 'uiSrc/utils/test-utils'; +import { cloneDeep } from 'lodash' +import { apiService } from 'uiSrc/services' +import { initialStateDefault, mockedStore } from 'uiSrc/utils/test-utils' import reducer, { initialState, loadClientCerts, @@ -8,23 +8,23 @@ import reducer, { loadClientCertsFailure, clientCertsSelector, fetchClientCerts, -} from '../clientCerts'; +} from '../clientCerts' -jest.mock('uiSrc/services'); +jest.mock('uiSrc/services') describe('clientCerts slice', () => { describe('reducer, actions and selectors', () => { it('should return the initial state on first run', () => { // Arrange - const nextState = initialState; + const nextState = initialState // Act - const result = reducer(undefined, {}); + const result = reducer(undefined, {}) // Assert - expect(result).toEqual(nextState); - }); - }); + expect(result).toEqual(nextState) + }) + }) describe('loadClientCerts', () => { it('should properly set the state before the fetch data', () => { @@ -32,20 +32,20 @@ describe('clientCerts slice', () => { const state = { ...initialState, loading: true, - }; + } // Act - const nextState = reducer(initialState, loadClientCerts()); + const nextState = reducer(initialState, loadClientCerts()) // Assert const rootState = Object.assign(initialStateDefault, { connections: { clientCerts: nextState, }, - }); - expect(clientCertsSelector(rootState)).toEqual(state); - }); - }); + }) + expect(clientCertsSelector(rootState)).toEqual(state) + }) + }) describe('loadClientCertsSuccess', () => { it('should properly set the state with fetched data', () => { @@ -53,92 +53,92 @@ describe('clientCerts slice', () => { const data = [ { id: '70b95d32-c19d-4311-bb24-e684af12cf15', name: 'client cert' }, - ]; + ] const state = { ...initialState, loading: false, data, - }; + } // Act - const nextState = reducer(initialState, loadClientCertsSuccess(data)); + const nextState = reducer(initialState, loadClientCertsSuccess(data)) // Assert const rootState = Object.assign(initialStateDefault, { connections: { clientCerts: nextState, }, - }); - expect(clientCertsSelector(rootState)).toEqual(state); - }); + }) + expect(clientCertsSelector(rootState)).toEqual(state) + }) it('should properly set the state with empty data', () => { // Arrange - const data: any = []; + const data: any = [] const state = { ...initialState, loading: false, data, - }; + } // Act - const nextState = reducer(initialState, loadClientCertsSuccess(data)); + const nextState = reducer(initialState, loadClientCertsSuccess(data)) // Assert const rootState = Object.assign(initialStateDefault, { connections: { clientCerts: nextState, }, - }); - expect(clientCertsSelector(rootState)).toEqual(state); - }); - }); + }) + expect(clientCertsSelector(rootState)).toEqual(state) + }) + }) describe('loadClientCertsFailure', () => { it('should properly set the error', () => { // Arrange - const data = 'some error'; + const data = 'some error' const state = { ...initialState, loading: false, error: data, data: [], - }; + } // Act - const nextState = reducer(initialState, loadClientCertsFailure(data)); + const nextState = reducer(initialState, loadClientCertsFailure(data)) // Assert const rootState = Object.assign(initialStateDefault, { connections: { clientCerts: nextState, }, - }); - expect(clientCertsSelector(rootState)).toEqual(state); - }); - }); + }) + expect(clientCertsSelector(rootState)).toEqual(state) + }) + }) describe('thunks', () => { it('call both fetchClientCerts and loadClientCertsSuccess when fetch is successed', async () => { // Arrange const data = [ { id: '70b95d32-c19d-4311-bb24-e684af12cf15', name: 'ca cert' }, - ]; - const responsePayload = { data, status: 200 }; + ] + const responsePayload = { data, status: 200 } - apiService.get = jest.fn().mockResolvedValue(responsePayload); - const store = cloneDeep(mockedStore); + apiService.get = jest.fn().mockResolvedValue(responsePayload) + const store = cloneDeep(mockedStore) // Act - await store.dispatch(fetchClientCerts()); + await store.dispatch(fetchClientCerts()) // Assert const expectedActions = [ loadClientCerts(), loadClientCertsSuccess(responsePayload.data), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); - }); -}); + ] + expect(store.getActions()).toEqual(expectedActions) + }) + }) +}) diff --git a/redisinsight/ui/src/slices/tests/cloud.spec.ts b/redisinsight/ui/src/slices/tests/cloud.spec.ts index e824a34f39..6fa8ec9f76 100644 --- a/redisinsight/ui/src/slices/tests/cloud.spec.ts +++ b/redisinsight/ui/src/slices/tests/cloud.spec.ts @@ -1,15 +1,15 @@ -import { AxiosError } from 'axios'; -import { cloneDeep } from 'lodash'; -import { apiService } from 'uiSrc/services'; +import { AxiosError } from 'axios' +import { cloneDeep } from 'lodash' +import { apiService } from 'uiSrc/services' import { cleanup, initialStateDefault, mockedStore, -} from 'uiSrc/utils/test-utils'; +} from 'uiSrc/utils/test-utils' import { GetCloudAccountShortInfoResponse, RedisCloudDatabase, -} from 'apiSrc/modules/redis-enterprise/dto/cloud.dto'; +} from 'apiSrc/modules/redis-enterprise/dto/cloud.dto' import reducer, { loadSubscriptionsRedisCloud, initialState, @@ -29,26 +29,26 @@ import reducer, { createInstancesRedisCloudFailure, createInstancesRedisCloud, createInstancesRedisCloudSuccess, -} from '../cloud'; -import { LoadedCloud } from '../interfaces'; -import { addErrorNotification } from '../app/notifications'; +} from '../cloud' +import { LoadedCloud } from '../interfaces' +import { addErrorNotification } from '../app/notifications' -jest.mock('uiSrc/services'); +jest.mock('uiSrc/services') -let store: typeof mockedStore; -let account: GetCloudAccountShortInfoResponse; -let instances: RedisCloudDatabase[]; +let store: typeof mockedStore +let account: GetCloudAccountShortInfoResponse +let instances: RedisCloudDatabase[] beforeEach(() => { - cleanup(); - store = cloneDeep(mockedStore); - store.clearActions(); + cleanup() + store = cloneDeep(mockedStore) + store.clearActions() account = { accountId: 40131, accountName: 'Redis Labs', ownerName: 'Danny Cohen', ownerEmail: 'danny.cohen@redis.com', - }; + } instances = [ { @@ -71,22 +71,22 @@ beforeEach(() => { isReplicaSource: false, }, }, - ]; -}); + ] +}) describe('cloud slice', () => { describe('reducer, actions and selectors', () => { it('should return the initial state on first run', () => { // Arrange - const nextState = initialState; + const nextState = initialState // Act - const result = reducer(undefined, {}); + const result = reducer(undefined, {}) // Assert - expect(result).toEqual(nextState); - }); - }); + expect(result).toEqual(nextState) + }) + }) describe('loadSubscriptionsRedisCloud', () => { it('should properly set the state before the fetch data', () => { @@ -94,20 +94,20 @@ describe('cloud slice', () => { const state = { ...initialState, loading: true, - }; + } // Act - const nextState = reducer(initialState, loadSubscriptionsRedisCloud()); + const nextState = reducer(initialState, loadSubscriptionsRedisCloud()) // Assert const rootState = Object.assign(initialStateDefault, { connections: { cloud: nextState, }, - }); - expect(cloudSelector(rootState)).toEqual(state); - }); - }); + }) + expect(cloudSelector(rootState)).toEqual(state) + }) + }) describe('loadSubscriptionsRedisCloudSuccess', () => { it('should properly set the state with fetched subscriptions', () => { @@ -120,12 +120,12 @@ describe('cloud slice', () => { numberOfDatabases: 1, status: 'active', }, - ]; + ] const credentials = { accessKey: '123', secretKey: '123', - }; + } const state = { ...initialState, loading: false, @@ -136,31 +136,31 @@ describe('cloud slice', () => { }, subscriptions: data, credentials, - }; + } // Act const nextState = reducer( initialState, loadSubscriptionsRedisCloudSuccess({ data, credentials }) - ); + ) // Assert const rootState = Object.assign(initialStateDefault, { connections: { cloud: nextState, }, - }); - expect(cloudSelector(rootState)).toEqual(state); - }); + }) + expect(cloudSelector(rootState)).toEqual(state) + }) it('should properly set the state with empty data', () => { // Arrange - const data: any[] = []; + const data: any[] = [] const credentials = { accessKey: '123', secretKey: '123', - }; + } const state = { ...initialState, loading: false, @@ -171,49 +171,49 @@ describe('cloud slice', () => { }, subscriptions: data, credentials, - }; + } // Act const nextState = reducer( initialState, loadSubscriptionsRedisCloudSuccess({ data, credentials }) - ); + ) // Assert const rootState = Object.assign(initialStateDefault, { connections: { cloud: nextState, }, - }); - expect(cloudSelector(rootState)).toEqual(state); - }); - }); + }) + expect(cloudSelector(rootState)).toEqual(state) + }) + }) describe('loadSubscriptionsRedisCloudFailure', () => { it('should properly set the error', () => { // Arrange - const data = 'some error'; + const data = 'some error' const state = { ...initialState, loading: false, error: data, - }; + } // Act const nextState = reducer( initialState, loadSubscriptionsRedisCloudFailure(data) - ); + ) // Assert const rootState = Object.assign(initialStateDefault, { connections: { cloud: nextState, }, - }); - expect(cloudSelector(rootState)).toEqual(state); - }); - }); + }) + expect(cloudSelector(rootState)).toEqual(state) + }) + }) describe('loadAccountRedisCloud', () => { it('should properly set the state before the fetch data', () => { @@ -221,20 +221,20 @@ describe('cloud slice', () => { const state = { ...initialState, loading: true, - }; + } // Act - const nextState = reducer(initialState, loadAccountRedisCloud()); + const nextState = reducer(initialState, loadAccountRedisCloud()) // Assert const rootState = Object.assign(initialStateDefault, { connections: { cloud: nextState, }, - }); - expect(cloudSelector(rootState)).toEqual(state); - }); - }); + }) + expect(cloudSelector(rootState)).toEqual(state) + }) + }) describe('loadAccountRedisCloudSuccess', () => { it('should properly set the state with fetched subscriptions', () => { @@ -245,7 +245,7 @@ describe('cloud slice', () => { accountName: 'Redis Labs', ownerName: 'Danny Cohen', ownerEmail: 'danny.cohen@redis.com', - }; + } const state = { ...initialState, @@ -255,31 +255,31 @@ describe('cloud slice', () => { data, error: '', }, - }; + } // Act const nextState = reducer( initialState, loadAccountRedisCloudSuccess({ data }) - ); + ) // Assert const rootState = Object.assign(initialStateDefault, { connections: { cloud: nextState, }, - }); - expect(cloudSelector(rootState)).toEqual(state); - }); + }) + expect(cloudSelector(rootState)).toEqual(state) + }) it('should properly set the state with empty data', () => { // Arrange - const data: any = {}; + const data: any = {} const credentials = { accessKey: '123', secretKey: '123', - }; + } const state = { ...initialState, loading: false, @@ -287,28 +287,28 @@ describe('cloud slice', () => { data, error: '', }, - }; + } // Act const nextState = reducer( initialState, loadAccountRedisCloudSuccess({ data, credentials }) - ); + ) // Assert const rootState = Object.assign(initialStateDefault, { connections: { cloud: nextState, }, - }); - expect(cloudSelector(rootState)).toEqual(state); - }); - }); + }) + expect(cloudSelector(rootState)).toEqual(state) + }) + }) describe('loadAccountRedisCloudFailure', () => { it('should properly set the error', () => { // Arrange - const data = 'some error'; + const data = 'some error' const state = { ...initialState, loading: false, @@ -316,23 +316,23 @@ describe('cloud slice', () => { data: null, error: data, }, - }; + } // Act const nextState = reducer( initialState, loadAccountRedisCloudFailure(data) - ); + ) // Assert const rootState = Object.assign(initialStateDefault, { connections: { cloud: nextState, }, - }); - expect(cloudSelector(rootState)).toEqual(state); - }); - }); + }) + expect(cloudSelector(rootState)).toEqual(state) + }) + }) describe('loadInstancesRedisCloud', () => { it('should properly set the state before the fetch data', () => { @@ -340,20 +340,20 @@ describe('cloud slice', () => { const state = { ...initialState, loading: true, - }; + } // Act - const nextState = reducer(initialState, loadInstancesRedisCloud()); + const nextState = reducer(initialState, loadInstancesRedisCloud()) // Assert const rootState = Object.assign(initialStateDefault, { connections: { cloud: nextState, }, - }); - expect(cloudSelector(rootState)).toEqual(state); - }); - }); + }) + expect(cloudSelector(rootState)).toEqual(state) + }) + }) describe('loadInstancesRedisCloudSuccess', () => { it('should properly set the state with fetched instances', () => { @@ -367,26 +367,26 @@ describe('cloud slice', () => { ...initialState.loaded, [LoadedCloud.Instances]: true, }, - }; + } // Act const nextState = reducer( initialState, loadInstancesRedisCloudSuccess({ instances }) - ); + ) // Assert const rootState = Object.assign(initialStateDefault, { connections: { cloud: nextState, }, - }); - expect(cloudSelector(rootState)).toEqual(state); - }); + }) + expect(cloudSelector(rootState)).toEqual(state) + }) it('should properly set the state with empty data', () => { // Arrange - const data: any = []; + const data: any = [] const state = { ...initialState, @@ -396,49 +396,49 @@ describe('cloud slice', () => { ...initialState.loaded, [LoadedCloud.Instances]: true, }, - }; + } // Act const nextState = reducer( initialState, loadInstancesRedisCloudSuccess({ data }) - ); + ) // Assert const rootState = Object.assign(initialStateDefault, { connections: { cloud: nextState, }, - }); - expect(cloudSelector(rootState)).toEqual(state); - }); - }); + }) + expect(cloudSelector(rootState)).toEqual(state) + }) + }) describe('loadInstancesRedisCloudFailure', () => { it('should properly set the error', () => { // Arrange - const data = 'some error'; + const data = 'some error' const state = { ...initialState, loading: false, error: data, - }; + } // Act const nextState = reducer( initialState, loadInstancesRedisCloudFailure(data) - ); + ) // Assert const rootState = Object.assign(initialStateDefault, { connections: { cloud: nextState, }, - }); - expect(cloudSelector(rootState)).toEqual(state); - }); - }); + }) + expect(cloudSelector(rootState)).toEqual(state) + }) + }) describe('createInstancesRedisCloud', () => { it('should properly set the state before the fetch data', () => { @@ -446,20 +446,20 @@ describe('cloud slice', () => { const state = { ...initialState, loading: true, - }; + } // Act - const nextState = reducer(initialState, createInstancesRedisCloud()); + const nextState = reducer(initialState, createInstancesRedisCloud()) // Assert const rootState = Object.assign(initialStateDefault, { connections: { cloud: nextState, }, - }); - expect(cloudSelector(rootState)).toEqual(state); - }); - }); + }) + expect(cloudSelector(rootState)).toEqual(state) + }) + }) describe('createInstancesRedisCloudSuccess', () => { it('should properly set the state with created instances', () => { @@ -473,7 +473,7 @@ describe('cloud slice', () => { subscriptionIdAdded: 113214, subscriptionName: '', }, - ]; + ] const state = { ...initialState, @@ -483,26 +483,26 @@ describe('cloud slice', () => { ...initialState.loaded, [LoadedCloud.InstancesAdded]: true, }, - }; + } // Act const nextState = reducer( initialState, createInstancesRedisCloudSuccess(instances) - ); + ) // Assert const rootState = Object.assign(initialStateDefault, { connections: { cloud: nextState, }, - }); - expect(cloudSelector(rootState)).toEqual(state); - }); + }) + expect(cloudSelector(rootState)).toEqual(state) + }) it('should properly set the state with empty data', () => { // Arrange - const data: any = []; + const data: any = [] const state = { ...initialState, @@ -512,49 +512,49 @@ describe('cloud slice', () => { ...initialState.loaded, [LoadedCloud.InstancesAdded]: true, }, - }; + } // Act const nextState = reducer( initialState, createInstancesRedisCloudSuccess(data) - ); + ) // Assert const rootState = Object.assign(initialStateDefault, { connections: { cloud: nextState, }, - }); - expect(cloudSelector(rootState)).toEqual(state); - }); - }); + }) + expect(cloudSelector(rootState)).toEqual(state) + }) + }) describe('createInstancesRedisCloudFailure', () => { it('should properly set the error', () => { // Arrange - const data = 'some error'; + const data = 'some error' const state = { ...initialState, loading: false, error: data, - }; + } // Act const nextState = reducer( initialState, createInstancesRedisCloudFailure(data) - ); + ) // Assert const rootState = Object.assign(initialStateDefault, { connections: { cloud: nextState, }, - }); - expect(cloudSelector(rootState)).toEqual(state); - }); - }); + }) + expect(cloudSelector(rootState)).toEqual(state) + }) + }) describe('thunks', () => { describe('fetchSubscriptionsRedisCloud', () => { @@ -567,17 +567,17 @@ describe('cloud slice', () => { numberOfDatabases: 1, status: 'active', }, - ]; + ] const credentials = { accessKey: '123', secretKey: '123', - }; - const responsePayload = { data, status: 200 }; + } + const responsePayload = { data, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(fetchSubscriptionsRedisCloud(credentials)); + await store.dispatch(fetchSubscriptionsRedisCloud(credentials)) // Assert const expectedActions = [ @@ -587,31 +587,30 @@ describe('cloud slice', () => { credentials, }), loadAccountRedisCloud(), - ]; + ] - expect(store.getActions()).toEqual(expectedActions); - }); + expect(store.getActions()).toEqual(expectedActions) + }) it('call fetchSubscriptionsRedisCloud, loadSubscriptionsRedisCloud, and loadSubscriptionsRedisCloudFailure when fetch is failure', async () => { // Arrange const credentials = { accessKey: '123', secretKey: '123', - }; + } - const errorMessage = - 'Could not connect to aoeu:123, please check the connection details.'; + const errorMessage = 'Could not connect to aoeu:123, please check the connection details.' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; + } - apiService.post = jest.fn().mockRejectedValueOnce(responsePayload); + apiService.post = jest.fn().mockRejectedValueOnce(responsePayload) // Act - await store.dispatch(fetchSubscriptionsRedisCloud(credentials)); + await store.dispatch(fetchSubscriptionsRedisCloud(credentials)) // Assert const expectedActions = [ @@ -620,11 +619,11 @@ describe('cloud slice', () => { responsePayload.response.data.message ), addErrorNotification(responsePayload as AxiosError), - ]; + ] - expect(store.getActions()).toEqual(expectedActions); - }); - }); + expect(store.getActions()).toEqual(expectedActions) + }) + }) describe('fetchAccountRedisCloud', () => { it('call fetchAccountRedisCloud and loadAccountRedisCloudSuccess when fetch is successed', async () => { @@ -632,13 +631,13 @@ describe('cloud slice', () => { const credentials = { accessKey: '123', secretKey: '123', - }; - const responsePayload = { data: account, status: 200 }; + } + const responsePayload = { data: account, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(fetchAccountRedisCloud(credentials)); + await store.dispatch(fetchAccountRedisCloud(credentials)) // Assert const expectedActions = [ @@ -646,59 +645,58 @@ describe('cloud slice', () => { loadAccountRedisCloudSuccess({ data: responsePayload.data, }), - ]; + ] - expect(store.getActions()).toEqual(expectedActions); - }); + expect(store.getActions()).toEqual(expectedActions) + }) it('call fetchAccountRedisCloud and loadAccountRedisCloudFailure when fetch is failure', async () => { // Arrange const credentials = { accessKey: '123', secretKey: '123', - }; + } - const errorMessage = - 'Could not connect to aoeu:123, please check the connection details.'; + const errorMessage = 'Could not connect to aoeu:123, please check the connection details.' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; + } - apiService.post = jest.fn().mockRejectedValueOnce(responsePayload); + apiService.post = jest.fn().mockRejectedValueOnce(responsePayload) // Act - await store.dispatch(fetchAccountRedisCloud(credentials)); + await store.dispatch(fetchAccountRedisCloud(credentials)) // Assert const expectedActions = [ loadAccountRedisCloud(), loadAccountRedisCloudFailure(responsePayload.response.data.message), addErrorNotification(responsePayload as AxiosError), - ]; + ] - expect(store.getActions()).toEqual(expectedActions); - }); - }); + expect(store.getActions()).toEqual(expectedActions) + }) + }) describe('fetchInstancesRedisCloud', () => { it('call fetchInstancesRedisCloud and loadInstancesRedisCloudSuccess when fetch is successed', async () => { // Arrange - const ids = [1, 2, 3]; + const ids = [1, 2, 3] const credentials = { accessKey: '123', secretKey: '123', - }; - const responsePayload = { data: instances, status: 200 }; + } + const responsePayload = { data: instances, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act await store.dispatch( fetchInstancesRedisCloud({ ids, credentials }) - ); + ) // Assert const expectedActions = [ @@ -707,95 +705,93 @@ describe('cloud slice', () => { data: responsePayload.data, credentials: { ids, credentials }, }), - ]; + ] - expect(store.getActions()).toEqual(expectedActions); - }); + expect(store.getActions()).toEqual(expectedActions) + }) it('call fetchInstancesRedisCloud and loadInstancesRedisCloudFailure when fetch is failure', async () => { // Arrange - const ids = [1, 2, 3]; + const ids = [1, 2, 3] const credentials = { accessKey: '123', secretKey: '123', - }; + } - const errorMessage = - 'Could not connect to aoeu:123, please check the connection details.'; + const errorMessage = 'Could not connect to aoeu:123, please check the connection details.' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; + } - apiService.post = jest.fn().mockRejectedValueOnce(responsePayload); + apiService.post = jest.fn().mockRejectedValueOnce(responsePayload) // Act await store.dispatch( fetchInstancesRedisCloud({ ids, credentials }) - ); + ) // Assert const expectedActions = [ loadInstancesRedisCloud(), loadInstancesRedisCloudFailure(responsePayload.response.data.message), addErrorNotification(responsePayload as AxiosError), - ]; + ] - expect(store.getActions()).toEqual(expectedActions); - }); - }); + expect(store.getActions()).toEqual(expectedActions) + }) + }) describe('addInstancesRedisCloud', () => { it('call addInstancesRedisCloud and createInstancesRedisCloudSuccess when fetch is successed', async () => { // Arrange - const databasesPicked = [{ subscriptionId: '1231', databaseId: '123' }]; + const databasesPicked = [{ subscriptionId: '1231', databaseId: '123' }] const credentials = { accessKey: '123', secretKey: '123', - }; - const responsePayload = { data: instances, status: 200 }; + } + const responsePayload = { data: instances, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act await store.dispatch( addInstancesRedisCloud({ databases: databasesPicked, credentials }) - ); + ) // Assert const expectedActions = [ createInstancesRedisCloud(), createInstancesRedisCloudSuccess(responsePayload.data), - ]; + ] - expect(store.getActions()).toEqual(expectedActions); - }); + expect(store.getActions()).toEqual(expectedActions) + }) it('call addInstancesRedisCloud and createInstancesRedisCloudFailure when fetch is failure', async () => { // Arrange - const databasesPicked = [{ subscriptionId: '1231', databaseId: '123' }]; + const databasesPicked = [{ subscriptionId: '1231', databaseId: '123' }] const credentials = { accessKey: '123', secretKey: '123', - }; + } - const errorMessage = - 'Could not connect to aoeu:123, please check the connection details.'; + const errorMessage = 'Could not connect to aoeu:123, please check the connection details.' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; + } - apiService.post = jest.fn().mockRejectedValueOnce(responsePayload); + apiService.post = jest.fn().mockRejectedValueOnce(responsePayload) // Act await store.dispatch( addInstancesRedisCloud({ databases: databasesPicked, credentials }) - ); + ) // Assert const expectedActions = [ @@ -804,10 +800,10 @@ describe('cloud slice', () => { responsePayload.response.data.message ), addErrorNotification(responsePayload as AxiosError), - ]; + ] - expect(store.getActions()).toEqual(expectedActions); - }); - }); - }); -}); + expect(store.getActions()).toEqual(expectedActions) + }) + }) + }) +}) diff --git a/redisinsight/ui/src/slices/tests/cluster.spec.ts b/redisinsight/ui/src/slices/tests/cluster.spec.ts index 186cc1598d..b93fe8aa62 100644 --- a/redisinsight/ui/src/slices/tests/cluster.spec.ts +++ b/redisinsight/ui/src/slices/tests/cluster.spec.ts @@ -1,16 +1,16 @@ -import { AxiosError } from 'axios'; -import { cloneDeep } from 'lodash'; -import { apiService } from 'uiSrc/services'; +import { AxiosError } from 'axios' +import { cloneDeep } from 'lodash' +import { apiService } from 'uiSrc/services' import { cleanup, initialStateDefault, mockedStore, -} from 'uiSrc/utils/test-utils'; +} from 'uiSrc/utils/test-utils' import { ClusterConnectionDetailsDto, RedisEnterpriseDatabase, -} from 'apiSrc/modules/redis-enterprise/dto/cluster.dto'; -import { AddRedisEnterpriseDatabaseResponse } from 'apiSrc/modules/instances/dto/redis-enterprise-cluster.dto'; +} from 'apiSrc/modules/redis-enterprise/dto/cluster.dto' +import { AddRedisEnterpriseDatabaseResponse } from 'apiSrc/modules/instances/dto/redis-enterprise-cluster.dto' import reducer, { initialState, loadInstancesRedisCluster, @@ -22,27 +22,27 @@ import reducer, { createInstancesRedisClusterSuccess, createInstancesRedisClusterFailure, addInstancesRedisCluster, -} from '../cluster'; +} from '../cluster' -import { addErrorNotification } from '../app/notifications'; +import { addErrorNotification } from '../app/notifications' -jest.mock('uiSrc/services'); +jest.mock('uiSrc/services') -let store: typeof mockedStore; -let defaultCredentials: ClusterConnectionDetailsDto; -let defaultData: RedisEnterpriseDatabase[]; -let defaultDataAdded: AddRedisEnterpriseDatabaseResponse[]; +let store: typeof mockedStore +let defaultCredentials: ClusterConnectionDetailsDto +let defaultData: RedisEnterpriseDatabase[] +let defaultDataAdded: AddRedisEnterpriseDatabaseResponse[] beforeEach(() => { - cleanup(); - store = cloneDeep(mockedStore); - store.clearActions(); + cleanup() + store = cloneDeep(mockedStore) + store.clearActions() defaultCredentials = { host: 'localhost', port: 9443, username: 'e@e.com', password: '1', - }; + } defaultData = [ { @@ -87,7 +87,7 @@ beforeEach(() => { isReplicaSource: false, }, }, - ]; + ] defaultDataAdded = [ { @@ -143,22 +143,22 @@ beforeEach(() => { }, }, }, - ]; -}); + ] +}) describe('cluster slice', () => { describe('reducer, actions and selectors', () => { it('should return the initial state on first run', () => { // Arrange - const nextState = initialState; + const nextState = initialState // Act - const result = reducer(undefined, {}); + const result = reducer(undefined, {}) // Assert - expect(result).toEqual(nextState); - }); - }); + expect(result).toEqual(nextState) + }) + }) describe('loadInstancesRedisCluster', () => { it('should properly set loading = true', () => { @@ -166,20 +166,20 @@ describe('cluster slice', () => { const state = { ...initialState, loading: true, - }; + } // Act - const nextState = reducer(initialState, loadInstancesRedisCluster()); + const nextState = reducer(initialState, loadInstancesRedisCluster()) // Assert const rootState = Object.assign(initialStateDefault, { connections: { cluster: nextState, }, - }); - expect(clusterSelector(rootState)).toEqual(state); - }); - }); + }) + expect(clusterSelector(rootState)).toEqual(state) + }) + }) describe('loadInstancesRedisClusterSuccess', () => { it('should properly set the state with fetched data', () => { @@ -187,13 +187,13 @@ describe('cluster slice', () => { const data = [ { id: '70b95d32-c19d-4311-bb24-e684af12cf15', name: 'ca cert' }, - ]; + ] const state = { ...initialState, loading: false, data: defaultData, credentials: defaultCredentials, - }; + } // Act const nextState = reducer( @@ -202,27 +202,27 @@ describe('cluster slice', () => { data: defaultData, credentials: defaultCredentials, }) - ); + ) // Assert const rootState = Object.assign(initialStateDefault, { connections: { cluster: nextState, }, - }); - expect(clusterSelector(rootState)).toEqual(state); - }); + }) + expect(clusterSelector(rootState)).toEqual(state) + }) it('should properly set the state with empty data', () => { // Arrange - const data: any = []; + const data: any = [] const state = { ...initialState, loading: false, data, credentials: defaultCredentials, - }; + } // Act const nextState = reducer( @@ -231,43 +231,43 @@ describe('cluster slice', () => { data, credentials: defaultCredentials, }) - ); + ) // Assert const rootState = Object.assign(initialStateDefault, { connections: { cluster: nextState, }, - }); - expect(clusterSelector(rootState)).toEqual(state); - }); - }); + }) + expect(clusterSelector(rootState)).toEqual(state) + }) + }) describe('loadInstancesRedisClusterFailure', () => { it('should properly set the error', () => { // Arrange - const data = 'some error'; + const data = 'some error' const state = { ...initialState, loading: false, error: data, - }; + } // Act const nextState = reducer( initialState, loadInstancesRedisClusterFailure(data) - ); + ) // Assert const rootState = Object.assign(initialStateDefault, { connections: { cluster: nextState, }, - }); - expect(clusterSelector(rootState)).toEqual(state); - }); - }); + }) + expect(clusterSelector(rootState)).toEqual(state) + }) + }) describe('createInstancesRedisCluster', () => { it('should properly set the state before the fetch data', () => { @@ -275,20 +275,20 @@ describe('cluster slice', () => { const state = { ...initialState, loading: true, - }; + } // Act - const nextState = reducer(initialState, createInstancesRedisCluster()); + const nextState = reducer(initialState, createInstancesRedisCluster()) // Assert const rootState = Object.assign(initialStateDefault, { connections: { cluster: nextState, }, - }); - expect(clusterSelector(rootState)).toEqual(state); - }); - }); + }) + expect(clusterSelector(rootState)).toEqual(state) + }) + }) describe('createInstancesRedisClusterSuccess', () => { it('should properly set the state with created instances', () => { @@ -305,93 +305,93 @@ describe('cluster slice', () => { statusAdded: 'active', messageAdded: undefined, }, - ]; + ] const state = { ...initialState, loading: false, dataAdded, - }; + } // Act const nextState = reducer( initialState, createInstancesRedisClusterSuccess(defaultData) - ); + ) // Assert const rootState = Object.assign(initialStateDefault, { connections: { cluster: nextState, }, - }); - expect(clusterSelector(rootState)).toEqual(state); - }); + }) + expect(clusterSelector(rootState)).toEqual(state) + }) it('should properly set the state with empty data', () => { // Arrange - const data: any = []; + const data: any = [] const state = { ...initialState, loading: false, dataAdded: data, - }; + } // Act const nextState = reducer( initialState, createInstancesRedisClusterSuccess(data) - ); + ) // Assert const rootState = Object.assign(initialStateDefault, { connections: { cluster: nextState, }, - }); - expect(clusterSelector(rootState)).toEqual(state); - }); - }); + }) + expect(clusterSelector(rootState)).toEqual(state) + }) + }) describe('createInstancesRedisClusterFailure', () => { it('should properly set the error', () => { // Arrange - const data = 'some error'; + const data = 'some error' const state = { ...initialState, loading: false, error: data, - }; + } // Act const nextState = reducer( initialState, createInstancesRedisClusterFailure(data) - ); + ) // Assert const rootState = Object.assign(initialStateDefault, { connections: { cluster: nextState, }, - }); - expect(clusterSelector(rootState)).toEqual(state); - }); - }); + }) + expect(clusterSelector(rootState)).toEqual(state) + }) + }) describe('thunks', () => { describe('fetchInstancesRedisCluster', () => { it('call both fetchInstancesRedisCluster and loadInstancesRedisClusterSuccess when fetch is successed', async () => { // Arrange - const responsePayload = { data: defaultData, status: 200 }; + const responsePayload = { data: defaultData, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act await store.dispatch( fetchInstancesRedisCluster(defaultCredentials) - ); + ) // Assert const expectedActions = [ @@ -400,27 +400,26 @@ describe('cluster slice', () => { data: responsePayload.data, credentials: defaultCredentials, }), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) it('call both fetchInstancesRedisCluster and loadInstancesRedisClusterFailure when fetch is fail', async () => { // Arrange - const errorMessage = - 'Could not connect to aoeu:123, please check the connection details.'; + const errorMessage = 'Could not connect to aoeu:123, please check the connection details.' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; + } - apiService.post = jest.fn().mockRejectedValueOnce(responsePayload); + apiService.post = jest.fn().mockRejectedValueOnce(responsePayload) // Act await store.dispatch( fetchInstancesRedisCluster(defaultCredentials) - ); + ) // Assert const expectedActions = [ @@ -429,52 +428,51 @@ describe('cluster slice', () => { responsePayload.response.data.message ), addErrorNotification(responsePayload as AxiosError), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) + }) describe('addInstancesRedisCluster', () => { it('call both addInstancesRedisCluster and createInstancesRedisClusterSuccess when fetch is successed', async () => { // Arrange - const uids = [1, 2]; - const responsePayload = { data: defaultDataAdded, status: 200 }; + const uids = [1, 2] + const responsePayload = { data: defaultDataAdded, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act await store.dispatch( addInstancesRedisCluster({ uids, credentials: defaultCredentials }) - ); + ) // Assert const expectedActions = [ createInstancesRedisCluster(), createInstancesRedisClusterSuccess(responsePayload.data), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) it('call both addInstancesRedisCluster and createInstancesRedisClusterFailure when fetch is fail', async () => { // Arrange - const uids = [1, 2]; + const uids = [1, 2] - const errorMessage = - 'Could not connect to aoeu:123, please check the connection details.'; + const errorMessage = 'Could not connect to aoeu:123, please check the connection details.' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; + } - apiService.post = jest.fn().mockRejectedValueOnce(responsePayload); + apiService.post = jest.fn().mockRejectedValueOnce(responsePayload) // Act await store.dispatch( addInstancesRedisCluster({ uids, credentials: defaultCredentials }) - ); + ) // Assert const expectedActions = [ @@ -483,9 +481,9 @@ describe('cluster slice', () => { responsePayload.response.data.message ), addErrorNotification(responsePayload as AxiosError), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); - }); - }); -}); + ] + expect(store.getActions()).toEqual(expectedActions) + }) + }) + }) +}) diff --git a/redisinsight/ui/src/slices/tests/hash.spec.ts b/redisinsight/ui/src/slices/tests/hash.spec.ts index 0c6c6c1285..10bce81689 100644 --- a/redisinsight/ui/src/slices/tests/hash.spec.ts +++ b/redisinsight/ui/src/slices/tests/hash.spec.ts @@ -1,20 +1,20 @@ -import { cloneDeep } from 'lodash'; -import { AxiosError } from 'axios'; -import { apiService } from 'uiSrc/services'; +import { cloneDeep } from 'lodash' +import { AxiosError } from 'axios' +import { apiService } from 'uiSrc/services' import { cleanup, initialStateDefault, mockedStore, mockStore, -} from 'uiSrc/utils/test-utils'; -import successMessages from 'uiSrc/components/notifications/success-messages'; +} from 'uiSrc/utils/test-utils' +import successMessages from 'uiSrc/components/notifications/success-messages' import { defaultSelectedKeyAction, refreshKeyInfo, deleteKeySuccess, deleteKeyFromList, updateSelectedKeyRefreshTime, -} from '../keys'; +} from '../keys' import reducer, { deleteHashFields, fetchMoreHashFields, @@ -39,40 +39,40 @@ import reducer, { updateFieldsInList, updateHashFieldsAction, refreshHashFieldsAction, -} from '../hash'; -import { addErrorNotification, addMessageNotification } from '../app/notifications'; +} from '../hash' +import { addErrorNotification, addMessageNotification } from '../app/notifications' -jest.mock('uiSrc/services'); +jest.mock('uiSrc/services') -let store: typeof mockedStore; -let dateNow: jest.SpyInstance; +let store: typeof mockedStore +let dateNow: jest.SpyInstance beforeEach(() => { - cleanup(); - store = cloneDeep(mockedStore); - store.clearActions(); -}); + cleanup() + store = cloneDeep(mockedStore) + store.clearActions() +}) describe('hash slice', () => { beforeAll(() => { - dateNow = jest.spyOn(Date, 'now').mockImplementation(() => 1629128049027); - }); + dateNow = jest.spyOn(Date, 'now').mockImplementation(() => 1629128049027) + }) afterAll(() => { - dateNow.mockRestore(); - }); + dateNow.mockRestore() + }) describe('reducer, actions and selectors', () => { it('should return the initial state on first run', () => { // Arrange - const nextState = initialState; + const nextState = initialState // Act - const result = reducer(undefined, {}); + const result = reducer(undefined, {}) // Assert - expect(result).toEqual(nextState); - }); - }); + expect(result).toEqual(nextState) + }) + }) describe('loadHashFields', () => { it('should properly set the state before the fetch data', () => { @@ -80,18 +80,18 @@ describe('hash slice', () => { const state = { ...initialState, loading: true, - }; + } // Act - const nextState = reducer(initialState, loadHashFields('*')); + const nextState = reducer(initialState, loadHashFields('*')) // Assert const rootState = Object.assign(initialStateDefault, { browser: { hash: nextState }, - }); - expect(hashSelector(rootState)).toEqual(state); - }); - }); + }) + expect(hashSelector(rootState)).toEqual(state) + }) + }) describe('loadHashFieldsSuccess', () => { it('should properly set the state with fetched data', () => { @@ -102,7 +102,7 @@ describe('hash slice', () => { nextCursor: 0, fields: [{ field: 'hash field', value: 'hash value' }], total: 1, - }; + } const state = { ...initialState, @@ -113,17 +113,17 @@ describe('hash slice', () => { key: data.keyName, match: '*', }, - }; + } // Act - const nextState = reducer(initialState, loadHashFieldsSuccess(data)); + const nextState = reducer(initialState, loadHashFieldsSuccess(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { hash: nextState }, - }); - expect(hashSelector(rootState)).toEqual(state); - }); + }) + expect(hashSelector(rootState)).toEqual(state) + }) it('should properly set the state with empty fields', () => { // Arrange @@ -132,7 +132,7 @@ describe('hash slice', () => { nextCursor: 0, fields: [], total: 0, - }; + } const state = { ...initialState, @@ -143,39 +143,39 @@ describe('hash slice', () => { key: data.keyName, match: '*', }, - }; + } // Act - const nextState = reducer(initialState, loadHashFieldsSuccess(data)); + const nextState = reducer(initialState, loadHashFieldsSuccess(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { hash: nextState }, - }); - expect(hashSelector(rootState)).toEqual(state); - }); - }); + }) + expect(hashSelector(rootState)).toEqual(state) + }) + }) describe('loadHashFieldsFailure', () => { it('should properly set the error', () => { // Arrange - const data = 'some error'; + const data = 'some error' const state = { ...initialState, loading: false, error: data, - }; + } // Act - const nextState = reducer(initialState, loadHashFieldsFailure(data)); + const nextState = reducer(initialState, loadHashFieldsFailure(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { hash: nextState }, - }); - expect(hashSelector(rootState)).toEqual(state); - }); - }); + }) + expect(hashSelector(rootState)).toEqual(state) + }) + }) describe('loadMoreHashFields', () => { it('should properly set the state before the fetch data', () => { @@ -184,18 +184,18 @@ describe('hash slice', () => { ...initialState, loading: true, error: '', - }; + } // Act - const nextState = reducer(initialState, loadMoreHashFields()); + const nextState = reducer(initialState, loadMoreHashFields()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { hash: nextState }, - }); - expect(hashSelector(rootState)).toEqual(state); - }); - }); + }) + expect(hashSelector(rootState)).toEqual(state) + }) + }) describe('loadMoreHashFieldsSuccess', () => { it('should properly set the state with fetched data', () => { @@ -206,7 +206,7 @@ describe('hash slice', () => { nextCursor: 0, fields: [{ field: 'hash field', value: 'hash value' }], total: 1, - }; + } const state = { ...initialState, @@ -215,17 +215,17 @@ describe('hash slice', () => { ...initialState.data, ...data, }, - }; + } // Act - const nextState = reducer(initialState, loadMoreHashFieldsSuccess(data)); + const nextState = reducer(initialState, loadMoreHashFieldsSuccess(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { hash: nextState }, - }); - expect(hashSelector(rootState)).toEqual(state); - }); + }) + expect(hashSelector(rootState)).toEqual(state) + }) it('should properly set the state with empty data', () => { // Arrange @@ -234,7 +234,7 @@ describe('hash slice', () => { nextCursor: 0, fields: [], total: 0, - }; + } const state = { ...initialState, @@ -243,39 +243,39 @@ describe('hash slice', () => { ...initialState.data, ...data, }, - }; + } // Act - const nextState = reducer(initialState, loadMoreHashFieldsSuccess(data)); + const nextState = reducer(initialState, loadMoreHashFieldsSuccess(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { hash: nextState }, - }); - expect(hashSelector(rootState)).toEqual(state); - }); - }); + }) + expect(hashSelector(rootState)).toEqual(state) + }) + }) describe('loadMoreHashFieldsFailure', () => { it('should properly set the error', () => { // Arrange - const data = 'some error'; + const data = 'some error' const state = { ...initialState, loading: false, error: data, - }; + } // Act - const nextState = reducer(initialState, loadMoreHashFieldsFailure(data)); + const nextState = reducer(initialState, loadMoreHashFieldsFailure(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { hash: nextState }, - }); - expect(hashSelector(rootState)).toEqual(state); - }); - }); + }) + expect(hashSelector(rootState)).toEqual(state) + }) + }) describe('removeHashFields', () => { it('should properly set the state before the fetch data', () => { @@ -283,18 +283,18 @@ describe('hash slice', () => { const state = { ...initialState, loading: true, - }; + } // Act - const nextState = reducer(initialState, removeHashFields()); + const nextState = reducer(initialState, removeHashFields()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { hash: nextState }, - }); - expect(hashSelector(rootState)).toEqual(state); - }); - }); + }) + expect(hashSelector(rootState)).toEqual(state) + }) + }) describe('removeHashFieldsSuccess', () => { it('should properly set the state with fetched data', () => { @@ -306,39 +306,39 @@ describe('hash slice', () => { ...initialState.data, fields: [{ field: 'hash field', value: 'hash value' }], }, - }; + } // Act - const nextState = reducer(initailStateRemove, removeHashFieldsSuccess()); + const nextState = reducer(initailStateRemove, removeHashFieldsSuccess()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { hash: nextState }, - }); - expect(hashSelector(rootState)).toEqual(initailStateRemove); - }); - }); + }) + expect(hashSelector(rootState)).toEqual(initailStateRemove) + }) + }) describe('removeHashFieldsFailure', () => { it('should properly set the error', () => { // Arrange - const data = 'some error'; + const data = 'some error' const state = { ...initialState, loading: false, error: data, - }; + } // Act - const nextState = reducer(initialState, removeHashFieldsFailure(data)); + const nextState = reducer(initialState, removeHashFieldsFailure(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { hash: nextState }, - }); - expect(hashSelector(rootState)).toEqual(state); - }); - }); + }) + expect(hashSelector(rootState)).toEqual(state) + }) + }) describe('removeFieldsFromList', () => { it('should properly set the error', () => { @@ -353,9 +353,9 @@ describe('hash slice', () => { { field: 'hash field3', value: 'hash value' }, ], }, - }; + } - const data = ['hash field', 'hash field3']; + const data = ['hash field', 'hash field3'] const state = { ...initailStateRemove, @@ -364,18 +364,18 @@ describe('hash slice', () => { total: initailStateRemove.data.total - 1, fields: [{ field: 'hash field2', value: 'hash value' }], }, - }; + } // Act - const nextState = reducer(initailStateRemove, removeFieldsFromList(data)); + const nextState = reducer(initailStateRemove, removeFieldsFromList(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { hash: nextState }, - }); - expect(hashSelector(rootState)).toEqual(state); - }); - }); + }) + expect(hashSelector(rootState)).toEqual(state) + }) + }) describe('updateValue', () => { it('should properly set the state while updating a hash key', () => { @@ -387,18 +387,18 @@ describe('hash slice', () => { loading: true, error: '', }, - }; + } // Act - const nextState = reducer(initialState, updateValue()); + const nextState = reducer(initialState, updateValue()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { hash: nextState }, - }); - expect(hashSelector(rootState)).toEqual(state); - }); - }); + }) + expect(hashSelector(rootState)).toEqual(state) + }) + }) describe('updateValueSuccess', () => { it('should properly set the state after successfully updated hash key', () => { @@ -410,23 +410,23 @@ describe('hash slice', () => { ...initialState.updateValue, loading: false, }, - }; + } // Act - const nextState = reducer(initialState, updateValueSuccess()); + const nextState = reducer(initialState, updateValueSuccess()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { hash: nextState }, - }); - expect(hashSelector(rootState)).toEqual(state); - }); - }); + }) + expect(hashSelector(rootState)).toEqual(state) + }) + }) describe('updateValueFailure', () => { it('should properly set the state on update hash key failure', () => { // Arrange - const data = 'some error'; + const data = 'some error' const state = { ...initialState, updateValue: { @@ -434,18 +434,18 @@ describe('hash slice', () => { loading: false, error: data, }, - }; + } // Act - const nextState = reducer(initialState, updateValueFailure(data)); + const nextState = reducer(initialState, updateValueFailure(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { hash: nextState }, - }); - expect(hashSelector(rootState)).toEqual(state); - }); - }); + }) + expect(hashSelector(rootState)).toEqual(state) + }) + }) describe('resetUpdateValue', () => { it('should properly reset the state', () => { @@ -457,18 +457,18 @@ describe('hash slice', () => { loading: false, error: '', }, - }; + } // Act - const nextState = reducer(initialState, resetUpdateValue()); + const nextState = reducer(initialState, resetUpdateValue()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { hash: nextState }, - }); - expect(hashSelector(rootState)).toEqual(state); - }); - }); + }) + expect(hashSelector(rootState)).toEqual(state) + }) + }) describe('thunks', () => { describe('fetchHashFields', () => { @@ -479,29 +479,29 @@ describe('hash slice', () => { nextCursor: 0, fields: [{ field: 'hash field', value: 'hash value' }], total: 3, - }; - const responsePayload = { data, status: 200 }; + } + const responsePayload = { data, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(fetchHashFields(data.keyName, 0, 20, '*')); + await store.dispatch(fetchHashFields(data.keyName, 0, 20, '*')) // Assert const expectedActions = [ loadHashFields('*'), loadHashFieldsSuccess(responsePayload.data), updateSelectedKeyRefreshTime(Date.now()), - ]; + ] - expect(store.getActions()).toEqual(expectedActions); - }); - }); + expect(store.getActions()).toEqual(expectedActions) + }) + }) describe('fetchMoreHashFields', () => { it( - 'call fetchMoreHashFields, loadMoreHashFieldsSuccess,' + - ' when fetch is successed', + 'call fetchMoreHashFields, loadMoreHashFieldsSuccess,' + + ' when fetch is successed', async () => { // Arrange const data = { @@ -509,26 +509,26 @@ describe('hash slice', () => { nextCursor: 0, fields: [{ field: 'hash field', value: 'hash value' }], total: 3, - }; - const responsePayload = { data, status: 200 }; + } + const responsePayload = { data, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act await store.dispatch( fetchMoreHashFields(data.keyName, 0, 20, '*') - ); + ) // Assert const expectedActions = [ loadMoreHashFields(), loadMoreHashFieldsSuccess(responsePayload.data), - ]; + ] - expect(mockedStore.getActions()).toEqual(expectedActions); + expect(mockedStore.getActions()).toEqual(expectedActions) } - ); - }); + ) + }) describe('refreshHashFieldsAction', () => { it('succeed to refresh hash data', async () => { @@ -538,34 +538,34 @@ describe('hash slice', () => { nextCursor: 0, fields: [{ field: 'hash field', value: 'hash value' }], total: 3, - }; - const responsePayload = { data, status: 200 }; + } + const responsePayload = { data, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(refreshHashFieldsAction(data.keyName)); + await store.dispatch(refreshHashFieldsAction(data.keyName)) // Assert const expectedActions = [ loadHashFields('*'), loadHashFieldsSuccess(responsePayload.data), - ]; + ] - expect(store.getActions()).toEqual(expectedActions); - }); - }); + expect(store.getActions()).toEqual(expectedActions) + }) + }) describe('deleteHashFields', () => { it( - 'call removeHashFields, removeHashFieldsSuccess,' + - ' and removeFieldsFromList when fetch is successed', + 'call removeHashFields, removeHashFieldsSuccess,' + + ' and removeFieldsFromList when fetch is successed', async () => { // Arrange - const key = 'key'; - const fields = ['hash field', 'hash field 2']; - const responsePayload = { status: 200, data: { affected: 2 } }; + const key = 'key' + const fields = ['hash field', 'hash field 2'] + const responsePayload = { status: 200, data: { affected: 2 } } const nextState = Object.assign(initialStateDefault, { browser: { hash: { @@ -576,14 +576,14 @@ describe('hash slice', () => { } } }, - }); + }) - const mockedStore = mockStore(nextState); + const mockedStore = mockStore(nextState) - apiService.delete = jest.fn().mockResolvedValue(responsePayload); + apiService.delete = jest.fn().mockResolvedValue(responsePayload) // Act - await mockedStore.dispatch(deleteHashFields(key, fields)); + await mockedStore.dispatch(deleteHashFields(key, fields)) // Assert const expectedActions = [ @@ -598,20 +598,20 @@ describe('hash slice', () => { 'Field' ) ) - ]; + ] - expect(mockedStore.getActions()).toEqual(expectedActions); + expect(mockedStore.getActions()).toEqual(expectedActions) } - ); + ) it( 'succeed to delete all fields from hast', async () => { // Arrange - const key = 'key'; - const fields = ['hash field', 'hash field 2']; - const responsePayload = { status: 200, data: { affected: 2 } }; + const key = 'key' + const fields = ['hash field', 'hash field 2'] + const responsePayload = { status: 200, data: { affected: 2 } } const nextState = Object.assign(initialStateDefault, { browser: { hash: { @@ -622,14 +622,14 @@ describe('hash slice', () => { } } }, - }); + }) - const mockedStore = mockStore(nextState); + const mockedStore = mockStore(nextState) - apiService.delete = jest.fn().mockResolvedValue(responsePayload); + apiService.delete = jest.fn().mockResolvedValue(responsePayload) // Act - await mockedStore.dispatch(deleteHashFields(key, fields)); + await mockedStore.dispatch(deleteHashFields(key, fields)) // Assert const expectedActions = [ @@ -639,74 +639,74 @@ describe('hash slice', () => { deleteKeySuccess(), deleteKeyFromList(key), addMessageNotification(successMessages.DELETED_KEY(key)) - ]; + ] - expect(mockedStore.getActions()).toEqual(expectedActions); + expect(mockedStore.getActions()).toEqual(expectedActions) } - ); - }); + ) + }) describe('addHashFields', () => { - const keyName = 'key'; + const keyName = 'key' const fields = [ { field: 'hash field', value: 'hash value' }, { field: 'hash field 2', value: 'hash value 2' }, - ]; + ] it('succeed to add fields to hash', async () => { // Arrange - const responsePayload = { status: 200 }; - apiService.put = jest.fn().mockResolvedValue(responsePayload); + const responsePayload = { status: 200 } + apiService.put = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(addHashFieldsAction({ keyName, fields })); + await store.dispatch(addHashFieldsAction({ keyName, fields })) // Assert const expectedActions = [ updateValue(), updateValueSuccess(), defaultSelectedKeyAction(), - ]; + ] - expect(mockedStore.getActions()).toEqual(expectedActions); - }); + expect(mockedStore.getActions()).toEqual(expectedActions) + }) it('failed to add fields to hash', async () => { // Arrange - const errorMessage = 'Something was wrong!'; + const errorMessage = 'Something was wrong!' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; - apiService.put = jest.fn().mockRejectedValue(responsePayload); + } + apiService.put = jest.fn().mockRejectedValue(responsePayload) // Act - await store.dispatch(addHashFieldsAction({ keyName, fields })); + await store.dispatch(addHashFieldsAction({ keyName, fields })) // Assert const expectedActions = [ updateValue(), addErrorNotification(responsePayload as AxiosError), updateValueFailure(errorMessage), - ]; + ] - expect(mockedStore.getActions()).toEqual(expectedActions); - }); - }); + expect(mockedStore.getActions()).toEqual(expectedActions) + }) + }) describe('updateHashFieldsAction', () => { - const keyName = 'key'; + const keyName = 'key' const fields = [ { field: 'hash field', value: 'hash value' }, { field: 'hash field 2', value: 'hash value 2' }, - ]; + ] it('succeed to update fields in hash', async () => { // Arrange - const responsePayload = { status: 200 }; - apiService.put = jest.fn().mockResolvedValue(responsePayload); + const responsePayload = { status: 200 } + apiService.put = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(updateHashFieldsAction({ keyName, fields })); + await store.dispatch(updateHashFieldsAction({ keyName, fields })) // Assert const expectedActions = [ @@ -714,33 +714,33 @@ describe('hash slice', () => { updateValueSuccess(), updateFieldsInList(fields), refreshKeyInfo(), - ]; + ] - expect(mockedStore.getActions()).toEqual(expectedActions); - }); + expect(mockedStore.getActions()).toEqual(expectedActions) + }) it('failed to update fields in hash', async () => { // Arrange - const errorMessage = 'Something was wrong!'; + const errorMessage = 'Something was wrong!' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; - apiService.put = jest.fn().mockRejectedValue(responsePayload); + } + apiService.put = jest.fn().mockRejectedValue(responsePayload) // Act - await store.dispatch(updateHashFieldsAction({ keyName, fields })); + await store.dispatch(updateHashFieldsAction({ keyName, fields })) // Assert const expectedActions = [ updateValue(), addErrorNotification(responsePayload as AxiosError), updateValueFailure(errorMessage), - ]; + ] - expect(mockedStore.getActions()).toEqual(expectedActions); - }); - }); - }); -}); + expect(mockedStore.getActions()).toEqual(expectedActions) + }) + }) + }) +}) diff --git a/redisinsight/ui/src/slices/tests/instances.spec.ts b/redisinsight/ui/src/slices/tests/instances.spec.ts index c1385175a3..e443a2a6ca 100644 --- a/redisinsight/ui/src/slices/tests/instances.spec.ts +++ b/redisinsight/ui/src/slices/tests/instances.spec.ts @@ -1,14 +1,14 @@ -import { AxiosError } from 'axios'; -import { cloneDeep, map } from 'lodash'; +import { AxiosError } from 'axios' +import { cloneDeep, map } from 'lodash' import { cleanup, initialStateDefault, mockedStore, -} from 'uiSrc/utils/test-utils'; -import { apiErrors } from 'uiSrc/constants'; -import { apiService } from 'uiSrc/services'; -import successMessages from 'uiSrc/components/notifications/success-messages'; +} from 'uiSrc/utils/test-utils' +import { apiErrors } from 'uiSrc/constants' +import { apiService } from 'uiSrc/services' +import successMessages from 'uiSrc/components/notifications/success-messages' import reducer, { initialState, @@ -35,21 +35,21 @@ import reducer, { changeInstanceAliasFailure, changeInstanceAliasSuccess, changeInstanceAliasAction, -} from '../instances'; -import { addErrorNotification, addMessageNotification, IAddInstanceErrorPayload } from '../app/notifications'; -import { ConnectionType, InitialStateInstances, Instance } from '../interfaces'; -import { loadMastersSentinel } from '../sentinel'; +} from '../instances' +import { addErrorNotification, addMessageNotification, IAddInstanceErrorPayload } from '../app/notifications' +import { ConnectionType, InitialStateInstances, Instance } from '../interfaces' +import { loadMastersSentinel } from '../sentinel' -jest.mock('uiSrc/services'); -jest.mock('uiSrc/constants'); +jest.mock('uiSrc/services') +jest.mock('uiSrc/constants') -let store: typeof mockedStore; -let instances: Instance[]; +let store: typeof mockedStore +let instances: Instance[] beforeEach(() => { - cleanup(); - store = cloneDeep(mockedStore); - store.clearActions(); + cleanup() + store = cloneDeep(mockedStore) + store.clearActions() instances = [ { @@ -102,22 +102,22 @@ beforeEach(() => { name: 'mymaster', }, }, - ]; -}); + ] +}) describe('instances slice', () => { describe('reducer, actions and selectors', () => { it('should return the initial state on first run', () => { // Arrange - const nextState = initialState; + const nextState = initialState // Act - const result = reducer(undefined, {}); + const result = reducer(undefined, {}) // Assert - expect(result).toEqual(nextState); - }); - }); + expect(result).toEqual(nextState) + }) + }) describe('loadInstances', () => { it('should properly set loading = true', () => { @@ -125,20 +125,20 @@ describe('instances slice', () => { const state = { ...initialState, loading: true, - }; + } // Act - const nextState = reducer(initialState, loadInstances()); + const nextState = reducer(initialState, loadInstances()) // Assert const rootState = Object.assign(initialStateDefault, { connections: { instances: nextState, }, - }); - expect(instancesSelector(rootState)).toEqual(state); - }); - }); + }) + expect(instancesSelector(rootState)).toEqual(state) + }) + }) describe('defaultInstanceChanging', () => { it('should properly set loading = true', () => { @@ -147,20 +147,20 @@ describe('instances slice', () => { const state = { ...initialState, loadingChanging: true, - }; + } // Act - const nextState = reducer(initialState, defaultInstanceChanging()); + const nextState = reducer(initialState, defaultInstanceChanging()) // Assert const rootState = Object.assign(initialStateDefault, { connections: { instances: nextState, }, - }); - expect(instancesSelector(rootState)).toEqual(state); - }); - }); + }) + expect(instancesSelector(rootState)).toEqual(state) + }) + }) describe('changeInstanceAlias', () => { it('should properly set loading = true', () => { @@ -170,69 +170,69 @@ describe('instances slice', () => { ...initialState, loadingChanging: true, errorChanging: '', - }; + } // Act - const nextState = reducer(initialState, changeInstanceAlias()); + const nextState = reducer(initialState, changeInstanceAlias()) // Assert const rootState = Object.assign(initialStateDefault, { connections: { instances: nextState, }, - }); - expect(instancesSelector(rootState)).toEqual(state); - }); - }); + }) + expect(instancesSelector(rootState)).toEqual(state) + }) + }) describe('changeInstanceAliasSuccess', () => { it('should properly set the state', () => { // Arrange const prevState: InitialStateInstances = { - ...initialState, + ...initialState, data: [instances[0], instances[1]], - }; + } const state = { ...initialState, loadingChanging: false, - data: [{...instances[0], name: 'newAlias'}, instances[1]], - }; + data: [{ ...instances[0], name: 'newAlias' }, instances[1]], + } // Act - const nextState = reducer(prevState, changeInstanceAliasSuccess({id: instances[0].id, newName: 'newAlias'})); + const nextState = reducer(prevState, changeInstanceAliasSuccess({ id: instances[0].id, newName: 'newAlias' })) // Assert const rootState = Object.assign(initialStateDefault, { connections: { instances: nextState, }, - }); - expect(instancesSelector(rootState)).toEqual(state); + }) + expect(instancesSelector(rootState)).toEqual(state) }) - }); + }) describe('changeInstanceAliasFailure', () => { it('should properly set the error', () => { // Arrange - const data = 'some error'; + const data = 'some error' const state = { ...initialState, loadingChanging: false, errorChanging: data, - }; + } // Act - const nextState = reducer(initialState, changeInstanceAliasFailure(data)); + const nextState = reducer(initialState, changeInstanceAliasFailure(data)) // Assert const rootState = Object.assign(initialStateDefault, { connections: { instances: nextState, }, - }); - expect(instancesSelector(rootState)).toEqual(state); - }); - }); + }) + expect(instancesSelector(rootState)).toEqual(state) + }) + }) describe('loadInstancesSuccess', () => { it('should properly set the state with fetched data', () => { @@ -242,93 +242,90 @@ describe('instances slice', () => { ...initialState, loading: false, data: instances, - }; + } // Act - const nextState = reducer(initialState, loadInstancesSuccess(instances)); + const nextState = reducer(initialState, loadInstancesSuccess(instances)) // Assert const rootState = Object.assign(initialStateDefault, { connections: { instances: nextState, }, - }); - expect(instancesSelector(rootState)).toEqual(state); - }); + }) + expect(instancesSelector(rootState)).toEqual(state) + }) it('should properly set the state with empty data', () => { // Arrange - const data: any = []; + const data: any = [] const state = { ...initialState, loading: false, data, - }; + } // Act - const nextState = reducer(initialState, loadInstancesSuccess(data)); + const nextState = reducer(initialState, loadInstancesSuccess(data)) // Assert const rootState = Object.assign(initialStateDefault, { connections: { instances: nextState, }, - }); - expect(instancesSelector(rootState)).toEqual(state); - }); - }); + }) + expect(instancesSelector(rootState)).toEqual(state) + }) + }) describe('loadInstancesFailure', () => { it('should properly set the error', () => { // Arrange - const data = 'some error'; + const data = 'some error' const state = { ...initialState, loading: false, error: data, data: [], - }; + } // Act - const nextState = reducer(initialState, loadInstancesFailure(data)); + const nextState = reducer(initialState, loadInstancesFailure(data)) // Assert const rootState = Object.assign(initialStateDefault, { connections: { instances: nextState, }, - }); - expect(instancesSelector(rootState)).toEqual(state); - }); - }); - + }) + expect(instancesSelector(rootState)).toEqual(state) + }) + }) describe('getDatabaseConfigInfo', () => { it('should properly set state before fetch data', () => { - // Arrange const state = { ...initialState, loading: true, - }; + } // Act - const nextState = reducer(initialState, getDatabaseConfigInfo()); + const nextState = reducer(initialState, getDatabaseConfigInfo()) // Assert const rootState = Object.assign(initialStateDefault, { connections: { instances: nextState, }, - }); - expect(instancesSelector(rootState)).toEqual(state); - }); - }); + }) + expect(instancesSelector(rootState)).toEqual(state) + }) + }) describe('getDatabaseConfigInfoSuccess', () => { it('should properly set state after fetch data', () => { - // Arrange const data = { version: '6.2', @@ -344,89 +341,87 @@ describe('instances slice', () => { ...initialState, loading: false, instanceOverview: data - }; + } // Act - const nextState = reducer(initialState, getDatabaseConfigInfoSuccess(data)); + const nextState = reducer(initialState, getDatabaseConfigInfoSuccess(data)) // Assert const rootState = Object.assign(initialStateDefault, { connections: { instances: nextState, }, - }); - expect(instancesSelector(rootState)).toEqual(state); - }); - }); + }) + expect(instancesSelector(rootState)).toEqual(state) + }) + }) describe('getDatabaseConfigInfoFailure', () => { it('should properly set error', () => { - // Arrange - const error = 'some error'; + const error = 'some error' const state = { ...initialState, loading: false, error - }; + } // Act - const nextState = reducer(initialState, getDatabaseConfigInfoFailure(error)); + const nextState = reducer(initialState, getDatabaseConfigInfoFailure(error)) // Assert const rootState = Object.assign(initialStateDefault, { connections: { instances: nextState, }, - }); - expect(instancesSelector(rootState)).toEqual(state); - }); - }); + }) + expect(instancesSelector(rootState)).toEqual(state) + }) + }) describe('thunks', () => { describe('fetchInstances', () => { it('call both fetchInstances and loadInstancesSuccess when fetch is successed', async () => { // Arrange - const responsePayload = { data: instances, status: 200 }; + const responsePayload = { data: instances, status: 200 } - apiService.get = jest.fn().mockResolvedValue(responsePayload); + apiService.get = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(fetchInstancesAction()); + await store.dispatch(fetchInstancesAction()) // Assert const expectedActions = [ loadInstances(), loadInstancesSuccess(responsePayload.data), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) it('call both fetchInstances and loadInstancesFailure when fetch is fail', async () => { // Arrange - const errorMessage = - 'Could not connect to aoeu:123, please check the connection details.'; + const errorMessage = 'Could not connect to aoeu:123, please check the connection details.' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; + } - apiService.get = jest.fn().mockRejectedValueOnce(responsePayload); + apiService.get = jest.fn().mockRejectedValueOnce(responsePayload) // Act - await store.dispatch(fetchInstancesAction()); + await store.dispatch(fetchInstancesAction()) // Assert const expectedActions = [ loadInstances(), loadInstancesFailure(responsePayload.response.data.message), addErrorNotification(responsePayload as AxiosError), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) + }) describe('createInstanceStandaloneAction', () => { it('call both createInstanceStandaloneAction and defaultInstanceChangingSuccess when fetch is successed', async () => { @@ -435,14 +430,14 @@ describe('instances slice', () => { name: 'db', host: 'localhost', port: 6379, - }; + } - const responsePayload = { status: 201 }; + const responsePayload = { status: 201 } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(createInstanceStandaloneAction(requestData, jest.fn())); + await store.dispatch(createInstanceStandaloneAction(requestData, jest.fn())) // Assert const expectedActions = [ @@ -450,10 +445,10 @@ describe('instances slice', () => { defaultInstanceChangingSuccess(), loadInstances(), addMessageNotification(successMessages.ADDED_NEW_INSTANCE(requestData.name)) - ]; + ] - expect(store.getActions().splice(0, expectedActions.length)).toEqual(expectedActions); - }); + expect(store.getActions().splice(0, expectedActions.length)).toEqual(expectedActions) + }) it('call both createInstanceStandaloneAction and defaultInstanceChangingFailure when fetch is fail', async () => { // Arrange @@ -461,32 +456,31 @@ describe('instances slice', () => { name: 'db', host: 'localhost', port: 6379, - }; + } - const errorMessage = - 'Could not connect to aoeu:123, please check the connection details.'; + const errorMessage = 'Could not connect to aoeu:123, please check the connection details.' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; + } - apiService.post = jest.fn().mockRejectedValueOnce(responsePayload); + apiService.post = jest.fn().mockRejectedValueOnce(responsePayload) // Act await store.dispatch( createInstanceStandaloneAction(requestData, () => ({})) - ); + ) // Assert const expectedActions = [ defaultInstanceChanging(), defaultInstanceChangingFailure(responsePayload.response.data.message), addErrorNotification(responsePayload as AxiosError), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) it('redirect to sentinel flow when user try connect to Sentinel like Stanalone createInstanceStandaloneAction', async () => { // Arrange @@ -494,10 +488,9 @@ describe('instances slice', () => { name: 'db', host: 'localhost', port: 6379, - }; + } - const errorMessage = - 'Could not connect to aoeu:123, please check the connection details.'; + const errorMessage = 'Could not connect to aoeu:123, please check the connection details.' const responsePayload = { response: { status: 400, @@ -506,37 +499,37 @@ describe('instances slice', () => { error: apiErrors.SentinelParamsRequired, }, }, - }; + } - apiService.post = jest.fn().mockRejectedValueOnce(responsePayload); + apiService.post = jest.fn().mockRejectedValueOnce(responsePayload) // Act await store.dispatch( createInstanceStandaloneAction(requestData, () => ({})) - ); + ) // Assert const expectedActions = [ defaultInstanceChanging(), defaultInstanceChangingFailure(responsePayload.response.data.message), loadMastersSentinel(), - ]; + ] - expect(store.getActions().splice(0, 3)).toEqual(expectedActions); - }); - }); + expect(store.getActions().splice(0, 3)).toEqual(expectedActions) + }) + }) describe('deleteInstances', () => { it('call both deleteInstances and setDefaultInstanceSuccess when fetch is successed for only one instance', async () => { // Arrange - const requestData = [instances[0]]; + const requestData = [instances[0]] - const responsePayload = { status: 200 }; + const responsePayload = { status: 200 } - apiService.delete = jest.fn().mockResolvedValue(responsePayload); + apiService.delete = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(deleteInstancesAction(requestData)); + await store.dispatch(deleteInstancesAction(requestData)) // Assert const expectedActions = [ @@ -544,21 +537,21 @@ describe('instances slice', () => { setDefaultInstanceSuccess(), loadInstances(), addMessageNotification(successMessages.DELETE_INSTANCE(requestData[0].name ?? '')) - ]; + ] - expect(store.getActions().splice(0, expectedActions.length)).toEqual(expectedActions); - }); + expect(store.getActions().splice(0, expectedActions.length)).toEqual(expectedActions) + }) it('call both deleteInstances and setDefaultInstanceSuccess when fetch is successed for several instances', async () => { // Arrange - const requestData = instances.slice(0,3); + const requestData = instances.slice(0, 3) - const responsePayload = { status: 200 }; + const responsePayload = { status: 200 } - apiService.delete = jest.fn().mockResolvedValue(responsePayload); + apiService.delete = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(deleteInstancesAction(requestData)); + await store.dispatch(deleteInstancesAction(requestData)) // Assert const expectedActions = [ @@ -566,38 +559,37 @@ describe('instances slice', () => { setDefaultInstanceSuccess(), loadInstances(), addMessageNotification(successMessages.DELETE_INSTANCES(map(requestData, 'name'))) - ]; + ] - expect(store.getActions().splice(0, expectedActions.length)).toEqual(expectedActions); - }); + expect(store.getActions().splice(0, expectedActions.length)).toEqual(expectedActions) + }) it('call both deleteInstances and setDefaultInstanceFailure when fetch is fail', async () => { // Arrange - const requestData = instances.slice(0, 3); + const requestData = instances.slice(0, 3) - const errorMessage = - 'Could not connect to aoeu:123, please check the connection details.'; + const errorMessage = 'Could not connect to aoeu:123, please check the connection details.' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; + } - apiService.delete = jest.fn().mockRejectedValueOnce(responsePayload); + apiService.delete = jest.fn().mockRejectedValueOnce(responsePayload) // Act - await store.dispatch(deleteInstancesAction(requestData)); + await store.dispatch(deleteInstancesAction(requestData)) // Assert const expectedActions = [ setDefaultInstance(), setDefaultInstanceFailure(responsePayload.response.data.message), addErrorNotification(responsePayload as AxiosError), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) + }) describe('updateInstance', () => { it('call both updateInstance and defaultInstanceChangingSuccess when fetch is successed', async () => { @@ -607,23 +599,23 @@ describe('instances slice', () => { name: 'db', host: 'localhost', port: 6379, - }; + } - const responsePayload = { status: 201 }; + const responsePayload = { status: 201 } - apiService.put = jest.fn().mockResolvedValue(responsePayload); + apiService.put = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(updateInstanceAction(requestData)); + await store.dispatch(updateInstanceAction(requestData)) // Assert const expectedActions = [ defaultInstanceChanging(), defaultInstanceChangingSuccess(), - ]; + ] - expect(store.getActions().splice(0, 2)).toEqual(expectedActions); - }); + expect(store.getActions().splice(0, 2)).toEqual(expectedActions) + }) it('call both updateInstance and defaultInstanceChangingFailure when fetch is fail', async () => { // Arrange @@ -632,198 +624,196 @@ describe('instances slice', () => { name: 'db', host: 'localhost', port: 6379, - }; + } - const errorMessage = - 'Could not connect to aoeu:123, please check the connection details.'; + const errorMessage = 'Could not connect to aoeu:123, please check the connection details.' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; + } - apiService.put = jest.fn().mockRejectedValueOnce(responsePayload); + apiService.put = jest.fn().mockRejectedValueOnce(responsePayload) // Act - await store.dispatch(updateInstanceAction(requestData)); + await store.dispatch(updateInstanceAction(requestData)) // Assert const expectedActions = [ defaultInstanceChanging(), defaultInstanceChangingFailure(responsePayload.response.data.message), addErrorNotification(responsePayload as AxiosError), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) + }) describe('checkConnectToInstance', () => { it('call both checkConnectToInstance and setDefaultInstanceSuccess when connection is successed', async () => { // Arrange - const requestId = '123'; + const requestId = '123' - const onSuccessAction = jest.fn(); - const onFailAction = jest.fn(); + const onSuccessAction = jest.fn() + const onFailAction = jest.fn() - const responsePayload = { status: 201 }; + const responsePayload = { status: 201 } - apiService.get = jest.fn().mockResolvedValue(responsePayload); + apiService.get = jest.fn().mockResolvedValue(responsePayload) // Act await store.dispatch( checkConnectToInstanceAction(requestId, onSuccessAction, onFailAction) - ); + ) // Assert const expectedActions = [ setDefaultInstance(), setDefaultInstanceSuccess(), - ]; + ] - expect(store.getActions().splice(0, 2)).toEqual(expectedActions); - }); + expect(store.getActions().splice(0, 2)).toEqual(expectedActions) + }) it('call both checkConnectToInstance and setDefaultInstanceFailure when fetch is fail', async () => { // Arrange - const requestId = '123'; + const requestId = '123' - const onSuccessAction = jest.fn(); - const onFailAction = jest.fn(); + const onSuccessAction = jest.fn() + const onFailAction = jest.fn() - const errorMessage = - 'Could not connect to aoeu:123, please check the connection details.'; + const errorMessage = 'Could not connect to aoeu:123, please check the connection details.' const responsePayload = { instanceId: requestId, response: { status: 500, data: { message: errorMessage }, }, - }; + } - apiService.get = jest.fn().mockRejectedValueOnce(responsePayload); + apiService.get = jest.fn().mockRejectedValueOnce(responsePayload) // Act await store.dispatch( checkConnectToInstanceAction(requestId, onSuccessAction, onFailAction) - ); + ) // Assert const expectedActions = [ setDefaultInstance(), setDefaultInstanceFailure(responsePayload.response.data.message), addErrorNotification(responsePayload as IAddInstanceErrorPayload), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) + }) describe('getDatabaseConfigInfoAction', () => { it('succeed to get database config info', async () => { // Arrange - const requestId = '123'; + const requestId = '123' const data = { databases: 1, server: {}, modules: [], version: '6.52' - }; - const responsePayload = { status: 200, data }; + } + const responsePayload = { status: 200, data } - apiService.get = jest.fn().mockResolvedValue(responsePayload); + apiService.get = jest.fn().mockResolvedValue(responsePayload) // Act await store.dispatch( getDatabaseConfigInfoAction(requestId, jest.fn()) - ); + ) // Assert const expectedActions = [ getDatabaseConfigInfo(), getDatabaseConfigInfoSuccess(data), - ]; + ] - expect(store.getActions()).toEqual(expectedActions); - }); + expect(store.getActions()).toEqual(expectedActions) + }) it('failed to get database config info', async () => { // Arrange - const requestId = '123'; - const errorMessage = 'Something was wrong!'; + const requestId = '123' + const errorMessage = 'Something was wrong!' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; + } - apiService.get = jest.fn().mockRejectedValue(responsePayload); + apiService.get = jest.fn().mockRejectedValue(responsePayload) // Act await store.dispatch( getDatabaseConfigInfoAction(requestId, jest.fn(), jest.fn()) - ); + ) // Assert const expectedActions = [ getDatabaseConfigInfo(), addErrorNotification(responsePayload as AxiosError), getDatabaseConfigInfoFailure(errorMessage), - ]; + ] - expect(store.getActions()).toEqual(expectedActions); - }); + expect(store.getActions()).toEqual(expectedActions) + }) }) describe('changeInstanceAliasAction', () => { - const requestPayload = {id: 'e37cc441-a4f2-402c-8bdb-fc2413cbbaff', newName: 'newAlias'} + const requestPayload = { id: 'e37cc441-a4f2-402c-8bdb-fc2413cbbaff', newName: 'newAlias' } it('succeed to change database alias', async () => { // Arrange const data = { oldName: 'databaseAlias', newName: 'newAlias', - }; - const responsePayload = { status: 200, data }; - apiService.patch = jest.fn().mockResolvedValue(responsePayload); + } + const responsePayload = { status: 200, data } + apiService.patch = jest.fn().mockResolvedValue(responsePayload) // Act await store.dispatch( changeInstanceAliasAction(requestPayload.id, requestPayload.newName) - ); + ) // Assert const expectedActions = [ changeInstanceAlias(), changeInstanceAliasSuccess(requestPayload), - ]; + ] - expect(store.getActions()).toEqual(expectedActions); - }); + expect(store.getActions()).toEqual(expectedActions) + }) it('failed to change database alias', async () => { // Arrange - const errorMessage = 'Not Found!'; + const errorMessage = 'Not Found!' const responsePayload = { response: { status: 404, data: { message: errorMessage }, }, - }; - apiService.patch = jest.fn().mockRejectedValue(responsePayload); + } + apiService.patch = jest.fn().mockRejectedValue(responsePayload) // Act await store.dispatch( changeInstanceAliasAction(requestPayload.id, requestPayload.newName) - ); + ) // Assert const expectedActions = [ changeInstanceAlias(), changeInstanceAliasFailure(errorMessage), addErrorNotification(responsePayload as AxiosError), - ]; + ] - expect(store.getActions()).toEqual(expectedActions); - }); - }); - }); -}); + expect(store.getActions()).toEqual(expectedActions) + }) + }) + }) +}) diff --git a/redisinsight/ui/src/slices/tests/keys.spec.ts b/redisinsight/ui/src/slices/tests/keys.spec.ts index 05ede4e01f..71d6720f16 100644 --- a/redisinsight/ui/src/slices/tests/keys.spec.ts +++ b/redisinsight/ui/src/slices/tests/keys.spec.ts @@ -1,11 +1,11 @@ -import { cloneDeep } from 'lodash'; -import { AxiosError } from 'axios'; -import { KeyTypes } from 'uiSrc/constants'; -import { apiService } from 'uiSrc/services'; -import { parseKeysListResponse } from 'uiSrc/utils'; -import { cleanup, initialStateDefault, mockedStore } from 'uiSrc/utils/test-utils'; -import { addErrorNotification, addMessageNotification } from 'uiSrc/slices/app/notifications'; -import successMessages from 'uiSrc/components/notifications/success-messages'; +import { cloneDeep } from 'lodash' +import { AxiosError } from 'axios' +import { KeyTypes } from 'uiSrc/constants' +import { apiService } from 'uiSrc/services' +import { parseKeysListResponse } from 'uiSrc/utils' +import { cleanup, initialStateDefault, mockedStore } from 'uiSrc/utils/test-utils' +import { addErrorNotification, addMessageNotification } from 'uiSrc/slices/app/notifications' +import successMessages from 'uiSrc/components/notifications/success-messages' import { CreateHashWithExpireDto, CreateListWithExpireDto, @@ -14,7 +14,7 @@ import { CreateZSetWithExpireDto, ListElementDestination, SetStringWithExpireDto, -} from 'apiSrc/modules/browser/dto'; +} from 'apiSrc/modules/browser/dto' import reducer, { initialState, loadKeys, @@ -55,40 +55,40 @@ import reducer, { addStringKey, addZsetKey, updateSelectedKeyRefreshTime, -} from '../keys'; -import { getString } from '../string'; +} from '../keys' +import { getString } from '../string' -jest.mock('uiSrc/services'); +jest.mock('uiSrc/services') -let store: typeof mockedStore; -let dateNow: jest.SpyInstance; +let store: typeof mockedStore +let dateNow: jest.SpyInstance beforeEach(() => { - cleanup(); - store = cloneDeep(mockedStore); - store.clearActions(); -}); + cleanup() + store = cloneDeep(mockedStore) + store.clearActions() +}) describe('keys slice', () => { beforeAll(() => { - dateNow = jest.spyOn(Date, 'now').mockImplementation(() => 1629128049027); - }); + dateNow = jest.spyOn(Date, 'now').mockImplementation(() => 1629128049027) + }) afterAll(() => { - dateNow.mockRestore(); - }); + dateNow.mockRestore() + }) describe('reducer, actions and selectors', () => { it('should return the initial state on first run', () => { // Arrange - const nextState = initialState; + const nextState = initialState // Act - const result = reducer(undefined, {}); + const result = reducer(undefined, {}) // Assert - expect(result).toEqual(nextState); - }); - }); + expect(result).toEqual(nextState) + }) + }) describe('loadKeys', () => { it('should properly set the state before the fetch data', () => { @@ -96,18 +96,18 @@ describe('keys slice', () => { const state = { ...initialState, loading: true, - }; + } // Act - const nextState = reducer(initialState, loadKeys()); + const nextState = reducer(initialState, loadKeys()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { keys: nextState }, - }); - expect(keysSelector(rootState)).toEqual(state); - }); - }); + }) + expect(keysSelector(rootState)).toEqual(state) + }) + }) describe('loadKeysSuccess', () => { it('should properly set the state with fetched data', () => { @@ -130,7 +130,7 @@ describe('keys slice', () => { size: 3041, }, ], - }; + } const state = { ...initialState, @@ -141,24 +141,24 @@ describe('keys slice', () => { lastRefreshTime: Date.now(), previousResultCount: data.keys.length, }, - }; + } // Act const nextState = reducer( initialState, loadKeysSuccess({ data, isFiltered: false, isSearched: false }) - ); + ) // Assert const rootState = Object.assign(initialStateDefault, { browser: { keys: nextState }, - }); - expect(keysSelector(rootState)).toEqual(state); - }); + }) + expect(keysSelector(rootState)).toEqual(state) + }) it('should properly set the state with empty data', () => { // Arrange - const data: any = {}; + const data: any = {} const state = { ...initialState, @@ -169,26 +169,26 @@ describe('keys slice', () => { previousResultCount: data.keys?.length, lastRefreshTime: Date.now(), }, - }; + } // Act const nextState = reducer( initialState, loadKeysSuccess({ data, isFiltered: false, isSearched: false }) - ); + ) // Assert const rootState = Object.assign(initialStateDefault, { browser: { keys: nextState }, - }); - expect(keysSelector(rootState)).toEqual(state); - }); - }); + }) + expect(keysSelector(rootState)).toEqual(state) + }) + }) describe('loadKeysFailure', () => { it('should properly set the error', () => { // Arrange - const data = 'some error'; + const data = 'some error' const state = { ...initialState, loading: false, @@ -202,18 +202,18 @@ describe('keys slice', () => { shardsMeta: {}, previousResultCount: 0, }, - }; + } // Act - const nextState = reducer(initialState, loadKeysFailure(data)); + const nextState = reducer(initialState, loadKeysFailure(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { keys: nextState }, - }); - expect(keysSelector(rootState)).toEqual(state); - }); - }); + }) + expect(keysSelector(rootState)).toEqual(state) + }) + }) describe('loadMoreKeys', () => { it('should properly set the state before the fetch data', () => { @@ -231,18 +231,18 @@ describe('keys slice', () => { shardsMeta: {}, previousResultCount: 0, }, - }; + } // Act - const nextState = reducer(initialState, loadMoreKeys()); + const nextState = reducer(initialState, loadMoreKeys()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { keys: nextState }, - }); - expect(keysSelector(rootState)).toEqual(state); - }); - }); + }) + expect(keysSelector(rootState)).toEqual(state) + }) + }) describe('loadMoreKeysSuccess', () => { it('should properly set the state with fetched data', () => { @@ -267,7 +267,7 @@ describe('keys slice', () => { size: 3041, }, ], - }; + } const state = { ...initialState, @@ -278,17 +278,17 @@ describe('keys slice', () => { previousResultCount: data.keys.length, lastRefreshTime: initialState.data.lastRefreshTime }, - }; + } // Act - const nextState = reducer(initialState, loadMoreKeysSuccess(data)); + const nextState = reducer(initialState, loadMoreKeysSuccess(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { keys: nextState }, - }); - expect(keysSelector(rootState)).toEqual(state); - }); + }) + expect(keysSelector(rootState)).toEqual(state) + }) it('should properly set the state with empty data', () => { // Arrange @@ -298,23 +298,23 @@ describe('keys slice', () => { keys: [], scanned: 0, shardsMeta: {}, - }; + } // Act - const nextState = reducer(initialState, loadMoreKeysSuccess(data)); + const nextState = reducer(initialState, loadMoreKeysSuccess(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { keys: nextState }, - }); - expect(keysSelector(rootState)).toEqual(initialState); - }); - }); + }) + expect(keysSelector(rootState)).toEqual(initialState) + }) + }) describe('loadMoreKeysFailure', () => { it('should properly set the error', () => { // Arrange - const data = 'some error'; + const data = 'some error' const state = { ...initialState, loading: false, @@ -328,18 +328,18 @@ describe('keys slice', () => { shardsMeta: {}, previousResultCount: 0, }, - }; + } // Act - const nextState = reducer(initialState, loadMoreKeysFailure(data)); + const nextState = reducer(initialState, loadMoreKeysFailure(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { keys: nextState }, - }); - expect(keysSelector(rootState)).toEqual(state); - }); - }); + }) + expect(keysSelector(rootState)).toEqual(state) + }) + }) describe('loadKeyInfoSuccess', () => { it('should properly set the state', () => { @@ -349,7 +349,7 @@ describe('keys slice', () => { type: 'hash', ttl: -1, size: 279, - }; + } const state = { ...initialState, selectedKey: { @@ -359,18 +359,18 @@ describe('keys slice', () => { ...data, }, }, - }; + } // Act - const nextState = reducer(initialState, loadKeyInfoSuccess(data)); + const nextState = reducer(initialState, loadKeyInfoSuccess(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { keys: nextState }, - }); - expect(keysSelector(rootState)).toEqual(state); - }); - }); + }) + expect(keysSelector(rootState)).toEqual(state) + }) + }) describe('refreshKeyInfo', () => { it('should properly set the state', () => { @@ -381,18 +381,18 @@ describe('keys slice', () => { ...initialState.selectedKey, refreshing: true, }, - }; + } // Act - const nextState = reducer(initialState, refreshKeyInfo()); + const nextState = reducer(initialState, refreshKeyInfo()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { keys: nextState }, - }); - expect(keysSelector(rootState)).toEqual(state); - }); - }); + }) + expect(keysSelector(rootState)).toEqual(state) + }) + }) describe('refreshKeyInfoSuccess', () => { it('should properly set the state', () => { @@ -403,7 +403,7 @@ describe('keys slice', () => { ttl: -1, size: 279, length: 3, - }; + } const state = { ...initialState, selectedKey: { @@ -411,18 +411,18 @@ describe('keys slice', () => { refreshing: false, data: { ...initialState.selectedKey.data, ...data }, }, - }; + } // Act - const nextState = reducer(initialState, refreshKeyInfoSuccess(data)); + const nextState = reducer(initialState, refreshKeyInfoSuccess(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { keys: nextState }, - }); - expect(keysSelector(rootState)).toEqual(state); - }); - }); + }) + expect(keysSelector(rootState)).toEqual(state) + }) + }) describe('refreshKeyInfoFail', () => { it('should properly set the state', () => { @@ -433,18 +433,18 @@ describe('keys slice', () => { ...initialState.selectedKey, refreshing: false, }, - }; + } // Act - const nextState = reducer(initialState, refreshKeyInfoFail()); + const nextState = reducer(initialState, refreshKeyInfoFail()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { keys: nextState }, - }); - expect(keysSelector(rootState)).toEqual(state); - }); - }); + }) + expect(keysSelector(rootState)).toEqual(state) + }) + }) describe('addKey', () => { it('should properly set the state while adding a key', () => { @@ -456,18 +456,18 @@ describe('keys slice', () => { loading: true, error: '', }, - }; + } // Act - const nextState = reducer(initialState, addKey()); + const nextState = reducer(initialState, addKey()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { keys: nextState }, - }); - expect(keysSelector(rootState)).toEqual(state); - }); - }); + }) + expect(keysSelector(rootState)).toEqual(state) + }) + }) describe('addKeySuccess', () => { it('should properly set the state after successfully added key', () => { @@ -478,23 +478,23 @@ describe('keys slice', () => { ...initialState.addKey, loading: false, }, - }; + } // Act - const nextState = reducer(initialState, addKeySuccess()); + const nextState = reducer(initialState, addKeySuccess()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { keys: nextState }, - }); - expect(keysSelector(rootState)).toEqual(state); - }); - }); + }) + expect(keysSelector(rootState)).toEqual(state) + }) + }) describe('addKeyFailure', () => { it('should properly set the state on add key failure', () => { // Arrange - const data = 'some error'; + const data = 'some error' const state = { ...initialState, addKey: { @@ -502,18 +502,18 @@ describe('keys slice', () => { loading: false, error: data, }, - }; + } // Act - const nextState = reducer(initialState, addKeyFailure(data)); + const nextState = reducer(initialState, addKeyFailure(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { keys: nextState }, - }); - expect(keysSelector(rootState)).toEqual(state); - }); - }); + }) + expect(keysSelector(rootState)).toEqual(state) + }) + }) describe('resetAddKey', () => { it('should properly reset the state', () => { @@ -525,18 +525,18 @@ describe('keys slice', () => { loading: false, error: '', }, - }; + } // Act - const nextState = reducer(initialState, resetAddKey()); + const nextState = reducer(initialState, resetAddKey()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { keys: nextState }, - }); - expect(keysSelector(rootState)).toEqual(state); - }); - }); + }) + expect(keysSelector(rootState)).toEqual(state) + }) + }) describe('deleteKey', () => { it('should properly set the state before the delete key', () => { @@ -548,18 +548,18 @@ describe('keys slice', () => { loading: true, data: null, }, - }; + } // Act - const nextState = reducer(initialState, deleteKey()); + const nextState = reducer(initialState, deleteKey()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { keys: nextState }, - }); - expect(keysSelector(rootState)).toEqual(state); - }); - }); + }) + expect(keysSelector(rootState)).toEqual(state) + }) + }) describe('deleteKeySuccess', () => { it('should properly set the state before the delete key', () => { @@ -571,23 +571,23 @@ describe('keys slice', () => { loading: false, data: null, }, - }; + } // Act - const nextState = reducer(initialState, deleteKeySuccess()); + const nextState = reducer(initialState, deleteKeySuccess()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { keys: nextState }, - }); - expect(keysSelector(rootState)).toEqual(state); - }); - }); + }) + expect(keysSelector(rootState)).toEqual(state) + }) + }) describe('deleteKeyFailure', () => { it('should properly set the state before the delete key', () => { // Arrange - const data = 'some error'; + const data = 'some error' const state = { ...initialState, selectedKey: { @@ -595,18 +595,18 @@ describe('keys slice', () => { loading: false, error: data, }, - }; + } // Act - const nextState = reducer(initialState, deleteKeyFailure(data)); + const nextState = reducer(initialState, deleteKeyFailure(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { keys: nextState }, - }); - expect(keysSelector(rootState)).toEqual(state); - }); - }); + }) + expect(keysSelector(rootState)).toEqual(state) + }) + }) describe('defaultSelectedKeyAction', () => { it('should properly set the state before the delete key', () => { @@ -618,18 +618,18 @@ describe('keys slice', () => { loading: true, error: '', }, - }; + } // Act - const nextState = reducer(initialState, defaultSelectedKeyAction()); + const nextState = reducer(initialState, defaultSelectedKeyAction()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { keys: nextState }, - }); - expect(keysSelector(rootState)).toEqual(state); - }); - }); + }) + expect(keysSelector(rootState)).toEqual(state) + }) + }) describe('defaultSelectedKeyActionSuccess', () => { it('should properly set the state before the delete key', () => { @@ -640,23 +640,23 @@ describe('keys slice', () => { ...initialState.selectedKey, loading: false, }, - }; + } // Act - const nextState = reducer(initialState, defaultSelectedKeyActionSuccess()); + const nextState = reducer(initialState, defaultSelectedKeyActionSuccess()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { keys: nextState }, - }); - expect(keysSelector(rootState)).toEqual(state); - }); - }); + }) + expect(keysSelector(rootState)).toEqual(state) + }) + }) describe('defaultSelectedKeyActionFailure', () => { it('should properly set the state before the delete key', () => { // Arrange - const data = 'some error'; + const data = 'some error' const state = { ...initialState, selectedKey: { @@ -664,18 +664,18 @@ describe('keys slice', () => { loading: false, error: data, }, - }; + } // Act - const nextState = reducer(initialState, defaultSelectedKeyActionFailure(data)); + const nextState = reducer(initialState, defaultSelectedKeyActionFailure(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { keys: nextState }, - }); - expect(keysSelector(rootState)).toEqual(state); - }); - }); + }) + expect(keysSelector(rootState)).toEqual(state) + }) + }) describe('editKeyTTLFromList', () => { it('should properly set the state before the edit TTL', () => { @@ -684,31 +684,31 @@ describe('keys slice', () => { const data = { key: 'test', ttl: 1000, - }; + } const initialStateMock = { ...initialState, data: { keys: [{ name: data.key, ttl: -1 }], }, - }; + } const state = { ...initialState, data: { keys: [{ name: data.key, ttl: data.ttl }], }, - }; + } // Act - const nextState = reducer(initialStateMock, editKeyTTLFromList(data)); + const nextState = reducer(initialStateMock, editKeyTTLFromList(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { keys: nextState }, - }); - expect(keysSelector(rootState)).toEqual(state); - }); - }); + }) + expect(keysSelector(rootState)).toEqual(state) + }) + }) describe('editKeyFromList', () => { it('should properly set the state before the edit key', () => { @@ -717,31 +717,31 @@ describe('keys slice', () => { const data = { key: 'test', newKey: 'test2', - }; + } const initialStateMock = { ...initialState, data: { keys: [{ name: data.key }], }, - }; + } const state = { ...initialState, data: { keys: [{ name: data.newKey }], }, - }; + } // Act - const nextState = reducer(initialStateMock, editKeyFromList(data)); + const nextState = reducer(initialStateMock, editKeyFromList(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { keys: nextState }, - }); - expect(keysSelector(rootState)).toEqual(state); - }); - }); + }) + expect(keysSelector(rootState)).toEqual(state) + }) + }) describe('thunks', () => { describe('fetchKeys', () => { @@ -766,7 +766,7 @@ describe('keys slice', () => { size: 3041, }, ], - }; + } const responsePayload = { data: [ { @@ -777,12 +777,12 @@ describe('keys slice', () => { }, ], status: 200, - }; + } - apiService.get = jest.fn().mockResolvedValue(responsePayload); + apiService.get = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(fetchKeys(0, 20)); + await store.dispatch(fetchKeys(0, 20)) // Assert const expectedActions = [ @@ -792,34 +792,34 @@ describe('keys slice', () => { isFiltered: false, isSearched: false, }), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) it('failed to load keys', async () => { // Arrange - const errorMessage = 'some error'; + const errorMessage = 'some error' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; + } - apiService.get = jest.fn().mockRejectedValue(responsePayload); + apiService.get = jest.fn().mockRejectedValue(responsePayload) // Act - await store.dispatch(fetchKeys('0', 20)); + await store.dispatch(fetchKeys('0', 20)) // Assert const expectedActions = [ loadKeys(), addErrorNotification(responsePayload as AxiosError), loadKeysFailure(errorMessage), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) + }) describe('fetchMoreKeys', () => { it('call both loadMoreKeys and loadMoreKeysSuccess when fetch is successed', async () => { @@ -843,7 +843,7 @@ describe('keys slice', () => { size: 3041, }, ], - }; + } const responsePayload = { data: [ @@ -855,45 +855,45 @@ describe('keys slice', () => { }, ], status: 200, - }; + } - apiService.get = jest.fn().mockResolvedValue(responsePayload); + apiService.get = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(fetchMoreKeys('0', 20)); + await store.dispatch(fetchMoreKeys('0', 20)) // Assert const expectedActions = [ loadMoreKeys(), loadMoreKeysSuccess(parseKeysListResponse({}, responsePayload.data)), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) it('failed to fetch more keys', async () => { // Arrange - const errorMessage = 'some error'; + const errorMessage = 'some error' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; + } - apiService.get = jest.fn().mockRejectedValue(responsePayload); + apiService.get = jest.fn().mockRejectedValue(responsePayload) // Act - await store.dispatch(fetchMoreKeys('0', 20)); + await store.dispatch(fetchMoreKeys('0', 20)) // Assert const expectedActions = [ loadMoreKeys(), addErrorNotification(responsePayload as AxiosError), loadMoreKeysFailure(errorMessage), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) + }) describe('fetchKeyInfo', () => { it('call both defaultSelectedKeyAction and loadKeyInfoSuccess when fetch is successed', async () => { @@ -903,13 +903,13 @@ describe('keys slice', () => { type: KeyTypes.String, ttl: -1, size: 10, - }; - const responsePayload = { data, status: 200 }; + } + const responsePayload = { data, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(fetchKeyInfo(data.name)); + await store.dispatch(fetchKeyInfo(data.name)) // Assert const expectedActions = [ @@ -918,34 +918,34 @@ describe('keys slice', () => { updateSelectedKeyRefreshTime(Date.now()), // fetch keyInfo getString(), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) it('failed to fetch key info', async () => { // Arrange - const errorMessage = 'some error'; + const errorMessage = 'some error' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; + } - apiService.post = jest.fn().mockRejectedValue(responsePayload); + apiService.post = jest.fn().mockRejectedValue(responsePayload) // Act - await store.dispatch(fetchKeyInfo('keyName')); + await store.dispatch(fetchKeyInfo('keyName')) // Assert const expectedActions = [ defaultSelectedKeyAction(), addErrorNotification(responsePayload as AxiosError), defaultSelectedKeyActionFailure(errorMessage), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) + }) describe('refreshKeyInfoAction', () => { it('success to refresh key info', async () => { @@ -955,47 +955,47 @@ describe('keys slice', () => { type: 'hash', ttl: -1, size: 279, - }; - const responsePayload = { data, status: 200 }; + } + const responsePayload = { data, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(refreshKeyInfoAction('keyName')); + await store.dispatch(refreshKeyInfoAction('keyName')) // Assert const expectedActions = [ refreshKeyInfo(), refreshKeyInfoSuccess(responsePayload.data), updateSelectedKeyRefreshTime(Date.now()), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) it('failed to refresh key info', async () => { // Arrange - const errorMessage = 'some error'; + const errorMessage = 'some error' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; + } - apiService.post = jest.fn().mockRejectedValue(responsePayload); + apiService.post = jest.fn().mockRejectedValue(responsePayload) // Act - await store.dispatch(refreshKeyInfoAction('keyName')); + await store.dispatch(refreshKeyInfoAction('keyName')) // Assert const expectedActions = [ refreshKeyInfo(), refreshKeyInfoFail(), addErrorNotification(responsePayload as AxiosError), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) + }) describe('addHashKey', () => { it('success to add key', async () => { @@ -1003,13 +1003,13 @@ describe('keys slice', () => { const data: CreateHashWithExpireDto = { keyName: 'keyName', fields: [{ field: '1', value: '1' }], - }; - const responsePayload = { data, status: 200 }; + } + const responsePayload = { data, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(addHashKey(data, jest.fn())); + await store.dispatch(addHashKey(data, jest.fn())) // Assert const expectedActions = [ @@ -1017,10 +1017,10 @@ describe('keys slice', () => { addKeySuccess(), defaultSelectedKeyAction(), addMessageNotification(successMessages.ADDED_NEW_KEY(data.keyName)), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) + }) describe('addHashZset', () => { it('success to add key', async () => { @@ -1028,13 +1028,13 @@ describe('keys slice', () => { const data: CreateZSetWithExpireDto = { keyName: 'keyName', members: [{ name: '1', score: 1 }], - }; - const responsePayload = { data, status: 200 }; + } + const responsePayload = { data, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(addZsetKey(data, jest.fn())); + await store.dispatch(addZsetKey(data, jest.fn())) // Assert const expectedActions = [ @@ -1042,10 +1042,10 @@ describe('keys slice', () => { addKeySuccess(), defaultSelectedKeyAction(), addMessageNotification(successMessages.ADDED_NEW_KEY(data.keyName)), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) + }) describe('addHashSet', () => { it('success to add key', async () => { @@ -1053,13 +1053,13 @@ describe('keys slice', () => { const data: CreateSetWithExpireDto = { keyName: 'keyName', members: ['member'], - }; - const responsePayload = { data, status: 200 }; + } + const responsePayload = { data, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(addSetKey(data, jest.fn())); + await store.dispatch(addSetKey(data, jest.fn())) // Assert const expectedActions = [ @@ -1067,10 +1067,10 @@ describe('keys slice', () => { addKeySuccess(), defaultSelectedKeyAction(), addMessageNotification(successMessages.ADDED_NEW_KEY(data.keyName)), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) + }) describe('addStringKey', () => { it('success to add key', async () => { @@ -1078,13 +1078,13 @@ describe('keys slice', () => { const data: SetStringWithExpireDto = { keyName: 'keyName', value: 'string', - }; - const responsePayload = { data, status: 200 }; + } + const responsePayload = { data, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(addStringKey(data, jest.fn())); + await store.dispatch(addStringKey(data, jest.fn())) // Assert const expectedActions = [ @@ -1092,10 +1092,10 @@ describe('keys slice', () => { addKeySuccess(), defaultSelectedKeyAction(), addMessageNotification(successMessages.ADDED_NEW_KEY(data.keyName)), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) + }) describe('addListKey', () => { it('success to add key', async () => { @@ -1104,13 +1104,13 @@ describe('keys slice', () => { keyName: 'keyName', destination: 'TAIL' as ListElementDestination, element: '1', - }; - const responsePayload = { data, status: 200 }; + } + const responsePayload = { data, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(addListKey(data, jest.fn())); + await store.dispatch(addListKey(data, jest.fn())) // Assert const expectedActions = [ @@ -1118,10 +1118,10 @@ describe('keys slice', () => { addKeySuccess(), defaultSelectedKeyAction(), addMessageNotification(successMessages.ADDED_NEW_KEY(data.keyName)), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) + }) describe('addReJSONKey', () => { it('success to add key', async () => { @@ -1129,13 +1129,13 @@ describe('keys slice', () => { const data: CreateRejsonRlWithExpireDto = { keyName: 'keyName', data: '{}', - }; - const responsePayload = { data, status: 200 }; + } + const responsePayload = { data, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(addReJSONKey(data, jest.fn())); + await store.dispatch(addReJSONKey(data, jest.fn())) // Assert const expectedActions = [ @@ -1143,10 +1143,10 @@ describe('keys slice', () => { addKeySuccess(), defaultSelectedKeyAction(), addMessageNotification(successMessages.ADDED_NEW_KEY(data.keyName)), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) + }) describe('deleteKey', () => { it('call both deleteKey, deleteKeySuccess and deleteKeyFromList when delete is successed', async () => { @@ -1156,13 +1156,13 @@ describe('keys slice', () => { type: KeyTypes.String, ttl: -1, size: 10, - }; - const responsePayload = { data, status: 200 }; + } + const responsePayload = { data, status: 200 } - apiService.delete = jest.fn().mockResolvedValue(responsePayload); + apiService.delete = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(deleteKeyAction(data.name)); + await store.dispatch(deleteKeyAction(data.name)) // Assert const expectedActions = [ @@ -1170,40 +1170,40 @@ describe('keys slice', () => { deleteKeySuccess(), deleteKeyFromList(data.name), addMessageNotification(successMessages.DELETED_KEY(data.name)), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) + }) describe('editKey', () => { it('call both editKey, editKeySuccess and editKeyFromList when editing is successed', async () => { // Arrange - const key = 'string'; - const newKey = 'string2'; - const responsePayload = { data: newKey, status: 200 }; + const key = 'string' + const newKey = 'string2' + const responsePayload = { data: newKey, status: 200 } - apiService.patch = jest.fn().mockResolvedValue(responsePayload); + apiService.patch = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(editKey(key, newKey)); + await store.dispatch(editKey(key, newKey)) // Assert - const expectedActions = [defaultSelectedKeyAction(), editKeyFromList({ key, newKey })]; - expect(store.getActions()).toEqual(expectedActions); - }); - }); + const expectedActions = [defaultSelectedKeyAction(), editKeyFromList({ key, newKey })] + expect(store.getActions()).toEqual(expectedActions) + }) + }) describe('editKeyTTL', () => { it('success editKeyTTL with positive ttl', async () => { // Arrange - const key = 'string'; - const ttl = 1200; - const responsePayload = { status: 200 }; + const key = 'string' + const ttl = 1200 + const responsePayload = { status: 200 } - apiService.patch = jest.fn().mockResolvedValue(responsePayload); + apiService.patch = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(editKeyTTL(key, ttl)); + await store.dispatch(editKeyTTL(key, ttl)) // Assert const expectedActions = [ @@ -1213,20 +1213,20 @@ describe('keys slice', () => { // fetch keyInfo defaultSelectedKeyAction(), defaultSelectedKeyActionSuccess(), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) it('success editKeyTTL with ttl = 0', async () => { // Arrange - const key = 'string'; - const ttl = 0; - const responsePayload = { status: 200 }; + const key = 'string' + const ttl = 0 + const responsePayload = { status: 200 } - apiService.patch = jest.fn().mockResolvedValue(responsePayload); + apiService.patch = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(editKeyTTL(key, ttl)); + await store.dispatch(editKeyTTL(key, ttl)) // Assert const expectedActions = [ @@ -1234,9 +1234,9 @@ describe('keys slice', () => { deleteKeySuccess(), deleteKeyFromList(key), defaultSelectedKeyActionSuccess(), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); - }); - }); -}); + ] + expect(store.getActions()).toEqual(expectedActions) + }) + }) + }) +}) diff --git a/redisinsight/ui/src/slices/tests/list.spec.ts b/redisinsight/ui/src/slices/tests/list.spec.ts index 8996cf3621..e5d4eb7d85 100644 --- a/redisinsight/ui/src/slices/tests/list.spec.ts +++ b/redisinsight/ui/src/slices/tests/list.spec.ts @@ -1,21 +1,21 @@ -import { AxiosError } from 'axios'; -import { cloneDeep } from 'lodash'; -import { apiService } from 'uiSrc/services'; +import { AxiosError } from 'axios' +import { cloneDeep } from 'lodash' +import { apiService } from 'uiSrc/services' import { cleanup, initialStateDefault, mockedStore, mockStore, -} from 'uiSrc/utils/test-utils'; -import successMessages from 'uiSrc/components/notifications/success-messages'; -import { DeleteListElementsDto, PushElementToListDto } from 'apiSrc/modules/browser/dto'; +} from 'uiSrc/utils/test-utils' +import successMessages from 'uiSrc/components/notifications/success-messages' +import { DeleteListElementsDto, PushElementToListDto } from 'apiSrc/modules/browser/dto' import { defaultSelectedKeyAction, deleteKeyFromList, deleteKeySuccess, refreshKeyInfo, updateSelectedKeyRefreshTime, -} from '../keys'; +} from '../keys' import reducer, { initialState, setListInitialState, @@ -47,43 +47,43 @@ import reducer, { deleteListElements, deleteListElementsSuccess, deleteListElementsFailure -} from '../list'; -import { addErrorNotification, addMessageNotification } from '../app/notifications'; +} from '../list' +import { addErrorNotification, addMessageNotification } from '../app/notifications' -jest.mock('uiSrc/services'); +jest.mock('uiSrc/services') -let store: typeof mockedStore; -let dateNow: jest.SpyInstance; +let store: typeof mockedStore +let dateNow: jest.SpyInstance beforeEach(() => { - cleanup(); - store = cloneDeep(mockedStore); - store.clearActions(); -}); + cleanup() + store = cloneDeep(mockedStore) + store.clearActions() +}) describe('list slice', () => { beforeAll(() => { - dateNow = jest.spyOn(Date, 'now').mockImplementation(() => 1629128049027); - }); + dateNow = jest.spyOn(Date, 'now').mockImplementation(() => 1629128049027) + }) afterAll(() => { - dateNow.mockRestore(); - }); + dateNow.mockRestore() + }) describe('setListInitialState', () => { it('should properly set initialState', () => { // Arrange - const state = initialState; + const state = initialState // Act - const nextState = reducer(initialState, setListInitialState()); + const nextState = reducer(initialState, setListInitialState()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { list: nextState }, - }); - expect(listSelector(rootState)).toEqual(state); - }); - }); + }) + expect(listSelector(rootState)).toEqual(state) + }) + }) describe('loadListElements', () => { it('should properly set the state before the fetch data', () => { @@ -91,18 +91,18 @@ describe('list slice', () => { const state = { ...initialState, loading: true, - }; + } // Act - const nextState = reducer(initialState, loadListElements()); + const nextState = reducer(initialState, loadListElements()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { list: nextState }, - }); - expect(listSelector(rootState)).toEqual(state); - }); - }); + }) + expect(listSelector(rootState)).toEqual(state) + }) + }) describe('loadListElementsSuccess', () => { it('should properly set the state with fetched data', () => { @@ -114,7 +114,7 @@ describe('list slice', () => { elements: ['1', '2', '3'], total: 1, count: 123, - }; + } const state = { ...initialState, @@ -124,39 +124,39 @@ describe('list slice', () => { ...initialState.data, ...data, }, - }; + } // Act - const nextState = reducer(initialState, loadListElementsSuccess(data)); + const nextState = reducer(initialState, loadListElementsSuccess(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { list: nextState }, - }); - expect(listSelector(rootState)).toEqual(state); - }); - }); + }) + expect(listSelector(rootState)).toEqual(state) + }) + }) describe('loadListElementsFailure', () => { it('should properly set the error', () => { // Arrange - const data = 'some error'; + const data = 'some error' const state = { ...initialState, loading: false, error: data, - }; + } // Act - const nextState = reducer(initialState, loadListElementsFailure(data)); + const nextState = reducer(initialState, loadListElementsFailure(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { list: nextState }, - }); - expect(listSelector(rootState)).toEqual(state); - }); - }); + }) + expect(listSelector(rootState)).toEqual(state) + }) + }) describe('loadMoreListElements', () => { it('should properly set the state before the fetch data', () => { @@ -165,18 +165,18 @@ describe('list slice', () => { ...initialState, loading: true, error: '', - }; + } // Act - const nextState = reducer(initialState, loadMoreListElements()); + const nextState = reducer(initialState, loadMoreListElements()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { list: nextState }, - }); - expect(listSelector(rootState)).toEqual(state); - }); - }); + }) + expect(listSelector(rootState)).toEqual(state) + }) + }) describe('loadMoreListElementsSuccess', () => { it('should properly set the state with fetched data', () => { @@ -187,7 +187,7 @@ describe('list slice', () => { key: 'list', elements: ['1', '23', '432'], total: 1, - }; + } const state = { ...initialState, @@ -196,20 +196,20 @@ describe('list slice', () => { ...initialState.data, elements: data.elements, }, - }; + } // Act const nextState = reducer( initialState, loadMoreListElementsSuccess(data) - ); + ) // Assert const rootState = Object.assign(initialStateDefault, { browser: { list: nextState }, - }); - expect(listSelector(rootState)).toEqual(state); - }); + }) + expect(listSelector(rootState)).toEqual(state) + }) it('should properly set the state with empty data', () => { // Arrange @@ -217,45 +217,45 @@ describe('list slice', () => { keyName: 'hash', elements: [], total: 0, - }; + } // Act const nextState = reducer( initialState, loadMoreListElementsSuccess(data) - ); + ) // Assert const rootState = Object.assign(initialStateDefault, { browser: { list: nextState }, - }); - expect(listSelector(rootState)).toEqual(initialState); - }); - }); + }) + expect(listSelector(rootState)).toEqual(initialState) + }) + }) describe('loadMoreListElementsFailure', () => { it('should properly set the error', () => { // Arrange - const data = 'some error'; + const data = 'some error' const state = { ...initialState, loading: false, error: data, - }; + } // Act const nextState = reducer( initialState, loadMoreListElementsFailure(data) - ); + ) // Assert const rootState = Object.assign(initialStateDefault, { browser: { list: nextState }, - }); - expect(listSelector(rootState)).toEqual(state); - }); - }); + }) + expect(listSelector(rootState)).toEqual(state) + }) + }) describe('updateValue', () => { it('should properly set the state while updating a list key', () => { @@ -267,18 +267,18 @@ describe('list slice', () => { loading: true, error: '', }, - }; + } // Act - const nextState = reducer(initialState, updateValue()); + const nextState = reducer(initialState, updateValue()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { list: nextState }, - }); - expect(listSelector(rootState)).toEqual(state); - }); - }); + }) + expect(listSelector(rootState)).toEqual(state) + }) + }) describe('updateValueSuccess', () => { it('should properly set the state after successfully updated list key', () => { @@ -290,23 +290,23 @@ describe('list slice', () => { ...initialState.updateValue, loading: false, }, - }; + } // Act - const nextState = reducer(initialState, updateValueSuccess()); + const nextState = reducer(initialState, updateValueSuccess()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { list: nextState }, - }); - expect(listSelector(rootState)).toEqual(state); - }); - }); + }) + expect(listSelector(rootState)).toEqual(state) + }) + }) describe('updateValueFailure', () => { it('should properly set the state on update list key failure', () => { // Arrange - const data = 'some error'; + const data = 'some error' const state = { ...initialState, updateValue: { @@ -314,18 +314,18 @@ describe('list slice', () => { loading: false, error: data, }, - }; + } // Act - const nextState = reducer(initialState, updateValueFailure(data)); + const nextState = reducer(initialState, updateValueFailure(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { list: nextState }, - }); - expect(listSelector(rootState)).toEqual(state); - }); - }); + }) + expect(listSelector(rootState)).toEqual(state) + }) + }) describe('resetUpdateValue', () => { it('should properly reset the state', () => { @@ -337,23 +337,23 @@ describe('list slice', () => { loading: false, error: '', }, - }; + } // Act - const nextState = reducer(initialState, resetUpdateValue()); + const nextState = reducer(initialState, resetUpdateValue()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { list: nextState }, - }); - expect(listSelector(rootState)).toEqual(state); - }); - }); + }) + expect(listSelector(rootState)).toEqual(state) + }) + }) describe('loadSearchingListElement', () => { it('should properly set the state before the fetch data', () => { // Arrange - const searchedIndex = 10; + const searchedIndex = 10 const state = { ...initialState, loading: true, @@ -362,21 +362,21 @@ describe('list slice', () => { ...initialState.data, searchedIndex, }, - }; + } // Act const nextState = reducer( initialState, loadSearchingListElement(searchedIndex) - ); + ) // Assert const rootState = Object.assign(initialStateDefault, { browser: { list: nextState }, - }); - expect(listSelector(rootState)).toEqual(state); - }); - }); + }) + expect(listSelector(rootState)).toEqual(state) + }) + }) describe('loadSearchingListElementSuccess', () => { it('should properly set the state with fetched data', () => { @@ -385,7 +385,7 @@ describe('list slice', () => { const data = { keyName: 'list', value: '12311', - }; + } const state = { ...initialState, @@ -394,27 +394,27 @@ describe('list slice', () => { ...initialState.data, elements: [data.value], }, - }; + } // Act const nextState = reducer( initialState, loadSearchingListElementSuccess(data) - ); + ) // Assert const rootState = Object.assign(initialStateDefault, { browser: { list: nextState }, - }); - expect(listSelector(rootState)).toEqual(state); - }); + }) + expect(listSelector(rootState)).toEqual(state) + }) it('should properly set the state with empty data', () => { // Arrange const data = { keyName: 'list', value: '', - }; + } const state = { ...initialState, @@ -423,45 +423,45 @@ describe('list slice', () => { ...initialState.data, elements: [data.value], }, - }; + } // Act const nextState = reducer( initialState, loadSearchingListElementSuccess(data) - ); + ) // Assert const rootState = Object.assign(initialStateDefault, { browser: { list: nextState }, - }); - expect(listSelector(rootState)).toEqual(state); - }); - }); + }) + expect(listSelector(rootState)).toEqual(state) + }) + }) describe('loadSearchingListElementFailure', () => { it('should properly set the error', () => { // Arrange - const data = 'some error'; + const data = 'some error' const state = { ...initialState, loading: false, error: data, - }; + } // Act const nextState = reducer( initialState, loadSearchingListElementFailure(data) - ); + ) // Assert const rootState = Object.assign(initialStateDefault, { browser: { list: nextState }, - }); - expect(listSelector(rootState)).toEqual(state); - }); - }); + }) + expect(listSelector(rootState)).toEqual(state) + }) + }) describe('insertListElements', () => { it('should properly set the state before the fetch data', () => { @@ -474,15 +474,15 @@ describe('list slice', () => { const nextState = reducer( initialState, insertListElements() - ); + ) // Assert const rootState = Object.assign(initialStateDefault, { browser: { list: nextState }, - }); - expect(listSelector(rootState)).toEqual(state); - }); - }); + }) + expect(listSelector(rootState)).toEqual(state) + }) + }) describe('insertListElementsSuccess', () => { it('should properly set the state after the fetch data', () => { @@ -495,39 +495,39 @@ describe('list slice', () => { const nextState = reducer( initialState, insertListElementsSuccess() - ); + ) // Assert const rootState = Object.assign(initialStateDefault, { browser: { list: nextState }, - }); - expect(listSelector(rootState)).toEqual(state); - }); - }); + }) + expect(listSelector(rootState)).toEqual(state) + }) + }) describe('insertListElementsFailure', () => { it('should properly set the error after the fetch data', () => { // Arrange - const error = 'some error'; + const error = 'some error' const state = { ...initialState, loading: false, error - }; + } // Act const nextState = reducer( initialState, insertListElementsFailure(error) - ); + ) // Assert const rootState = Object.assign(initialStateDefault, { browser: { list: nextState }, - }); - expect(listSelector(rootState)).toEqual(state); - }); - }); + }) + expect(listSelector(rootState)).toEqual(state) + }) + }) describe('deleteListElements', () => { it('should properly set the state before the fetch data', () => { @@ -540,15 +540,15 @@ describe('list slice', () => { const nextState = reducer( initialState, deleteListElements() - ); + ) // Assert const rootState = Object.assign(initialStateDefault, { browser: { list: nextState }, - }); - expect(listSelector(rootState)).toEqual(state); - }); - }); + }) + expect(listSelector(rootState)).toEqual(state) + }) + }) describe('deleteListElementsSuccess', () => { it('should properly set the state after the fetch data', () => { @@ -561,40 +561,39 @@ describe('list slice', () => { const nextState = reducer( initialState, deleteListElementsSuccess() - ); + ) // Assert const rootState = Object.assign(initialStateDefault, { browser: { list: nextState }, - }); - expect(listSelector(rootState)).toEqual(state); - }); - }); + }) + expect(listSelector(rootState)).toEqual(state) + }) + }) describe('deleteListElementsFailure', () => { it('should properly set the error after the fetch data', () => { // Arrange - const error = 'some error'; + const error = 'some error' const state = { ...initialState, loading: false, error - }; + } // Act const nextState = reducer( initialState, deleteListElementsFailure(error) - ); + ) // Assert const rootState = Object.assign(initialStateDefault, { browser: { list: nextState }, - }); - expect(listSelector(rootState)).toEqual(state); - }); - }); - + }) + expect(listSelector(rootState)).toEqual(state) + }) + }) describe('thunks', () => { describe('fetchListElements', () => { @@ -605,25 +604,25 @@ describe('list slice', () => { keyName: 'small list', elements: ['123', '123', '321'], total: 3, - }; + } - const responsePayload = { data, status: 200 }; + const responsePayload = { data, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(fetchListElements(data.keyName, 0, 20)); + await store.dispatch(fetchListElements(data.keyName, 0, 20)) // Assert const expectedActions = [ loadListElements(), loadListElementsSuccess(responsePayload.data), updateSelectedKeyRefreshTime(Date.now()), - ]; + ] - expect(store.getActions()).toEqual(expectedActions); - }); - }); + expect(store.getActions()).toEqual(expectedActions) + }) + }) describe('fetchMoreListElements', () => { it('call fetchMoreListElements, loadMoreListElementsSuccess when fetch is successed', async () => { @@ -632,79 +631,79 @@ describe('list slice', () => { keyName: 'small list', elements: ['123', '123', '321'], total: 3, - }; - const responsePayload = { data, status: 200 }; + } + const responsePayload = { data, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(fetchMoreListElements(data.keyName, 0, 20)); + await store.dispatch(fetchMoreListElements(data.keyName, 0, 20)) // Assert const expectedActions = [ loadMoreListElements(), loadMoreListElementsSuccess(responsePayload.data), - ]; + ] - expect(mockedStore.getActions()).toEqual(expectedActions); - }); - }); + expect(mockedStore.getActions()).toEqual(expectedActions) + }) + }) describe('fetchSearchingListElementAction', () => { it('call fetchSearchingListElementAction, loadSearchingListElementSuccess when search is successed', async () => { // Arrange - const searchingIndex = 10; + const searchingIndex = 10 const data = { keyName: 'small list', value: 'value', - }; + } - const responsePayload = { data, status: 200 }; + const responsePayload = { data, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act await store.dispatch( fetchSearchingListElementAction(data.keyName, searchingIndex) - ); + ) // Assert const expectedActions = [ loadSearchingListElement(searchingIndex), loadSearchingListElementSuccess(responsePayload.data), updateSelectedKeyRefreshTime(Date.now()), - ]; + ] - expect(store.getActions()).toEqual(expectedActions); - }); - }); + expect(store.getActions()).toEqual(expectedActions) + }) + }) describe('refreshListElementsAction', () => { it('call refreshListElementsAction without searchingIndex, call loadListElements when fetch is successed', async () => { // Act - await store.dispatch(refreshListElementsAction()); + await store.dispatch(refreshListElementsAction()) // Assert - const expectedActions = [loadListElements()]; + const expectedActions = [loadListElements()] - expect(store.getActions()).toEqual(expectedActions); - }); - }); + expect(store.getActions()).toEqual(expectedActions) + }) + }) describe('updateListElementAction', () => { - const keyName = 'key'; + const keyName = 'key' const data = { keyName, index: 123, element: 'value', - }; + } it('succeed to update element in list', async () => { // Arrange - const responsePayload = { status: 200 }; - apiService.patch = jest.fn().mockResolvedValue(responsePayload); + const responsePayload = { status: 200 } + apiService.patch = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(updateListElementAction(data)); + await store.dispatch(updateListElementAction(data)) // Assert const expectedActions = [ @@ -712,92 +711,92 @@ describe('list slice', () => { updateValueSuccess(), updateElementInList(data), refreshKeyInfo(), - ]; + ] - expect(mockedStore.getActions()).toEqual(expectedActions); - }); + expect(mockedStore.getActions()).toEqual(expectedActions) + }) it('failed to update element in list', async () => { // Arrange - const errorMessage = 'Something was wrong!'; + const errorMessage = 'Something was wrong!' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; - apiService.patch = jest.fn().mockRejectedValue(responsePayload); + } + apiService.patch = jest.fn().mockRejectedValue(responsePayload) // Act - await store.dispatch(updateListElementAction(data)); + await store.dispatch(updateListElementAction(data)) // Assert const expectedActions = [ updateValue(), addErrorNotification(responsePayload as AxiosError), updateValueFailure(errorMessage), - ]; + ] - expect(mockedStore.getActions()).toEqual(expectedActions); - }); - }); + expect(mockedStore.getActions()).toEqual(expectedActions) + }) + }) describe('insertListElementsAction', () => { const data = { keyName: 'keyName', destination: 'TAIL', element: 'value', - } as PushElementToListDto; + } as PushElementToListDto it('succeed to insert element in list', async () => { // Arrange - const responsePayload = { status: 200 }; - apiService.put = jest.fn().mockResolvedValue(responsePayload); + const responsePayload = { status: 200 } + apiService.put = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(insertListElementsAction(data)); + await store.dispatch(insertListElementsAction(data)) // Assert const expectedActions = [ insertListElements(), insertListElementsSuccess(), defaultSelectedKeyAction(), - ]; + ] - expect(mockedStore.getActions()).toEqual(expectedActions); - }); + expect(mockedStore.getActions()).toEqual(expectedActions) + }) it('failed to insert element in list', async () => { // Arrange - const errorMessage = 'Something was wrong!'; + const errorMessage = 'Something was wrong!' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; - apiService.put = jest.fn().mockRejectedValue(responsePayload); + } + apiService.put = jest.fn().mockRejectedValue(responsePayload) // Act - await store.dispatch(insertListElementsAction(data)); + await store.dispatch(insertListElementsAction(data)) // Assert const expectedActions = [ insertListElements(), addErrorNotification(responsePayload as AxiosError), insertListElementsFailure(errorMessage), - ]; + ] - expect(mockedStore.getActions()).toEqual(expectedActions); - }); - }); + expect(mockedStore.getActions()).toEqual(expectedActions) + }) + }) describe('deleteListElementsAction', () => { const data = { keyName: 'keyName', destination: 'TAIL', count: 2, - } as DeleteListElementsDto; + } as DeleteListElementsDto it('succeed to delete elements from list', async () => { // Arrange - const responsePayload = { status: 200, data: { elements: ['zx', 'zz'] } }; + const responsePayload = { status: 200, data: { elements: ['zx', 'zz'] } } const nextState = Object.assign(initialStateDefault, { browser: { list: { @@ -808,14 +807,14 @@ describe('list slice', () => { } } }, - }); + }) - const mockedStore = mockStore(nextState); + const mockedStore = mockStore(nextState) - apiService.delete = jest.fn().mockResolvedValue(responsePayload); + apiService.delete = jest.fn().mockResolvedValue(responsePayload) // Act - await mockedStore.dispatch(deleteListElementsAction(data)); + await mockedStore.dispatch(deleteListElementsAction(data)) // Assert const expectedActions = [ @@ -829,14 +828,14 @@ describe('list slice', () => { responsePayload.data.elements ) ) - ]; + ] - expect(mockedStore.getActions()).toEqual(expectedActions); - }); + expect(mockedStore.getActions()).toEqual(expectedActions) + }) it('succeed to delete all elements from list', async () => { // Arrange - const responsePayload = { status: 200 }; + const responsePayload = { status: 200 } const nextState = Object.assign(initialStateDefault, { browser: { list: { @@ -847,14 +846,14 @@ describe('list slice', () => { } } }, - }); + }) - const mockedStore = mockStore(nextState); + const mockedStore = mockStore(nextState) - apiService.delete = jest.fn().mockResolvedValue(responsePayload); + apiService.delete = jest.fn().mockResolvedValue(responsePayload) // Act - await mockedStore.dispatch(deleteListElementsAction(data)); + await mockedStore.dispatch(deleteListElementsAction(data)) // Assert const expectedActions = [ @@ -863,34 +862,34 @@ describe('list slice', () => { deleteKeySuccess(), deleteKeyFromList(data.keyName), addMessageNotification(successMessages.DELETED_KEY(data.keyName)) - ]; + ] - expect(mockedStore.getActions()).toEqual(expectedActions); - }); + expect(mockedStore.getActions()).toEqual(expectedActions) + }) it('failed to delete elements in list', async () => { // Arrange - const errorMessage = 'Something was wrong!'; + const errorMessage = 'Something was wrong!' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; - apiService.delete = jest.fn().mockRejectedValue(responsePayload); + } + apiService.delete = jest.fn().mockRejectedValue(responsePayload) // Act - await store.dispatch(deleteListElementsAction(data)); + await store.dispatch(deleteListElementsAction(data)) // Assert const expectedActions = [ deleteListElements(), addErrorNotification(responsePayload as AxiosError), deleteListElementsFailure(errorMessage), - ]; + ] - expect(mockedStore.getActions()).toEqual(expectedActions); - }); - }); - }); -}); + expect(mockedStore.getActions()).toEqual(expectedActions) + }) + }) + }) +}) diff --git a/redisinsight/ui/src/slices/tests/rejson.spec.ts b/redisinsight/ui/src/slices/tests/rejson.spec.ts index c043b10e2f..f389985f09 100644 --- a/redisinsight/ui/src/slices/tests/rejson.spec.ts +++ b/redisinsight/ui/src/slices/tests/rejson.spec.ts @@ -1,14 +1,14 @@ -import { AxiosError } from 'axios'; -import { cloneDeep } from 'lodash'; -import { apiService } from 'uiSrc/services'; +import { AxiosError } from 'axios' +import { cloneDeep } from 'lodash' +import { apiService } from 'uiSrc/services' import { cleanup, initialStateDefault, mockedStore, mockStore, -} from 'uiSrc/utils/test-utils'; -import successMessages from 'uiSrc/components/notifications/success-messages'; -import { GetRejsonRlResponseDto } from 'apiSrc/modules/browser/dto'; +} from 'uiSrc/utils/test-utils' +import successMessages from 'uiSrc/components/notifications/success-messages' +import { GetRejsonRlResponseDto } from 'apiSrc/modules/browser/dto' import reducer, { initialState, loadRejsonBranch, @@ -29,19 +29,19 @@ import reducer, { setReJSONDataAction, appendReJSONArrayItemAction, removeReJSONKeyAction, -} from '../rejson'; -import { addErrorNotification, addMessageNotification } from '../app/notifications'; -import { refreshKeyInfo } from '../keys'; +} from '../rejson' +import { addErrorNotification, addMessageNotification } from '../app/notifications' +import { refreshKeyInfo } from '../keys' -jest.mock('uiSrc/services'); +jest.mock('uiSrc/services') -let store: typeof mockedStore; -let storeWithSelectedKey: typeof mockedStore; -let defaultData: GetRejsonRlResponseDto; +let store: typeof mockedStore +let storeWithSelectedKey: typeof mockedStore +let defaultData: GetRejsonRlResponseDto beforeEach(() => { - cleanup(); - store = cloneDeep(mockedStore); - store.clearActions(); + cleanup() + store = cloneDeep(mockedStore) + store.clearActions() defaultData = { downloaded: false, @@ -50,7 +50,7 @@ beforeEach(() => { { key: 'glossary', path: "['glossary']", cardinality: 2, type: 'object' }, ], type: 'object', - }; + } const rootStateWithSelectedKey = Object.assign(initialStateDefault, { browser: { @@ -62,24 +62,24 @@ beforeEach(() => { }, }, }, - }); + }) - storeWithSelectedKey = mockStore(rootStateWithSelectedKey); -}); + storeWithSelectedKey = mockStore(rootStateWithSelectedKey) +}) describe('rejson slice', () => { describe('reducer, actions and selectors', () => { it('should return the initial state on first run', () => { // Arrange - const nextState = initialState; + const nextState = initialState // Act - const result = reducer(undefined, {}); + const result = reducer(undefined, {}) // Assert - expect(result).toEqual(nextState); - }); - }); + expect(result).toEqual(nextState) + }) + }) describe('loadRejsonBranch', () => { it('should properly set loading = true', () => { @@ -87,20 +87,20 @@ describe('rejson slice', () => { const state = { ...initialState, loading: true, - }; + } // Act - const nextState = reducer(initialState, loadRejsonBranch()); + const nextState = reducer(initialState, loadRejsonBranch()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { rejson: nextState, }, - }); - expect(rejsonSelector(rootState)).toEqual(state); - }); - }); + }) + expect(rejsonSelector(rootState)).toEqual(state) + }) + }) describe('loadRejsonBranchSuccess', () => { it('should properly set the state with fetched data', () => { @@ -110,68 +110,68 @@ describe('rejson slice', () => { ...initialState, loading: false, data: defaultData, - }; + } // Act const nextState = reducer( initialState, loadRejsonBranchSuccess(defaultData) - ); + ) // Assert const rootState = Object.assign(initialStateDefault, { browser: { rejson: nextState, }, - }); - expect(rejsonSelector(rootState)).toEqual(state); - }); + }) + expect(rejsonSelector(rootState)).toEqual(state) + }) it('should properly set the state with empty data', () => { // Arrange - const data: any = []; + const data: any = [] const state = { ...initialState, loading: false, data, - }; + } // Act - const nextState = reducer(initialState, loadRejsonBranchSuccess(data)); + const nextState = reducer(initialState, loadRejsonBranchSuccess(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { rejson: nextState, }, - }); - expect(rejsonSelector(rootState)).toEqual(state); - }); - }); + }) + expect(rejsonSelector(rootState)).toEqual(state) + }) + }) describe('loadRejsonBranchFailure', () => { it('should properly set the error', () => { // Arrange - const data = 'some error'; + const data = 'some error' const state = { ...initialState, loading: false, error: data, - }; + } // Act - const nextState = reducer(initialState, loadRejsonBranchFailure(data)); + const nextState = reducer(initialState, loadRejsonBranchFailure(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { rejson: nextState, }, - }); - expect(rejsonSelector(rootState)).toEqual(state); - }); - }); + }) + expect(rejsonSelector(rootState)).toEqual(state) + }) + }) describe('appendReJSONArrayItem', () => { it('should properly set loading = true', () => { @@ -179,62 +179,62 @@ describe('rejson slice', () => { const state = { ...initialState, loading: true, - }; + } // Act - const nextState = reducer(initialState, appendReJSONArrayItem()); + const nextState = reducer(initialState, appendReJSONArrayItem()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { rejson: nextState, }, - }); - expect(rejsonSelector(rootState)).toEqual(state); - }); - }); + }) + expect(rejsonSelector(rootState)).toEqual(state) + }) + }) describe('appendReJSONArrayItemSuccess', () => { it('should properly set the state after append', () => { const state = { ...initialState, loading: false - }; + } // Act - const nextState = reducer(initialState, appendReJSONArrayItemSuccess()); + const nextState = reducer(initialState, appendReJSONArrayItemSuccess()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { rejson: nextState, }, - }); - expect(rejsonSelector(rootState)).toEqual(state); - }); + }) + expect(rejsonSelector(rootState)).toEqual(state) + }) }) describe('appendReJSONArrayItemFailure', () => { it('should properly set the error', () => { // Arrange - const data = 'some error'; + const data = 'some error' const state = { ...initialState, loading: false, error: data, - }; + } // Act - const nextState = reducer(initialState, appendReJSONArrayItemFailure(data)); + const nextState = reducer(initialState, appendReJSONArrayItemFailure(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { rejson: nextState, }, - }); - expect(rejsonSelector(rootState)).toEqual(state); - }); + }) + expect(rejsonSelector(rootState)).toEqual(state) + }) }) describe('setReJSONData', () => { @@ -243,63 +243,63 @@ describe('rejson slice', () => { const state = { ...initialState, loading: true, - }; + } // Act - const nextState = reducer(initialState, setReJSONData()); + const nextState = reducer(initialState, setReJSONData()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { rejson: nextState, }, - }); - expect(rejsonSelector(rootState)).toEqual(state); - }); - }); + }) + expect(rejsonSelector(rootState)).toEqual(state) + }) + }) describe('setReJSONDataSuccess', () => { it('should properly set the state after append', () => { const state = { ...initialState, loading: false - }; + } // Act - const nextState = reducer(initialState, setReJSONDataSuccess()); + const nextState = reducer(initialState, setReJSONDataSuccess()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { rejson: nextState, }, - }); - expect(rejsonSelector(rootState)).toEqual(state); - }); + }) + expect(rejsonSelector(rootState)).toEqual(state) + }) }) describe('setReJSONDataFailure', () => { it('should properly set the error', () => { // Arrange - const data = 'some error'; + const data = 'some error' const state = { ...initialState, loading: false, error: data, - }; + } // Act - const nextState = reducer(initialState, setReJSONDataFailure(data)); + const nextState = reducer(initialState, setReJSONDataFailure(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { rejson: nextState, }, - }); - expect(rejsonSelector(rootState)).toEqual(state); - }); - }); + }) + expect(rejsonSelector(rootState)).toEqual(state) + }) + }) describe('removeRejsonKey', () => { it('should properly set loading = true', () => { @@ -307,131 +307,130 @@ describe('rejson slice', () => { const state = { ...initialState, loading: true, - }; + } // Act - const nextState = reducer(initialState, removeRejsonKey()); + const nextState = reducer(initialState, removeRejsonKey()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { rejson: nextState, }, - }); - expect(rejsonSelector(rootState)).toEqual(state); - }); - }); + }) + expect(rejsonSelector(rootState)).toEqual(state) + }) + }) describe('removeRejsonKeySuccess', () => { it('should properly set the state after append', () => { const state = { ...initialState, loading: false - }; + } // Act - const nextState = reducer(initialState, removeRejsonKeySuccess()); + const nextState = reducer(initialState, removeRejsonKeySuccess()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { rejson: nextState, }, - }); - expect(rejsonSelector(rootState)).toEqual(state); - }); + }) + expect(rejsonSelector(rootState)).toEqual(state) + }) }) describe('removeRejsonKeyFailure', () => { it('should properly set the error', () => { // Arrange - const data = 'some error'; + const data = 'some error' const state = { ...initialState, loading: false, error: data, - }; + } // Act - const nextState = reducer(initialState, removeRejsonKeyFailure(data)); + const nextState = reducer(initialState, removeRejsonKeyFailure(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { rejson: nextState, }, - }); - expect(rejsonSelector(rootState)).toEqual(state); - }); - }); + }) + expect(rejsonSelector(rootState)).toEqual(state) + }) + }) describe('thunks', () => { describe('fetchReJSON', () => { it('call both fetchReJSON and loadRejsonBranchSuccess when fetch is successed', async () => { // Arrange - const key = 'key'; - const path = '.'; + const key = 'key' + const path = '.' - const responsePayload = { data: defaultData, status: 200 }; + const responsePayload = { data: defaultData, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(fetchReJSON(key, path)); + await store.dispatch(fetchReJSON(key, path)) // Assert const expectedActions = [ loadRejsonBranch(), loadRejsonBranchSuccess(responsePayload.data) - ]; - expect(store.getActions()).toEqual(expectedActions); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) it('call both fetchReJSON and loadRejsonBranchFailure when fetch is fail', async () => { // Arrange - const key = 'key'; - const path = '.'; - const errorMessage = - 'Could not connect to aoeu:123, please check the connection details.'; + const key = 'key' + const path = '.' + const errorMessage = 'Could not connect to aoeu:123, please check the connection details.' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; + } - apiService.post = jest.fn().mockRejectedValueOnce(responsePayload); + apiService.post = jest.fn().mockRejectedValueOnce(responsePayload) // Act - await store.dispatch(fetchReJSON(key, path)); + await store.dispatch(fetchReJSON(key, path)) // Assert const expectedActions = [ loadRejsonBranch(), loadRejsonBranchFailure(responsePayload.response.data.message), addErrorNotification(responsePayload as AxiosError), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) + }) describe('setReJSONDataAction', () => { it('succeed to fetch set json data', async () => { // Arrange - const key = 'key'; - const path = '.'; + const key = 'key' + const path = '.' const data = '{}' - const responsePayload = { status: 200 }; + const responsePayload = { status: 200 } - apiService.patch = jest.fn().mockResolvedValue(responsePayload); + apiService.patch = jest.fn().mockResolvedValue(responsePayload) - const responsePayload2 = { data: defaultData, status: 200 }; + const responsePayload2 = { data: defaultData, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload2); + apiService.post = jest.fn().mockResolvedValue(responsePayload2) // Act - await store.dispatch(setReJSONDataAction(key, path, data)); + await store.dispatch(setReJSONDataAction(key, path, data)) // Assert const expectedActions = [ @@ -439,54 +438,54 @@ describe('rejson slice', () => { setReJSONDataSuccess(), loadRejsonBranch(), refreshKeyInfo() - ]; - expect(store.getActions()).toEqual(expectedActions); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) it('failed to fetch set json data', async () => { // Arrange - const key = 'key'; - const path = '.'; - const errorMessage = 'some error'; + const key = 'key' + const path = '.' + const errorMessage = 'some error' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; + } - apiService.patch = jest.fn().mockRejectedValueOnce(responsePayload); + apiService.patch = jest.fn().mockRejectedValueOnce(responsePayload) // Act - await store.dispatch(setReJSONDataAction(key, path, '{')); + await store.dispatch(setReJSONDataAction(key, path, '{')) // Assert const expectedActions = [ setReJSONData(), setReJSONDataFailure(responsePayload.response.data.message), addErrorNotification(responsePayload as AxiosError), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) + }) describe('appendReJSONArrayItemAction', () => { it('succeed to fetch append array data', async () => { // Arrange - const key = 'key'; - const path = '.'; + const key = 'key' + const path = '.' const data = '123' - const responsePayload = { status: 200 }; + const responsePayload = { status: 200 } - apiService.patch = jest.fn().mockResolvedValue(responsePayload); + apiService.patch = jest.fn().mockResolvedValue(responsePayload) - const responsePayload2 = { data: defaultData, status: 200 }; + const responsePayload2 = { data: defaultData, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload2); + apiService.post = jest.fn().mockResolvedValue(responsePayload2) // Act - await store.dispatch(appendReJSONArrayItemAction(key, path, data)); + await store.dispatch(appendReJSONArrayItemAction(key, path, data)) // Assert const expectedActions = [ @@ -494,54 +493,54 @@ describe('rejson slice', () => { appendReJSONArrayItemSuccess(), loadRejsonBranch(), refreshKeyInfo() - ]; - expect(store.getActions()).toEqual(expectedActions); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) it('failed to fetch append array data', async () => { // Arrange - const key = 'key'; - const path = '.'; - const errorMessage = 'some error'; + const key = 'key' + const path = '.' + const errorMessage = 'some error' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; + } - apiService.patch = jest.fn().mockRejectedValueOnce(responsePayload); + apiService.patch = jest.fn().mockRejectedValueOnce(responsePayload) // Act - await store.dispatch(appendReJSONArrayItemAction(key, path, '{')); + await store.dispatch(appendReJSONArrayItemAction(key, path, '{')) // Assert const expectedActions = [ appendReJSONArrayItem(), appendReJSONArrayItemFailure(responsePayload.response.data.message), addErrorNotification(responsePayload as AxiosError), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) + }) describe('removeReJSONKeyAction', () => { it('succeed to fetch remove json key', async () => { // Arrange - const key = 'key'; - const path = '.'; + const key = 'key' + const path = '.' const jsonKeyName = 'jsonKeyName' - const responsePayload = { status: 200 }; + const responsePayload = { status: 200 } - apiService.delete = jest.fn().mockResolvedValue(responsePayload); + apiService.delete = jest.fn().mockResolvedValue(responsePayload) - const responsePayload2 = { data: defaultData, status: 200 }; + const responsePayload2 = { data: defaultData, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload2); + apiService.post = jest.fn().mockResolvedValue(responsePayload2) // Act - await store.dispatch(removeReJSONKeyAction(key, path, jsonKeyName)); + await store.dispatch(removeReJSONKeyAction(key, path, jsonKeyName)) // Assert const expectedActions = [ @@ -556,56 +555,56 @@ describe('rejson slice', () => { 'JSON key' ) ) - ]; - expect(store.getActions()).toEqual(expectedActions); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) it('failed to fetch remove json key', async () => { // Arrange - const key = 'key'; - const path = '.'; - const errorMessage = 'some error'; + const key = 'key' + const path = '.' + const errorMessage = 'some error' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; + } - apiService.delete = jest.fn().mockRejectedValueOnce(responsePayload); + apiService.delete = jest.fn().mockRejectedValueOnce(responsePayload) // Act - await store.dispatch(removeReJSONKeyAction(key, path)); + await store.dispatch(removeReJSONKeyAction(key, path)) // Assert const expectedActions = [ removeRejsonKey(), removeRejsonKeyFailure(responsePayload.response.data.message), addErrorNotification(responsePayload as AxiosError), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) + }) describe('fetchVisualisationResults', () => { it('call both fetchVisualisationResults and loadRejsonBranchSuccess when fetch is successed', async () => { // Arrange - const path = '.'; + const path = '.' - const responsePayload = { data: defaultData, status: 200 }; + const responsePayload = { data: defaultData, status: 200 } - const expectedResult = defaultData; + const expectedResult = defaultData - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act const result = await storeWithSelectedKey.dispatch( fetchVisualisationResults(path) - ); + ) // Assert - expect(result).toEqual(expectedResult); - }); - }); - }); -}); + expect(result).toEqual(expectedResult) + }) + }) + }) +}) diff --git a/redisinsight/ui/src/slices/tests/sentinel.spec.ts b/redisinsight/ui/src/slices/tests/sentinel.spec.ts index 157d2e9531..260c81fd62 100644 --- a/redisinsight/ui/src/slices/tests/sentinel.spec.ts +++ b/redisinsight/ui/src/slices/tests/sentinel.spec.ts @@ -1,15 +1,15 @@ -import { AxiosError } from 'axios'; -import { cloneDeep } from 'lodash'; +import { AxiosError } from 'axios' +import { cloneDeep } from 'lodash' import { cleanup, initialStateDefault, mockedStore, -} from 'uiSrc/utils/test-utils'; -import { apiService } from 'uiSrc/services'; -import { parseAddedMastersSentinel, parseMastersSentinel } from 'uiSrc/utils'; -import { SentinelMaster } from 'apiSrc/modules/redis-sentinel/models/sentinel'; -import { AddSentinelMasterResponse } from 'apiSrc/modules/instances/dto/redis-sentinel.dto'; +} from 'uiSrc/utils/test-utils' +import { apiService } from 'uiSrc/services' +import { parseAddedMastersSentinel, parseMastersSentinel } from 'uiSrc/utils' +import { SentinelMaster } from 'apiSrc/modules/redis-sentinel/models/sentinel' +import { AddSentinelMasterResponse } from 'apiSrc/modules/instances/dto/redis-sentinel.dto' import reducer, { initialState, @@ -24,22 +24,22 @@ import reducer, { createMastersSentinel, createMastersSentinelFailure, updateMastersSentinel, -} from '../sentinel'; -import { addErrorNotification } from '../app/notifications'; -import { LoadedSentinel, ModifiedSentinelMaster } from '../interfaces'; +} from '../sentinel' +import { addErrorNotification } from '../app/notifications' +import { LoadedSentinel, ModifiedSentinelMaster } from '../interfaces' -jest.mock('uiSrc/services'); +jest.mock('uiSrc/services') -let store: typeof mockedStore; -let masters: SentinelMaster[]; -let parsedMasters: ModifiedSentinelMaster[]; -let parsedAddedMasters: ModifiedSentinelMaster[]; -let addedMastersStatuses: AddSentinelMasterResponse[]; +let store: typeof mockedStore +let masters: SentinelMaster[] +let parsedMasters: ModifiedSentinelMaster[] +let parsedAddedMasters: ModifiedSentinelMaster[] +let addedMastersStatuses: AddSentinelMasterResponse[] beforeEach(() => { - cleanup(); - store = cloneDeep(mockedStore); - store.clearActions(); + cleanup() + store = cloneDeep(mockedStore) + store.clearActions() masters = [ { @@ -59,7 +59,7 @@ beforeEach(() => { { host: '127.0.0.1', port: 5006 }, ], }, - ]; + ] addedMastersStatuses = [ { @@ -79,28 +79,28 @@ beforeEach(() => { error: 'Unauthorized', }, }, - ]; + ] - parsedMasters = parseMastersSentinel(masters); + parsedMasters = parseMastersSentinel(masters) parsedAddedMasters = parseAddedMastersSentinel( parsedMasters, addedMastersStatuses - ); -}); + ) +}) describe('sentinel slice', () => { describe('reducer, actions and selectors', () => { it('should return the initial state on first run', () => { // Arrange - const nextState = initialState; + const nextState = initialState // Act - const result = reducer(undefined, {}); + const result = reducer(undefined, {}) // Assert - expect(result).toEqual(nextState); - }); - }); + expect(result).toEqual(nextState) + }) + }) describe('loadMastersSentinel', () => { it('should properly set loading = true', () => { @@ -108,20 +108,20 @@ describe('sentinel slice', () => { const state = { ...initialState, loading: true, - }; + } // Act - const nextState = reducer(initialState, loadMastersSentinel()); + const nextState = reducer(initialState, loadMastersSentinel()) // Assert const rootState = Object.assign(initialStateDefault, { connections: { sentinel: nextState, }, - }); - expect(sentinelSelector(rootState)).toEqual(state); - }); - }); + }) + expect(sentinelSelector(rootState)).toEqual(state) + }) + }) describe('updateMastersSentinel', () => { it('should properly set loading = true', () => { @@ -129,25 +129,25 @@ describe('sentinel slice', () => { const data: ModifiedSentinelMaster[] = [ { name: 'mymaster', host: 'localhost', port: 0, numberOfSlaves: 10 }, - ]; + ] const state = { ...initialState, data, - }; + } // Act - const nextState = reducer(initialState, updateMastersSentinel(data)); + const nextState = reducer(initialState, updateMastersSentinel(data)) // Assert const rootState = Object.assign(initialStateDefault, { connections: { sentinel: nextState, }, - }); - expect(sentinelSelector(rootState)).toEqual(state); - }); - }); + }) + expect(sentinelSelector(rootState)).toEqual(state) + }) + }) describe('loadMastersSentinelSuccess', () => { it('should properly set the state with fetched data', () => { @@ -161,26 +161,26 @@ describe('sentinel slice', () => { ...initialState.loaded, [LoadedSentinel.Masters]: true, }, - }; + } // Act const nextState = reducer( initialState, loadMastersSentinelSuccess(masters) - ); + ) // Assert const rootState = Object.assign(initialStateDefault, { connections: { sentinel: nextState, }, - }); - expect(sentinelSelector(rootState)).toEqual(state); - }); + }) + expect(sentinelSelector(rootState)).toEqual(state) + }) it('should properly set the state with empty data', () => { // Arrange - const data: any = []; + const data: any = [] const state = { ...initialState, @@ -190,44 +190,44 @@ describe('sentinel slice', () => { ...initialState.loaded, [LoadedSentinel.Masters]: true, }, - }; + } // Act - const nextState = reducer(initialState, loadMastersSentinelSuccess(data)); + const nextState = reducer(initialState, loadMastersSentinelSuccess(data)) // Assert const rootState = Object.assign(initialStateDefault, { connections: { sentinel: nextState, }, - }); - expect(sentinelSelector(rootState)).toEqual(state); - }); - }); + }) + expect(sentinelSelector(rootState)).toEqual(state) + }) + }) describe('loadMastersSentinelFailure', () => { it('should properly set the error', () => { // Arrange - const data = 'some error'; + const data = 'some error' const state = { ...initialState, loading: false, error: data, data: [], - }; + } // Act - const nextState = reducer(initialState, loadMastersSentinelFailure(data)); + const nextState = reducer(initialState, loadMastersSentinelFailure(data)) // Assert const rootState = Object.assign(initialStateDefault, { connections: { sentinel: nextState, }, - }); - expect(sentinelSelector(rootState)).toEqual(state); - }); - }); + }) + expect(sentinelSelector(rootState)).toEqual(state) + }) + }) describe('createMastersSentinel', () => { it('should properly set loading = true', () => { @@ -235,20 +235,20 @@ describe('sentinel slice', () => { const state = { ...initialState, loading: true, - }; + } // Act - const nextState = reducer(initialState, createMastersSentinel()); + const nextState = reducer(initialState, createMastersSentinel()) // Assert const rootState = Object.assign(initialStateDefault, { connections: { sentinel: nextState, }, - }); - expect(sentinelSelector(rootState)).toEqual(state); - }); - }); + }) + expect(sentinelSelector(rootState)).toEqual(state) + }) + }) describe('createMastersSentinelSuccess', () => { it('should properly set the state with fetched data', () => { @@ -263,26 +263,26 @@ describe('sentinel slice', () => { ...initialState.loaded, [LoadedSentinel.MastersAdded]: true, }, - }; + } // Act const nextState = reducer( { ...initialState, data: parsedMasters }, createMastersSentinelSuccess(addedMastersStatuses) - ); + ) // Assert const rootState = Object.assign(initialStateDefault, { connections: { sentinel: nextState, }, - }); - expect(sentinelSelector(rootState)).toEqual(state); - }); + }) + expect(sentinelSelector(rootState)).toEqual(state) + }) it('should properly set the state with empty data', () => { // Arrange - const data: any = []; + const data: any = [] const state = { ...initialState, @@ -292,50 +292,50 @@ describe('sentinel slice', () => { ...initialState.loaded, [LoadedSentinel.MastersAdded]: true, }, - }; + } // Act const nextState = reducer( initialState, createMastersSentinelSuccess(data) - ); + ) // Assert const rootState = Object.assign(initialStateDefault, { connections: { sentinel: nextState, }, - }); - expect(sentinelSelector(rootState)).toEqual(state); - }); - }); + }) + expect(sentinelSelector(rootState)).toEqual(state) + }) + }) describe('createMastersSentinelFailure', () => { it('should properly set the error', () => { // Arrange - const data = 'some error'; + const data = 'some error' const state = { ...initialState, loading: false, error: data, data: [], - }; + } // Act const nextState = reducer( initialState, createMastersSentinelFailure(data) - ); + ) // Assert const rootState = Object.assign(initialStateDefault, { connections: { sentinel: nextState, }, - }); - expect(sentinelSelector(rootState)).toEqual(state); - }); - }); + }) + expect(sentinelSelector(rootState)).toEqual(state) + }) + }) describe('thunks', () => { it('call both fetchMastersSentinelAction and loadMastersSentinelSuccess when fetch is successed', async () => { @@ -343,54 +343,53 @@ describe('sentinel slice', () => { const requestData = { host: 'localhost', port: 5005, - }; + } - const responsePayload = { data: masters, status: 200 }; + const responsePayload = { data: masters, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(fetchMastersSentinelAction(requestData)); + await store.dispatch(fetchMastersSentinelAction(requestData)) // Assert const expectedActions = [ loadMastersSentinel(), setInstanceSentinel(requestData), loadMastersSentinelSuccess(responsePayload.data), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) it('call both fetchMastersSentinelAction and loadMastersSentinelFailure when fetch is fail', async () => { // Arrange const requestData = { host: 'localhost', port: 5005, - }; + } - const errorMessage = - 'Could not connect to aoeu:123, please check the connection details.'; + const errorMessage = 'Could not connect to aoeu:123, please check the connection details.' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; + } - apiService.post = jest.fn().mockRejectedValueOnce(responsePayload); + apiService.post = jest.fn().mockRejectedValueOnce(responsePayload) // Act - await store.dispatch(fetchMastersSentinelAction(requestData)); + await store.dispatch(fetchMastersSentinelAction(requestData)) // Assert const expectedActions = [ loadMastersSentinel(), loadMastersSentinelFailure(responsePayload.response.data.message), addErrorNotification(responsePayload as AxiosError), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) + }) it('call both createMastersSentinelAction and createMastersSentinelSuccess when fetch is successed', async () => { // Arrange @@ -405,22 +404,22 @@ describe('sentinel slice', () => { username: 'egor', password: '123', }, - ]; + ] - const responsePayload = { data: addedMastersStatuses, status: 200 }; + const responsePayload = { data: addedMastersStatuses, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(createMastersSentinelAction(requestData)); + await store.dispatch(createMastersSentinelAction(requestData)) // Assert const expectedActions = [ createMastersSentinel(), createMastersSentinelSuccess(responsePayload.data), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) it('call both createMastersSentinelAction and createMastersSentinelFailure when fetch is fail', async () => { // Arrange @@ -435,28 +434,27 @@ describe('sentinel slice', () => { username: 'egor', password: '123', }, - ]; + ] - const errorMessage = - 'Could not connect to aoeu:123, please check the connection details.'; + const errorMessage = 'Could not connect to aoeu:123, please check the connection details.' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; + } - apiService.post = jest.fn().mockRejectedValueOnce(responsePayload); + apiService.post = jest.fn().mockRejectedValueOnce(responsePayload) // Act - await store.dispatch(createMastersSentinelAction(requestData)); + await store.dispatch(createMastersSentinelAction(requestData)) // Assert const expectedActions = [ createMastersSentinel(), createMastersSentinelFailure(responsePayload.response.data.message), addErrorNotification(responsePayload as AxiosError), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); -}); + ] + expect(store.getActions()).toEqual(expectedActions) + }) +}) diff --git a/redisinsight/ui/src/slices/tests/set.spec.ts b/redisinsight/ui/src/slices/tests/set.spec.ts index 20cbc920aa..a968320bae 100644 --- a/redisinsight/ui/src/slices/tests/set.spec.ts +++ b/redisinsight/ui/src/slices/tests/set.spec.ts @@ -1,21 +1,21 @@ -import { cloneDeep } from 'lodash'; -import { AxiosError } from 'axios'; -import { apiService } from 'uiSrc/services'; +import { cloneDeep } from 'lodash' +import { AxiosError } from 'axios' +import { apiService } from 'uiSrc/services' import { cleanup, initialStateDefault, mockedStore, mockStore, -} from 'uiSrc/utils/test-utils'; -import { addErrorNotification, addMessageNotification } from 'uiSrc/slices/app/notifications'; -import successMessages from 'uiSrc/components/notifications/success-messages'; +} from 'uiSrc/utils/test-utils' +import { addErrorNotification, addMessageNotification } from 'uiSrc/slices/app/notifications' +import successMessages from 'uiSrc/components/notifications/success-messages' import { defaultSelectedKeyAction, deleteKeyFromList, deleteKeySuccess, refreshKeyInfo, updateSelectedKeyRefreshTime, -} from '../keys'; +} from '../keys' import reducer, { initialState, loadMoreSetMembers, @@ -36,39 +36,39 @@ import reducer, { fetchMoreSetMembers, addSetMembersAction, deleteSetMembers, -} from '../set'; +} from '../set' -jest.mock('uiSrc/services'); +jest.mock('uiSrc/services') -let store: typeof mockedStore; -let dateNow: jest.SpyInstance; +let store: typeof mockedStore +let dateNow: jest.SpyInstance beforeEach(() => { - cleanup(); - store = cloneDeep(mockedStore); - store.clearActions(); -}); + cleanup() + store = cloneDeep(mockedStore) + store.clearActions() +}) describe('set slice', () => { beforeAll(() => { - dateNow = jest.spyOn(Date, 'now').mockImplementation(() => 1629128049027); - }); + dateNow = jest.spyOn(Date, 'now').mockImplementation(() => 1629128049027) + }) afterAll(() => { - dateNow.mockRestore(); - }); + dateNow.mockRestore() + }) describe('reducer, actions and selectors', () => { it('should return the initial state on first run', () => { // Arrange - const nextState = initialState; + const nextState = initialState // Act - const result = reducer(undefined, {}); + const result = reducer(undefined, {}) // Assert - expect(result).toEqual(nextState); - }); - }); + expect(result).toEqual(nextState) + }) + }) describe('loadSetMembers', () => { it('should properly set the state before the fetch data', () => { @@ -76,18 +76,18 @@ describe('set slice', () => { const state = { ...initialState, loading: true, - }; + } // Act - const nextState = reducer(initialState, loadSetMembers('')); + const nextState = reducer(initialState, loadSetMembers('')) // Assert const rootState = Object.assign(initialStateDefault, { browser: { set: nextState }, - }); - expect(setSelector(rootState)).toEqual(state); - }); - }); + }) + expect(setSelector(rootState)).toEqual(state) + }) + }) describe('loadSetMembersSuccess', () => { it('should properly set the state with fetched data', () => { @@ -101,29 +101,29 @@ describe('set slice', () => { nextCursor: 67, members: ['1', '2'], match: '*1*' - }; + } const state = { loading: false, error: '', data, - }; + } // Act - const nextState = reducer(initialState, loadSetMembersSuccess(data)); + const nextState = reducer(initialState, loadSetMembersSuccess(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { set: nextState }, - }); - expect(setSelector(rootState)).toEqual(state); - }); + }) + expect(setSelector(rootState)).toEqual(state) + }) it('should properly set the state with empty data', () => { // Arrange const data: any = { keyName: '' - }; + } const state = { loading: false, @@ -132,23 +132,23 @@ describe('set slice', () => { ...initialState.data, ...data }, - }; + } // Act - const nextState = reducer(initialState, loadSetMembersSuccess(data)); + const nextState = reducer(initialState, loadSetMembersSuccess(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { set: nextState }, - }); - expect(setSelector(rootState)).toEqual(state); - }); - }); + }) + expect(setSelector(rootState)).toEqual(state) + }) + }) describe('loadSetMembersFailure', () => { it('should properly set the error', () => { // Arrange - const data = 'some error'; + const data = 'some error' const state = { loading: false, error: data, @@ -160,18 +160,18 @@ describe('set slice', () => { nextCursor: 0, match: '*' }, - }; + } // Act - const nextState = reducer(initialState, loadSetMembersFailure(data)); + const nextState = reducer(initialState, loadSetMembersFailure(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { set: nextState }, - }); - expect(setSelector(rootState)).toEqual(state); - }); - }); + }) + expect(setSelector(rootState)).toEqual(state) + }) + }) describe('loadMoreSetMembers', () => { it('should properly set the state before the fetch data', () => { @@ -187,18 +187,18 @@ describe('set slice', () => { nextCursor: 0, match: '*' }, - }; + } // Act - const nextState = reducer(initialState, loadMoreSetMembers()); + const nextState = reducer(initialState, loadMoreSetMembers()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { set: nextState }, - }); - expect(setSelector(rootState)).toEqual(state); - }); - }); + }) + expect(setSelector(rootState)).toEqual(state) + }) + }) describe('loadMoreSetMembersSuccess', () => { it('should properly set the state with fetched data', () => { @@ -211,23 +211,23 @@ describe('set slice', () => { total: 0, members: ['2', '3'], match: '*2*' - }; + } const state = { loading: false, error: '', data, - }; + } // Act - const nextState = reducer(initialState, loadMoreSetMembersSuccess(data)); + const nextState = reducer(initialState, loadMoreSetMembersSuccess(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { set: nextState }, - }); - expect(setSelector(rootState)).toEqual(state); - }); + }) + expect(setSelector(rootState)).toEqual(state) + }) it('should properly set the state with empty data', () => { // Arrange @@ -237,7 +237,7 @@ describe('set slice', () => { total: 10, nextCursor: 67, members: [], - }; + } const state = { ...initialState, @@ -246,23 +246,23 @@ describe('set slice', () => { ...initialState.data, ...data, }, - }; + } // Act - const nextState = reducer(initialState, loadMoreSetMembersSuccess(data)); + const nextState = reducer(initialState, loadMoreSetMembersSuccess(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { set: nextState }, - }); - expect(setSelector(rootState)).toEqual(state); - }); - }); + }) + expect(setSelector(rootState)).toEqual(state) + }) + }) describe('loadMoreSetMembersFailure', () => { it('should properly set the error', () => { // Arrange - const data = 'some error'; + const data = 'some error' const state = { loading: false, error: data, @@ -274,18 +274,18 @@ describe('set slice', () => { nextCursor: 0, match: '*' }, - }; + } // Act - const nextState = reducer(initialState, loadMoreSetMembersFailure(data)); + const nextState = reducer(initialState, loadMoreSetMembersFailure(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { set: nextState }, - }); - expect(setSelector(rootState)).toEqual(state); - }); - }); + }) + expect(setSelector(rootState)).toEqual(state) + }) + }) describe('addSetMembers', () => { it('should properly set the state before the fetch data', () => { @@ -293,18 +293,18 @@ describe('set slice', () => { const state = { ...initialState, loading: true, - }; + } // Act - const nextState = reducer(initialState, addSetMembers()); + const nextState = reducer(initialState, addSetMembers()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { set: nextState }, - }); - expect(setSelector(rootState)).toEqual(state); - }); - }); + }) + expect(setSelector(rootState)).toEqual(state) + }) + }) describe('addSetMembersSuccess', () => { it('should properly set the state with fetched data', () => { @@ -312,39 +312,39 @@ describe('set slice', () => { const state = { ...initialState, loading: false, - }; + } // Act - const nextState = reducer(initialState, addSetMembersSuccess()); + const nextState = reducer(initialState, addSetMembersSuccess()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { set: nextState }, - }); - expect(setSelector(rootState)).toEqual(state); - }); - }); + }) + expect(setSelector(rootState)).toEqual(state) + }) + }) describe('addSetMembersFailure', () => { it('should properly set the error', () => { // Arrange - const data = 'some error'; + const data = 'some error' const state = { ...initialState, loading: false, error: data - }; + } // Act - const nextState = reducer(initialState, addSetMembersFailure(data)); + const nextState = reducer(initialState, addSetMembersFailure(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { set: nextState }, - }); - expect(setSelector(rootState)).toEqual(state); - }); - }); + }) + expect(setSelector(rootState)).toEqual(state) + }) + }) describe('removeSetMembers', () => { it('should properly set the state before the fetch data', () => { @@ -352,18 +352,18 @@ describe('set slice', () => { const state = { ...initialState, loading: true, - }; + } // Act - const nextState = reducer(initialState, removeSetMembers()); + const nextState = reducer(initialState, removeSetMembers()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { set: nextState }, - }); - expect(setSelector(rootState)).toEqual(state); - }); - }); + }) + expect(setSelector(rootState)).toEqual(state) + }) + }) describe('removeSetMembersSuccess', () => { it('should properly set the state with fetched data', () => { @@ -375,23 +375,23 @@ describe('set slice', () => { ...initialState.data, members: ['1', '2', '3'], }, - }; + } // Act - const nextState = reducer(initailStateRemove, removeSetMembersSuccess()); + const nextState = reducer(initailStateRemove, removeSetMembersSuccess()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { set: nextState }, - }); - expect(setSelector(rootState)).toEqual(initailStateRemove); - }); - }); + }) + expect(setSelector(rootState)).toEqual(initailStateRemove) + }) + }) describe('removeSetMembersFailure', () => { it('should properly set the error', () => { // Arrange - const data = 'some error'; + const data = 'some error' const state = { loading: false, error: data, @@ -403,18 +403,18 @@ describe('set slice', () => { nextCursor: 0, match: '*' }, - }; + } // Act - const nextState = reducer(initialState, removeSetMembersFailure(data)); + const nextState = reducer(initialState, removeSetMembersFailure(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { set: nextState }, - }); - expect(setSelector(rootState)).toEqual(state); - }); - }); + }) + expect(setSelector(rootState)).toEqual(state) + }) + }) describe('removeMembersFromList', () => { it('should properly set the error', () => { // Arrange @@ -424,9 +424,9 @@ describe('set slice', () => { ...initialState.data, members: ['1', '2', '3'], }, - }; + } - const data = ['1', '3']; + const data = ['1', '3'] const state = { ...initailStateRemove, @@ -435,21 +435,21 @@ describe('set slice', () => { total: initailStateRemove.data.total - 1, members: ['2'], }, - }; + } // Act const nextState = reducer( initailStateRemove, removeMembersFromList(data) - ); + ) // Assert const rootState = Object.assign(initialStateDefault, { browser: { set: nextState }, - }); - expect(setSelector(rootState)).toEqual(state); - }); - }); + }) + expect(setSelector(rootState)).toEqual(state) + }) + }) describe('thunks', () => { describe('fetchSetMembers', () => { @@ -460,50 +460,50 @@ describe('set slice', () => { members: ['123', '123', '1'], total: 3, match: '*' - }; + } it('call fetchSetMembers, loadSetMembersSuccess when fetch is successed', async () => { // Arrange - const responsePayload = { data, status: 200 }; + const responsePayload = { data, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(fetchSetMembers(data.keyName, 0, 20, '*')); + await store.dispatch(fetchSetMembers(data.keyName, 0, 20, '*')) // Assert const expectedActions = [ loadSetMembers(data.match), loadSetMembersSuccess(responsePayload.data), updateSelectedKeyRefreshTime(Date.now()), - ]; + ] - expect(store.getActions()).toEqual(expectedActions); - }); + expect(store.getActions()).toEqual(expectedActions) + }) it('failed to fetch Set members', async () => { // Arrange - const errorMessage = 'Something was wrong!'; + const errorMessage = 'Something was wrong!' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; - apiService.post = jest.fn().mockRejectedValue(responsePayload); + } + apiService.post = jest.fn().mockRejectedValue(responsePayload) // Act - await store.dispatch(fetchSetMembers(data.keyName, 0, 20, '*')); + await store.dispatch(fetchSetMembers(data.keyName, 0, 20, '*')) // Assert const expectedActions = [ loadSetMembers('*'), addErrorNotification(responsePayload as AxiosError), loadSetMembersFailure(errorMessage), - ]; + ] - expect(mockedStore.getActions()).toEqual(expectedActions); - }); - }); - }); + expect(mockedStore.getActions()).toEqual(expectedActions) + }) + }) + }) describe('fetchMoreSetMembers', () => { // Arrange @@ -512,101 +512,101 @@ describe('set slice', () => { nextCursor: 0, members: ['123', '123', '1'], total: 3, - }; + } it('call fetchMoreSetMembers, loadMoreSetMembersSuccess when fetch is successed', async () => { - const responsePayload = { data, status: 200 }; + const responsePayload = { data, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(fetchMoreSetMembers(data.keyName, 0, 20, '*')); + await store.dispatch(fetchMoreSetMembers(data.keyName, 0, 20, '*')) // Assert const expectedActions = [ loadMoreSetMembers(), loadMoreSetMembersSuccess(responsePayload.data), - ]; + ] - expect(mockedStore.getActions()).toEqual(expectedActions); - }); + expect(mockedStore.getActions()).toEqual(expectedActions) + }) it('failed to fetch more Set members', async () => { // Arrange - const errorMessage = 'Something was wrong!'; + const errorMessage = 'Something was wrong!' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; - apiService.post = jest.fn().mockRejectedValue(responsePayload); + } + apiService.post = jest.fn().mockRejectedValue(responsePayload) // Act - await store.dispatch(fetchMoreSetMembers(data.keyName, 0, 20, '*')); + await store.dispatch(fetchMoreSetMembers(data.keyName, 0, 20, '*')) // Assert const expectedActions = [ loadMoreSetMembers(), addErrorNotification(responsePayload as AxiosError), loadMoreSetMembersFailure(errorMessage), - ]; + ] - expect(mockedStore.getActions()).toEqual(expectedActions); - }); - }); + expect(mockedStore.getActions()).toEqual(expectedActions) + }) + }) describe('addSetMembersAction', () => { - const keyName = 'key'; - const members = ['member1', 'member2']; + const keyName = 'key' + const members = ['member1', 'member2'] it('succeed to add members to set', async () => { // Arrange - const responsePayload = { status: 200 }; - apiService.put = jest.fn().mockResolvedValue(responsePayload); + const responsePayload = { status: 200 } + apiService.put = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(addSetMembersAction({ keyName, members }, jest.fn)); + await store.dispatch(addSetMembersAction({ keyName, members }, jest.fn)) // Assert const expectedActions = [ addSetMembers(), addSetMembersSuccess(), defaultSelectedKeyAction(), - ]; + ] - expect(mockedStore.getActions()).toEqual(expectedActions); - }); + expect(mockedStore.getActions()).toEqual(expectedActions) + }) it('failed to add members to set', async () => { // Arrange - const errorMessage = 'Something was wrong!'; + const errorMessage = 'Something was wrong!' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; - apiService.put = jest.fn().mockRejectedValue(responsePayload); + } + apiService.put = jest.fn().mockRejectedValue(responsePayload) // Act - await store.dispatch(addSetMembersAction({ keyName, members }, jest.fn(), jest.fn())); + await store.dispatch(addSetMembersAction({ keyName, members }, jest.fn(), jest.fn())) // Assert const expectedActions = [ addSetMembers(), addErrorNotification(responsePayload as AxiosError), addSetMembersFailure(errorMessage), - ]; + ] - expect(mockedStore.getActions()).toEqual(expectedActions); - }); - }); + expect(mockedStore.getActions()).toEqual(expectedActions) + }) + }) describe('deleteSetMembers', () => { - const key = 'key'; - const members = ['123', '123', '1']; + const key = 'key' + const members = ['123', '123', '1'] it('call removeSetMembers, removeSetMembersSuccess, and removeMembersFromList when fetch is successed', async () => { // Arrange - const responsePayload = { status: 200, data: { affected: 3 } }; + const responsePayload = { status: 200, data: { affected: 3 } } - apiService.delete = jest.fn().mockResolvedValue(responsePayload); + apiService.delete = jest.fn().mockResolvedValue(responsePayload) const nextState = Object.assign(initialStateDefault, { browser: { set: { @@ -617,12 +617,12 @@ describe('set slice', () => { } } }, - }); + }) - const mockedStore = mockStore(nextState); + const mockedStore = mockStore(nextState) // Act - await mockedStore.dispatch(deleteSetMembers(key, members)); + await mockedStore.dispatch(deleteSetMembers(key, members)) // Assert const expectedActions = [ @@ -637,16 +637,16 @@ describe('set slice', () => { 'Member' ) ) - ]; + ] - expect(mockedStore.getActions()).toEqual(expectedActions); - }); + expect(mockedStore.getActions()).toEqual(expectedActions) + }) it('succeed to delete all members from set', async () => { // Arrange - const responsePayload = { status: 200, data: { affected: 3 } }; + const responsePayload = { status: 200, data: { affected: 3 } } - apiService.delete = jest.fn().mockResolvedValue(responsePayload); + apiService.delete = jest.fn().mockResolvedValue(responsePayload) const nextState = Object.assign(initialStateDefault, { browser: { set: { @@ -657,12 +657,12 @@ describe('set slice', () => { } } }, - }); + }) - const mockedStore = mockStore(nextState); + const mockedStore = mockStore(nextState) // Act - await mockedStore.dispatch(deleteSetMembers(key, members)); + await mockedStore.dispatch(deleteSetMembers(key, members)) // Assert const expectedActions = [ @@ -672,33 +672,33 @@ describe('set slice', () => { deleteKeySuccess(), deleteKeyFromList(key), addMessageNotification(successMessages.DELETED_KEY(key)) - ]; + ] - expect(mockedStore.getActions()).toEqual(expectedActions); - }); + expect(mockedStore.getActions()).toEqual(expectedActions) + }) it('failed to delete member from set', async () => { // Arrange - const errorMessage = 'Something was wrong!'; + const errorMessage = 'Something was wrong!' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; - apiService.delete = jest.fn().mockRejectedValue(responsePayload); + } + apiService.delete = jest.fn().mockRejectedValue(responsePayload) // Act - await store.dispatch(deleteSetMembers(key, members)); + await store.dispatch(deleteSetMembers(key, members)) // Assert const expectedActions = [ removeSetMembers(), addErrorNotification(responsePayload as AxiosError), removeSetMembersFailure(errorMessage), - ]; + ] - expect(mockedStore.getActions()).toEqual(expectedActions); - }); - }); -}); + expect(mockedStore.getActions()).toEqual(expectedActions) + }) + }) +}) diff --git a/redisinsight/ui/src/slices/tests/string.spec.ts b/redisinsight/ui/src/slices/tests/string.spec.ts index e10eb05973..66bf49068f 100644 --- a/redisinsight/ui/src/slices/tests/string.spec.ts +++ b/redisinsight/ui/src/slices/tests/string.spec.ts @@ -1,7 +1,9 @@ -import { AxiosError } from 'axios'; -import { cloneDeep } from 'lodash'; -import { apiService } from 'uiSrc/services'; -import { refreshKeyInfo } from '../keys'; +import { AxiosError } from 'axios' +import { cloneDeep } from 'lodash' +import { apiService } from 'uiSrc/services' +import { cleanup, initialStateDefault, mockedStore } from 'uiSrc/utils/test-utils' +import { addErrorNotification } from 'uiSrc/slices/app/notifications' +import { refreshKeyInfo } from '../keys' import reducer, { initialState, getString, @@ -15,33 +17,29 @@ import reducer, { updateValueFailure, resetStringValue, updateStringValueAction -} from '../string'; -import { cleanup, initialStateDefault, mockedStore } from 'uiSrc/utils/test-utils'; -import { addErrorNotification } from 'uiSrc/slices/app/notifications'; +} from '../string' - -let store: typeof mockedStore; +let store: typeof mockedStore beforeEach(() => { - cleanup(); - store = cloneDeep(mockedStore); - store.clearActions(); -}); -jest.mock('uiSrc/services'); - + cleanup() + store = cloneDeep(mockedStore) + store.clearActions() +}) +jest.mock('uiSrc/services') describe('string slice', () => { describe('reducer, actions and selectors', () => { it('should return the initial state on first run', () => { // Arrange - const nextState = initialState; + const nextState = initialState // Act - const result = reducer(undefined, {}); + const result = reducer(undefined, {}) // Assert - expect(result).toEqual(nextState); - }); - }); + expect(result).toEqual(nextState) + }) + }) describe('getString', () => { it('should properly set the state before the fetch data', () => { @@ -49,21 +47,21 @@ describe('string slice', () => { const state = { ...initialState, loading: true, - }; + } // Act - const nextState = reducer(initialState, getString()); + const nextState = reducer(initialState, getString()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { string: nextState, }, - }); - expect(stringSelector(rootState)).toEqual(state); - expect(stringDataSelector(rootState)).toEqual(state.data); - }); - }); + }) + expect(stringSelector(rootState)).toEqual(state) + expect(stringDataSelector(rootState)).toEqual(state.data) + }) + }) describe('getStringSuccess', () => { it('should properly set the state with fetched data', () => { @@ -71,7 +69,7 @@ describe('string slice', () => { const data = { keyName: 'zxc', value: 'val' - }; + } const state = { ...initialState, loading: false, @@ -79,27 +77,27 @@ describe('string slice', () => { key: data.keyName, value: data.value } - }; + } // Act - const nextState = reducer(initialState, getStringSuccess(data)); + const nextState = reducer(initialState, getStringSuccess(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { string: nextState, }, - }); - expect(stringSelector(rootState)).toEqual(state); - expect(stringDataSelector(rootState)).toEqual(state.data); - }); + }) + expect(stringSelector(rootState)).toEqual(state) + expect(stringDataSelector(rootState)).toEqual(state.data) + }) it('should properly set the state with empty data', () => { // Arrange const data = { keyName: '', value: '' - }; + } const state = { ...initialState, @@ -108,45 +106,45 @@ describe('string slice', () => { key: data.keyName, value: data.value } - }; + } // Act - const nextState = reducer(initialState, getStringSuccess(data)); + const nextState = reducer(initialState, getStringSuccess(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { string: nextState, }, - }); - expect(stringSelector(rootState)).toEqual(state); - expect(stringDataSelector(rootState)).toEqual(state.data); - }); - }); + }) + expect(stringSelector(rootState)).toEqual(state) + expect(stringDataSelector(rootState)).toEqual(state.data) + }) + }) describe('getStringFailure', () => { it('should properly set the error', () => { // Arrange - const data = 'some error'; + const data = 'some error' const state = { ...initialState, loading: false, error: data, - }; + } // Act - const nextState = reducer(initialState, getStringFailure(data)); + const nextState = reducer(initialState, getStringFailure(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { string: nextState, }, - }); - expect(stringSelector(rootState)).toEqual(state); - expect(stringDataSelector(rootState)).toEqual(state.data); - }); - }); + }) + expect(stringSelector(rootState)).toEqual(state) + expect(stringDataSelector(rootState)).toEqual(state.data) + }) + }) describe('updateValue', () => { it('should properly set the state before the fetch data', () => { @@ -154,27 +152,27 @@ describe('string slice', () => { const state = { ...initialState, loading: true, - }; + } // Act - const nextState = reducer(initialState, updateValue()); + const nextState = reducer(initialState, updateValue()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { string: nextState, }, - }); - expect(stringSelector(rootState)).toEqual(state); - expect(stringDataSelector(rootState)).toEqual(state.data); - }); - }); + }) + expect(stringSelector(rootState)).toEqual(state) + expect(stringDataSelector(rootState)).toEqual(state.data) + }) + }) describe('updateValueSuccess', () => { it('should properly set the state with fetched data', () => { // Arrange - const data = 'test test'; + const data = 'test test' const state = { ...initialState, loading: false, @@ -182,24 +180,24 @@ describe('string slice', () => { ...initialState.data, value: data }, - }; + } // Act - const nextState = reducer(initialState, updateValueSuccess(data)); + const nextState = reducer(initialState, updateValueSuccess(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { string: nextState, }, - }); - expect(stringSelector(rootState)).toEqual(state); - expect(stringDataSelector(rootState)).toEqual(state.data); - }); + }) + expect(stringSelector(rootState)).toEqual(state) + expect(stringDataSelector(rootState)).toEqual(state.data) + }) it('should properly set the state with empty data', () => { // Arrange - const data = ''; + const data = '' const state = { ...initialState, @@ -208,89 +206,88 @@ describe('string slice', () => { ...initialState.data, value: data }, - }; + } // Act - const nextState = reducer(initialState, updateValueSuccess(data)); + const nextState = reducer(initialState, updateValueSuccess(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { string: nextState, }, - }); - expect(stringSelector(rootState)).toEqual(state); - expect(stringDataSelector(rootState)).toEqual(state.data); - }); - }); + }) + expect(stringSelector(rootState)).toEqual(state) + expect(stringDataSelector(rootState)).toEqual(state.data) + }) + }) describe('updateValueFailure', () => { it('should properly set the error', () => { // Arrange - const data = 'some error'; + const data = 'some error' const state = { ...initialState, loading: false, error: data, - }; + } // Act - const nextState = reducer(initialState, updateValueFailure(data)); + const nextState = reducer(initialState, updateValueFailure(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { string: nextState, }, - }); - expect(stringSelector(rootState)).toEqual(state); - expect(stringDataSelector(rootState)).toEqual(state.data); - }); - }); + }) + expect(stringSelector(rootState)).toEqual(state) + expect(stringDataSelector(rootState)).toEqual(state.data) + }) + }) describe('resetStringValue', () => { it('should properly set the error', () => { // Arrange const state = { ...initialState - }; + } // Act - const nextState = reducer(initialState, resetStringValue()); + const nextState = reducer(initialState, resetStringValue()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { string: nextState, }, - }); - expect(stringSelector(rootState)).toEqual(state); - expect(stringDataSelector(rootState)).toEqual(state.data); - }); - }); - + }) + expect(stringSelector(rootState)).toEqual(state) + expect(stringDataSelector(rootState)).toEqual(state.data) + }) + }) describe('thunks', () => { describe('fetchString', () => { it('call both fetchString, getStringSuccess when fetch is successed', async () => { // Arrange - const data = 'test'; - const responsePayload = {data, status: 200}; + const data = 'test' + const responsePayload = { data, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(fetchString('')); + await store.dispatch(fetchString('')) // Assert const expectedActions = [ getString(), getStringSuccess(responsePayload.data), - ]; + ] - expect(store.getActions()).toEqual(expectedActions); - }); - }); + expect(store.getActions()).toEqual(expectedActions) + }) + }) describe('updateStringValueAction', () => { it('succeed to fetch update string value', async () => { @@ -299,49 +296,49 @@ describe('string slice', () => { keyName: 'stringKey', value: 'string value' } - const responsePayload = { status: 200 }; + const responsePayload = { status: 200 } - apiService.put = jest.fn().mockResolvedValue(responsePayload); + apiService.put = jest.fn().mockResolvedValue(responsePayload) // Act await store.dispatch( updateStringValueAction(data.keyName, data.value, jest.fn()) - ); + ) // Assert const expectedActions = [ updateValue(), updateValueSuccess(data.value), refreshKeyInfo() - ]; + ] - expect(store.getActions()).toEqual(expectedActions); - }); + expect(store.getActions()).toEqual(expectedActions) + }) it('failed to fetch update string value', async () => { - const errorMessage = 'Something was wrong!'; + const errorMessage = 'Something was wrong!' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; - apiService.put = jest.fn().mockRejectedValue(responsePayload); + } + apiService.put = jest.fn().mockRejectedValue(responsePayload) // Act await store.dispatch( updateStringValueAction('', '', jest.fn(), jest.fn()) - ); + ) // Assert const expectedActions = [ updateValue(), addErrorNotification(responsePayload as AxiosError), updateValueFailure(errorMessage) - ]; + ] - expect(store.getActions()).toEqual(expectedActions); - }); - }); - }); -}); + expect(store.getActions()).toEqual(expectedActions) + }) + }) + }) +}) diff --git a/redisinsight/ui/src/slices/tests/user/settings.spec.ts b/redisinsight/ui/src/slices/tests/user/settings.spec.ts index dabfeb7192..565603a3cb 100644 --- a/redisinsight/ui/src/slices/tests/user/settings.spec.ts +++ b/redisinsight/ui/src/slices/tests/user/settings.spec.ts @@ -1,9 +1,9 @@ -import { cloneDeep } from 'lodash'; -import { AxiosError } from 'axios'; +import { cloneDeep } from 'lodash' +import { AxiosError } from 'axios' -import { apiService } from 'uiSrc/services'; -import { cleanup, mockedStore, initialStateDefault } from 'uiSrc/utils/test-utils'; -import { addErrorNotification } from 'uiSrc/slices/app/notifications'; +import { apiService } from 'uiSrc/services' +import { cleanup, mockedStore, initialStateDefault } from 'uiSrc/utils/test-utils' +import { addErrorNotification } from 'uiSrc/slices/app/notifications' import reducer, { initialState, @@ -22,47 +22,46 @@ import reducer, { fetchUserSettingsSpec, updateUserConfigSettingsAction, userSettingsSelector -} from '../../user/user-settings'; +} from '../../user/user-settings' -let store: typeof mockedStore; +let store: typeof mockedStore beforeEach(() => { - cleanup(); - store = cloneDeep(mockedStore); - store.clearActions(); -}); + cleanup() + store = cloneDeep(mockedStore) + store.clearActions() +}) describe('userSettings slice', () => { describe('reducer, actions and selectors', () => { it('should return the initial state on first run', () => { // Arrange - const nextState = initialState; + const nextState = initialState // Act - const result = reducer(undefined, {}); + const result = reducer(undefined, {}) // Assert - expect(result).toEqual(nextState); - }); - }); + expect(result).toEqual(nextState) + }) + }) describe('setUserSettingsInitialState', () => { it('should properly set the initial state', () => { // Arrange const state = { ...initialState - }; + } // Act - const nextState = reducer(initialState, setUserSettingsInitialState()); + const nextState = reducer(initialState, setUserSettingsInitialState()) // Assert const rootState = Object.assign(initialStateDefault, { user: { settings: nextState }, - }); - expect(userSettingsSelector(rootState)).toEqual(state); - }); - }); - + }) + expect(userSettingsSelector(rootState)).toEqual(state) + }) + }) describe('setSettingsPopupState', () => { it('should properly set the state', () => { @@ -70,18 +69,18 @@ describe('userSettings slice', () => { const state = { ...initialState, isShowConceptsPopup: true, - }; + } // Act - const nextState = reducer(initialState, setSettingsPopupState(true)); + const nextState = reducer(initialState, setSettingsPopupState(true)) // Assert const rootState = Object.assign(initialStateDefault, { user: { settings: nextState }, - }); - expect(userSettingsSelector(rootState)).toEqual(state); - }); - }); + }) + expect(userSettingsSelector(rootState)).toEqual(state) + }) + }) describe('getUserConfigSettings', () => { it('should properly set the state before fetch', () => { @@ -89,18 +88,18 @@ describe('userSettings slice', () => { const state = { ...initialState, loading: true, - }; + } // Act - const nextState = reducer(initialState, getUserConfigSettings()); + const nextState = reducer(initialState, getUserConfigSettings()) // Assert const rootState = Object.assign(initialStateDefault, { user: { settings: nextState }, - }); - expect(userSettingsSelector(rootState)).toEqual(state); - }); - }); + }) + expect(userSettingsSelector(rootState)).toEqual(state) + }) + }) describe('getUserConfigSettingsSuccess', () => { it('should properly set the state after fetch the data', () => { @@ -109,44 +108,44 @@ describe('userSettings slice', () => { agreements: { eula: true } - }; + } const state = { ...initialState, loading: false, config: data - }; + } // Act - const nextState = reducer(initialState, getUserConfigSettingsSuccess(data)); + const nextState = reducer(initialState, getUserConfigSettingsSuccess(data)) // Assert const rootState = Object.assign(initialStateDefault, { user: { settings: nextState }, - }); - expect(userSettingsSelector(rootState)).toEqual(state); - }); - }); + }) + expect(userSettingsSelector(rootState)).toEqual(state) + }) + }) describe('getUserConfigSettingsFailure', () => { it('should properly set the error', () => { // Arrange - const error = 'some error'; + const error = 'some error' const state = { ...initialState, loading: false, error - }; + } // Act - const nextState = reducer(initialState, getUserConfigSettingsFailure(error)); + const nextState = reducer(initialState, getUserConfigSettingsFailure(error)) // Assert const rootState = Object.assign(initialStateDefault, { user: { settings: nextState }, - }); - expect(userSettingsSelector(rootState)).toEqual(state); - }); - }); + }) + expect(userSettingsSelector(rootState)).toEqual(state) + }) + }) describe('updateUserConfigSettings', () => { it('should properly set the state before fetch', () => { @@ -154,18 +153,18 @@ describe('userSettings slice', () => { const state = { ...initialState, loading: true, - }; + } // Act - const nextState = reducer(initialState, updateUserConfigSettings()); + const nextState = reducer(initialState, updateUserConfigSettings()) // Assert const rootState = Object.assign(initialStateDefault, { user: { settings: nextState }, - }); - expect(userSettingsSelector(rootState)).toEqual(state); - }); - }); + }) + expect(userSettingsSelector(rootState)).toEqual(state) + }) + }) describe('updateUserConfigSettingsSuccess', () => { it('should properly set the state after fetch the data', () => { @@ -181,39 +180,39 @@ describe('userSettings slice', () => { loading: false, isShowConceptsPopup: false, config - }; + } // Act - const nextState = reducer(initialState, updateUserConfigSettingsSuccess(config)); + const nextState = reducer(initialState, updateUserConfigSettingsSuccess(config)) // Assert const rootState = Object.assign(initialStateDefault, { user: { settings: nextState }, - }); - expect(userSettingsSelector(rootState)).toEqual(state); - }); - }); + }) + expect(userSettingsSelector(rootState)).toEqual(state) + }) + }) describe('updateUserConfigSettingsFailure', () => { it('should properly set the error', () => { // Arrange - const error = 'some error'; + const error = 'some error' const state = { ...initialState, loading: false, error - }; + } // Act - const nextState = reducer(initialState, updateUserConfigSettingsFailure(error)); + const nextState = reducer(initialState, updateUserConfigSettingsFailure(error)) // Assert const rootState = Object.assign(initialStateDefault, { user: { settings: nextState }, - }); - expect(userSettingsSelector(rootState)).toEqual(state); - }); - }); + }) + expect(userSettingsSelector(rootState)).toEqual(state) + }) + }) describe('getUserSettingsSpec', () => { it('should properly set the state before fetch', () => { @@ -221,18 +220,18 @@ describe('userSettings slice', () => { const state = { ...initialState, loading: true, - }; + } // Act - const nextState = reducer(initialState, getUserSettingsSpec()); + const nextState = reducer(initialState, getUserSettingsSpec()) // Assert const rootState = Object.assign(initialStateDefault, { user: { settings: nextState }, - }); - expect(userSettingsSelector(rootState)).toEqual(state); - }); - }); + }) + expect(userSettingsSelector(rootState)).toEqual(state) + }) + }) describe('getUserSettingsSpecSuccess', () => { it('should properly set the state after fetch the data', () => { @@ -249,48 +248,47 @@ describe('userSettings slice', () => { label: 'Text' } } - }; + } const state = { ...initialState, loading: false, spec: data - }; + } // Act - const nextState = reducer(initialState, getUserSettingsSpecSuccess(data)); + const nextState = reducer(initialState, getUserSettingsSpecSuccess(data)) // Assert const rootState = Object.assign(initialStateDefault, { user: { settings: nextState }, - }); - expect(userSettingsSelector(rootState)).toEqual(state); - }); - }); + }) + expect(userSettingsSelector(rootState)).toEqual(state) + }) + }) describe('getUserSettingsSpecFailure', () => { it('should properly set the error', () => { // Arrange - const error = 'some error'; + const error = 'some error' const state = { ...initialState, loading: false, error - }; + } // Act - const nextState = reducer(initialState, getUserSettingsSpecFailure(error)); + const nextState = reducer(initialState, getUserSettingsSpecFailure(error)) // Assert const rootState = Object.assign(initialStateDefault, { user: { settings: nextState }, - }); - expect(userSettingsSelector(rootState)).toEqual(state); - }); - }); + }) + expect(userSettingsSelector(rootState)).toEqual(state) + }) + }) // thunks describe('thunks', () => { - describe('fetchUserConfigSettings', () => { it('succeed to fetch data', async () => { // Arrange @@ -299,46 +297,46 @@ describe('userSettings slice', () => { eula: true, analytics: false } - }; - const responsePayload = {data, status: 200}; + } + const responsePayload = { data, status: 200 } - apiService.get = jest.fn().mockResolvedValue(responsePayload); + apiService.get = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(fetchUserConfigSettings()); + await store.dispatch(fetchUserConfigSettings()) // Assert const expectedActions = [ getUserConfigSettings(), getUserConfigSettingsSuccess(responsePayload.data), - ]; + ] - expect(store.getActions()).toEqual(expectedActions); - }); + expect(store.getActions()).toEqual(expectedActions) + }) it('failed to fetch data', async () => { - const errorMessage = 'Something was wrong!'; + const errorMessage = 'Something was wrong!' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; + } - apiService.get = jest.fn().mockRejectedValue(responsePayload); + apiService.get = jest.fn().mockRejectedValue(responsePayload) // Act - await store.dispatch(fetchUserConfigSettings()); + await store.dispatch(fetchUserConfigSettings()) // Assert const expectedActions = [ getUserConfigSettings(), getUserConfigSettingsFailure(errorMessage) - ]; + ] - expect(store.getActions()).toEqual(expectedActions); - }); - }); + expect(store.getActions()).toEqual(expectedActions) + }) + }) describe('fetchUserSettingsSpec', () => { it('succeed to fetch data', async () => { @@ -355,90 +353,90 @@ describe('userSettings slice', () => { label: 'Text' } } - }; - const responsePayload = {data, status: 200}; + } + const responsePayload = { data, status: 200 } - apiService.get = jest.fn().mockResolvedValue(responsePayload); + apiService.get = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(fetchUserSettingsSpec()); + await store.dispatch(fetchUserSettingsSpec()) // Assert const expectedActions = [ getUserSettingsSpec(), getUserSettingsSpecSuccess(responsePayload.data), - ]; + ] - expect(store.getActions()).toEqual(expectedActions); - }); + expect(store.getActions()).toEqual(expectedActions) + }) it('failed to fetch data', async () => { - const errorMessage = 'Something was wrong!'; + const errorMessage = 'Something was wrong!' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; + } - apiService.get = jest.fn().mockRejectedValue(responsePayload); + apiService.get = jest.fn().mockRejectedValue(responsePayload) // Act - await store.dispatch(fetchUserSettingsSpec()); + await store.dispatch(fetchUserSettingsSpec()) // Assert const expectedActions = [ getUserSettingsSpec(), getUserSettingsSpecFailure(errorMessage) - ]; + ] - expect(store.getActions()).toEqual(expectedActions); - }); - }); + expect(store.getActions()).toEqual(expectedActions) + }) + }) describe('updateUserConfigSettingsAction', () => { it('succeed to update settings', async () => { // Arrange - const data = { agreements: { eula: true } }; - const responsePayload = {data, status: 200}; + const data = { agreements: { eula: true } } + const responsePayload = { data, status: 200 } - apiService.patch = jest.fn().mockResolvedValue(responsePayload); + apiService.patch = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(updateUserConfigSettingsAction({ agreements: { eula: true } })); + await store.dispatch(updateUserConfigSettingsAction({ agreements: { eula: true } })) // Assert const expectedActions = [ updateUserConfigSettings(), updateUserConfigSettingsSuccess(data), - ]; + ] - expect(store.getActions()).toEqual(expectedActions); - }); + expect(store.getActions()).toEqual(expectedActions) + }) it('failed to update settings', async () => { - const errorMessage = 'Something was wrong!'; + const errorMessage = 'Something was wrong!' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; + } - apiService.patch = jest.fn().mockRejectedValue(responsePayload); + apiService.patch = jest.fn().mockRejectedValue(responsePayload) // Act - await store.dispatch(updateUserConfigSettingsAction({ agreements: { eula: true } })); + await store.dispatch(updateUserConfigSettingsAction({ agreements: { eula: true } })) // Assert const expectedActions = [ updateUserConfigSettings(), updateUserConfigSettingsFailure(errorMessage), addErrorNotification(responsePayload as AxiosError), - ]; + ] - expect(store.getActions()).toEqual(expectedActions); - }); - }); - }); -}); + expect(store.getActions()).toEqual(expectedActions) + }) + }) + }) +}) diff --git a/redisinsight/ui/src/slices/tests/workbench/wb-results.spec.ts b/redisinsight/ui/src/slices/tests/workbench/wb-results.spec.ts index 5100954f3f..6a47aefe0d 100644 --- a/redisinsight/ui/src/slices/tests/workbench/wb-results.spec.ts +++ b/redisinsight/ui/src/slices/tests/workbench/wb-results.spec.ts @@ -1,5 +1,5 @@ -import { cloneDeep, first } from 'lodash'; -import { AxiosError } from 'axios'; +import { cloneDeep, first } from 'lodash' +import { AxiosError } from 'axios' import { cleanup, @@ -7,11 +7,11 @@ import { initialStateDefault, clearStoreActions, mockStore, -} from 'uiSrc/utils/test-utils'; -import { apiService } from 'uiSrc/services'; +} from 'uiSrc/utils/test-utils' +import { apiService } from 'uiSrc/services' import { addErrorNotification } from 'uiSrc/slices/app/notifications' -import { ClusterNodeRole, CommandExecutionStatus } from 'uiSrc/slices/interfaces/cli'; -import { SendClusterCommandDto, SendClusterCommandResponse } from 'apiSrc/modules/cli/dto/cli.dto'; +import { ClusterNodeRole, CommandExecutionStatus } from 'uiSrc/slices/interfaces/cli' +import { SendClusterCommandDto, SendClusterCommandResponse } from 'apiSrc/modules/cli/dto/cli.dto' import reducer, { initialState, sendWBCommand, @@ -21,39 +21,39 @@ import reducer, { workbenchResultsSelector, sendWBCommandAction, sendWBCommandClusterAction, -} from '../../workbench/wb-results'; +} from '../../workbench/wb-results' -jest.mock('uiSrc/services'); +jest.mock('uiSrc/services') -let store: typeof mockedStore; +let store: typeof mockedStore beforeEach(() => { - cleanup(); - store = cloneDeep(mockedStore); - store.clearActions(); -}); + cleanup() + store = cloneDeep(mockedStore) + store.clearActions() +}) describe('workbench results slice', () => { describe('updateWBCommandHistory', () => { it('should properly updated cli history output', () => { - const data = ['lalal', 'tatata']; + const data = ['lalal', 'tatata'] // Arrange const state: typeof initialState = { ...initialState, commandHistory: data, - }; + } // Act - const nextState = reducer(initialState, updateWBCommandHistory(data)); + const nextState = reducer(initialState, updateWBCommandHistory(data)) // Assert const rootState = Object.assign(initialStateDefault, { workbench: { results: nextState, }, - }); - expect(workbenchResultsSelector(rootState)).toEqual(state); - }); - }); + }) + expect(workbenchResultsSelector(rootState)).toEqual(state) + }) + }) describe('sendWBCommand', () => { it('should properly set loading = true', () => { @@ -61,20 +61,20 @@ describe('workbench results slice', () => { const state = { ...initialState, loading: true, - }; + } // Act - const nextState = reducer(initialState, sendWBCommand()); + const nextState = reducer(initialState, sendWBCommand()) // Assert const rootState = Object.assign(initialStateDefault, { workbench: { results: nextState, }, - }); - expect(workbenchResultsSelector(rootState)).toEqual(state); - }); - }); + }) + expect(workbenchResultsSelector(rootState)).toEqual(state) + }) + }) describe('sendWBCommandSuccess', () => { it('should properly set the state with fetched data', () => { @@ -83,110 +83,110 @@ describe('workbench results slice', () => { const state = { ...initialState, loading: false, - }; + } // Act - const nextState = reducer(initialState, sendWBCommandSuccess()); + const nextState = reducer(initialState, sendWBCommandSuccess()) // Assert const rootState = Object.assign(initialStateDefault, { workbench: { results: nextState, }, - }); - expect(workbenchResultsSelector(rootState)).toEqual(state); - }); - }); + }) + expect(workbenchResultsSelector(rootState)).toEqual(state) + }) + }) describe('sendWBCommandFailure', () => { it('should properly set the error', () => { // Arrange - const data = 'some error'; + const data = 'some error' const state = { ...initialState, loading: false, error: data, - }; + } // Act - const nextState = reducer(initialState, sendWBCommandFailure(data)); + const nextState = reducer(initialState, sendWBCommandFailure(data)) // Assert const rootState = Object.assign(initialStateDefault, { workbench: { results: nextState, }, - }); - expect(workbenchResultsSelector(rootState)).toEqual(state); - }); - }); + }) + expect(workbenchResultsSelector(rootState)).toEqual(state) + }) + }) describe('thunks', () => { describe('Standalone Cli command', () => { it('call both sendCliStandaloneCommandAction and sendWBCommandSuccess when response status is successed', async () => { // Arrange - const command = 'keys *'; + const command = 'keys *' const data = { response: 'tatata', status: CommandExecutionStatus.Success, - }; - const responsePayload = { data, status: 200 }; + } + const responsePayload = { data, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(sendWBCommandAction(command, Date.now())); + await store.dispatch(sendWBCommandAction(command, Date.now())) // Assert - const expectedActions = [sendWBCommand(), sendWBCommandSuccess()]; - expect(clearStoreActions(store.getActions())).toEqual(clearStoreActions(expectedActions)); - }); + const expectedActions = [sendWBCommand(), sendWBCommandSuccess()] + expect(clearStoreActions(store.getActions())).toEqual(clearStoreActions(expectedActions)) + }) it('call both sendCliStandaloneCommandAction and sendWBCommandSuccess when response status is fail', async () => { // Arrange - const command = 'keys *'; + const command = 'keys *' const data = { response: '(err) tatata', status: CommandExecutionStatus.Fail, - }; - const responsePayload = { data, status: 200 }; + } + const responsePayload = { data, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(sendWBCommandAction(command, Date.now())); + await store.dispatch(sendWBCommandAction(command, Date.now())) // Assert - const expectedActions = [sendWBCommand(), sendWBCommandSuccess()]; + const expectedActions = [sendWBCommand(), sendWBCommandSuccess()] - expect(clearStoreActions(store.getActions())).toEqual(clearStoreActions(expectedActions)); - }); + expect(clearStoreActions(store.getActions())).toEqual(clearStoreActions(expectedActions)) + }) it('call both sendCliStandaloneCommandAction and sendWBCommandFailure when fetch is fail', async () => { // Arrange - const command = 'keys *'; - const errorMessage = 'Could not connect to aoeu:123, please check the connection details.'; + const command = 'keys *' + const errorMessage = 'Could not connect to aoeu:123, please check the connection details.' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; + } - apiService.post = jest.fn().mockRejectedValueOnce(responsePayload); + apiService.post = jest.fn().mockRejectedValueOnce(responsePayload) // Act - await store.dispatch(sendWBCommandAction(command, Date.now())); + await store.dispatch(sendWBCommandAction(command, Date.now())) // Assert const expectedActions = [ sendWBCommand(), addErrorNotification(responsePayload as AxiosError), sendWBCommandFailure(responsePayload.response.data.message), - ]; - expect(clearStoreActions(store.getActions())).toEqual(clearStoreActions(expectedActions)); - }); - }); + ] + expect(clearStoreActions(store.getActions())).toEqual(clearStoreActions(expectedActions)) + }) + }) describe('Single Node Cluster Cli command', () => { const options: SendClusterCommandDto = { @@ -197,76 +197,76 @@ describe('workbench results slice', () => { enableRedirection: true, }, role: ClusterNodeRole.All, - }; + } it('call both sendWBCommandClusterAction and sendWBCommandSuccess when response status is successed', async () => { // Arrange - const command = 'keys *'; + const command = 'keys *' const data: SendClusterCommandResponse[] = [ { response: '-> Redirected to slot [6918] located at 127.0.0.1:7002\n(nil)', status: 'success', node: { host: '127.0.0.1', port: 7002 }, }, - ]; - const responsePayload = { data, status: 200 }; + ] + const responsePayload = { data, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(sendWBCommandClusterAction(command, Date.now(), options)); + await store.dispatch(sendWBCommandClusterAction(command, Date.now(), options)) // Assert - const expectedActions = [sendWBCommand(), sendWBCommandSuccess()]; - expect(clearStoreActions(store.getActions())).toEqual(clearStoreActions(expectedActions)); - }); + const expectedActions = [sendWBCommand(), sendWBCommandSuccess()] + expect(clearStoreActions(store.getActions())).toEqual(clearStoreActions(expectedActions)) + }) it('call both sendWBCommandClusterAction and sendWBCommandSuccess when response status is fail', async () => { // Arrange - const command = 'keys *'; + const command = 'keys *' const data: SendClusterCommandResponse[] = [ { response: '-> Redirected to slot [6918] located at 127.0.0.1:7002\n(nil)', status: 'success', node: { host: '127.0.0.1', port: 7002 }, }, - ]; - const responsePayload = { data, status: 200 }; + ] + const responsePayload = { data, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(sendWBCommandClusterAction(command, Date.now(), options)); + await store.dispatch(sendWBCommandClusterAction(command, Date.now(), options)) // Assert - const expectedActions = [sendWBCommand(), sendWBCommandSuccess()]; - expect(clearStoreActions(store.getActions())).toEqual(clearStoreActions(expectedActions)); - }); + const expectedActions = [sendWBCommand(), sendWBCommandSuccess()] + expect(clearStoreActions(store.getActions())).toEqual(clearStoreActions(expectedActions)) + }) it('call both sendWBCommandClusterAction and sendWBCommandFailure when fetch is fail', async () => { // Arrange - const command = 'keys *'; - const errorMessage = 'Could not connect to aoeu:123, please check the connection details.'; + const command = 'keys *' + const errorMessage = 'Could not connect to aoeu:123, please check the connection details.' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; + } - apiService.post = jest.fn().mockRejectedValueOnce(responsePayload); + apiService.post = jest.fn().mockRejectedValueOnce(responsePayload) // Act - await store.dispatch(sendWBCommandClusterAction(command, Date.now(), options)); + await store.dispatch(sendWBCommandClusterAction(command, Date.now(), options)) // Assert const expectedActions = [ sendWBCommand(), addErrorNotification(responsePayload as AxiosError), sendWBCommandFailure(responsePayload.response.data.message), - ]; - expect(clearStoreActions(store.getActions())).toEqual(clearStoreActions(expectedActions)); - }); - }); - }); -}); + ] + expect(clearStoreActions(store.getActions())).toEqual(clearStoreActions(expectedActions)) + }) + }) + }) +}) diff --git a/redisinsight/ui/src/slices/tests/workbench/wb-settings.spec.ts b/redisinsight/ui/src/slices/tests/workbench/wb-settings.spec.ts index 58b26570e0..2aa0e9ae35 100644 --- a/redisinsight/ui/src/slices/tests/workbench/wb-settings.spec.ts +++ b/redisinsight/ui/src/slices/tests/workbench/wb-settings.spec.ts @@ -1,6 +1,6 @@ -import { cloneDeep } from 'lodash'; -import { apiService } from 'uiSrc/services'; -import { cleanup, mockedStore, initialStateDefault } from 'uiSrc/utils/test-utils'; +import { cloneDeep } from 'lodash' +import { apiService } from 'uiSrc/services' +import { cleanup, mockedStore, initialStateDefault } from 'uiSrc/utils/test-utils' import reducer, { createWBClientAction, initialState, @@ -9,24 +9,22 @@ import reducer, { processWBClientSuccess, workbenchSettingsSelector, updateWBClientAction, -} from '../../workbench/wb-settings'; +} from '../../workbench/wb-settings' -let store: typeof mockedStore; +let store: typeof mockedStore beforeEach(() => { - cleanup(); - store = cloneDeep(mockedStore); - store.clearActions(); -}); - -jest.mock('uiSrc/services', () => { - return { - ...jest.requireActual('uiSrc/services'), - localStorageService: { - set: jest.fn(), - get: jest.fn(), - }, - }; -}); + cleanup() + store = cloneDeep(mockedStore) + store.clearActions() +}) + +jest.mock('uiSrc/services', () => ({ + ...jest.requireActual('uiSrc/services'), + localStorageService: { + set: jest.fn(), + get: jest.fn(), + }, +})) describe('workbenchSettings slice', () => { describe('processWBClient', () => { @@ -35,175 +33,175 @@ describe('workbenchSettings slice', () => { const state = { ...initialState, loading: true, - }; + } // Act - const nextState = reducer(initialState, processWBClient()); + const nextState = reducer(initialState, processWBClient()) // Assert const rootState = Object.assign(initialStateDefault, { workbench: { settings: nextState, }, - }); - expect(workbenchSettingsSelector(rootState)).toEqual(state); - }); - }); + }) + expect(workbenchSettingsSelector(rootState)).toEqual(state) + }) + }) describe('processWBClientSuccess', () => { it('should properly set the state with fetched data', () => { // Arrange - const data = { uuid: '70b95d32-c19d-4311-bb24-e684af12cf15' }; + const data = { uuid: '70b95d32-c19d-4311-bb24-e684af12cf15' } const state = { ...initialState, loading: false, wbClientUuid: data.uuid, - }; + } // Act - const nextState = reducer(initialState, processWBClientSuccess(data?.uuid)); + const nextState = reducer(initialState, processWBClientSuccess(data?.uuid)) // Assert const rootState = Object.assign(initialStateDefault, { workbench: { settings: nextState, }, - }); - expect(workbenchSettingsSelector(rootState)).toEqual(state); - }); + }) + expect(workbenchSettingsSelector(rootState)).toEqual(state) + }) it('should properly set the state with empty data', () => { // Arrange - const data = { uuid: '' }; + const data = { uuid: '' } const state = { ...initialState, loading: false, wbClientUuid: data.uuid, - }; + } // Act - const nextState = reducer(initialState, processWBClientSuccess(data?.uuid)); + const nextState = reducer(initialState, processWBClientSuccess(data?.uuid)) // Assert const rootState = Object.assign(initialStateDefault, { workbench: { settings: nextState, }, - }); - expect(workbenchSettingsSelector(rootState)).toEqual(state); - }); - }); + }) + expect(workbenchSettingsSelector(rootState)).toEqual(state) + }) + }) describe('processWBClientFailure', () => { it('should properly set the error', () => { // Arrange - const data = 'some error'; + const data = 'some error' const state = { ...initialState, loading: false, errorClient: data, - }; + } // Act - const nextState = reducer(initialState, processWBClientFailure(data)); + const nextState = reducer(initialState, processWBClientFailure(data)) // Assert const rootState = Object.assign(initialStateDefault, { workbench: { settings: nextState, }, - }); - expect(workbenchSettingsSelector(rootState)).toEqual(state); - }); - }); + }) + expect(workbenchSettingsSelector(rootState)).toEqual(state) + }) + }) describe('thunks', () => { it('call both createWBClientAction and processWBClientSuccess when fetch is successed', async () => { // Arrange - const data = { uuid: '70b95d32-c19d-4311-bb24-e684af12cf15' }; - const responsePayload = { data, status: 200 }; + const data = { uuid: '70b95d32-c19d-4311-bb24-e684af12cf15' } + const responsePayload = { data, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(createWBClientAction()); + await store.dispatch(createWBClientAction()) // Assert const expectedActions = [ processWBClient(), processWBClientSuccess(responsePayload.data?.uuid), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) it('call both createWBClientAction and processWBClientFailure when fetch is fail', async () => { // Arrange - const errorMessage = 'Could not connect to aoeu:123, please check the connection details.'; + const errorMessage = 'Could not connect to aoeu:123, please check the connection details.' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; + } - apiService.post = jest.fn().mockRejectedValueOnce(responsePayload); + apiService.post = jest.fn().mockRejectedValueOnce(responsePayload) // Act - await store.dispatch(createWBClientAction()); + await store.dispatch(createWBClientAction()) // Assert const expectedActions = [ processWBClient(), processWBClientFailure(responsePayload.response.data.message), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) it('call both updateWBClientAction and processWBClientSuccess when fetch is successed', async () => { // Arrange - const instanceId = '123'; - const uuid = '70b95d32-c19d-4311-bb24-e684af12cf15'; - const data = { uuid }; - const responsePayload = { data, status: 200 }; + const instanceId = '123' + const uuid = '70b95d32-c19d-4311-bb24-e684af12cf15' + const data = { uuid } + const responsePayload = { data, status: 200 } - apiService.patch = jest.fn().mockResolvedValue(responsePayload); + apiService.patch = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(updateWBClientAction(instanceId, uuid)); + await store.dispatch(updateWBClientAction(instanceId, uuid)) // Assert const expectedActions = [ processWBClient(), processWBClientSuccess(responsePayload.data?.uuid), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); + ] + expect(store.getActions()).toEqual(expectedActions) + }) it('call both updateWBClientAction and processWBClientFailure when fetch is fail', async () => { // Arrange - const instanceId = '123'; - const uuid = '70b95d32-c19d-4311-bb24-e684af12cf15'; - const errorMessage = 'Could not connect to aoeu:123, please check the connection details.'; + const instanceId = '123' + const uuid = '70b95d32-c19d-4311-bb24-e684af12cf15' + const errorMessage = 'Could not connect to aoeu:123, please check the connection details.' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; + } - apiService.patch = jest.fn().mockRejectedValueOnce(responsePayload); + apiService.patch = jest.fn().mockRejectedValueOnce(responsePayload) // Act - await store.dispatch(updateWBClientAction(instanceId, uuid)); + await store.dispatch(updateWBClientAction(instanceId, uuid)) // Assert const expectedActions = [ processWBClient(), processWBClientFailure(responsePayload.response.data.message), - ]; - expect(store.getActions()).toEqual(expectedActions); - }); - }); -}); + ] + expect(store.getActions()).toEqual(expectedActions) + }) + }) +}) diff --git a/redisinsight/ui/src/slices/tests/zset.spec.ts b/redisinsight/ui/src/slices/tests/zset.spec.ts index 132a74a1bf..1957dfedc6 100644 --- a/redisinsight/ui/src/slices/tests/zset.spec.ts +++ b/redisinsight/ui/src/slices/tests/zset.spec.ts @@ -1,23 +1,23 @@ -import { cloneDeep } from 'lodash'; -import { SortOrder } from 'uiSrc/constants'; -import { apiService } from 'uiSrc/services'; -import { AxiosError } from 'axios'; +import { cloneDeep } from 'lodash' +import { SortOrder } from 'uiSrc/constants' +import { apiService } from 'uiSrc/services' +import { AxiosError } from 'axios' import { cleanup, initialStateDefault, mockedStore, mockStore, -} from 'uiSrc/utils/test-utils'; -import { addErrorNotification, addMessageNotification } from 'uiSrc/slices/app/notifications'; -import successMessages from 'uiSrc/components/notifications/success-messages'; -import { AddMembersToZSetDto, ZSetMemberDto } from 'apiSrc/modules/browser/dto'; +} from 'uiSrc/utils/test-utils' +import { addErrorNotification, addMessageNotification } from 'uiSrc/slices/app/notifications' +import successMessages from 'uiSrc/components/notifications/success-messages' +import { AddMembersToZSetDto, ZSetMemberDto } from 'apiSrc/modules/browser/dto' import { defaultSelectedKeyAction, deleteKeyFromList, deleteKeySuccess, refreshKeyInfo, updateSelectedKeyRefreshTime, -} from '../keys'; +} from '../keys' import reducer, { initialState, setZsetInitialState, @@ -51,49 +51,49 @@ import reducer, { fetchSearchZSetMembers, fetchSearchMoreZSetMembers, refreshZsetMembersAction, -} from '../zset'; +} from '../zset' -jest.mock('uiSrc/services'); +jest.mock('uiSrc/services') -let store: typeof mockedStore; -let dateNow: jest.SpyInstance; -const errorMessage = 'some error'; +let store: typeof mockedStore +let dateNow: jest.SpyInstance +const errorMessage = 'some error' beforeEach(() => { - cleanup(); - store = cloneDeep(mockedStore); - store.clearActions(); -}); + cleanup() + store = cloneDeep(mockedStore) + store.clearActions() +}) describe('zset slice', () => { beforeAll(() => { - dateNow = jest.spyOn(Date, 'now').mockImplementation(() => 1629128049027); - }); + dateNow = jest.spyOn(Date, 'now').mockImplementation(() => 1629128049027) + }) afterAll(() => { - dateNow.mockRestore(); - }); + dateNow.mockRestore() + }) describe('reducer, actions and selectors', () => { it('should return the initial state on first run', () => { // Arrange - const nextState = initialState; + const nextState = initialState // Act - const result = reducer(undefined, {}); + const result = reducer(undefined, {}) // Assert - expect(result).toEqual(nextState); - }); - }); + expect(result).toEqual(nextState) + }) + }) describe('setZsetInitialState', () => { it('should properly set initial state', () => { - const nextState = reducer(initialState, setZsetInitialState()); + const nextState = reducer(initialState, setZsetInitialState()) const rootState = Object.assign(initialStateDefault, { browser: { zset: nextState }, - }); - expect(zsetSelector(rootState)).toEqual(initialState); + }) + expect(zsetSelector(rootState)).toEqual(initialState) }) }) @@ -103,18 +103,18 @@ describe('zset slice', () => { const state = { ...initialState, loading: true, - }; + } // Act - const nextState = reducer(initialState, loadZSetMembers(initialState.data.sortOrder)); + const nextState = reducer(initialState, loadZSetMembers(initialState.data.sortOrder)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { zset: nextState }, - }); - expect(zsetSelector(rootState)).toEqual(state); - }); - }); + }) + expect(zsetSelector(rootState)).toEqual(state) + }) + }) describe('loadZSetMembersSuccess', () => { it('should properly set the state with fetched data', () => { @@ -126,7 +126,7 @@ describe('zset slice', () => { total: 1, size: 67, members: [{ name: '1', score: '1' }], - }; + } const state = { ...initialState, @@ -137,17 +137,17 @@ describe('zset slice', () => { members: data.members, total: data.total } - }; + } // Act - const nextState = reducer(initialState, loadZSetMembersSuccess(data)); + const nextState = reducer(initialState, loadZSetMembersSuccess(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { zset: nextState }, - }); - expect(zsetSelector(rootState)).toEqual(state); - }); + }) + expect(zsetSelector(rootState)).toEqual(state) + }) it('should properly set the state with empty data', () => { // Arrange @@ -155,7 +155,7 @@ describe('zset slice', () => { keyName: '', members: [], total: 0 - }; + } const state = { ...initialState, @@ -164,18 +164,18 @@ describe('zset slice', () => { ...initialState.data, ...data } - }; + } // Act - const nextState = reducer(initialState, loadZSetMembersSuccess(data)); + const nextState = reducer(initialState, loadZSetMembersSuccess(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { zset: nextState }, - }); - expect(zsetSelector(rootState)).toEqual(state); - }); - }); + }) + expect(zsetSelector(rootState)).toEqual(state) + }) + }) describe('loadZSetMembersFailure', () => { it('should properly set the error', () => { @@ -189,18 +189,18 @@ describe('zset slice', () => { loading: false, error: '', } - }; + } // Act - const nextState = reducer(initialState, loadZSetMembersFailure(errorMessage)); + const nextState = reducer(initialState, loadZSetMembersFailure(errorMessage)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { zset: nextState }, - }); - expect(zsetSelector(rootState)).toEqual(state); - }); - }); + }) + expect(zsetSelector(rootState)).toEqual(state) + }) + }) describe('searchZSetMembers', () => { it('should properly set the state before the fetch data', () => { @@ -213,14 +213,14 @@ describe('zset slice', () => { ...initialState.data, match: '*' } - }; + } // Act - const nextState = reducer(initialState, searchZSetMembers('*')); + const nextState = reducer(initialState, searchZSetMembers('*')) const rootState = Object.assign(initialStateDefault, { browser: { zset: nextState } }) - expect(zsetSelector(rootState)).toEqual(state); + expect(zsetSelector(rootState)).toEqual(state) }) }) @@ -246,13 +246,13 @@ describe('zset slice', () => { } // Act - const nextState = reducer(initialState, searchZSetMembersSuccess(data)); + const nextState = reducer(initialState, searchZSetMembersSuccess(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { zset: nextState } - }); - expect(zsetSelector(rootState)).toEqual(state); + }) + expect(zsetSelector(rootState)).toEqual(state) }) it('should properly set the state with empty members', () => { @@ -276,13 +276,13 @@ describe('zset slice', () => { } // Act - const nextState = reducer(initialState, searchZSetMembersSuccess(data)); + const nextState = reducer(initialState, searchZSetMembersSuccess(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { zset: nextState } - }); - expect(zsetSelector(rootState)).toEqual(state); + }) + expect(zsetSelector(rootState)).toEqual(state) }) }) @@ -292,22 +292,22 @@ describe('zset slice', () => { ...initialState, loading: false, error: errorMessage, - }; + } // Act - const nextState = reducer(initialState, searchZSetMembersFailure(errorMessage)); + const nextState = reducer(initialState, searchZSetMembersFailure(errorMessage)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { zset: nextState } }) - expect(zsetSelector(rootState)).toEqual(state); + expect(zsetSelector(rootState)).toEqual(state) }) }) describe('searchMoreZSetMembers', () => { it('should properly set the state before the fetch data', () => { - const data = '*'; + const data = '*' const state = { ...initialState, loading: true, @@ -319,13 +319,13 @@ describe('zset slice', () => { } // Act - const nextState = reducer(initialState, searchMoreZSetMembers(data)); + const nextState = reducer(initialState, searchMoreZSetMembers(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { zset: nextState } }) - expect(zsetSelector(rootState)).toEqual(state); + expect(zsetSelector(rootState)).toEqual(state) }) }) @@ -335,7 +335,7 @@ describe('zset slice', () => { nextCursor: 0, members: [{ name: 'member name', score: 10 }], total: 1 - }; + } const state = { ...initialState, loading: false, @@ -346,13 +346,13 @@ describe('zset slice', () => { } // Act - const nextState = reducer(initialState, searchMoreZSetMembersSuccess(data)); + const nextState = reducer(initialState, searchMoreZSetMembersSuccess(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { zset: nextState } }) - expect(zsetSelector(rootState)).toEqual(state); + expect(zsetSelector(rootState)).toEqual(state) }) it('should properly set the state with empty data', () => { @@ -361,16 +361,16 @@ describe('zset slice', () => { nextCursor: 0, members: [], total: 0 - }; + } // Act - const nextState = reducer(initialState, searchMoreZSetMembersSuccess(data)); + const nextState = reducer(initialState, searchMoreZSetMembersSuccess(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { zset: nextState } }) - expect(zsetSelector(rootState)).toEqual(initialState); + expect(zsetSelector(rootState)).toEqual(initialState) }) }) @@ -380,16 +380,16 @@ describe('zset slice', () => { ...initialState, loading: false, error: errorMessage, - }; + } // Act - const nextState = reducer(initialState, searchMoreZSetMembersFailure(errorMessage)); + const nextState = reducer(initialState, searchMoreZSetMembersFailure(errorMessage)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { zset: nextState } }) - expect(zsetSelector(rootState)).toEqual(state); + expect(zsetSelector(rootState)).toEqual(state) }) }) @@ -399,18 +399,18 @@ describe('zset slice', () => { const state = { ...initialState, loading: true, - }; + } // Act - const nextState = reducer(initialState, loadMoreZSetMembers()); + const nextState = reducer(initialState, loadMoreZSetMembers()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { zset: nextState }, - }); - expect(zsetSelector(rootState)).toEqual(state); - }); - }); + }) + expect(zsetSelector(rootState)).toEqual(state) + }) + }) describe('loadMoreZSetMembersSuccess', () => { it('should properly set the state with fetched data', () => { @@ -427,7 +427,7 @@ describe('zset slice', () => { { name: '12', score: '12' }, { name: '2', score: '2' }, ], - }; + } const state = { ...initialState, @@ -436,17 +436,17 @@ describe('zset slice', () => { ...initialState.data, ...data } - }; + } // Act - const nextState = reducer(initialState, loadMoreZSetMembersSuccess(data)); + const nextState = reducer(initialState, loadMoreZSetMembersSuccess(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { zset: nextState }, - }); - expect(zsetSelector(rootState)).toEqual(state); - }); + }) + expect(zsetSelector(rootState)).toEqual(state) + }) it('should properly set the state with empty data', () => { // Arrange @@ -456,18 +456,18 @@ describe('zset slice', () => { total: 10, size: 67, members: [], - }; + } // Act - const nextState = reducer(initialState, loadMoreZSetMembersSuccess(data)); + const nextState = reducer(initialState, loadMoreZSetMembersSuccess(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { zset: nextState }, - }); - expect(zsetSelector(rootState)).toEqual(initialState); - }); - }); + }) + expect(zsetSelector(rootState)).toEqual(initialState) + }) + }) describe('loadMoreZSetMembersFailure', () => { it('should properly set the error', () => { @@ -476,76 +476,76 @@ describe('zset slice', () => { ...initialState, loading: false, error: errorMessage, - }; + } // Act - const nextState = reducer(initialState, loadMoreZSetMembersFailure(errorMessage)); + const nextState = reducer(initialState, loadMoreZSetMembersFailure(errorMessage)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { zset: nextState }, - }); - expect(zsetSelector(rootState)).toEqual(state); - }); - }); + }) + expect(zsetSelector(rootState)).toEqual(state) + }) + }) describe('removeZsetMembers', () => { - it('should properly set the state before the fetch data',() => { + it('should properly set the state before the fetch data', () => { // Arrange const state = { ...initialState, loading: true, - }; + } // Act - const nextState = reducer(initialState, removeZsetMembers()); + const nextState = reducer(initialState, removeZsetMembers()) // Assert const rootSate = Object.assign(initialStateDefault, { browser: { zset: nextState } }) - expect(zsetSelector(rootSate)).toEqual(state); - }); - }); + expect(zsetSelector(rootSate)).toEqual(state) + }) + }) describe('removeZsetMembersSuccess', () => { - it('should properly set the state with fetched data',() => { + it('should properly set the state with fetched data', () => { const initialStateRemove = { ...initialState, data: { ...initialState.data, members: [{ name: 'member name', score: 10 }], }, - }; + } // Act - const nextState = reducer(initialStateRemove, removeZsetMembersSuccess()); + const nextState = reducer(initialStateRemove, removeZsetMembersSuccess()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { zset: nextState } }) - expect(zsetSelector(rootState)).toEqual(initialStateRemove); - }); + expect(zsetSelector(rootState)).toEqual(initialStateRemove) + }) }) describe('removeZsetMembersFailure', () => { - it('should properly set the error',() => { + it('should properly set the error', () => { const state = { ...initialState, loading: false, error: errorMessage, - }; + } // Act - const nextState = reducer(initialState, removeZsetMembersFailure(errorMessage)); + const nextState = reducer(initialState, removeZsetMembersFailure(errorMessage)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { zset: nextState } }) - expect(zsetSelector(rootState)).toEqual(state); - }); + expect(zsetSelector(rootState)).toEqual(state) + }) }) describe('removeMembersFromList', () => { @@ -561,29 +561,29 @@ describe('zset slice', () => { { name: 'member name2', score: 3 }, ], }, - }; + } - const data = ['member name', 'member name1']; + const data = ['member name', 'member name1'] const state = { ...initialStateRemove, data: { ...initialStateRemove.data, total: initialStateRemove.data.total - 1, - members: [{ name: 'member name2', score: 3}], + members: [{ name: 'member name2', score: 3 }], }, - }; + } // Act - const nextState = reducer(initialStateRemove, removeMembersFromList(data)); + const nextState = reducer(initialStateRemove, removeMembersFromList(data)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { zset: nextState }, - }); - expect(zsetSelector(rootState)).toEqual(state); - }); - }); + }) + expect(zsetSelector(rootState)).toEqual(state) + }) + }) describe('updateScore', () => { it('should properly set the state while updating a zset score', () => { @@ -595,22 +595,21 @@ describe('zset slice', () => { loading: true, error: '', }, - }; + } // Act - const nextState = reducer(initialState, updateScore()); + const nextState = reducer(initialState, updateScore()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { zset: nextState }, - }); - expect(zsetSelector(rootState)).toEqual(state); - }); - }); + }) + expect(zsetSelector(rootState)).toEqual(state) + }) + }) describe('updateScoreSuccess', () => { it('should properly set the state after successfully updated zset score', () => { - // Arrange const state = { ...initialState, @@ -618,22 +617,21 @@ describe('zset slice', () => { ...initialState.updateScore, loading: false, }, - }; + } // Act - const nextState = reducer(initialState, updateScoreSuccess()); + const nextState = reducer(initialState, updateScoreSuccess()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { zset: nextState }, - }); - expect(zsetSelector(rootState)).toEqual(state); - }); - }); + }) + expect(zsetSelector(rootState)).toEqual(state) + }) + }) describe('updateScoreFailure', () => { it('should properly set the state on update zset score failure', () => { - // Arrange const state = { ...initialState, @@ -642,18 +640,18 @@ describe('zset slice', () => { loading: false, error: errorMessage, }, - }; + } // Act - const nextState = reducer(initialState, updateScoreFailure(errorMessage)); + const nextState = reducer(initialState, updateScoreFailure(errorMessage)) // Assert const rootState = Object.assign(initialStateDefault, { browser: { zset: nextState }, - }); - expect(zsetSelector(rootState)).toEqual(state); - }); - }); + }) + expect(zsetSelector(rootState)).toEqual(state) + }) + }) describe('resetUpdateScore', () => { it('should properly reset the state', () => { @@ -665,22 +663,21 @@ describe('zset slice', () => { loading: false, error: '', }, - }; + } // Act - const nextState = reducer(initialState, resetUpdateScore()); + const nextState = reducer(initialState, resetUpdateScore()) // Assert const rootState = Object.assign(initialStateDefault, { browser: { zset: nextState }, - }); - expect(zsetSelector(rootState)).toEqual(state); - }); - }); + }) + expect(zsetSelector(rootState)).toEqual(state) + }) + }) describe('updateMembersInList', () => { it('should properly update members in list', () => { - // Arrange const initialStateToUpdate = { ...initialState, @@ -724,8 +721,8 @@ describe('zset slice', () => { // Assert const rootState = Object.assign(initialStateDefault, { browser: { zset: nextState }, - }); - expect(zsetSelector(rootState)).toEqual(state); + }) + expect(zsetSelector(rootState)).toEqual(state) }) }) @@ -739,52 +736,52 @@ describe('zset slice', () => { total: 1, size: 67, members: [{ name: '1', score: '1' }], - }; - const responsePayload = { data, status: 200 }; + } + const responsePayload = { data, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act await store.dispatch( fetchZSetMembers(data.keyName, 0, 20, SortOrder.ASC) - ); + ) // Assert const expectedActions = [ loadZSetMembers(SortOrder.ASC), loadZSetMembersSuccess(responsePayload.data), updateSelectedKeyRefreshTime(Date.now()), - ]; + ] - expect(store.getActions()).toEqual(expectedActions); - }); + expect(store.getActions()).toEqual(expectedActions) + }) it('failed to fetch zset members', async () => { // Arrange - const errorMessage = 'Something was wrong!'; + const errorMessage = 'Something was wrong!' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; - apiService.post = jest.fn().mockRejectedValue(responsePayload); + } + apiService.post = jest.fn().mockRejectedValue(responsePayload) // Act await store.dispatch( fetchZSetMembers('', 0, 20, SortOrder.ASC) - ); + ) // Assert const expectedActions = [ loadZSetMembers(SortOrder.ASC), addErrorNotification(responsePayload as AxiosError), loadZSetMembersFailure(errorMessage), - ]; + ] - expect(store.getActions()).toEqual(expectedActions); - }); - }); + expect(store.getActions()).toEqual(expectedActions) + }) + }) describe('fetchMoreZSetMembers', () => { it('succeed to fetch more zset members', async () => { @@ -795,40 +792,40 @@ describe('zset slice', () => { total: 1, size: 67, members: [{ name: '1', score: '1' }], - }; - const responsePayload = { data, status: 200 }; + } + const responsePayload = { data, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act await store.dispatch( fetchMoreZSetMembers(data.keyName, 0, 20, SortOrder.ASC) - ); + ) // Assert const expectedActions = [ loadMoreZSetMembers(), loadMoreZSetMembersSuccess(responsePayload.data), - ]; + ] - expect(store.getActions()).toEqual(expectedActions); - }); + expect(store.getActions()).toEqual(expectedActions) + }) it('failed to fetch more zset members', async () => { // Arrange - const errorMessage = 'Something was wrong!'; + const errorMessage = 'Something was wrong!' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; - apiService.post = jest.fn().mockRejectedValue(responsePayload); + } + apiService.post = jest.fn().mockRejectedValue(responsePayload) // Act await store.dispatch( fetchMoreZSetMembers('', 0, 20, SortOrder.ASC) - ); + ) // Assert const expectedActions = [ @@ -837,9 +834,9 @@ describe('zset slice', () => { loadMoreZSetMembersFailure(errorMessage), ] - expect(store.getActions()).toEqual(expectedActions); + expect(store.getActions()).toEqual(expectedActions) }) - }); + }) describe('fetchAddZSetMembers', () => { it('succeed to fetch add zset members', async () => { @@ -847,60 +844,60 @@ describe('zset slice', () => { const data: AddMembersToZSetDto = { keyName: 'small zset', members: [{ name: '1', score: 1 }], - }; - const responsePayload = { status: 200 }; + } + const responsePayload = { status: 200 } - apiService.put = jest.fn().mockResolvedValue(responsePayload); + apiService.put = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(fetchAddZSetMembers(data, jest.fn())); + await store.dispatch(fetchAddZSetMembers(data, jest.fn())) // Assert const expectedActions = [ updateScore(), updateScoreSuccess(), defaultSelectedKeyAction(), - ]; + ] - expect(store.getActions()).toEqual(expectedActions); - }); + expect(store.getActions()).toEqual(expectedActions) + }) it('failed to fetch add zset members', async () => { - const errorMessage = 'Something was wrong!'; + const errorMessage = 'Something was wrong!' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; - apiService.put = jest.fn().mockRejectedValue(responsePayload); + } + apiService.put = jest.fn().mockRejectedValue(responsePayload) // Act await store.dispatch(fetchAddZSetMembers( { keyName: '', members: [] }, jest.fn(), jest.fn() - )); + )) // Assert const expectedActions = [ updateScore(), addErrorNotification(responsePayload as AxiosError), updateScoreFailure(errorMessage), - ]; + ] - expect(store.getActions()).toEqual(expectedActions); - }); + expect(store.getActions()).toEqual(expectedActions) + }) }) describe('deleteZSetMembers', () => { it('succeed to fetch delete zset members', async () => { // Arrange const key = 'zset key' - const members = ['member#1', 'member#2']; - const responsePayload = { status: 200, data: { affected: 2 } }; + const members = ['member#1', 'member#2'] + const responsePayload = { status: 200, data: { affected: 2 } } - apiService.delete = jest.fn().mockResolvedValue(responsePayload); + apiService.delete = jest.fn().mockResolvedValue(responsePayload) const nextState = Object.assign(initialStateDefault, { browser: { zset: { @@ -911,12 +908,12 @@ describe('zset slice', () => { } } }, - }); + }) - const mockedStore = mockStore(nextState); + const mockedStore = mockStore(nextState) // Act - await mockedStore.dispatch(deleteZSetMembers(key, members)); + await mockedStore.dispatch(deleteZSetMembers(key, members)) // Assert const expectedActions = [ @@ -931,18 +928,18 @@ describe('zset slice', () => { 'Member' ) ) - ]; + ] - expect(mockedStore.getActions()).toEqual(expectedActions); - }); + expect(mockedStore.getActions()).toEqual(expectedActions) + }) it('succeed to fetch delete all zset members', async () => { // Arrange const key = 'zset key' - const members = ['member#1', 'member#2']; - const responsePayload = { status: 200, data: { affected: 2 } }; + const members = ['member#1', 'member#2'] + const responsePayload = { status: 200, data: { affected: 2 } } - apiService.delete = jest.fn().mockResolvedValue(responsePayload); + apiService.delete = jest.fn().mockResolvedValue(responsePayload) const nextState = Object.assign(initialStateDefault, { browser: { zset: { @@ -953,12 +950,12 @@ describe('zset slice', () => { } } }, - }); + }) - const mockedStore = mockStore(nextState); + const mockedStore = mockStore(nextState) // Act - await mockedStore.dispatch(deleteZSetMembers(key, members)); + await mockedStore.dispatch(deleteZSetMembers(key, members)) // Assert const expectedActions = [ @@ -968,34 +965,34 @@ describe('zset slice', () => { deleteKeySuccess(), deleteKeyFromList(key), addMessageNotification(successMessages.DELETED_KEY(key)) - ]; + ] - expect(mockedStore.getActions()).toEqual(expectedActions); - }); + expect(mockedStore.getActions()).toEqual(expectedActions) + }) it('failed to fetch delete zset members', async () => { - const errorMessage = 'Something was wrong!'; + const errorMessage = 'Something was wrong!' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; - apiService.delete = jest.fn().mockRejectedValue(responsePayload); + } + apiService.delete = jest.fn().mockRejectedValue(responsePayload) // Act - await store.dispatch(deleteZSetMembers('key', [])); + await store.dispatch(deleteZSetMembers('key', [])) // Assert const expectedActions = [ removeZsetMembers(), addErrorNotification(responsePayload as AxiosError), removeZsetMembersFailure(errorMessage) - ]; + ] - expect(store.getActions()).toEqual(expectedActions); - }); - }); + expect(store.getActions()).toEqual(expectedActions) + }) + }) describe('updateZSetMembers', () => { it('succeed to fetch update zset members', async () => { @@ -1003,13 +1000,13 @@ describe('zset slice', () => { const data: AddMembersToZSetDto = { keyName: 'small zset', members: [{ name: '1', score: 1 }], - }; - const responsePayload = { status: 200 }; + } + const responsePayload = { status: 200 } - apiService.put = jest.fn().mockResolvedValue(responsePayload); + apiService.put = jest.fn().mockResolvedValue(responsePayload) // Act - await store.dispatch(updateZSetMembers(data, jest.fn())); + await store.dispatch(updateZSetMembers(data, jest.fn())) // Assert const expectedActions = [ @@ -1017,135 +1014,135 @@ describe('zset slice', () => { updateScoreSuccess(), updateMembersInList(data.members), refreshKeyInfo(), - ]; + ] - expect(store.getActions()).toEqual(expectedActions); - }); + expect(store.getActions()).toEqual(expectedActions) + }) it('failed to fetch update zset members', async () => { - const errorMessage = 'Something was wrong!'; + const errorMessage = 'Something was wrong!' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; - apiService.put = jest.fn().mockRejectedValue(responsePayload); + } + apiService.put = jest.fn().mockRejectedValue(responsePayload) // Act await store.dispatch(updateZSetMembers( { keyName: '', members: [] }, jest.fn(), jest.fn() - )); + )) // Assert const expectedActions = [ updateScore(), addErrorNotification(responsePayload as AxiosError), updateScoreFailure(errorMessage) - ]; + ] - expect(store.getActions()).toEqual(expectedActions); - }); - }); + expect(store.getActions()).toEqual(expectedActions) + }) + }) describe('fetchSearchZSetMembers', () => { it('succeed to fetch search zset members', async () => { // Arrange const data = { members: [] } - const responsePayload = { status: 200, data }; + const responsePayload = { status: 200, data } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act await store.dispatch( fetchSearchZSetMembers('key', 0, 20, 'zz') - ); + ) // Assert const expectedActions = [ searchZSetMembers('zz'), searchZSetMembersSuccess(data), updateSelectedKeyRefreshTime(Date.now()), - ]; + ] - expect(store.getActions()).toEqual(expectedActions); - }); + expect(store.getActions()).toEqual(expectedActions) + }) it('failed to fetch search zset members', async () => { - const errorMessage = 'Something was wrong!'; + const errorMessage = 'Something was wrong!' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; - apiService.post = jest.fn().mockRejectedValue(responsePayload); + } + apiService.post = jest.fn().mockRejectedValue(responsePayload) // Act await store.dispatch( fetchSearchZSetMembers('key', 0, 20, 'zz') - ); + ) // Assert const expectedActions = [ searchZSetMembers('zz'), addErrorNotification(responsePayload as AxiosError), searchZSetMembersFailure(errorMessage) - ]; + ] - expect(store.getActions()).toEqual(expectedActions); - }); - }); + expect(store.getActions()).toEqual(expectedActions) + }) + }) describe('fetchSearchMoreZSetMembers', () => { it('succeed to fetch search more zset members', async () => { // Arrange const responseData = { members: [] } - const responsePayload = { status: 200, data: responseData }; + const responsePayload = { status: 200, data: responseData } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act await store.dispatch( fetchSearchMoreZSetMembers('key', 0, 20, 'zz') - ); + ) // Assert const expectedActions = [ searchMoreZSetMembers('zz'), searchMoreZSetMembersSuccess(responseData), - ]; + ] - expect(store.getActions()).toEqual(expectedActions); - }); + expect(store.getActions()).toEqual(expectedActions) + }) it('failed to fetch search more zset members', async () => { - const errorMessage = 'Something was wrong!'; + const errorMessage = 'Something was wrong!' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; - apiService.post = jest.fn().mockRejectedValue(responsePayload); + } + apiService.post = jest.fn().mockRejectedValue(responsePayload) // Act await store.dispatch( fetchSearchMoreZSetMembers('key', 0, 20, 'zz') - ); + ) // Assert const expectedActions = [ searchMoreZSetMembers('zz'), addErrorNotification(responsePayload as AxiosError), searchMoreZSetMembersFailure(errorMessage) - ]; + ] - expect(store.getActions()).toEqual(expectedActions); - }); - }); + expect(store.getActions()).toEqual(expectedActions) + }) + }) describe('refreshStringMembersAction', () => { it('succeed to fetch zset members after refresh', async () => { @@ -1156,55 +1153,55 @@ describe('zset slice', () => { total: 1, size: 67, members: [{ name: '1', score: '1' }], - }; - const responsePayload = { data, status: 200 }; + } + const responsePayload = { data, status: 200 } - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) // Act await store.dispatch( refreshZsetMembersAction(data.keyName) - ); + ) // Assert const expectedActions = [ loadZSetMembers(SortOrder.ASC), loadZSetMembersSuccess(responsePayload.data), - ]; + ] - expect(store.getActions()).toEqual(expectedActions); - }); + expect(store.getActions()).toEqual(expectedActions) + }) it('failed to fetch zset members after refresh', async () => { // Arrange - const errorMessage = 'Something was wrong!'; + const errorMessage = 'Something was wrong!' const responsePayload = { response: { status: 500, data: { message: errorMessage }, }, - }; - apiService.post = jest.fn().mockRejectedValue(responsePayload); + } + apiService.post = jest.fn().mockRejectedValue(responsePayload) // Act await store.dispatch( refreshZsetMembersAction() - ); + ) // Assert const expectedActions = [ loadZSetMembers(SortOrder.ASC), addErrorNotification(responsePayload as AxiosError), loadZSetMembersFailure(errorMessage), - ]; + ] - expect(store.getActions()).toEqual(expectedActions); - }); + expect(store.getActions()).toEqual(expectedActions) + }) it('succeed to search zset members after refresh', async () => { // Arrange const data = { members: [] } - const responsePayload = { status: 200, data }; + const responsePayload = { status: 200, data } // Act const nextState = Object.assign(initialStateDefault, { browser: { @@ -1213,24 +1210,23 @@ describe('zset slice', () => { searching: true } }, - }); - const mockedStore = mockStore(nextState); + }) + const mockedStore = mockStore(nextState) - apiService.post = jest.fn().mockResolvedValue(responsePayload); + apiService.post = jest.fn().mockResolvedValue(responsePayload) await mockedStore.dispatch( refreshZsetMembersAction() - ); + ) // Assert const expectedActions = [ searchZSetMembers(''), searchZSetMembersSuccess(data), - ]; - - expect(mockedStore.getActions()).toEqual(expectedActions); - }); - }); + ] - }); -}); + expect(mockedStore.getActions()).toEqual(expectedActions) + }) + }) + }) +}) diff --git a/redisinsight/ui/src/telemetry/tests/loadSegmentAnalytics.spec.ts b/redisinsight/ui/src/telemetry/tests/loadSegmentAnalytics.spec.ts index ea297797e4..7b2dd59de5 100644 --- a/redisinsight/ui/src/telemetry/tests/loadSegmentAnalytics.spec.ts +++ b/redisinsight/ui/src/telemetry/tests/loadSegmentAnalytics.spec.ts @@ -1,23 +1,23 @@ -import loadSegmentAnalytics from '../loadSegmentAnalytics'; +import loadSegmentAnalytics from '../loadSegmentAnalytics' beforeEach(() => { - window.analytics = {}; - window.console = { error: jest.fn() }; -}); + window.analytics = {} + window.console = { error: jest.fn() } +}) describe('loadSegmentAnalytics', () => { - const writeKeyMock = '123123'; + const writeKeyMock = '123123' it('"window.analytics" should be invoked', () => { - loadSegmentAnalytics(writeKeyMock); + loadSegmentAnalytics(writeKeyMock) - expect(window.analytics.invoked).toBeTruthy(); - }); + expect(window.analytics.invoked).toBeTruthy() + }) it('second call "loadSegmentAnalytics" should return console.error', () => { - loadSegmentAnalytics(writeKeyMock); - loadSegmentAnalytics(writeKeyMock); + loadSegmentAnalytics(writeKeyMock) + loadSegmentAnalytics(writeKeyMock) - expect(window.analytics.invoked).toBeTruthy(); - expect(console.error).toBeCalled(); - }); -}); + expect(window.analytics.invoked).toBeTruthy() + expect(console.error).toBeCalled() + }) +}) diff --git a/redisinsight/ui/src/utils/tests/apiResponse.spec.ts b/redisinsight/ui/src/utils/tests/apiResponse.spec.ts index 277d2c4de7..c6124e888f 100644 --- a/redisinsight/ui/src/utils/tests/apiResponse.spec.ts +++ b/redisinsight/ui/src/utils/tests/apiResponse.spec.ts @@ -1,13 +1,13 @@ -import { getApiErrorMessage } from 'uiSrc/utils'; -import { AxiosError } from 'axios'; +import { getApiErrorMessage } from 'uiSrc/utils' +import { AxiosError } from 'axios' -const error = { response: { data: { message: 'error' } } } as AxiosError; -const errors = { response: { data: { message: ['error1', 'error2'] } } } as AxiosError; +const error = { response: { data: { message: 'error' } } } as AxiosError +const errors = { response: { data: { message: ['error1', 'error2'] } } } as AxiosError describe('getApiErrorMessage', () => { it('should return proper message', () => { - expect(getApiErrorMessage(error)).toEqual('error'); - expect(getApiErrorMessage(null)).toEqual('Something was wrong!'); - expect(getApiErrorMessage(errors)).toEqual('error1'); - }); -}); + expect(getApiErrorMessage(error)).toEqual('error') + expect(getApiErrorMessage(null)).toEqual('Something was wrong!') + expect(getApiErrorMessage(errors)).toEqual('error1') + }) +}) diff --git a/redisinsight/ui/src/utils/tests/commands.spec.ts b/redisinsight/ui/src/utils/tests/commands.spec.ts index 4ae9286224..1edcc51d1a 100644 --- a/redisinsight/ui/src/utils/tests/commands.spec.ts +++ b/redisinsight/ui/src/utils/tests/commands.spec.ts @@ -13,8 +13,8 @@ interface IMockedCommands { } beforeEach(() => { - cleanup(); -}); + cleanup() +}) const mockedCommands: IMockedCommands[] = [ { @@ -133,58 +133,58 @@ const mockedCommands: IMockedCommands[] = [ ], complexityShortMock: 'O(log(N))', }, -]; +] describe('getComplexityShortNotation', () => { it('Complexity short should return text according mocked data', () => { mockedCommands.forEach(({ matchedCommand = '', complexityShortMock }) => { - const complexity = ALL_REDIS_COMMANDS[matchedCommand?.toUpperCase()]?.complexity ?? ''; - const complexityShort = getComplexityShortNotation(complexity); + const complexity = ALL_REDIS_COMMANDS[matchedCommand?.toUpperCase()]?.complexity ?? '' + const complexityShort = getComplexityShortNotation(complexity) if (complexityShort) { - expect(complexityShort).toEqual(complexityShortMock); + expect(complexityShort).toEqual(complexityShortMock) } else { - expect(complexityShort).toEqual(''); + expect(complexityShort).toEqual('') } - }); - }); -}); + }) + }) +}) describe('generateArgs', () => { it('generateArgs short should return argument with GeneratedName (with Enums names)', () => { mockedCommands.forEach(({ matchedCommand = '', argsNamesMock = [] }) => { - const argsInit = ALL_REDIS_COMMANDS[matchedCommand?.toUpperCase()]?.arguments ?? []; + const argsInit = ALL_REDIS_COMMANDS[matchedCommand?.toUpperCase()]?.arguments ?? [] const argsMocked: ICommandArgGenerated[] = argsInit.map((arg, i) => ({ ...arg, generatedName: argsNamesMock[i] ?? '', - })); + })) - const args = generateArgs(argsInit); + const args = generateArgs(argsInit) - expect(args).toEqual(argsMocked); - }); - }); -}); + expect(args).toEqual(argsMocked) + }) + }) +}) describe('generateArgName', () => { it('Arguments names should return text according mocked data (with Enums values)', () => { mockedCommands.forEach(({ matchedCommand = '', argsNamesWithEnumsMock }) => { - const args = ALL_REDIS_COMMANDS[matchedCommand?.toUpperCase()]?.arguments ?? []; + const args = ALL_REDIS_COMMANDS[matchedCommand?.toUpperCase()]?.arguments ?? [] - const generatedArgNames = generateArgsNames(args); - expect(generatedArgNames).toEqual(argsNamesWithEnumsMock); - }); - }); + const generatedArgNames = generateArgsNames(args) + expect(generatedArgNames).toEqual(argsNamesWithEnumsMock) + }) + }) it('Arguments names should return text according mocked data (with Enums names)', () => { mockedCommands.forEach(({ matchedCommand = '', argsNamesMock }) => { - const args = ALL_REDIS_COMMANDS[matchedCommand?.toUpperCase()]?.arguments ?? []; + const args = ALL_REDIS_COMMANDS[matchedCommand?.toUpperCase()]?.arguments ?? [] - const generatedArgNames = generateArgsNames(args, true); - expect(generatedArgNames).toEqual(argsNamesMock); - }); - }); -}); + const generatedArgNames = generateArgsNames(args, true) + expect(generatedArgNames).toEqual(argsNamesMock) + }) + }) +}) const getDocUrlForCommandTests: any[] = [ ['SET', CommandGroup.String, 'https://redis.io/commands/set'], diff --git a/redisinsight/ui/src/utils/tests/compareConsents.spec.ts b/redisinsight/ui/src/utils/tests/compareConsents.spec.ts index 067ec845f7..12121b0608 100644 --- a/redisinsight/ui/src/utils/tests/compareConsents.spec.ts +++ b/redisinsight/ui/src/utils/tests/compareConsents.spec.ts @@ -1,4 +1,4 @@ -import { compareConsents, isDifferentConsentsExists } from 'uiSrc/utils'; +import { compareConsents, isDifferentConsentsExists } from 'uiSrc/utils' const spec = { agreements: { @@ -18,46 +18,45 @@ describe('compareConsents', () => { const agreements1 = { eula: true, version: '1.0.2' - }; + } const agreements2 = { eula: true, eulaNew: false, version: '1.0.2' - }; + } const agreements3 = { eula: false, version: '1.0.0' - }; - - expect(compareConsents(spec.agreements, agreements1)).toHaveLength(0); - expect(compareConsents(spec.agreements, agreements2)).toHaveLength(0); - expect(compareConsents(spec.agreements, agreements3)).toHaveLength(1); - }); -}); + } + expect(compareConsents(spec.agreements, agreements1)).toHaveLength(0) + expect(compareConsents(spec.agreements, agreements2)).toHaveLength(0) + expect(compareConsents(spec.agreements, agreements3)).toHaveLength(1) + }) +}) describe('isDifferentConsentsExists', () => { it('isDifferentConsentsExists should return true if some difference in consents', () => { const agreements1 = { eula: true, version: '1.0.2' - }; + } const agreements2 = { eula: true, eulaNew: false, version: '1.0.2' - }; + } const agreements3 = { eula: false, version: '1.0.0' } - expect(isDifferentConsentsExists(spec.agreements, agreements1)).toBeFalsy(); - expect(isDifferentConsentsExists(spec.agreements, agreements2)).toBeFalsy(); - expect(isDifferentConsentsExists(spec.agreements, agreements3)).toBeTruthy(); - }); -}); + expect(isDifferentConsentsExists(spec.agreements, agreements1)).toBeFalsy() + expect(isDifferentConsentsExists(spec.agreements, agreements2)).toBeFalsy() + expect(isDifferentConsentsExists(spec.agreements, agreements3)).toBeTruthy() + }) +}) diff --git a/redisinsight/ui/src/utils/tests/compareVersions.spec.ts b/redisinsight/ui/src/utils/tests/compareVersions.spec.ts index 6ba52357b1..79d8e78372 100644 --- a/redisinsight/ui/src/utils/tests/compareVersions.spec.ts +++ b/redisinsight/ui/src/utils/tests/compareVersions.spec.ts @@ -1,49 +1,49 @@ -import { isVersionHigherOrEquals, isVersionHigher } from 'uiSrc/utils'; +import { isVersionHigherOrEquals, isVersionHigher } from 'uiSrc/utils' describe('isVersionHigherOrEqual', () => { it('isVersionHigherOrEqual should return true if the first version provided is higher or equal', () => { - const version1 = '6.2'; - const version2 = '6.2.9'; - const version3 = '6.2.1'; - const version4 = '6.1.9'; - const version5 = '1.2'; - const version6 = '10.2'; - const version7 = '6.2.10'; - const version8 = '10'; - const version9 = '10.0.0'; + const version1 = '6.2' + const version2 = '6.2.9' + const version3 = '6.2.1' + const version4 = '6.1.9' + const version5 = '1.2' + const version6 = '10.2' + const version7 = '6.2.10' + const version8 = '10' + const version9 = '10.0.0' - expect(isVersionHigherOrEquals(version1, version1)).toBeTruthy(); - expect(isVersionHigherOrEquals(version2, '6.2')).toBeTruthy(); - expect(isVersionHigherOrEquals(version3, '6.2.4')).toBeFalsy(); - expect(isVersionHigherOrEquals(version4, '6.2')).toBeFalsy(); - expect(isVersionHigherOrEquals(version5, '6.2')).toBeFalsy(); - expect(isVersionHigherOrEquals(version6, '6.2')).toBeTruthy(); - expect(isVersionHigherOrEquals(version7, '6.2')).toBeTruthy(); - expect(isVersionHigherOrEquals(version8, '6.2')).toBeTruthy(); - expect(isVersionHigherOrEquals(version9, '6.2')).toBeTruthy(); - }); -}); + expect(isVersionHigherOrEquals(version1, version1)).toBeTruthy() + expect(isVersionHigherOrEquals(version2, '6.2')).toBeTruthy() + expect(isVersionHigherOrEquals(version3, '6.2.4')).toBeFalsy() + expect(isVersionHigherOrEquals(version4, '6.2')).toBeFalsy() + expect(isVersionHigherOrEquals(version5, '6.2')).toBeFalsy() + expect(isVersionHigherOrEquals(version6, '6.2')).toBeTruthy() + expect(isVersionHigherOrEquals(version7, '6.2')).toBeTruthy() + expect(isVersionHigherOrEquals(version8, '6.2')).toBeTruthy() + expect(isVersionHigherOrEquals(version9, '6.2')).toBeTruthy() + }) +}) describe('isVersionHigher', () => { it('isVersionHigher should return true if the first version provided is higher', () => { - const version1 = '6.2'; - const version2 = '6.2.9'; - const version3 = '6.2.1'; - const version4 = '6.1.9'; - const version5 = '1.2'; - const version6 = '10.2'; - const version7 = '6.2.10'; - const version8 = '10'; - const version9 = '10.0.0'; + const version1 = '6.2' + const version2 = '6.2.9' + const version3 = '6.2.1' + const version4 = '6.1.9' + const version5 = '1.2' + const version6 = '10.2' + const version7 = '6.2.10' + const version8 = '10' + const version9 = '10.0.0' - expect(isVersionHigher(version1, version1)).toBeFalsy(); - expect(isVersionHigher(version2, '6.2')).toBeTruthy(); - expect(isVersionHigher(version3, '6.2.4')).toBeFalsy(); - expect(isVersionHigher(version4, '6.2')).toBeFalsy(); - expect(isVersionHigher(version5, '6.2')).toBeFalsy(); - expect(isVersionHigher(version6, '6.2')).toBeTruthy(); - expect(isVersionHigher(version7, '6.2')).toBeTruthy(); - expect(isVersionHigher(version8, '6.2')).toBeTruthy(); - expect(isVersionHigher(version9, '6.2')).toBeTruthy(); - }); -}); + expect(isVersionHigher(version1, version1)).toBeFalsy() + expect(isVersionHigher(version2, '6.2')).toBeTruthy() + expect(isVersionHigher(version3, '6.2.4')).toBeFalsy() + expect(isVersionHigher(version4, '6.2')).toBeFalsy() + expect(isVersionHigher(version5, '6.2')).toBeFalsy() + expect(isVersionHigher(version6, '6.2')).toBeTruthy() + expect(isVersionHigher(version7, '6.2')).toBeTruthy() + expect(isVersionHigher(version8, '6.2')).toBeTruthy() + expect(isVersionHigher(version9, '6.2')).toBeTruthy() + }) +}) diff --git a/redisinsight/ui/src/utils/tests/instanceOptions.spec.ts b/redisinsight/ui/src/utils/tests/instanceOptions.spec.ts index bf9ed30103..ec77fbdc2f 100644 --- a/redisinsight/ui/src/utils/tests/instanceOptions.spec.ts +++ b/redisinsight/ui/src/utils/tests/instanceOptions.spec.ts @@ -1,6 +1,6 @@ -import { mock } from 'ts-mockito'; -import { parseInstanceOptionsCloud, parseInstanceOptionsCluster } from 'uiSrc/utils'; -import { InstanceRedisCloud, InstanceRedisCluster } from 'uiSrc/slices/interfaces'; +import { mock } from 'ts-mockito' +import { parseInstanceOptionsCloud, parseInstanceOptionsCluster } from 'uiSrc/utils' +import { InstanceRedisCloud, InstanceRedisCluster } from 'uiSrc/slices/interfaces' const instancesRedisClusterMock = [ { @@ -18,7 +18,7 @@ const instancesRedisClusterMock = [ ...mock(), uid: 3 } -]; +] const instancesRedisCloudMock = [ { @@ -36,21 +36,20 @@ const instancesRedisCloudMock = [ ...mock(), databaseId: 3 } -]; - +] describe('parseInstanceOptionsCluster', () => { it('should parse', () => { expect(parseInstanceOptionsCluster(1, instancesRedisClusterMock)).toEqual({ id: 1 }) - }); -}); + }) +}) describe('parseInstanceOptionsCloud', () => { it('should parse', () => { expect(parseInstanceOptionsCloud(1, instancesRedisCloudMock)).toEqual({ id: 1 }) - }); + }) }) diff --git a/redisinsight/ui/src/utils/tests/longNames.spec.ts b/redisinsight/ui/src/utils/tests/longNames.spec.ts index 45dfd512c4..865d613e88 100644 --- a/redisinsight/ui/src/utils/tests/longNames.spec.ts +++ b/redisinsight/ui/src/utils/tests/longNames.spec.ts @@ -1,27 +1,27 @@ -import { formatLongName, formatNameShort, getDbIndex } from 'uiSrc/utils'; +import { formatLongName, formatNameShort, getDbIndex } from 'uiSrc/utils' -const longName = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ut varius massa. Vestibulum non nulla turpis. ' + - 'Morbi non viverra risus. Curabitur aliquet lorem at interdum ultrices. Praesent accumsan leo sit amet purus vestibulum, non placerat sem vestibulum. ' + - 'Cras mattis tempus vulputate. Nam in libero.' +const longName = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ut varius massa. Vestibulum non nulla turpis. ' + + 'Morbi non viverra risus. Curabitur aliquet lorem at interdum ultrices. Praesent accumsan leo sit amet purus vestibulum, non placerat sem vestibulum. ' + + 'Cras mattis tempus vulputate. Nam in libero.' describe('formatLongName', () => { it('should format long names', () => { - expect(formatLongName(longName, 50, 10,'...')).toEqual('Lorem ipsum dolor sit amet, consectet...in libero.'); - expect(formatLongName(longName, 10, 5,'...')).toEqual('Lo...bero.'); - expect(formatLongName(longName, 30, 1,' ')).toEqual('Lorem ipsum dolor sit amet, .'); - }); -}); + expect(formatLongName(longName, 50, 10, '...')).toEqual('Lorem ipsum dolor sit amet, consectet...in libero.') + expect(formatLongName(longName, 10, 5, '...')).toEqual('Lo...bero.') + expect(formatLongName(longName, 30, 1, ' ')).toEqual('Lorem ipsum dolor sit amet, .') + }) +}) describe('getDbIndex', () => { it('should format long names', () => { - expect(getDbIndex(0)).toEqual(''); - expect(getDbIndex(1)).toEqual('[1]'); - expect(getDbIndex(10)).toEqual('[10]'); - }); -}); + expect(getDbIndex(0)).toEqual('') + expect(getDbIndex(1)).toEqual('[1]') + expect(getDbIndex(10)).toEqual('[10]') + }) +}) describe('formatNameShort', () => { it('should format long values', () => { - expect(formatNameShort(longName)).toEqual('Lorem ipsum dolor sit amet, consectetur adipiscing... Nam in libero.'); - }); -}); + expect(formatNameShort(longName)).toEqual('Lorem ipsum dolor sit amet, consectetur adipiscing... Nam in libero.') + }) +}) diff --git a/redisinsight/ui/src/utils/tests/monaco.spec.ts b/redisinsight/ui/src/utils/tests/monaco.spec.ts index 033d025632..9caad52b33 100644 --- a/redisinsight/ui/src/utils/tests/monaco.spec.ts +++ b/redisinsight/ui/src/utils/tests/monaco.spec.ts @@ -19,7 +19,7 @@ describe('removeMonacoComments', () => { ], // Multiline command with comments slashes in the apostrophes [ - "set\r\n foo `// key name`\r\n // comment line\r\n // key value", + 'set\r\n foo `// key name`\r\n // comment line\r\n // key value', 'set\r\n foo `// key name`' ], // Multiline command with comments @@ -56,8 +56,8 @@ describe('multilineCommandToOneLine', () => { ], // Multiline command with quotes [ - `"hset test2\n 'http://' 'http://123'\n 'test//test' 'test//test'"`, - `"hset test2 'http://' 'http://123' 'test//test' 'test//test'"` + '"hset test2\n \'http://\' \'http://123\'\n \'test//test\' \'test//test\'"', + '"hset test2 \'http://\' \'http://123\' \'test//test\' \'test//test\'"' ], ] test.each(cases)( diff --git a/redisinsight/ui/src/utils/tests/parseResponse.spec.ts b/redisinsight/ui/src/utils/tests/parseResponse.spec.ts index d503375a5a..1c229dd171 100644 --- a/redisinsight/ui/src/utils/tests/parseResponse.spec.ts +++ b/redisinsight/ui/src/utils/tests/parseResponse.spec.ts @@ -1,5 +1,5 @@ -import { parseKeysListResponse } from 'uiSrc/utils'; -import { omit } from 'lodash'; +import { parseKeysListResponse } from 'uiSrc/utils' +import { omit } from 'lodash' describe('parseKeysListResponse', () => { it('should handle empty array in response', () => { @@ -9,17 +9,17 @@ describe('parseKeysListResponse', () => { nextCursor: '0', keys: [], shardsMeta: {}, - }; - const scanResponse = []; - expect(parseKeysListResponse(currentState.shardsMeta, scanResponse)).toEqual(currentState); - }); + } + const scanResponse = [] + expect(parseKeysListResponse(currentState.shardsMeta, scanResponse)).toEqual(currentState) + }) it('should summarize data with initial state (standalone)', () => { const currentState = { nextCursor: '0', total: 0, scanned: 0, shardsMeta: {}, - }; + } const scanResponse = [ { cursor: 100, @@ -27,29 +27,29 @@ describe('parseKeysListResponse', () => { scanned: 150, keys: ['keywithdetails'] } - ]; - const result = parseKeysListResponse(currentState.shardsMeta, scanResponse); + ] + const result = parseKeysListResponse(currentState.shardsMeta, scanResponse) expect(result).toEqual({ ...omit(scanResponse[0], 'cursor'), - nextCursor: '' + scanResponse[0].cursor, + nextCursor: `${scanResponse[0].cursor}`, shardsMeta: { - 'standalone': omit(scanResponse[0], 'keys'), + standalone: omit(scanResponse[0], 'keys'), } }) - }); + }) it('should summarize data with existing one (standalone)', () => { const currentState = { nextCursor: '100', total: 200, scanned: 150, shardsMeta: { - 'standalone': { + standalone: { cursor: 100, total: 200, scanned: 150, } }, - }; + } const scanResponse = [ { cursor: 0, @@ -57,27 +57,27 @@ describe('parseKeysListResponse', () => { scanned: 150, keys: ['keywithdetails'] } - ]; - const result = parseKeysListResponse(currentState.shardsMeta, scanResponse); + ] + const result = parseKeysListResponse(currentState.shardsMeta, scanResponse) expect(result).toEqual({ ...omit(scanResponse[0], 'cursor'), scanned: scanResponse[0].total, - nextCursor: '' + scanResponse[0].cursor, + nextCursor: `${scanResponse[0].cursor}`, shardsMeta: { - 'standalone': { + standalone: { ...omit(scanResponse[0], 'keys'), scanned: scanResponse[0].total, }, } }) - }); + }) it('should summarize data with initial state (cluster)', () => { const currentState = { nextCursor: '127.0.0.1:7000@100||127.0.0.1:7002@9', total: 200 + 50 + 400, scanned: 150 + 50 + 150, shardsMeta: {}, - }; + } const scanResponse = [ { cursor: 100, @@ -103,8 +103,8 @@ describe('parseKeysListResponse', () => { host: '127.0.0.1', port: 7002, } - ]; - const result = parseKeysListResponse(currentState.shardsMeta, scanResponse); + ] + const result = parseKeysListResponse(currentState.shardsMeta, scanResponse) expect(result).toEqual({ nextCursor: '127.0.0.1:7000@100||127.0.0.1:7002@9', total: 200 + 50 + 400, @@ -133,8 +133,8 @@ describe('parseKeysListResponse', () => { port: 7002, }, } - }); - }); + }) + }) it('should summarize data with initial one (cluster)', () => { const currentState = { nextCursor: '127.0.0.1:7000@100||127.0.0.1:7002@9', @@ -164,7 +164,7 @@ describe('parseKeysListResponse', () => { port: 7002, }, }, - }; + } const scanResponse = [ { cursor: 0, @@ -182,8 +182,8 @@ describe('parseKeysListResponse', () => { host: '127.0.0.1', port: 7002, } - ]; - const result = parseKeysListResponse(currentState.shardsMeta, scanResponse); + ] + const result = parseKeysListResponse(currentState.shardsMeta, scanResponse) expect(result).toEqual({ nextCursor: '127.0.0.1:7002@18', total: 201 + 50 + 400, @@ -212,6 +212,6 @@ describe('parseKeysListResponse', () => { port: 7002, }, } - }); - }); -}); + }) + }) +}) diff --git a/redisinsight/ui/src/utils/tests/removeEmpty.spec.ts b/redisinsight/ui/src/utils/tests/removeEmpty.spec.ts index a626561312..c62d24b181 100644 --- a/redisinsight/ui/src/utils/tests/removeEmpty.spec.ts +++ b/redisinsight/ui/src/utils/tests/removeEmpty.spec.ts @@ -1,9 +1,9 @@ -import { removeEmpty } from 'uiSrc/utils'; +import { removeEmpty } from 'uiSrc/utils' describe('removeEmpty', () => { it('should remove empty fields from object', () => { - expect(removeEmpty({ a: '', b: { c: '', d: { g: ''} }, e: 1 })).toEqual({ b: { d: {} }, e: 1}) - expect(removeEmpty({ a: ''})).toEqual({}) - expect(removeEmpty({ a: '', b: { c: '' }, e: 1 })).toEqual({ b: { }, e: 1}) - }); + expect(removeEmpty({ a: '', b: { c: '', d: { g: '' } }, e: 1 })).toEqual({ b: { d: {} }, e: 1 }) + expect(removeEmpty({ a: '' })).toEqual({}) + expect(removeEmpty({ a: '', b: { c: '' }, e: 1 })).toEqual({ b: { }, e: 1 }) + }) }) diff --git a/redisinsight/ui/src/utils/tests/replaceSpaces.spec.ts b/redisinsight/ui/src/utils/tests/replaceSpaces.spec.ts index 0ee2297140..ecbe8d1be0 100644 --- a/redisinsight/ui/src/utils/tests/replaceSpaces.spec.ts +++ b/redisinsight/ui/src/utils/tests/replaceSpaces.spec.ts @@ -1,23 +1,23 @@ -import replaceSpaces from '../replaceSpaces'; +import replaceSpaces from '../replaceSpaces' describe('replaceSpaces test', () => { it('replaceSpaces should return text with replaced spaces', () => { - const text1 = '10'; - const text2 = ' trala la '; - const text3 = 'tr la lo lu'; - const text4 = 'tralalala'; - const text5 = ' 1233 123123 tral lalal '; + const text1 = '10' + const text2 = ' trala la ' + const text3 = 'tr la lo lu' + const text4 = 'tralalala' + const text5 = ' 1233 123123 tral lalal ' - const expectedResponse1 = text1.replace(/\s\s/g, '\u00a0\u00a0'); - const expectedResponse2 = text2.replace(/\s\s/g, '\u00a0\u00a0'); - const expectedResponse3 = text3.replace(/\s\s/g, '\u00a0\u00a0'); - const expectedResponse4 = text4.replace(/\s\s/g, '\u00a0\u00a0'); - const expectedResponse5 = text5.replace(/\s\s/g, '\u00a0\u00a0'); + const expectedResponse1 = text1.replace(/\s\s/g, '\u00a0\u00a0') + const expectedResponse2 = text2.replace(/\s\s/g, '\u00a0\u00a0') + const expectedResponse3 = text3.replace(/\s\s/g, '\u00a0\u00a0') + const expectedResponse4 = text4.replace(/\s\s/g, '\u00a0\u00a0') + const expectedResponse5 = text5.replace(/\s\s/g, '\u00a0\u00a0') - expect(replaceSpaces(text1)).toEqual(expectedResponse1); - expect(replaceSpaces(text2)).toEqual(expectedResponse2); - expect(replaceSpaces(text3)).toEqual(expectedResponse3); - expect(replaceSpaces(text4)).toEqual(expectedResponse4); - expect(replaceSpaces(text5)).toEqual(expectedResponse5); - }); -}); + expect(replaceSpaces(text1)).toEqual(expectedResponse1) + expect(replaceSpaces(text2)).toEqual(expectedResponse2) + expect(replaceSpaces(text3)).toEqual(expectedResponse3) + expect(replaceSpaces(text4)).toEqual(expectedResponse4) + expect(replaceSpaces(text5)).toEqual(expectedResponse5) + }) +}) diff --git a/redisinsight/ui/src/utils/tests/routerWithSubRoutes.spec.tsx b/redisinsight/ui/src/utils/tests/routerWithSubRoutes.spec.tsx index bfdaca292b..5dcede21c6 100644 --- a/redisinsight/ui/src/utils/tests/routerWithSubRoutes.spec.tsx +++ b/redisinsight/ui/src/utils/tests/routerWithSubRoutes.spec.tsx @@ -1,9 +1,8 @@ -import React from 'react'; -import Router from 'uiSrc/Router'; -import { render } from 'uiSrc/utils/test-utils'; -import RouteWithSubRoutes from 'uiSrc/utils/routerWithSubRoutes'; -import ROUTES from 'uiSrc/constants/routes'; - +import React from 'react' +import Router from 'uiSrc/Router' +import { render } from 'uiSrc/utils/test-utils' +import RouteWithSubRoutes from 'uiSrc/utils/routerWithSubRoutes' +import ROUTES from 'uiSrc/constants/routes' describe('RouteWithSubRoutes', () => { it('should render', () => { @@ -13,6 +12,7 @@ describe('RouteWithSubRoutes', () => { key={1} {...ROUTES[0]} /> - )).toBeTruthy() - }); -}); + + )).toBeTruthy() + }) +}) diff --git a/redisinsight/ui/src/utils/tests/truncateNumber.spec.ts b/redisinsight/ui/src/utils/tests/truncateNumber.spec.ts index b53033bdb4..2fb1e1908a 100644 --- a/redisinsight/ui/src/utils/tests/truncateNumber.spec.ts +++ b/redisinsight/ui/src/utils/tests/truncateNumber.spec.ts @@ -19,7 +19,7 @@ describe('truncateNumberToRange', () => { expect(truncateNumberToRange(number3)).toEqual(expectedResponse3) expect(truncateNumberToRange(number4)).toEqual(expectedResponse4) expect(truncateNumberToRange(number5)).toEqual(expectedResponse5) - }); + }) it('truncateNumberToRange should return value between 1 K and 99 K', () => { const number1 = 10_000 @@ -39,7 +39,7 @@ describe('truncateNumberToRange', () => { expect(truncateNumberToRange(number3)).toEqual(expectedResponse3) expect(truncateNumberToRange(number4)).toEqual(expectedResponse4) expect(truncateNumberToRange(number5)).toEqual(expectedResponse5) - }); + }) it('truncateNumberToRange should return value between 1 M and 999 M', () => { const number1 = 10_000_000 @@ -59,7 +59,7 @@ describe('truncateNumberToRange', () => { expect(truncateNumberToRange(number3)).toEqual(expectedResponse3) expect(truncateNumberToRange(number4)).toEqual(expectedResponse4) expect(truncateNumberToRange(number5)).toEqual(expectedResponse5) - }); + }) it('truncateNumberToRange should return value between 1 B and 2 B', () => { const number1 = 1_000_000_001 diff --git a/redisinsight/ui/src/utils/tests/truncateTTL.spec.ts b/redisinsight/ui/src/utils/tests/truncateTTL.spec.ts index e24f2c7ca4..149d970a96 100644 --- a/redisinsight/ui/src/utils/tests/truncateTTL.spec.ts +++ b/redisinsight/ui/src/utils/tests/truncateTTL.spec.ts @@ -2,134 +2,134 @@ import { truncateTTLToDuration, truncateTTLToRange, truncateTTLToSeconds, -} from '../truncateTTL'; +} from '../truncateTTL' describe('Truncate TTL util tests', () => { describe('truncateTTLToRange', () => { it('truncateTTLToRange should return "No limit"', () => { - const ttl = -1; - const expectedResponse = 'No limit'; + const ttl = -1 + const expectedResponse = 'No limit' - expect(truncateTTLToRange(ttl)).toEqual(expectedResponse); - }); + expect(truncateTTLToRange(ttl)).toEqual(expectedResponse) + }) it('truncateTTLToRange should return value between 0 and 999', () => { - const ttl1 = 10; - const ttl2 = 100; - const ttl3 = 256; - const ttl4 = 612; - const ttl5 = 999; - - const expectedResponse1 = '10'; - const expectedResponse2 = '100'; - const expectedResponse3 = '256'; - const expectedResponse4 = '612'; - const expectedResponse5 = '999'; - - expect(truncateTTLToRange(ttl1)).toEqual(expectedResponse1); - expect(truncateTTLToRange(ttl2)).toEqual(expectedResponse2); - expect(truncateTTLToRange(ttl3)).toEqual(expectedResponse3); - expect(truncateTTLToRange(ttl4)).toEqual(expectedResponse4); - expect(truncateTTLToRange(ttl5)).toEqual(expectedResponse5); - }); + const ttl1 = 10 + const ttl2 = 100 + const ttl3 = 256 + const ttl4 = 612 + const ttl5 = 999 + + const expectedResponse1 = '10' + const expectedResponse2 = '100' + const expectedResponse3 = '256' + const expectedResponse4 = '612' + const expectedResponse5 = '999' + + expect(truncateTTLToRange(ttl1)).toEqual(expectedResponse1) + expect(truncateTTLToRange(ttl2)).toEqual(expectedResponse2) + expect(truncateTTLToRange(ttl3)).toEqual(expectedResponse3) + expect(truncateTTLToRange(ttl4)).toEqual(expectedResponse4) + expect(truncateTTLToRange(ttl5)).toEqual(expectedResponse5) + }) it('truncateTTLToRange should return value between 1 K and 99 K', () => { - const ttl1 = 10_000; - const ttl2 = 100_000; - const ttl3 = 256_000; - const ttl4 = 612_000; - const ttl5 = 999_000; - - const expectedResponse1 = '10 K'; - const expectedResponse2 = '100 K'; - const expectedResponse3 = '256 K'; - const expectedResponse4 = '612 K'; - const expectedResponse5 = '999 K'; - - expect(truncateTTLToRange(ttl1)).toEqual(expectedResponse1); - expect(truncateTTLToRange(ttl2)).toEqual(expectedResponse2); - expect(truncateTTLToRange(ttl3)).toEqual(expectedResponse3); - expect(truncateTTLToRange(ttl4)).toEqual(expectedResponse4); - expect(truncateTTLToRange(ttl5)).toEqual(expectedResponse5); - }); + const ttl1 = 10_000 + const ttl2 = 100_000 + const ttl3 = 256_000 + const ttl4 = 612_000 + const ttl5 = 999_000 + + const expectedResponse1 = '10 K' + const expectedResponse2 = '100 K' + const expectedResponse3 = '256 K' + const expectedResponse4 = '612 K' + const expectedResponse5 = '999 K' + + expect(truncateTTLToRange(ttl1)).toEqual(expectedResponse1) + expect(truncateTTLToRange(ttl2)).toEqual(expectedResponse2) + expect(truncateTTLToRange(ttl3)).toEqual(expectedResponse3) + expect(truncateTTLToRange(ttl4)).toEqual(expectedResponse4) + expect(truncateTTLToRange(ttl5)).toEqual(expectedResponse5) + }) it('truncateTTLToRange should return value between 1 M and 999 M', () => { - const ttl1 = 10_000_000; - const ttl2 = 100_000_000; - const ttl3 = 256_000_000; - const ttl4 = 612_000_000; - const ttl5 = 999_000_000; - - const expectedResponse1 = '10 M'; - const expectedResponse2 = '100 M'; - const expectedResponse3 = '256 M'; - const expectedResponse4 = '612 M'; - const expectedResponse5 = '999 M'; - - expect(truncateTTLToRange(ttl1)).toEqual(expectedResponse1); - expect(truncateTTLToRange(ttl2)).toEqual(expectedResponse2); - expect(truncateTTLToRange(ttl3)).toEqual(expectedResponse3); - expect(truncateTTLToRange(ttl4)).toEqual(expectedResponse4); - expect(truncateTTLToRange(ttl5)).toEqual(expectedResponse5); - }); + const ttl1 = 10_000_000 + const ttl2 = 100_000_000 + const ttl3 = 256_000_000 + const ttl4 = 612_000_000 + const ttl5 = 999_000_000 + + const expectedResponse1 = '10 M' + const expectedResponse2 = '100 M' + const expectedResponse3 = '256 M' + const expectedResponse4 = '612 M' + const expectedResponse5 = '999 M' + + expect(truncateTTLToRange(ttl1)).toEqual(expectedResponse1) + expect(truncateTTLToRange(ttl2)).toEqual(expectedResponse2) + expect(truncateTTLToRange(ttl3)).toEqual(expectedResponse3) + expect(truncateTTLToRange(ttl4)).toEqual(expectedResponse4) + expect(truncateTTLToRange(ttl5)).toEqual(expectedResponse5) + }) it('truncateTTLToRange should return value between 1 B and 2 B', () => { - const ttl1 = 1_000_000_001; - const ttl2 = 1_500_001_200; - const ttl3 = 2_120_042_300; + const ttl1 = 1_000_000_001 + const ttl2 = 1_500_001_200 + const ttl3 = 2_120_042_300 - const expectedResponse1 = '1 B'; - const expectedResponse2 = '1 B'; - const expectedResponse3 = '2 B'; + const expectedResponse1 = '1 B' + const expectedResponse2 = '1 B' + const expectedResponse3 = '2 B' - expect(truncateTTLToRange(ttl1)).toEqual(expectedResponse1); - expect(truncateTTLToRange(ttl2)).toEqual(expectedResponse2); - expect(truncateTTLToRange(ttl3)).toEqual(expectedResponse3); - }); - }); + expect(truncateTTLToRange(ttl1)).toEqual(expectedResponse1) + expect(truncateTTLToRange(ttl2)).toEqual(expectedResponse2) + expect(truncateTTLToRange(ttl3)).toEqual(expectedResponse3) + }) + }) describe('truncateTTLToDuration', () => { it('truncateTTLToDuration should return appropriate value', () => { - const ttl1 = 100; - const ttl2 = 1_534; - const ttl3 = 54_334; - const ttl4 = 4_325_634; - const ttl5 = 112_012_330; - const ttl6 = 2_120_042_300; - - const expectedResponse1 = '1 min, 40 s'; - const expectedResponse2 = '25 min, 34 s'; - const expectedResponse3 = '15 h, 5 min, 34 s'; - const expectedResponse4 = '1 mo, 19 d, 1 h, 33 min, 54 s'; + const ttl1 = 100 + const ttl2 = 1_534 + const ttl3 = 54_334 + const ttl4 = 4_325_634 + const ttl5 = 112_012_330 + const ttl6 = 2_120_042_300 + + const expectedResponse1 = '1 min, 40 s' + const expectedResponse2 = '25 min, 34 s' + const expectedResponse3 = '15 h, 5 min, 34 s' + const expectedResponse4 = '1 mo, 19 d, 1 h, 33 min, 54 s' // TODO started failing // const expectedResponse5 = '3 yr, 6 mo, 19 d, 10 h, 32 min, 10 s'; // const expectedResponse6 = '67 yr, 2 mo, 6 d, 12 h, 38 min, 20 s'; - expect(truncateTTLToDuration(ttl1)).toEqual(expectedResponse1); - expect(truncateTTLToDuration(ttl2)).toEqual(expectedResponse2); - expect(truncateTTLToDuration(ttl3)).toEqual(expectedResponse3); - expect(truncateTTLToDuration(ttl4)).toEqual(expectedResponse4); + expect(truncateTTLToDuration(ttl1)).toEqual(expectedResponse1) + expect(truncateTTLToDuration(ttl2)).toEqual(expectedResponse2) + expect(truncateTTLToDuration(ttl3)).toEqual(expectedResponse3) + expect(truncateTTLToDuration(ttl4)).toEqual(expectedResponse4) // expect(truncateTTLToDuration(ttl5)).toEqual(expectedResponse5); // expect(truncateTTLToDuration(ttl6)).toEqual(expectedResponse6); - }); - }); + }) + }) describe('truncateTTLToSeconds', () => { it('truncateTTLToSeconds should return appropriate value', () => { - const ttl1 = 100; - const ttl2 = 10_000; - const ttl3 = 1_231_231; - const ttl4 = 122_331_231; - - const expectedResponse1 = '100'; - const expectedResponse2 = '10 000'; - const expectedResponse3 = '1 231 231'; - const expectedResponse4 = '122 331 231'; - - expect(truncateTTLToSeconds(ttl1)).toEqual(expectedResponse1); - expect(truncateTTLToSeconds(ttl2)).toEqual(expectedResponse2); - expect(truncateTTLToSeconds(ttl3)).toEqual(expectedResponse3); - expect(truncateTTLToSeconds(ttl4)).toEqual(expectedResponse4); - }); - }); -}); + const ttl1 = 100 + const ttl2 = 10_000 + const ttl3 = 1_231_231 + const ttl4 = 122_331_231 + + const expectedResponse1 = '100' + const expectedResponse2 = '10 000' + const expectedResponse3 = '1 231 231' + const expectedResponse4 = '122 331 231' + + expect(truncateTTLToSeconds(ttl1)).toEqual(expectedResponse1) + expect(truncateTTLToSeconds(ttl2)).toEqual(expectedResponse2) + expect(truncateTTLToSeconds(ttl3)).toEqual(expectedResponse3) + expect(truncateTTLToSeconds(ttl4)).toEqual(expectedResponse4) + }) + }) +}) diff --git a/redisinsight/ui/src/utils/tests/validations.spec.ts b/redisinsight/ui/src/utils/tests/validations.spec.ts index 411fa0f835..5ada751bdf 100644 --- a/redisinsight/ui/src/utils/tests/validations.spec.ts +++ b/redisinsight/ui/src/utils/tests/validations.spec.ts @@ -10,156 +10,156 @@ import { validateTTLNumberForAddKey, MAX_DATABASE_INDEX_NUMBER, validateDatabaseNumber -} from '../validations'; +} from '../validations' -const text1 = '123 123 123'; -const text2 = 'lorem lorem12312 lorem'; -const text3 = 'мама мыла раму'; -const text4 = 'euihao crhrc.hrch !@#^&*($@#$'; -const text5 = 'test@test.com'; -const text6 = '-2323'; -const text7 = '348234'; -const text8 = '34823443924234234'; -const text9 = '-3482.344392424'; -const text10 = '348.344392421312321312312316786724'; -const text11 = '3.3.1'; -const text12 = '-3-2'; -const text13 = '5'; +const text1 = '123 123 123' +const text2 = 'lorem lorem12312 lorem' +const text3 = 'мама мыла раму' +const text4 = 'euihao crhrc.hrch !@#^&*($@#$' +const text5 = 'test@test.com' +const text6 = '-2323' +const text7 = '348234' +const text8 = '34823443924234234' +const text9 = '-3482.344392424' +const text10 = '348.344392421312321312312316786724' +const text11 = '3.3.1' +const text12 = '-3-2' +const text13 = '5' describe('Validations utils', () => { describe('validateField', () => { it('validateField should return text without empty spaces', () => { - const expectedResponse1 = '123123123'; - const expectedResponse2 = 'loremlorem12312lorem'; - const expectedResponse3 = 'мамамылараму'; - const expectedResponse4 = 'euihaocrhrc.hrch!@#^&*($@#$'; + const expectedResponse1 = '123123123' + const expectedResponse2 = 'loremlorem12312lorem' + const expectedResponse3 = 'мамамылараму' + const expectedResponse4 = 'euihaocrhrc.hrch!@#^&*($@#$' - expect(validateField(text1)).toEqual(expectedResponse1); - expect(validateField(text2)).toEqual(expectedResponse2); - expect(validateField(text3)).toEqual(expectedResponse3); - expect(validateField(text4)).toEqual(expectedResponse4); - }); - }); + expect(validateField(text1)).toEqual(expectedResponse1) + expect(validateField(text2)).toEqual(expectedResponse2) + expect(validateField(text3)).toEqual(expectedResponse3) + expect(validateField(text4)).toEqual(expectedResponse4) + }) + }) describe('validateCountNumber', () => { it('validateCountNumber should return only positive numbers', () => { - const expectedResponse1 = '123123123'; - const expectedResponse2 = '12312'; - const expectedResponse4 = ''; - const expectedResponse5 = ''; - const expectedResponse6 = '2323'; - const expectedResponse7 = '348234'; + const expectedResponse1 = '123123123' + const expectedResponse2 = '12312' + const expectedResponse4 = '' + const expectedResponse5 = '' + const expectedResponse6 = '2323' + const expectedResponse7 = '348234' - expect(validateCountNumber(text1)).toEqual(expectedResponse1); - expect(validateCountNumber(text2)).toEqual(expectedResponse2); - expect(validateCountNumber(text4)).toEqual(expectedResponse4); - expect(validateCountNumber(text5)).toEqual(expectedResponse5); - expect(validateCountNumber(text6)).toEqual(expectedResponse6); - expect(validateCountNumber(text7)).toEqual(expectedResponse7); - }); - }); + expect(validateCountNumber(text1)).toEqual(expectedResponse1) + expect(validateCountNumber(text2)).toEqual(expectedResponse2) + expect(validateCountNumber(text4)).toEqual(expectedResponse4) + expect(validateCountNumber(text5)).toEqual(expectedResponse5) + expect(validateCountNumber(text6)).toEqual(expectedResponse6) + expect(validateCountNumber(text7)).toEqual(expectedResponse7) + }) + }) describe('validateTTLNumber', () => { it('validateTTLNumber should return only numbers between 0 and MAX_TTL_NUMBER', () => { - const expectedResponse1 = '123123123'; - const expectedResponse2 = '12312'; - const expectedResponse4 = ''; - const expectedResponse5 = ''; - const expectedResponse6 = '2323'; - const expectedResponse7 = '348234'; - const expectedResponse8 = `${MAX_TTL_NUMBER}`; + const expectedResponse1 = '123123123' + const expectedResponse2 = '12312' + const expectedResponse4 = '' + const expectedResponse5 = '' + const expectedResponse6 = '2323' + const expectedResponse7 = '348234' + const expectedResponse8 = `${MAX_TTL_NUMBER}` - expect(validateTTLNumber(text1)).toEqual(expectedResponse1); - expect(validateTTLNumber(text2)).toEqual(expectedResponse2); - expect(validateTTLNumber(text4)).toEqual(expectedResponse4); - expect(validateTTLNumber(text5)).toEqual(expectedResponse5); - expect(validateTTLNumber(text6)).toEqual(expectedResponse6); - expect(validateTTLNumber(text7)).toEqual(expectedResponse7); - expect(validateTTLNumber(text8)).toEqual(expectedResponse8); - }); - }); + expect(validateTTLNumber(text1)).toEqual(expectedResponse1) + expect(validateTTLNumber(text2)).toEqual(expectedResponse2) + expect(validateTTLNumber(text4)).toEqual(expectedResponse4) + expect(validateTTLNumber(text5)).toEqual(expectedResponse5) + expect(validateTTLNumber(text6)).toEqual(expectedResponse6) + expect(validateTTLNumber(text7)).toEqual(expectedResponse7) + expect(validateTTLNumber(text8)).toEqual(expectedResponse8) + }) + }) describe('validateTTLNumberForAddKey', () => { it('validateTTLNumberForAddKey should return only numbers between 1 and MAX_TTL_NUMBER', () => { - expect(validateTTLNumberForAddKey('0')).toEqual(''); - expect(validateTTLNumberForAddKey('0123')).toEqual('123'); - expect(validateTTLNumberForAddKey('300')).toEqual('300'); - }); - }); + expect(validateTTLNumberForAddKey('0')).toEqual('') + expect(validateTTLNumberForAddKey('0123')).toEqual('123') + expect(validateTTLNumberForAddKey('300')).toEqual('300') + }) + }) describe('validateScoreNumber', () => { it('validateScoreNumber should return numbers with 15 decimal places max, negative values are allowed', () => { - const expectedResponse1 = '123123123'; - const expectedResponse2 = '12312'; - const expectedResponse6 = '-2323'; - const expectedResponse7 = '348234'; - const expectedResponse9 = '-3482.344392424'; - const expectedResponse10 = '348.344392421312321'; - const expectedResponse11 = '3.31'; - const expectedResponse12 = '-32'; + const expectedResponse1 = '123123123' + const expectedResponse2 = '12312' + const expectedResponse6 = '-2323' + const expectedResponse7 = '348234' + const expectedResponse9 = '-3482.344392424' + const expectedResponse10 = '348.344392421312321' + const expectedResponse11 = '3.31' + const expectedResponse12 = '-32' - expect(validateScoreNumber(text1)).toEqual(expectedResponse1); - expect(validateScoreNumber(text2)).toEqual(expectedResponse2); - expect(validateScoreNumber(text6)).toEqual(expectedResponse6); - expect(validateScoreNumber(text7)).toEqual(expectedResponse7); - expect(validateScoreNumber(text9)).toEqual(expectedResponse9); - expect(validateScoreNumber(text10)).toEqual(expectedResponse10); - expect(validateScoreNumber(text11)).toEqual(expectedResponse11); - expect(validateScoreNumber(text12)).toEqual(expectedResponse12); + expect(validateScoreNumber(text1)).toEqual(expectedResponse1) + expect(validateScoreNumber(text2)).toEqual(expectedResponse2) + expect(validateScoreNumber(text6)).toEqual(expectedResponse6) + expect(validateScoreNumber(text7)).toEqual(expectedResponse7) + expect(validateScoreNumber(text9)).toEqual(expectedResponse9) + expect(validateScoreNumber(text10)).toEqual(expectedResponse10) + expect(validateScoreNumber(text11)).toEqual(expectedResponse11) + expect(validateScoreNumber(text12)).toEqual(expectedResponse12) }) }) describe('validatePortNumber', () => { it('validatePortNumber should return only numbers between 0 and MAX_PORT_NUMBER', () => { - const expectedResponse1 = `${MAX_PORT_NUMBER}`; - const expectedResponse2 = '12312'; - const expectedResponse4 = '0'; - const expectedResponse5 = '0'; - const expectedResponse6 = '2323'; - const expectedResponse7 = `${MAX_PORT_NUMBER}`; - const expectedResponse8 = `${MAX_PORT_NUMBER}`; + const expectedResponse1 = `${MAX_PORT_NUMBER}` + const expectedResponse2 = '12312' + const expectedResponse4 = '0' + const expectedResponse5 = '0' + const expectedResponse6 = '2323' + const expectedResponse7 = `${MAX_PORT_NUMBER}` + const expectedResponse8 = `${MAX_PORT_NUMBER}` - expect(validatePortNumber(text1)).toEqual(expectedResponse1); - expect(validatePortNumber(text2)).toEqual(expectedResponse2); - expect(validatePortNumber(text4)).toEqual(expectedResponse4); - expect(validatePortNumber(text5)).toEqual(expectedResponse5); - expect(validatePortNumber(text6)).toEqual(expectedResponse6); - expect(validatePortNumber(text7)).toEqual(expectedResponse7); - expect(validatePortNumber(text8)).toEqual(expectedResponse8); - }); - }); + expect(validatePortNumber(text1)).toEqual(expectedResponse1) + expect(validatePortNumber(text2)).toEqual(expectedResponse2) + expect(validatePortNumber(text4)).toEqual(expectedResponse4) + expect(validatePortNumber(text5)).toEqual(expectedResponse5) + expect(validatePortNumber(text6)).toEqual(expectedResponse6) + expect(validatePortNumber(text7)).toEqual(expectedResponse7) + expect(validatePortNumber(text8)).toEqual(expectedResponse8) + }) + }) describe('validateDatabaseNumber', () => { it('validateDatabaseNumber should return only numbers between 0 and MAX_DATABASE_INDEX_NUMBER', () => { - const expectedResponse1 = `${MAX_DATABASE_INDEX_NUMBER}`; - const expectedResponse2 = `${MAX_DATABASE_INDEX_NUMBER}`; - const expectedResponse4 = '0'; - const expectedResponse5 = '0'; - const expectedResponse6 = `${MAX_DATABASE_INDEX_NUMBER}`; - const expectedResponse7 = `${MAX_DATABASE_INDEX_NUMBER}`; - const expectedResponse8 = `${MAX_DATABASE_INDEX_NUMBER}`; - const expectedResponse13 = '5'; + const expectedResponse1 = `${MAX_DATABASE_INDEX_NUMBER}` + const expectedResponse2 = `${MAX_DATABASE_INDEX_NUMBER}` + const expectedResponse4 = '0' + const expectedResponse5 = '0' + const expectedResponse6 = `${MAX_DATABASE_INDEX_NUMBER}` + const expectedResponse7 = `${MAX_DATABASE_INDEX_NUMBER}` + const expectedResponse8 = `${MAX_DATABASE_INDEX_NUMBER}` + const expectedResponse13 = '5' - expect(validateDatabaseNumber(text1)).toEqual(expectedResponse1); - expect(validateDatabaseNumber(text2)).toEqual(expectedResponse2); - expect(validateDatabaseNumber(text4)).toEqual(expectedResponse4); - expect(validateDatabaseNumber(text5)).toEqual(expectedResponse5); - expect(validateDatabaseNumber(text6)).toEqual(expectedResponse6); - expect(validateDatabaseNumber(text7)).toEqual(expectedResponse7); - expect(validateDatabaseNumber(text8)).toEqual(expectedResponse8); - expect(validateDatabaseNumber(text13)).toEqual(expectedResponse13); - }); - }); + expect(validateDatabaseNumber(text1)).toEqual(expectedResponse1) + expect(validateDatabaseNumber(text2)).toEqual(expectedResponse2) + expect(validateDatabaseNumber(text4)).toEqual(expectedResponse4) + expect(validateDatabaseNumber(text5)).toEqual(expectedResponse5) + expect(validateDatabaseNumber(text6)).toEqual(expectedResponse6) + expect(validateDatabaseNumber(text7)).toEqual(expectedResponse7) + expect(validateDatabaseNumber(text8)).toEqual(expectedResponse8) + expect(validateDatabaseNumber(text13)).toEqual(expectedResponse13) + }) + }) describe('validateEmail', () => { it('validateEmail should return "true" only for email format text', () => { - expect(validateEmail(text1)).toBeFalsy(); - expect(validateEmail(text2)).toBeFalsy(); - expect(validateEmail(text4)).toBeFalsy(); - expect(validateEmail(text5)).toBeTruthy(); - expect(validateEmail(text6)).toBeFalsy(); - expect(validateEmail(text7)).toBeFalsy(); - expect(validateEmail(text8)).toBeFalsy(); - }); - }); -}); + expect(validateEmail(text1)).toBeFalsy() + expect(validateEmail(text2)).toBeFalsy() + expect(validateEmail(text4)).toBeFalsy() + expect(validateEmail(text5)).toBeTruthy() + expect(validateEmail(text6)).toBeFalsy() + expect(validateEmail(text7)).toBeFalsy() + expect(validateEmail(text8)).toBeFalsy() + }) + }) +})