Skip to content

Commit 702a7c9

Browse files
committed
#RI-5345 - update capability promotion from paths to ids
1 parent efb29c2 commit 702a7c9

File tree

3 files changed

+44
-52
lines changed

3 files changed

+44
-52
lines changed

redisinsight/ui/src/pages/home/components/capability-promotion/CapabilityPromotion.spec.tsx

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import { render, screen, fireEvent, mockedStore, cleanup } from 'uiSrc/utils/tes
66
import { changeSelectedTab, toggleInsightsPanel } from 'uiSrc/slices/panels/insights'
77
import { InsightsPanelTabs } from 'uiSrc/slices/interfaces/insights'
88
import { sendEventTelemetry, TELEMETRY_EMPTY_VALUE, TelemetryEvent } from 'uiSrc/telemetry'
9-
import { capabilities } from './constants'
9+
import { MOCK_EXPLORE_GUIDES } from 'uiSrc/constants/mocks/mock-explore-guides'
10+
import { findTutorialPath } from 'uiSrc/utils'
1011

1112
import CapabilityPromotion from './CapabilityPromotion'
1213

@@ -15,6 +16,18 @@ jest.mock('uiSrc/telemetry', () => ({
1516
sendEventTelemetry: jest.fn(),
1617
}))
1718

19+
jest.mock('uiSrc/slices/content/guide-links', () => ({
20+
...jest.requireActual('uiSrc/slices/content/guide-links'),
21+
guideLinksSelector: jest.fn().mockReturnValue({
22+
data: MOCK_EXPLORE_GUIDES
23+
})
24+
}))
25+
26+
jest.mock('uiSrc/utils', () => ({
27+
...jest.requireActual('uiSrc/utils'),
28+
findTutorialPath: jest.fn(),
29+
}))
30+
1831
let store: typeof mockedStore
1932
beforeEach(() => {
2033
cleanup()
@@ -30,16 +43,17 @@ describe('CapabilityPromotion', () => {
3043
it('should render capabilities', () => {
3144
render(<CapabilityPromotion />)
3245

33-
capabilities.forEach(({ id }) => {
34-
expect(screen.getByTestId(`capability-promotion-${id}`)).toBeInTheDocument()
46+
MOCK_EXPLORE_GUIDES.forEach(({ tutorialId }) => {
47+
expect(screen.getByTestId(`capability-promotion-${tutorialId}`)).toBeInTheDocument()
3548
})
3649
})
3750

3851
it('should call proper actions and history push on click capability', () => {
3952
const pushMock = jest.fn()
40-
reactRouterDom.useHistory = jest.fn().mockReturnValue({ push: pushMock })
53+
reactRouterDom.useHistory = jest.fn().mockReturnValue({ push: pushMock });
54+
(findTutorialPath as jest.Mock).mockImplementation(() => '0/1/0')
4155

42-
const id = capabilities[0]?.id
56+
const id = MOCK_EXPLORE_GUIDES[0]?.tutorialId
4357
render(<CapabilityPromotion />)
4458

4559
fireEvent.click(screen.getByTestId(`capability-promotion-${id}`))
@@ -50,16 +64,16 @@ describe('CapabilityPromotion', () => {
5064
]
5165

5266
expect(store.getActions()).toEqual(expectedActions)
53-
expect(pushMock).toBeCalledWith({
54-
search: `guidePath=${id}`
67+
expect(pushMock).toHaveBeenCalledWith({
68+
search: 'path=tutorials/0/1/0'
5569
})
5670
})
5771

5872
it('should call proper telemetry after click capability', () => {
5973
const sendEventTelemetryMock = jest.fn();
6074
(sendEventTelemetry as jest.Mock).mockImplementation(() => sendEventTelemetryMock)
6175

62-
const id = capabilities[0]?.id
76+
const id = MOCK_EXPLORE_GUIDES[0]?.tutorialId
6377
render(<CapabilityPromotion />)
6478

6579
fireEvent.click(screen.getByTestId(`capability-promotion-${id}`))

redisinsight/ui/src/pages/home/components/capability-promotion/CapabilityPromotion.tsx

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ import React from 'react'
22

33
import { EuiIcon, EuiText, EuiTitle } from '@elastic/eui'
44
import cx from 'classnames'
5-
import { useDispatch } from 'react-redux'
5+
import { useDispatch, useSelector } from 'react-redux'
66
import { useHistory } from 'react-router-dom'
77
import ClickLearnRocketIcon from 'uiSrc/assets/img/click-learn-rocket.svg'
88

99
import { openTutorialByPath } from 'uiSrc/slices/panels/insights'
1010
import { sendEventTelemetry, TELEMETRY_EMPTY_VALUE, TelemetryEvent } from 'uiSrc/telemetry'
11-
import { capabilities } from './constants'
11+
import { guideLinksSelector } from 'uiSrc/slices/content/guide-links'
12+
import GUIDE_ICONS from 'uiSrc/components/explore-guides/icons'
13+
import { findTutorialPath } from 'uiSrc/utils'
1214
import styles from './styles.module.scss'
1315

1416
export interface Props {
@@ -18,12 +20,14 @@ export interface Props {
1820

1921
const CapabilityPromotion = (props: Props) => {
2022
const { mode = 'wide', wrapperClassName } = props
23+
const { data } = useSelector(guideLinksSelector)
2124

2225
const dispatch = useDispatch()
2326
const history = useHistory()
2427

2528
const onClickTutorial = (id: string) => {
26-
dispatch(openTutorialByPath(id, history))
29+
const tutorialPath = findTutorialPath({ id: id ?? '' })
30+
dispatch(openTutorialByPath(tutorialPath ?? '', history))
2731

2832
sendEventTelemetry({
2933
event: TelemetryEvent.INSIGHTS_PANEL_OPENED,
@@ -35,6 +39,10 @@ const CapabilityPromotion = (props: Props) => {
3539
})
3640
}
3741

42+
if (!data?.length) {
43+
return null
44+
}
45+
3846
return (
3947
<div className={cx(styles.wrapper, mode, wrapperClassName)} data-testid="capability-promotion">
4048
<img
@@ -46,17 +54,23 @@ const CapabilityPromotion = (props: Props) => {
4654
<span>Click & Learn</span>
4755
</EuiTitle>
4856
<div className={styles.guides}>
49-
{capabilities.map(({ title, id, icon }) => (
57+
{data.map(({ title, tutorialId, icon }) => (
5058
// eslint-disable-next-line jsx-a11y/click-events-have-key-events
5159
<div
52-
key={id}
60+
key={tutorialId}
5361
tabIndex={0}
5462
role="button"
55-
onClick={() => onClickTutorial(id)}
63+
onClick={() => onClickTutorial(tutorialId)}
5664
className={styles.guideItem}
57-
data-testid={`capability-promotion-${id}`}
65+
data-testid={`capability-promotion-${tutorialId}`}
5866
>
59-
<EuiIcon type={icon} className={styles.guideIcon} />
67+
{icon in GUIDE_ICONS && (
68+
<EuiIcon
69+
className={styles.guideIcon}
70+
type={GUIDE_ICONS[icon]}
71+
data-testid={`guide-icon-${icon}`}
72+
/>
73+
)}
6074
<EuiText>{title}</EuiText>
6175
</div>
6276
))}

redisinsight/ui/src/pages/home/components/capability-promotion/constants.ts

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

0 commit comments

Comments
 (0)