Skip to content

Commit 41b942d

Browse files
committed
change b to span for PageHeader.tsx
add tests for SentinelDatabases.stories.tsx
1 parent 7713b3d commit 41b942d

File tree

4 files changed

+75
-10
lines changed

4 files changed

+75
-10
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { Title } from 'uiSrc/components/base/text/Title'
1818
import { EmptyButton } from 'uiSrc/components/base/forms/buttons'
1919
import { RedisLogoFullIcon } from 'uiSrc/components/base/icons'
2020
import styles from './PageHeader.module.scss'
21+
import { ColorText } from 'uiSrc/components/base/text'
2122

2223
interface Props {
2324
title?: string
@@ -59,7 +60,9 @@ const PageHeader = (props: Props) => {
5960
<div>
6061
{title && (
6162
<Title size="L" data-testid="page-title">
62-
<b data-testid="page-header-title">{title}</b>
63+
<ColorText variant="semiBold" data-testid="page-header-title">
64+
{title}
65+
</ColorText>
6366
</Title>
6467
)}
6568
{subtitle ? <span data-testid="page-subtitle">{subtitle}</span> : ''}

redisinsight/ui/src/pages/autodiscover-cloud/utils.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,16 @@ export const getSelectionColumn = <T extends object>({
1818
size,
1919
isHeaderCustom: true,
2020
header: ({ table }) => (
21-
<Table.HeaderMultiRowSelectionButton table={table} />
21+
<Table.HeaderMultiRowSelectionButton
22+
table={table}
23+
data-testid="row-selection"
24+
/>
25+
),
26+
cell: ({ row }) => (
27+
<Table.RowSelectionButton
28+
row={row}
29+
data-testid={`row-selection-${row.id}`}
30+
/>
2231
),
23-
cell: ({ row }) => <Table.RowSelectionButton row={row} />,
2432
}
2533
}

redisinsight/ui/src/pages/autodiscover-sentinel/sentinel-databases/components/SentinelDatabases/SentinelDatabases.stories.tsx

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
import React, { useState } from 'react'
22
import type { Meta, StoryObj } from '@storybook/react-vite'
33
import { action } from 'storybook/actions'
4+
import { expect, fn, screen } from 'storybook/test'
45

56
import SentinelDatabases from './SentinelDatabases'
67
import {
78
AddRedisDatabaseStatus,
89
ModifiedSentinelMaster,
910
} from 'uiSrc/slices/interfaces'
1011
import { RowSelectionState } from '@redis-ui/table'
11-
import {
12-
colFactory,
13-
getRowId,
14-
} from 'uiSrc/pages/autodiscover-sentinel/sentinel-databases/useSentinelDatabasesConfig'
12+
import { colFactory, getRowId } from '../../useSentinelDatabasesConfig'
1513

1614
const meta: Meta<typeof SentinelDatabases> = {
1715
component: SentinelDatabases,
16+
args: {
17+
onBack: fn(),
18+
onClose: fn(),
19+
onSubmit: fn(),
20+
},
1821
}
1922

2023
export default meta
@@ -74,9 +77,9 @@ const DefaultRender = () => {
7477
selection={selection || []}
7578
columns={columnsMock}
7679
masters={mastersMock}
77-
onClose={action('onClose')}
78-
onBack={action('onBack')}
79-
onSubmit={action('onSubmit')}
80+
onClose={meta.args?.onClose!}
81+
onBack={meta.args?.onBack!}
82+
onSubmit={meta.args?.onSubmit!}
8083
onSelectionChange={(sel) => {
8184
setSelection(sel)
8285
}}
@@ -86,6 +89,41 @@ const DefaultRender = () => {
8689

8790
export const Default: Story = {
8891
render: () => <DefaultRender />,
92+
play: async ({ canvas, userEvent, args, step }) => {
93+
await step('Ensure render', async () => {
94+
await expect(canvas.getByTestId('row-selection')).toBeInTheDocument()
95+
await expect(canvas.getByText('mymaster')).toBeInTheDocument()
96+
await expect(canvas.getByText('mymaster2')).toBeInTheDocument()
97+
await expect(
98+
canvas.getByText('Auto-Discover Redis Sentinel Primary Groups'),
99+
).toBeInTheDocument()
100+
await expect(canvas.getByText('Add databases')).toBeInTheDocument()
101+
})
102+
// you can group interactions with `step`
103+
await step('Ensure cancel is called', async () => {
104+
await userEvent.click(canvas.getByRole('button', { name: 'Cancel' }))
105+
await userEvent.click(screen.getByRole('button', { name: 'Proceed' }))
106+
await expect(args.onClose).toHaveBeenCalled()
107+
})
108+
// or you can just call actions sequentially
109+
// await userEvent.click(canvas.getByRole('button', { name: 'Cancel' }))
110+
// await userEvent.click(screen.getByRole('button', { name: 'Proceed' }))
111+
// await expect(args.onClose).toHaveBeenCalled()
112+
await step('Back to add databases screen is called', async () => {
113+
await userEvent.click(
114+
canvas.getByRole('button', { name: 'Add databases' }),
115+
)
116+
await expect(args.onBack).toHaveBeenCalled()
117+
})
118+
await step('Primary group selection', async () => {
119+
await userEvent.click(canvas.getByTestId('row-selection-1'))
120+
await userEvent.click(
121+
// name can be exact matching string or regex
122+
canvas.getByRole('button', { name: /add primary group/i }),
123+
)
124+
await expect(args.onSubmit).toHaveBeenCalled()
125+
})
126+
},
89127
}
90128
const emptyColumnsMock = colFactory([], () => {})
91129
export const Empty: Story = {
@@ -98,4 +136,9 @@ export const Empty: Story = {
98136
onSubmit: action('onSubmit'),
99137
onSelectionChange: action('on selection change'),
100138
},
139+
play: async ({ canvas }) => {
140+
await expect(
141+
canvas.getByText('Your Redis Sentinel has no primary groups available'),
142+
).toBeInTheDocument()
143+
},
101144
}

stories/Start.mdx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,14 @@ import { Meta } from "@storybook/addon-docs/blocks";
88
Redis Insight is a visual tool that provides capabilities to design, develop, and optimize your Redis application.
99

1010
Query, analyse and interact with your Redis data. [Download it here](https://redis.io/insight/#insight-form)!
11+
12+
### Storybook
13+
14+
#### [Play function](https://storybook.js.org/docs/writing-stories/play-function)
15+
Besides development in isolation, Storybook also provides a way to test interactions and user flows.
16+
17+
#### [Interaction testing](https://storybook.js.org/docs/writing-tests/interaction-testing)
18+
Every story you write can be render tested. A render test is a simple version of an interaction test that only tests the ability of a component to render successfully in a given state.
19+
20+
#### [Accessibility testing](https://storybook.js.org/docs/writing-tests/accessibility-testing)
21+
Storybook provides a way to test accessibility of our components.

0 commit comments

Comments
 (0)