Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions redisinsight/ui/src/pages/home/HomePage.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react'
import { render, screen } from 'uiSrc/utils/test-utils'

import { localStorageService } from 'uiSrc/services'
import { MOCK_EXPLORE_GUIDES } from 'uiSrc/constants/mocks/mock-explore-guides'
import HomePage from './HomePage'

jest.mock('uiSrc/slices/content/create-redis-buttons', () => ({
Expand All @@ -17,6 +18,13 @@ jest.mock('uiSrc/services', () => ({
},
}))

jest.mock('uiSrc/slices/content/guide-links', () => ({
...jest.requireActual('uiSrc/slices/content/guide-links'),
guideLinksSelector: jest.fn().mockReturnValue({
data: MOCK_EXPLORE_GUIDES
})
}))

jest.mock('uiSrc/slices/panels/insights', () => ({
...jest.requireActual('uiSrc/slices/panels/insights'),
insightsPanelSelector: jest.fn().mockReturnValue({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { render, screen, fireEvent, mockedStore, cleanup } from 'uiSrc/utils/tes
import { changeSelectedTab, toggleInsightsPanel } from 'uiSrc/slices/panels/insights'
import { InsightsPanelTabs } from 'uiSrc/slices/interfaces/insights'
import { sendEventTelemetry, TELEMETRY_EMPTY_VALUE, TelemetryEvent } from 'uiSrc/telemetry'
import { capabilities } from './constants'
import { MOCK_EXPLORE_GUIDES } from 'uiSrc/constants/mocks/mock-explore-guides'
import { findTutorialPath } from 'uiSrc/utils'

import CapabilityPromotion from './CapabilityPromotion'

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

jest.mock('uiSrc/slices/content/guide-links', () => ({
...jest.requireActual('uiSrc/slices/content/guide-links'),
guideLinksSelector: jest.fn().mockReturnValue({
data: MOCK_EXPLORE_GUIDES
})
}))

jest.mock('uiSrc/utils', () => ({
...jest.requireActual('uiSrc/utils'),
findTutorialPath: jest.fn(),
}))

let store: typeof mockedStore
beforeEach(() => {
cleanup()
Expand All @@ -30,16 +43,17 @@ describe('CapabilityPromotion', () => {
it('should render capabilities', () => {
render(<CapabilityPromotion />)

capabilities.forEach(({ id }) => {
expect(screen.getByTestId(`capability-promotion-${id}`)).toBeInTheDocument()
MOCK_EXPLORE_GUIDES.forEach(({ tutorialId }) => {
expect(screen.getByTestId(`capability-promotion-${tutorialId}`)).toBeInTheDocument()
})
})

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

const id = capabilities[0]?.id
const id = MOCK_EXPLORE_GUIDES[0]?.tutorialId
render(<CapabilityPromotion />)

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

expect(store.getActions()).toEqual(expectedActions)
expect(pushMock).toBeCalledWith({
search: `guidePath=${id}`
expect(pushMock).toHaveBeenCalledWith({
search: 'path=tutorials/0/1/0'
})
})

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

const id = capabilities[0]?.id
const id = MOCK_EXPLORE_GUIDES[0]?.tutorialId
render(<CapabilityPromotion />)

fireEvent.click(screen.getByTestId(`capability-promotion-${id}`))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import React from 'react'

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

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

export interface Props {
Expand All @@ -18,12 +20,14 @@ export interface Props {

const CapabilityPromotion = (props: Props) => {
const { mode = 'wide', wrapperClassName } = props
const { data } = useSelector(guideLinksSelector)

const dispatch = useDispatch()
const history = useHistory()

const onClickTutorial = (id: string) => {
dispatch(openTutorialByPath(id, history))
const tutorialPath = findTutorialPath({ id: id ?? '' })
dispatch(openTutorialByPath(tutorialPath ?? '', history))

sendEventTelemetry({
event: TelemetryEvent.INSIGHTS_PANEL_OPENED,
Expand All @@ -35,6 +39,10 @@ const CapabilityPromotion = (props: Props) => {
})
}

if (!data?.length) {
return null
}

return (
<div className={cx(styles.wrapper, mode, wrapperClassName)} data-testid="capability-promotion">
<img
Expand All @@ -46,17 +54,23 @@ const CapabilityPromotion = (props: Props) => {
<span>Click & Learn</span>
</EuiTitle>
<div className={styles.guides}>
{capabilities.map(({ title, id, icon }) => (
{data.map(({ title, tutorialId, icon }) => (
// eslint-disable-next-line jsx-a11y/click-events-have-key-events
<div
key={id}
key={tutorialId}
tabIndex={0}
role="button"
onClick={() => onClickTutorial(id)}
onClick={() => onClickTutorial(tutorialId)}
className={styles.guideItem}
data-testid={`capability-promotion-${id}`}
data-testid={`capability-promotion-${tutorialId}`}
>
<EuiIcon type={icon} className={styles.guideIcon} />
{icon in GUIDE_ICONS && (
<EuiIcon
className={styles.guideIcon}
type={GUIDE_ICONS[icon]}
data-testid={`guide-icon-${icon}`}
/>
)}
<EuiText>{title}</EuiText>
</div>
))}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from 'react'
import { instance, mock } from 'ts-mockito'
import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
import { render, screen, fireEvent } from 'uiSrc/utils/test-utils'
import { MOCK_EXPLORE_GUIDES } from 'uiSrc/constants/mocks/mock-explore-guides'
import HomeHeader, { Props } from './HomeHeader'

const mockedProps = mock<Props>()
Expand All @@ -18,6 +19,13 @@ jest.mock('uiSrc/slices/content/create-redis-buttons', () => {
}
})

jest.mock('uiSrc/slices/content/guide-links', () => ({
...jest.requireActual('uiSrc/slices/content/guide-links'),
guideLinksSelector: jest.fn().mockReturnValue({
data: MOCK_EXPLORE_GUIDES
})
}))

jest.mock('uiSrc/telemetry', () => ({
...jest.requireActual('uiSrc/telemetry'),
sendEventTelemetry: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { AddDbType } from 'uiSrc/pages/home/constants'
import { setSocialDialogState } from 'uiSrc/slices/oauth/cloud'
import { OAuthSocialSource } from 'uiSrc/slices/interfaces'
import { appFeatureFlagsFeaturesSelector } from 'uiSrc/slices/app/features'
import { MOCK_EXPLORE_GUIDES } from 'uiSrc/constants/mocks/mock-explore-guides'
import WelcomeComponent, { Props } from './WelcomeComponent'

jest.mock('uiSrc/slices/content/create-redis-buttons', () => ({
Expand All @@ -27,6 +28,13 @@ jest.mock('uiSrc/slices/panels/insights', () => ({
}),
}))

jest.mock('uiSrc/slices/content/guide-links', () => ({
...jest.requireActual('uiSrc/slices/content/guide-links'),
guideLinksSelector: jest.fn().mockReturnValue({
data: MOCK_EXPLORE_GUIDES
})
}))

const mockedProps = mock<Props>()

let store: typeof mockedStore
Expand Down