Skip to content

Commit 973ef61

Browse files
author
Roman.Sergeenko
committed
#RI-1756 - add unit tests, refactor
1 parent 5d74240 commit 973ef61

File tree

9 files changed

+116
-30
lines changed

9 files changed

+116
-30
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { cloneDeep } from 'lodash'
2+
import React from 'react'
3+
4+
import { cleanup, fireEvent, mockedStore, render, screen } from 'uiSrc/utils/test-utils'
5+
import { toggleCli, toggleCliHelper } from 'uiSrc/slices/cli/cli-settings'
6+
7+
import BottomGroupComponents from './BottomGroupComponents'
8+
9+
jest.mock('uiSrc/slices/cli/cli-settings', () => ({
10+
...jest.requireActual('uiSrc/slices/cli/cli-settings'),
11+
cliSettingsSelector: jest.fn().mockReturnValue({
12+
isShowCli: true,
13+
isShowHelper: true
14+
}),
15+
}))
16+
17+
let store: typeof mockedStore
18+
beforeEach(() => {
19+
cleanup()
20+
store = cloneDeep(mockedStore)
21+
store.clearActions()
22+
})
23+
24+
describe('BottomGroupComponents', () => {
25+
it('should render', () => {
26+
expect(
27+
render(<BottomGroupComponents />)
28+
).toBeTruthy()
29+
})
30+
31+
it('should render Cli when isShowCli truthy', () => {
32+
render(<BottomGroupComponents />)
33+
expect(screen.getByTestId('cli')).toBeInTheDocument()
34+
})
35+
36+
it('should render Command Helper when isShowHelper truthy', () => {
37+
render(<BottomGroupComponents />)
38+
expect(screen.getByTestId('command-helper')).toBeInTheDocument()
39+
})
40+
41+
it('should not to close command helper after closing cli', () => {
42+
render(<BottomGroupComponents />)
43+
fireEvent.click(screen.getByTestId('collapse-cli'))
44+
const expectedActions = [toggleCli()]
45+
expect(store.getActions()).toEqual(expectedActions)
46+
47+
expect(screen.getByTestId('command-helper')).toBeInTheDocument()
48+
})
49+
50+
it('should not to close cli after closing command-helper', () => {
51+
render(<BottomGroupComponents />)
52+
fireEvent.click(screen.getByTestId('close-command-helper'))
53+
54+
const expectedActions = [toggleCliHelper()]
55+
expect(store.getActions()).toEqual(expectedActions)
56+
57+
expect(screen.getByTestId('cli')).toBeInTheDocument()
58+
})
59+
})

redisinsight/ui/src/components/bottom-group-components/BottomGroupComponents.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ import BottomGroupMinimized from './components/bottom-group-minimized/BottomGrou
99
import styles from './styles.module.scss'
1010

1111
const BottomGroupComponents = () => {
12-
const { isShowCli } = useSelector(cliSettingsSelector)
13-
const {
14-
isShowHelper,
15-
} = useSelector(cliSettingsSelector)
12+
const { isShowCli, isShowHelper } = useSelector(cliSettingsSelector)
1613

1714
return (
1815
<div className={styles.groupComponentsWrapper}>
Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,37 @@
11
import React from 'react'
22
import { cloneDeep } from 'lodash'
33

4-
import { toggleCli } from 'uiSrc/slices/cli/cli-settings'
5-
import { fireEvent, mockedStore, render, screen } from 'uiSrc/utils/test-utils'
4+
import { toggleCli, toggleCliHelper } from 'uiSrc/slices/cli/cli-settings'
5+
import { cleanup, fireEvent, mockedStore, render, screen } from 'uiSrc/utils/test-utils'
66
import BottomGroupMinimized from './BottomGroupMinimized'
77

8-
describe('CliHeaderMinimized', () => {
8+
let store: typeof mockedStore
9+
beforeEach(() => {
10+
cleanup()
11+
store = cloneDeep(mockedStore)
12+
store.clearActions()
13+
})
14+
15+
describe('BottomGroupMinimized', () => {
916
it('should render', () => {
1017
expect(
1118
render(<BottomGroupMinimized />)
1219
).toBeTruthy()
1320
})
1421

15-
it('should "toggleCli" & "clearSearchingCommand" actions be called after click "expand-cli" button', () => {
16-
const store = cloneDeep(mockedStore)
17-
22+
it('should "toggleCli" action be called after click "expand-cli" button', () => {
1823
render(<BottomGroupMinimized />)
1924
fireEvent.click(screen.getByTestId('expand-cli'))
2025

2126
const expectedActions = [toggleCli()]
2227
expect(store.getActions()).toEqual(expectedActions)
2328
})
29+
30+
it('should "toggleCliHelper" action be called after click "expand-command-helper" button', () => {
31+
render(<BottomGroupMinimized />)
32+
fireEvent.click(screen.getByTestId('expand-command-helper'))
33+
34+
const expectedActions = [toggleCliHelper()]
35+
expect(store.getActions()).toEqual(expectedActions)
36+
})
2437
})

redisinsight/ui/src/components/bottom-group-components/components/bottom-group-minimized/BottomGroupMinimized.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const BottomGroupMinimized = () => {
5757
className={styles.componentBadgeItem}
5858
grow={false}
5959
onClick={handleExpandHelper}
60-
data-testid="expand-helper"
60+
data-testid="expand-command-helper"
6161
>
6262
<EuiBadge className={cx(styles.componentBadge, { [styles.active]: isShowHelper })}>
6363
<EuiIcon type="documents" size="m" />

redisinsight/ui/src/components/bottom-group-components/styles.module.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
border: none !important;
4545

4646
&:hover {
47-
background-color: #364DA8 !important;
47+
background-color: var(--buttonIconPrimaryHover) !important;
4848
}
4949

5050
&.active {

redisinsight/ui/src/components/cli/Cli/Cli.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import CliBodyWrapper from 'uiSrc/components/cli/components/cli-body'
55
import styles from './styles.module.scss'
66

77
const CLI = () => (
8-
<div className={styles.container}>
8+
<div className={styles.container} data-testid="cli">
99
<div className={styles.main}>
1010
<CliHeader />
1111
<CliBodyWrapper />

redisinsight/ui/src/components/cli/components/cli-header/CliHeader.spec.tsx

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,6 @@ describe('CliHeader', () => {
6666
expect(store.getActions()).toEqual(expectedActions)
6767
})
6868

69-
// it('should "toggleCliHelper" action be called after click "collapse-cli-helper" button', async () => {
70-
// const mockUuid = 'test-uuid'
71-
// sessionStorageMock.getItem = jest.fn().mockReturnValue(mockUuid)
72-
//
73-
// render(<CliHeader {...instance(mockedProps)} />)
74-
//
75-
// await waitFor(() => {
76-
// fireEvent.click(screen.getByTestId('collapse-cli-helper'))
77-
// })
78-
//
79-
// const expectedActions = [toggleCliHelper()]
80-
// expect(store.getActions().slice(0, expectedActions.length)).toEqual(expectedActions)
81-
// })
82-
8369
it('should "processCliClient" action be called after unmount with mocked sessionStorage item ', () => {
8470
const mockUuid = 'test-uuid'
8571
sessionStorageService.get = jest.fn().mockReturnValue(mockUuid)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React from 'react'
2+
import { cloneDeep } from 'lodash'
3+
import {
4+
cleanup,
5+
fireEvent, mockedStore,
6+
render,
7+
screen,
8+
} from 'uiSrc/utils/test-utils'
9+
import { toggleCliHelper } from 'uiSrc/slices/cli/cli-settings'
10+
import CommandHelperHeader from './CommandHelperHeader'
11+
12+
let store: typeof mockedStore
13+
beforeEach(() => {
14+
cleanup()
15+
store = cloneDeep(mockedStore)
16+
store.clearActions()
17+
})
18+
19+
describe('CommandHelperHeader', () => {
20+
it('should render', () => {
21+
expect(render(<CommandHelperHeader />)).toBeTruthy()
22+
})
23+
24+
it('should "toggleCli" action be called after click "close-command-helper" button', () => {
25+
render(<CommandHelperHeader />)
26+
fireEvent.click(screen.getByTestId('close-command-helper'))
27+
28+
const expectedActions = [toggleCliHelper()]
29+
expect(store.getActions()).toEqual(expectedActions)
30+
})
31+
})

redisinsight/ui/src/components/command-helper/CommandHelperWrapper.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import styles from './CommandHelper/styles.module.scss'
1919

2020
const CommandHelperWrapper = () => {
2121
const {
22-
matchedCommand,
23-
searchedCommand,
22+
matchedCommand = '',
23+
searchedCommand = '',
2424
isSearching,
2525
isEnteringCommand,
2626
searchingCommand,
@@ -90,7 +90,7 @@ const CommandHelperWrapper = () => {
9090
}
9191

9292
return (
93-
<div className={styles.commandHelperWrapper}>
93+
<div className={styles.commandHelperWrapper} data-testid="command-helper">
9494
<CommandHelperHeader />
9595
<CommandHelper
9696
commandLine={lastMatchedCommand}

0 commit comments

Comments
 (0)