@registrucentras/rc-ses-react-components 1.6.1 → 1.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/icons/WarningCircleIcon.d.ts +3 -0
- package/dist/components/common/DataPagination/components/DataPaginationSkeleton.d.ts +5 -0
- package/dist/components/common/DataPagination/index.d.ts +2 -1
- package/dist/components/common/ListWithIcons/ListWithIcons.types.d.ts +11 -0
- package/dist/components/common/ListWithIcons/components/ListWithIconsItem.d.ts +3 -6
- package/dist/components/common/ListWithIcons/index.d.ts +3 -8
- package/dist/components/common/SelectableCardList/components/SelectableCardListItem.d.ts +11 -0
- package/dist/components/common/SelectableCardList/index.d.ts +16 -0
- package/dist/library/icons.d.ts +2 -1
- package/dist/library/index.d.ts +2 -0
- package/dist/library/types.d.ts +4 -1
- package/dist/registrucentras-rc-ses-react-components.cjs +9 -9
- package/dist/registrucentras-rc-ses-react-components.js +2345 -2129
- package/dist/stories/components/SelectableCardList.stories.d.ts +29 -0
- package/dist/stories/components/display/ListWithIcons.stories.d.ts +3 -2
- package/dist/stories/components/navigation/DataPagination.stories.d.ts +1 -1
- package/dist/types/assets/IconProps.d.ts +16 -0
- package/dist/types/buttons/ButtonProps.d.ts +4 -0
- package/dist/types/cards/CardServiceProps.d.ts +7 -0
- package/dist/types/common/ColorType.d.ts +2 -0
- package/dist/types/common/QuickLinkType.d.ts +5 -0
- package/dist/types/inputs/InputIconProps.d.ts +4 -0
- package/dist/types/lists/ListNewsItemType.d.ts +5 -0
- package/dist/types/lists/ListServicesItemType.d.ts +7 -0
- package/dist/types/order/OrderItemStatusType.d.ts +2 -0
- package/package.json +3 -2
- package/src/assets/icons/WarningCircleIcon.tsx +16 -0
- package/src/components/common/DataPagination/components/DataPaginationSkeleton.tsx +48 -0
- package/src/components/common/DataPagination/components/PaginationButton.tsx +1 -2
- package/src/components/common/DataPagination/index.tsx +40 -22
- package/src/components/common/ListWithIcons/ListWithIcons.types.ts +9 -0
- package/src/components/common/ListWithIcons/components/ListWithIconsItem.tsx +18 -7
- package/src/components/common/ListWithIcons/index.test.tsx +3 -13
- package/src/components/common/ListWithIcons/index.tsx +22 -17
- package/src/components/common/SelectableCardList/components/SelectableCardListItem.test.tsx +97 -0
- package/src/components/common/SelectableCardList/components/SelectableCardListItem.tsx +106 -0
- package/src/components/common/SelectableCardList/index.test.tsx +106 -0
- package/src/components/common/SelectableCardList/index.tsx +98 -0
- package/src/components/layout/ServiceWizardStepper/components/MobileStepper.tsx +1 -2
- package/src/examples/ListWithPagination/index.tsx +110 -57
- package/src/library/icons.ts +2 -0
- package/src/library/index.ts +3 -0
- package/src/library/types.ts +4 -4
- package/src/stories/components/SelectableCardList.stories.tsx +99 -0
- package/src/stories/components/display/ListWithIcons.stories.tsx +5 -9
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { StoryObj } from '@storybook/react';
|
|
2
|
+
import { SelectableCardListItemData, SelectableCardListProps } from '../../components/common/SelectableCardList';
|
|
3
|
+
declare const meta: {
|
|
4
|
+
title: string;
|
|
5
|
+
component: ({ items, selectedId, onSelect, error, }: SelectableCardListProps) => import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
tags: string[];
|
|
7
|
+
args: {
|
|
8
|
+
items: SelectableCardListItemData[];
|
|
9
|
+
selectedId: null;
|
|
10
|
+
error: undefined;
|
|
11
|
+
onSelect: () => void;
|
|
12
|
+
};
|
|
13
|
+
argTypes: {
|
|
14
|
+
onSelect: {
|
|
15
|
+
action: string;
|
|
16
|
+
};
|
|
17
|
+
items: {
|
|
18
|
+
control: false;
|
|
19
|
+
};
|
|
20
|
+
error: {
|
|
21
|
+
control: false;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export default meta;
|
|
26
|
+
type Story = StoryObj<typeof meta>;
|
|
27
|
+
export declare const Main: Story;
|
|
28
|
+
export declare const Loading: Story;
|
|
29
|
+
export declare const Error: Story;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { StoryObj } from '@storybook/react';
|
|
2
|
-
import { ListWithIconsItemData
|
|
2
|
+
import { ListWithIconsItemData } from '../../../components/common/ListWithIcons/ListWithIcons.types';
|
|
3
|
+
import { ListWithIconsProps } from '../../../components/common/ListWithIcons';
|
|
3
4
|
declare const meta: {
|
|
4
5
|
title: string;
|
|
5
|
-
component: ({ items, layout, isLoading }: ListWithIconsProps) => import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
component: ({ items, layout, isLoading, skeletonCount, }: ListWithIconsProps) => import("react/jsx-runtime").JSX.Element;
|
|
6
7
|
tags: string[];
|
|
7
8
|
args: {
|
|
8
9
|
items: ListWithIconsItemData[];
|
|
@@ -2,7 +2,7 @@ import { StoryObj } from '@storybook/react';
|
|
|
2
2
|
import { DataPaginationProps } from '../../../components/common/DataPagination';
|
|
3
3
|
declare const meta: {
|
|
4
4
|
title: string;
|
|
5
|
-
component: ({ count, page, defaultPage, onChange, prevLabel, nextLabel, }: DataPaginationProps) => import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
component: ({ count, page, defaultPage, onChange, prevLabel, nextLabel, isLoading, }: DataPaginationProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
6
6
|
tags: string[];
|
|
7
7
|
args: {
|
|
8
8
|
count: number;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ColorType } from '../common/ColorType';
|
|
2
|
+
type IconProps = {
|
|
3
|
+
className?: string;
|
|
4
|
+
width?: number;
|
|
5
|
+
height?: number;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
color?: ColorType | string;
|
|
8
|
+
};
|
|
9
|
+
export declare const IconDefaultProps: {
|
|
10
|
+
className: undefined;
|
|
11
|
+
disabled: boolean;
|
|
12
|
+
color: undefined;
|
|
13
|
+
width: undefined;
|
|
14
|
+
height: undefined;
|
|
15
|
+
};
|
|
16
|
+
export default IconProps;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@registrucentras/rc-ses-react-components",
|
|
3
3
|
"author": "VĮ REGISTRŲ CENTRAS",
|
|
4
|
-
"version": "1.6.
|
|
4
|
+
"version": "1.6.3",
|
|
5
5
|
"description": "RC SES React komponentų biblioteka",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"private": false,
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
"scripts": {
|
|
26
26
|
"dev": "vite",
|
|
27
27
|
"build": "tsc && vite build",
|
|
28
|
-
"build:lib": "npm i && tsc --p ./tsconfig.lib.json && vite build --config vite.config.lib.ts",
|
|
28
|
+
"build:lib": "npm i && tsc --p ./tsconfig.lib.json && vite build --config vite.config.lib.ts && tsc --p ./tsconfig.check-dist.json",
|
|
29
|
+
"check:dist": "tsc --p ./tsconfig.check-dist.json",
|
|
29
30
|
"preview": "vite preview",
|
|
30
31
|
"lint": "eslint .",
|
|
31
32
|
"lint:fix": "eslint --fix .",
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { WarningCircleIcon as WarningCircle } from '@phosphor-icons/react'
|
|
2
|
+
|
|
3
|
+
import IconProps from '../IconProps'
|
|
4
|
+
|
|
5
|
+
function WarningCircleIcon({ className, size = 24, fillColor, ...rest }: IconProps) {
|
|
6
|
+
return (
|
|
7
|
+
<WarningCircle
|
|
8
|
+
{...rest}
|
|
9
|
+
className={className}
|
|
10
|
+
size={size}
|
|
11
|
+
weight='fill'
|
|
12
|
+
color={fillColor}
|
|
13
|
+
/>
|
|
14
|
+
)
|
|
15
|
+
}
|
|
16
|
+
export default WarningCircleIcon
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Box, Skeleton } from '@mui/material'
|
|
2
|
+
|
|
3
|
+
interface DataPaginationSkeletonProps {
|
|
4
|
+
isMobile: boolean
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const SIZES = {
|
|
8
|
+
item: '2.5rem',
|
|
9
|
+
buttonDesktop: '4.8125rem',
|
|
10
|
+
gap: '0.375rem',
|
|
11
|
+
paddingX: '0.1875rem',
|
|
12
|
+
radius: '0.5rem',
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const ITEMS_COUNT = 5
|
|
16
|
+
|
|
17
|
+
const DataPaginationSkeleton = ({ isMobile }: DataPaginationSkeletonProps) => {
|
|
18
|
+
const buttonWidth = isMobile ? SIZES.item : SIZES.buttonDesktop
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<>
|
|
22
|
+
<Skeleton variant='rounded' width={buttonWidth} height={SIZES.item} />
|
|
23
|
+
|
|
24
|
+
<Box
|
|
25
|
+
sx={{
|
|
26
|
+
display: 'flex',
|
|
27
|
+
gap: SIZES.gap,
|
|
28
|
+
px: SIZES.paddingX,
|
|
29
|
+
borderRadius: SIZES.radius,
|
|
30
|
+
}}
|
|
31
|
+
>
|
|
32
|
+
{Array.from({ length: ITEMS_COUNT }).map((_, index) => (
|
|
33
|
+
<Skeleton
|
|
34
|
+
// eslint-disable-next-line react/no-array-index-key
|
|
35
|
+
key={index}
|
|
36
|
+
variant='rounded'
|
|
37
|
+
width={SIZES.item}
|
|
38
|
+
height={SIZES.item}
|
|
39
|
+
/>
|
|
40
|
+
))}
|
|
41
|
+
</Box>
|
|
42
|
+
|
|
43
|
+
<Skeleton variant='rounded' width={buttonWidth} height={SIZES.item} />
|
|
44
|
+
</>
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export default DataPaginationSkeleton
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Pagination, useMediaQuery, useTheme } from '@mui/material'
|
|
2
|
-
import { Box } from '@mui/system'
|
|
1
|
+
import { Box, Pagination, useMediaQuery, useTheme } from '@mui/material'
|
|
3
2
|
import { useState } from 'react'
|
|
4
3
|
|
|
5
4
|
import ArrowLeftIcon from '@/assets/icons/ArrowLeftIcon'
|
|
6
5
|
import ArrowRightIcon from '@/assets/icons/ArrowRightIcon'
|
|
7
6
|
|
|
7
|
+
import DataPaginationSkeleton from './components/DataPaginationSkeleton'
|
|
8
8
|
import PaginationButton from './components/PaginationButton'
|
|
9
9
|
|
|
10
10
|
export interface DataPaginationProps {
|
|
@@ -14,6 +14,7 @@ export interface DataPaginationProps {
|
|
|
14
14
|
onChange?: (page: number) => void
|
|
15
15
|
prevLabel?: string
|
|
16
16
|
nextLabel?: string
|
|
17
|
+
isLoading?: boolean
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
const DataPagination = ({
|
|
@@ -23,6 +24,7 @@ const DataPagination = ({
|
|
|
23
24
|
onChange,
|
|
24
25
|
prevLabel = 'Atgal',
|
|
25
26
|
nextLabel = 'Kitas',
|
|
27
|
+
isLoading = false,
|
|
26
28
|
}: DataPaginationProps) => {
|
|
27
29
|
const theme = useTheme()
|
|
28
30
|
const isMobile = useMediaQuery(theme.breakpoints.down('md'))
|
|
@@ -41,28 +43,44 @@ const DataPagination = ({
|
|
|
41
43
|
onChange?.(newPage)
|
|
42
44
|
}
|
|
43
45
|
|
|
46
|
+
if (isLoading) {
|
|
47
|
+
return (
|
|
48
|
+
<Box display='flex' alignItems='center' gap={1}>
|
|
49
|
+
<DataPaginationSkeleton isMobile={isMobile} />
|
|
50
|
+
</Box>
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const hidePagination = count <= 1
|
|
55
|
+
|
|
56
|
+
if (hidePagination) {
|
|
57
|
+
return null
|
|
58
|
+
}
|
|
59
|
+
|
|
44
60
|
return (
|
|
45
61
|
<Box display='flex' alignItems='center' gap={1}>
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
<>
|
|
63
|
+
<PaginationButton
|
|
64
|
+
onClick={() => handlePageChange(currentPage - 1)}
|
|
65
|
+
disabled={currentPage === 1}
|
|
66
|
+
label={prevLabel}
|
|
67
|
+
icon={<ArrowLeftIcon size={16} />}
|
|
68
|
+
/>
|
|
69
|
+
<Pagination
|
|
70
|
+
count={count}
|
|
71
|
+
page={currentPage}
|
|
72
|
+
siblingCount={isMobile ? 0 : 1}
|
|
73
|
+
boundaryCount={1}
|
|
74
|
+
onChange={(_, p) => handlePageChange(p)}
|
|
75
|
+
/>
|
|
76
|
+
<PaginationButton
|
|
77
|
+
onClick={() => handlePageChange(currentPage + 1)}
|
|
78
|
+
disabled={currentPage === count}
|
|
79
|
+
label={nextLabel}
|
|
80
|
+
icon={<ArrowRightIcon size={16} />}
|
|
81
|
+
iconPosition='end'
|
|
82
|
+
/>
|
|
83
|
+
</>
|
|
66
84
|
</Box>
|
|
67
85
|
)
|
|
68
86
|
}
|
|
@@ -2,15 +2,22 @@ import { Box, Skeleton, Tooltip, Typography } from '@mui/material'
|
|
|
2
2
|
|
|
3
3
|
import palette from '@/theme/palette'
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
disabled?: boolean
|
|
9
|
-
tooltip?: string
|
|
5
|
+
import { ListWithIconsItemData } from '../ListWithIcons.types'
|
|
6
|
+
|
|
7
|
+
interface Props extends ListWithIconsItemData {
|
|
10
8
|
isLoading?: boolean
|
|
11
9
|
}
|
|
12
10
|
|
|
13
|
-
const ListWithIconsItem = ({
|
|
11
|
+
const ListWithIconsItem = ({
|
|
12
|
+
icon,
|
|
13
|
+
text,
|
|
14
|
+
disabled,
|
|
15
|
+
tooltip,
|
|
16
|
+
textColor,
|
|
17
|
+
isLoading,
|
|
18
|
+
}: Props) => {
|
|
19
|
+
const Icon = icon
|
|
20
|
+
|
|
14
21
|
const content = (
|
|
15
22
|
<Box
|
|
16
23
|
sx={{
|
|
@@ -20,13 +27,17 @@ const ListWithIconsItem = ({ icon, text, disabled, tooltip, isLoading }: Props)
|
|
|
20
27
|
maxWidth: { xs: '100%', md: 'none' },
|
|
21
28
|
}}
|
|
22
29
|
>
|
|
23
|
-
<Box sx={{ display: 'flex', alignItems: 'center'
|
|
30
|
+
<Box sx={{ display: 'flex', alignItems: 'center' }}>
|
|
31
|
+
{Icon && <Icon fillColor={textColor ?? palette.grey[600]} size={16} />}
|
|
32
|
+
</Box>
|
|
24
33
|
<Typography
|
|
25
34
|
variant='body2'
|
|
26
35
|
sx={{
|
|
27
36
|
fontSize: '14px',
|
|
37
|
+
lineHeight: '20px',
|
|
28
38
|
fontWeight: 300,
|
|
29
39
|
whiteSpace: 'nowrap',
|
|
40
|
+
color: textColor,
|
|
30
41
|
}}
|
|
31
42
|
>
|
|
32
43
|
{text}
|
|
@@ -16,14 +16,12 @@ describe('ListWithIcons', () => {
|
|
|
16
16
|
<ListWithIcons
|
|
17
17
|
items={[
|
|
18
18
|
{
|
|
19
|
-
|
|
20
|
-
icon: <span data-testid='first-icon'>I1</span>,
|
|
19
|
+
icon: () => <span data-testid='first-icon'>I1</span>,
|
|
21
20
|
text: 'First item',
|
|
22
21
|
tooltip: 'First tooltip',
|
|
23
22
|
},
|
|
24
23
|
{
|
|
25
|
-
|
|
26
|
-
icon: <span data-testid='second-icon'>I2</span>,
|
|
24
|
+
icon: () => <span data-testid='second-icon'>I2</span>,
|
|
27
25
|
text: 'Second item',
|
|
28
26
|
tooltip: 'Second tooltip',
|
|
29
27
|
},
|
|
@@ -41,14 +39,7 @@ describe('ListWithIcons', () => {
|
|
|
41
39
|
|
|
42
40
|
test('renders one loading skeleton per item when isLoading is true', () => {
|
|
43
41
|
const { container } = renderListWithIcons(
|
|
44
|
-
<ListWithIcons
|
|
45
|
-
isLoading
|
|
46
|
-
items={[
|
|
47
|
-
{ id: 'first', text: 'First item' },
|
|
48
|
-
{ id: 'second', text: 'Second item' },
|
|
49
|
-
{ id: 'third', text: 'Third item' },
|
|
50
|
-
]}
|
|
51
|
-
/>,
|
|
42
|
+
<ListWithIcons isLoading skeletonCount={3} items={[]} />,
|
|
52
43
|
)
|
|
53
44
|
|
|
54
45
|
expect(container.querySelectorAll('.MuiSkeleton-root')).toHaveLength(3)
|
|
@@ -60,7 +51,6 @@ describe('ListWithIcons', () => {
|
|
|
60
51
|
<ListWithIcons
|
|
61
52
|
items={[
|
|
62
53
|
{
|
|
63
|
-
id: 'first',
|
|
64
54
|
text: 'Hover me',
|
|
65
55
|
tooltip: 'Helpful tooltip text',
|
|
66
56
|
},
|
|
@@ -1,31 +1,28 @@
|
|
|
1
1
|
import { Box } from '@mui/material'
|
|
2
2
|
|
|
3
|
+
import { ListWithIconsItemData } from './ListWithIcons.types'
|
|
3
4
|
import ListWithIconsItem from './components/ListWithIconsItem'
|
|
4
5
|
|
|
5
|
-
export interface ListWithIconsItemData {
|
|
6
|
-
id: string
|
|
7
|
-
icon?: React.ReactNode
|
|
8
|
-
text?: string
|
|
9
|
-
disabled?: boolean
|
|
10
|
-
tooltip?: string
|
|
11
|
-
}
|
|
12
|
-
|
|
13
6
|
export interface ListWithIconsProps {
|
|
14
7
|
items: ListWithIconsItemData[]
|
|
15
8
|
layout?: 'horizontal' | 'vertical'
|
|
16
9
|
isLoading?: boolean
|
|
10
|
+
skeletonCount?: number
|
|
17
11
|
}
|
|
18
12
|
|
|
19
|
-
const ListWithIcons = ({
|
|
13
|
+
const ListWithIcons = ({
|
|
14
|
+
items,
|
|
15
|
+
layout = 'vertical',
|
|
16
|
+
isLoading = false,
|
|
17
|
+
skeletonCount = 3,
|
|
18
|
+
}: ListWithIconsProps) => (
|
|
20
19
|
<Box
|
|
21
20
|
component='ul'
|
|
22
21
|
sx={{
|
|
23
22
|
p: 0,
|
|
24
23
|
m: 0,
|
|
25
24
|
width: '100%',
|
|
26
|
-
minWidth: {
|
|
27
|
-
md: 120,
|
|
28
|
-
},
|
|
25
|
+
minWidth: { md: '7.5rem' },
|
|
29
26
|
display: 'flex',
|
|
30
27
|
flexDirection: {
|
|
31
28
|
xs: 'column',
|
|
@@ -33,14 +30,22 @@ const ListWithIcons = ({ items, layout = 'vertical', isLoading }: ListWithIconsP
|
|
|
33
30
|
},
|
|
34
31
|
flexWrap: layout === 'horizontal' ? 'wrap' : 'nowrap',
|
|
35
32
|
gap: {
|
|
36
|
-
xs: '
|
|
37
|
-
md: layout === 'horizontal' ? '
|
|
33
|
+
xs: '0.25rem',
|
|
34
|
+
md: layout === 'horizontal' ? '1rem' : '0.5rem',
|
|
38
35
|
},
|
|
39
36
|
}}
|
|
40
37
|
>
|
|
41
|
-
{
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
{isLoading ? (
|
|
39
|
+
<>
|
|
40
|
+
{Array.from({ length: skeletonCount }).map((_, index) => (
|
|
41
|
+
// eslint-disable-next-line react/no-array-index-key
|
|
42
|
+
<ListWithIconsItem key={index} isLoading />
|
|
43
|
+
))}
|
|
44
|
+
</>
|
|
45
|
+
) : (
|
|
46
|
+
// eslint-disable-next-line react/no-array-index-key
|
|
47
|
+
items?.map((item, index) => <ListWithIconsItem key={index} {...item} />)
|
|
48
|
+
)}
|
|
44
49
|
</Box>
|
|
45
50
|
)
|
|
46
51
|
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { ThemeProvider } from '@mui/material/styles'
|
|
2
|
+
import { render, screen } from '@testing-library/react'
|
|
3
|
+
import { type ReactElement } from 'react'
|
|
4
|
+
import { describe, expect, test, vi } from 'vitest'
|
|
5
|
+
|
|
6
|
+
import theme from '@/theme/light'
|
|
7
|
+
|
|
8
|
+
import SelectableCardListItem from './SelectableCardListItem'
|
|
9
|
+
|
|
10
|
+
const renderItem = (ui: ReactElement) =>
|
|
11
|
+
render(<ThemeProvider theme={theme}>{ui}</ThemeProvider>)
|
|
12
|
+
|
|
13
|
+
describe('SelectableCardListItem', () => {
|
|
14
|
+
test('renders title and subtitle', () => {
|
|
15
|
+
renderItem(
|
|
16
|
+
<SelectableCardListItem
|
|
17
|
+
title='Main title'
|
|
18
|
+
subtitle='Some subtitle'
|
|
19
|
+
selected={false}
|
|
20
|
+
onSelect={vi.fn()}
|
|
21
|
+
listItems={[]}
|
|
22
|
+
/>,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
expect(screen.getByRole('heading', { name: 'Main title' })).toBeInTheDocument()
|
|
26
|
+
expect(screen.getByText('Some subtitle')).toBeInTheDocument()
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test('omits subtitle when not provided', () => {
|
|
30
|
+
renderItem(
|
|
31
|
+
<SelectableCardListItem
|
|
32
|
+
title='Title only'
|
|
33
|
+
selected={false}
|
|
34
|
+
onSelect={vi.fn()}
|
|
35
|
+
listItems={[]}
|
|
36
|
+
/>,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
expect(screen.getByText('Title only')).toBeInTheDocument()
|
|
40
|
+
expect(screen.queryByText('Some subtitle')).not.toBeInTheDocument()
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
test('renders loading skeletons when isLoading is true', () => {
|
|
44
|
+
const { container } = renderItem(
|
|
45
|
+
<SelectableCardListItem
|
|
46
|
+
title=''
|
|
47
|
+
selected={false}
|
|
48
|
+
onSelect={vi.fn()}
|
|
49
|
+
isLoading
|
|
50
|
+
listItems={[]}
|
|
51
|
+
/>,
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
expect(container.querySelectorAll('.MuiSkeleton-root').length).toBeGreaterThan(0)
|
|
55
|
+
expect(screen.queryByRole('radio')).not.toBeInTheDocument()
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
test('radio is checked when selected=true', () => {
|
|
59
|
+
renderItem(
|
|
60
|
+
<SelectableCardListItem
|
|
61
|
+
title='Selected'
|
|
62
|
+
selected
|
|
63
|
+
onSelect={vi.fn()}
|
|
64
|
+
listItems={[]}
|
|
65
|
+
/>,
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
expect(screen.getByRole('radio')).toBeChecked()
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
test('radio is unchecked when selected=false', () => {
|
|
72
|
+
renderItem(
|
|
73
|
+
<SelectableCardListItem
|
|
74
|
+
title='Not selected'
|
|
75
|
+
selected={false}
|
|
76
|
+
onSelect={vi.fn()}
|
|
77
|
+
listItems={[]}
|
|
78
|
+
/>,
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
expect(screen.getByRole('radio')).not.toBeChecked()
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
test('renders list items when provided', () => {
|
|
85
|
+
renderItem(
|
|
86
|
+
<SelectableCardListItem
|
|
87
|
+
title='With list'
|
|
88
|
+
selected={false}
|
|
89
|
+
onSelect={vi.fn()}
|
|
90
|
+
listItems={[{ text: 'List entry A' }, { text: 'List entry B' }]}
|
|
91
|
+
/>,
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
expect(screen.getByText('List entry A')).toBeInTheDocument()
|
|
95
|
+
expect(screen.getByText('List entry B')).toBeInTheDocument()
|
|
96
|
+
})
|
|
97
|
+
})
|