Skip to content

Commit 6c4d0c9

Browse files
authored
Merge pull request #3205 from RedisInsight/latest
Latest to main
2 parents 7bffc1d + 7e533a5 commit 6c4d0c9

File tree

6 files changed

+75
-11
lines changed

6 files changed

+75
-11
lines changed

redisinsight/api/src/modules/autodiscovery/autodiscovery.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Database } from 'src/modules/database/models/database';
77
import { DatabaseService } from 'src/modules/database/database.service';
88
import { ClientContext, ClientMetadata } from 'src/common/models';
99
import { RedisClientFactory } from 'src/modules/redis/redis.client.factory';
10+
import { plainToClass } from 'class-transformer';
1011

1112
const SERVER_CONFIG = config.get('server') as Config['server'];
1213

@@ -74,7 +75,7 @@ export class AutodiscoveryService implements OnModuleInit {
7475
{
7576
context: ClientContext.Common,
7677
} as ClientMetadata,
77-
endpoint as Database,
78+
plainToClass(Database, endpoint),
7879
{ useRetry: false, connectionName: 'redisinsight-auto-discovery' },
7980
);
8081

redisinsight/ui/src/components/json-viewer/JSONViewer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ interface Props {
1111
}
1212

1313
const JSONViewer = (props: Props) => {
14-
const { value, expanded = false, space = 2 } = props
14+
const { value, expanded = false, space = 2, useNativeBigInt = true } = props
1515

1616
try {
17-
const data = JSONBigInt({ useNativeBigInt: true }).parse(value)
17+
const data = JSONBigInt({ useNativeBigInt }).parse(value)
1818

1919
return {
2020
value: (
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import React from 'react'
2+
import { cloneDeep } from 'lodash'
3+
4+
import reactRouterDom from 'react-router-dom'
5+
import { render, screen, fireEvent, mockedStore, cleanup } from 'uiSrc/utils/test-utils'
6+
import { resetDataRedisCluster } from 'uiSrc/slices/instances/cluster'
7+
import { resetDataRedisCloud } from 'uiSrc/slices/instances/cloud'
8+
import { resetDataSentinel } from 'uiSrc/slices/instances/sentinel'
9+
import PageHeader from './PageHeader'
10+
11+
jest.mock('react-router-dom', () => ({
12+
...jest.requireActual('react-router-dom'),
13+
useHistory: () => ({
14+
push: jest.fn,
15+
}),
16+
}))
17+
18+
let store: typeof mockedStore
19+
beforeEach(() => {
20+
cleanup()
21+
store = cloneDeep(mockedStore)
22+
store.clearActions()
23+
})
24+
25+
describe('PageHeader', () => {
26+
it('should render', () => {
27+
expect(render(<PageHeader title="Page" />)).toBeTruthy()
28+
})
29+
30+
it('should render proper components', () => {
31+
render(<PageHeader title="Page" subtitle="subtitle" />)
32+
33+
expect(screen.getByTestId('page-title')).toHaveTextContent('Page')
34+
expect(screen.getByTestId('page-subtitle')).toHaveTextContent('subtitle')
35+
})
36+
37+
it('should call proper actions after click logo', () => {
38+
const pushMock = jest.fn()
39+
reactRouterDom.useHistory = jest.fn().mockReturnValue({ push: pushMock })
40+
41+
render(<PageHeader title="Page" subtitle="subtitle" />)
42+
43+
fireEvent.click(screen.getByTestId('redis-logo-home'))
44+
45+
expect(store.getActions()).toEqual([
46+
resetDataRedisCluster(),
47+
resetDataRedisCloud(),
48+
resetDataSentinel(),
49+
])
50+
51+
expect(pushMock).toBeCalledWith('/')
52+
pushMock.mockRestore()
53+
})
54+
55+
it('should render custom component instead of logo', () => {
56+
render(<PageHeader title="Page" logo={(<div data-testid="custom-logo" />)} />)
57+
58+
expect(screen.getByTestId('custom-logo')).toBeInTheDocument()
59+
expect(screen.queryByTestId('redis-logo-home')).not.toBeInTheDocument()
60+
})
61+
})

redisinsight/ui/src/components/page-header/PageHeader.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { resetDataRedisCloud } from 'uiSrc/slices/instances/cloud'
99
import { ThemeContext } from 'uiSrc/contexts/themeContext'
1010
import { resetDataRedisCluster } from 'uiSrc/slices/instances/cluster'
1111
import { resetDataSentinel } from 'uiSrc/slices/instances/sentinel'
12-
import { CapabilityPromotion } from 'uiSrc/pages/home/components/capability-promotion'
1312

1413
import darkLogo from 'uiSrc/assets/img/dark_logo.svg'
1514
import lightLogo from 'uiSrc/assets/img/light_logo.svg'
@@ -45,14 +44,13 @@ const PageHeader = (props: Props) => {
4544
<div className={cx(styles.pageHeader, className)}>
4645
<div className={styles.pageHeaderTop}>
4746
<div>
48-
<EuiTitle size="s" className={styles.title}>
47+
<EuiTitle size="s" className={styles.title} data-testid="page-title">
4948
<h1>
5049
<b>{title}</b>
5150
</h1>
5251
</EuiTitle>
53-
{subtitle ? <span>{subtitle}</span> : ''}
52+
{subtitle ? <span data-testid="page-subtitle">{subtitle}</span> : ''}
5453
</div>
55-
<CapabilityPromotion wrapperClassName={cx(styles.section, styles.capabilityPromotion)} />
5654
{logo || (
5755
<div className={styles.pageHeaderLogo}>
5856
<EuiButtonEmpty
@@ -62,6 +60,7 @@ const PageHeader = (props: Props) => {
6260
className={styles.logo}
6361
tabIndex={0}
6462
iconType={theme === Theme.Dark ? darkLogo : lightLogo}
63+
data-testid="redis-logo-home"
6564
/>
6665
</div>
6766
)}

redisinsight/ui/src/pages/home/HomePage.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import InsightsTrigger from 'uiSrc/components/insights-trigger'
3333
import DatabasesList from './components/databases-list-component'
3434
import WelcomeComponent from './components/welcome-component'
3535
import HomeHeader from './components/home-header'
36+
import { CapabilityPromotion } from './components/capability-promotion'
3637

3738
import './styles.scss'
3839
import styles from './styles.module.scss'
@@ -223,7 +224,10 @@ const HomePage = () => {
223224
title="My Redis databases"
224225
className={styles.pageHeader}
225226
logo={(
226-
<InsightsTrigger source="home page" />
227+
<>
228+
<CapabilityPromotion wrapperClassName={cx(styles.section, styles.capabilityPromotion)} />
229+
<InsightsTrigger source="home page" />
230+
</>
227231
)}
228232
/>
229233
<div className={styles.pageWrapper}>

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ const formattingBuffer = (
108108
try {
109109
const vector = Array.from(bufferToFloat32Array(reply.data))
110110
const value = JSONBigInt.stringify(vector)
111-
return JSONViewer({ value, ...props })
111+
return JSONViewer({ value, useNativeBigInt: false, ...props })
112112
} catch (e) {
113113
return { value: bufferToUTF8(reply), isValid: false }
114114
}
@@ -117,8 +117,7 @@ const formattingBuffer = (
117117
try {
118118
const vector = Array.from(bufferToFloat64Array(reply.data))
119119
const value = JSONBigInt.stringify(vector)
120-
121-
return JSONViewer({ value, ...props })
120+
return JSONViewer({ value, useNativeBigInt: false, ...props })
122121
} catch (e) {
123122
return { value: bufferToUTF8(reply), isValid: false }
124123
}

0 commit comments

Comments
 (0)