@registrucentras/rc-ses-react-components 1.7.1 → 1.9.0

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.
Files changed (57) hide show
  1. package/dist/assets/icons/CheckCircleFillIcon.d.ts +1 -1
  2. package/dist/assets/icons/CopyIcon.d.ts +3 -0
  3. package/dist/assets/icons/InfoFillIcon.d.ts +1 -1
  4. package/dist/assets/icons/QuestionFillIcon.d.ts +1 -1
  5. package/dist/assets/icons/WarningFillIcon.d.ts +1 -1
  6. package/dist/components/common/Button/index.d.ts +1 -1
  7. package/dist/components/loaders/FullPageLoader/index.d.ts +9 -0
  8. package/dist/components/loaders/Loader/index.d.ts +26 -0
  9. package/dist/components/loaders/LoadingSpinner/index.d.ts +10 -0
  10. package/dist/components/overlays/Dialog/index.d.ts +11 -0
  11. package/dist/components/overlays/Modal/index.d.ts +16 -0
  12. package/dist/library/icons.d.ts +2 -1
  13. package/dist/library/index.d.ts +6 -1
  14. package/dist/library/types.d.ts +8 -1
  15. package/dist/registrucentras-rc-ses-react-components.cjs +10 -10
  16. package/dist/registrucentras-rc-ses-react-components.js +2009 -1680
  17. package/dist/stories/components/actions/Button.stories.d.ts +26 -0
  18. package/dist/stories/components/loaders/FullPageLoader.stories.d.ts +37 -0
  19. package/dist/stories/components/loaders/Loader.stories.d.ts +36 -0
  20. package/dist/stories/components/loaders/LoadingSpinner.stories.d.ts +62 -0
  21. package/dist/stories/components/overlays/Dialog.stories.d.ts +9 -0
  22. package/dist/stories/components/overlays/Modal.stories.d.ts +10 -0
  23. package/package.json +1 -1
  24. package/src/assets/icons/CheckCircleFillIcon.tsx +8 -2
  25. package/src/assets/icons/CopyIcon.tsx +23 -0
  26. package/src/assets/icons/InfoFillIcon.tsx +8 -2
  27. package/src/assets/icons/QuestionFillIcon.tsx +8 -2
  28. package/src/assets/icons/WarningFillIcon.tsx +8 -2
  29. package/src/components/common/Button/index.test.tsx +175 -0
  30. package/src/components/common/Button/index.tsx +46 -4
  31. package/src/components/common/Snackbar/index.test.tsx +10 -4
  32. package/src/components/form/inputs/CheckboxFormControl.test.tsx +11 -7
  33. package/src/components/loaders/FullPageLoader/index.test.tsx +80 -0
  34. package/src/components/loaders/FullPageLoader/index.tsx +68 -0
  35. package/src/components/loaders/Loader/index.test.tsx +58 -0
  36. package/src/components/loaders/Loader/index.tsx +65 -0
  37. package/src/components/loaders/LoadingSpinner/index.test.tsx +48 -0
  38. package/src/components/loaders/LoadingSpinner/index.tsx +70 -0
  39. package/src/components/overlays/Dialog/index.test.tsx +85 -0
  40. package/src/components/overlays/Dialog/index.tsx +85 -0
  41. package/src/components/overlays/Modal/index.test.tsx +94 -0
  42. package/src/components/overlays/Modal/index.tsx +116 -0
  43. package/src/i18n/namespaces/common/en.json +6 -0
  44. package/src/i18n/namespaces/common/lt.json +6 -0
  45. package/src/i18n/namespaces/input/en.json +18 -0
  46. package/src/i18n/namespaces/input/lt.json +18 -0
  47. package/src/library/icons.ts +2 -0
  48. package/src/library/index.ts +10 -0
  49. package/src/library/types.ts +19 -0
  50. package/src/setupTests.ts +13 -0
  51. package/src/stories/components/actions/Button.stories.tsx +201 -0
  52. package/src/stories/components/icons/Icons.stories.tsx +5 -0
  53. package/src/stories/components/loaders/FullPageLoader.stories.tsx +126 -0
  54. package/src/stories/components/loaders/Loader.stories.tsx +76 -0
  55. package/src/stories/components/loaders/LoadingSpinner.stories.tsx +126 -0
  56. package/src/stories/components/overlays/Dialog.stories.tsx +271 -0
  57. package/src/stories/components/overlays/Modal.stories.tsx +98 -0
@@ -0,0 +1,80 @@
1
+ import { ThemeProvider, alpha } from '@mui/material/styles'
2
+ import { render, screen } from '@testing-library/react'
3
+ import { type ReactElement } from 'react'
4
+ import { beforeEach, describe, expect, it } from 'vitest'
5
+
6
+ import i18n from '@/i18n/i18n'
7
+ import theme from '@/theme/light'
8
+
9
+ import RcSesFullPageLoader from './index'
10
+
11
+ const getDefaultLoaderLabel = () => i18n.t('components.Loader.loading', { ns: 'common' })
12
+
13
+ const renderWithTheme = (ui: ReactElement) =>
14
+ render(<ThemeProvider theme={theme}>{ui}</ThemeProvider>)
15
+
16
+ describe('RcSesFullPageLoader', () => {
17
+ beforeEach(async () => {
18
+ await i18n.changeLanguage('lt')
19
+ })
20
+
21
+ it('should render paper container in full page mode', () => {
22
+ renderWithTheme(<RcSesFullPageLoader />)
23
+
24
+ expect(screen.getByRole('status').closest('.MuiPaper-root')).toBeInTheDocument()
25
+ expect(screen.getByRole('progressbar')).toHaveStyle({ height: '64px', width: '64px' })
26
+ })
27
+
28
+ it('should render light backdrop variant', () => {
29
+ renderWithTheme(<RcSesFullPageLoader backdrop='light' />)
30
+
31
+ const backdrop = document.querySelector('.MuiBackdrop-root') as HTMLElement
32
+
33
+ expect(backdrop).toHaveStyle({
34
+ backgroundColor: alpha(theme.palette.common.white, 0.72),
35
+ })
36
+ })
37
+
38
+ it('should render dark backdrop variant', () => {
39
+ renderWithTheme(<RcSesFullPageLoader backdrop='dark' />)
40
+
41
+ const backdrop = document.querySelector('.MuiBackdrop-root') as HTMLElement
42
+
43
+ expect(backdrop).toHaveStyle({
44
+ backgroundColor: alpha(theme.palette.grey[900], 0.45),
45
+ })
46
+ })
47
+
48
+ it('should prevent and restore background focus', () => {
49
+ const backgroundButton = document.createElement('button')
50
+ backgroundButton.textContent = 'Background action'
51
+ document.body.appendChild(backgroundButton)
52
+ backgroundButton.focus()
53
+
54
+ const { unmount } = renderWithTheme(<RcSesFullPageLoader />)
55
+
56
+ expect(backgroundButton).not.toHaveFocus()
57
+
58
+ unmount()
59
+
60
+ expect(backgroundButton).toHaveFocus()
61
+ document.body.removeChild(backgroundButton)
62
+ })
63
+
64
+ it('should pass loader props to base loader', () => {
65
+ renderWithTheme(<RcSesFullPageLoader label='Duomenys kraunami' showLabel={false} />)
66
+
67
+ expect(screen.queryByText('Duomenys kraunami')).not.toBeInTheDocument()
68
+ expect(screen.getByRole('status')).toHaveAttribute('aria-label', 'Duomenys kraunami')
69
+ })
70
+
71
+ it('should use translated aria-label when label is hidden', () => {
72
+ renderWithTheme(<RcSesFullPageLoader showLabel={false} />)
73
+
74
+ expect(screen.queryByText(getDefaultLoaderLabel())).not.toBeInTheDocument()
75
+ expect(screen.getByRole('status')).toHaveAttribute(
76
+ 'aria-label',
77
+ getDefaultLoaderLabel(),
78
+ )
79
+ })
80
+ })
@@ -0,0 +1,68 @@
1
+ import { Box, BoxProps, Modal, Paper } from '@mui/material'
2
+ import { alpha } from '@mui/material/styles'
3
+
4
+ import RcSesLoader, { RcSesLoaderProps } from '@/components/loaders/Loader'
5
+
6
+ export type RcSesLoaderBackdrop = 'dark' | 'light'
7
+
8
+ // dimensions are based on the Figma design specifications
9
+ const FULL_PAGE_LOADER_CONTAINER_WIDTH = 187
10
+ const FULL_PAGE_LOADER_CONTAINER_HEIGHT = 198
11
+
12
+ type FullPageLoaderContentProps = Pick<RcSesLoaderProps, 'label' | 'showLabel'>
13
+
14
+ export interface RcSesFullPageLoaderProps
15
+ extends Omit<BoxProps, 'children' | 'sx'>,
16
+ FullPageLoaderContentProps {
17
+ backdrop?: RcSesLoaderBackdrop
18
+ }
19
+
20
+ function RcSesFullPageLoader({
21
+ backdrop = 'light',
22
+ label,
23
+ showLabel,
24
+ ...props
25
+ }: RcSesFullPageLoaderProps) {
26
+ return (
27
+ <Modal
28
+ disableEscapeKeyDown
29
+ open
30
+ slotProps={{
31
+ backdrop: {
32
+ sx: {
33
+ backgroundColor: (theme) =>
34
+ backdrop === 'dark'
35
+ ? alpha(theme.palette.grey[900], 0.45)
36
+ : alpha(theme.palette.common.white, 0.72),
37
+ },
38
+ },
39
+ }}
40
+ >
41
+ <Box
42
+ sx={{
43
+ display: 'grid',
44
+ inset: 0,
45
+ placeItems: 'center',
46
+ position: 'fixed',
47
+ }}
48
+ {...props}
49
+ >
50
+ <Paper
51
+ elevation={4}
52
+ sx={{
53
+ borderRadius: 2,
54
+ boxSizing: 'border-box',
55
+ display: 'grid',
56
+ height: FULL_PAGE_LOADER_CONTAINER_HEIGHT,
57
+ placeItems: 'center',
58
+ width: FULL_PAGE_LOADER_CONTAINER_WIDTH,
59
+ }}
60
+ >
61
+ <RcSesLoader label={label} showLabel={showLabel} size='large' />
62
+ </Paper>
63
+ </Box>
64
+ </Modal>
65
+ )
66
+ }
67
+
68
+ export default RcSesFullPageLoader
@@ -0,0 +1,58 @@
1
+ import { render, screen } from '@testing-library/react'
2
+ import { beforeEach, describe, expect, it } from 'vitest'
3
+
4
+ import i18n from '@/i18n/i18n'
5
+
6
+ import RcSesLoader from './index'
7
+
8
+ const getDefaultLoaderLabel = () => i18n.t('components.Loader.loading', { ns: 'common' })
9
+
10
+ describe('RcSesLoader', () => {
11
+ beforeEach(async () => {
12
+ await i18n.changeLanguage('lt')
13
+ })
14
+
15
+ it('should render loader with default label', () => {
16
+ render(<RcSesLoader />)
17
+
18
+ expect(screen.getByRole('status')).toBeInTheDocument()
19
+ expect(screen.getByText(getDefaultLoaderLabel())).toBeInTheDocument()
20
+ expect(screen.getByRole('progressbar')).toBeInTheDocument()
21
+ })
22
+
23
+ it.each([
24
+ ['small', '24px'],
25
+ ['medium', '40px'],
26
+ ['large', '64px'],
27
+ ] as const)('should render the proper loader size', (size, expectedSize) => {
28
+ render(<RcSesLoader size={size} />)
29
+
30
+ expect(screen.getByRole('progressbar')).toHaveStyle({
31
+ height: expectedSize,
32
+ width: expectedSize,
33
+ })
34
+ })
35
+
36
+ it('should render custom label', () => {
37
+ render(<RcSesLoader label='Duomenys kraunami' />)
38
+
39
+ expect(screen.getByText('Duomenys kraunami')).toBeInTheDocument()
40
+ })
41
+
42
+ it('should hide label and set aria-label when showLabel is false', () => {
43
+ render(<RcSesLoader showLabel={false} />)
44
+
45
+ expect(screen.queryByText(getDefaultLoaderLabel())).not.toBeInTheDocument()
46
+ expect(screen.getByRole('status')).toHaveAttribute(
47
+ 'aria-label',
48
+ getDefaultLoaderLabel(),
49
+ )
50
+ })
51
+
52
+ it('should use custom label for aria-label when label is string and showLabel is false', () => {
53
+ render(<RcSesLoader label='Duomenys kraunami' showLabel={false} />)
54
+
55
+ expect(screen.queryByText('Duomenys kraunami')).not.toBeInTheDocument()
56
+ expect(screen.getByRole('status')).toHaveAttribute('aria-label', 'Duomenys kraunami')
57
+ })
58
+ })
@@ -0,0 +1,65 @@
1
+ import { Stack, StackProps, Typography } from '@mui/material'
2
+ import { useTranslation } from 'react-i18next'
3
+
4
+ import RcSesLoadingSpinner from '@/components/loaders/LoadingSpinner'
5
+ import RcSesPalette from '@/theme/palette'
6
+
7
+ const LOADER_SIZE_MAP = {
8
+ small: {
9
+ gap: 1,
10
+ spinnerSize: '24px',
11
+ textVariant: 'body2',
12
+ },
13
+ medium: {
14
+ gap: 1.5,
15
+ spinnerSize: '40px',
16
+ textVariant: 'body1',
17
+ },
18
+ large: {
19
+ gap: 2,
20
+ spinnerSize: '64px',
21
+ textVariant: 'body1',
22
+ },
23
+ } as const
24
+
25
+ export type RcSesLoaderSize = keyof typeof LOADER_SIZE_MAP
26
+
27
+ export interface RcSesLoaderProps extends Omit<StackProps, 'children'> {
28
+ label?: string
29
+ size?: RcSesLoaderSize
30
+ showLabel?: boolean
31
+ }
32
+
33
+ function RcSesLoader({
34
+ 'aria-label': ariaLabel,
35
+ label,
36
+ size = 'medium',
37
+ showLabel = true,
38
+ sx,
39
+ ...props
40
+ }: RcSesLoaderProps) {
41
+ const { t } = useTranslation('common', { keyPrefix: 'components.Loader' })
42
+ const { gap, spinnerSize, textVariant } = LOADER_SIZE_MAP[size]
43
+ const resolvedLabel = label ?? t('loading')
44
+
45
+ return (
46
+ <Stack
47
+ role='status'
48
+ aria-live='polite'
49
+ aria-label={!showLabel ? (ariaLabel ?? resolvedLabel) : ariaLabel}
50
+ alignItems='center'
51
+ gap={gap}
52
+ sx={[{ color: RcSesPalette.primary[700] }, ...(Array.isArray(sx) ? sx : [sx])]}
53
+ {...props}
54
+ >
55
+ <RcSesLoadingSpinner color='inherit' size={spinnerSize} />
56
+ {showLabel && (
57
+ <Typography color='text.secondary' variant={textVariant}>
58
+ {resolvedLabel}
59
+ </Typography>
60
+ )}
61
+ </Stack>
62
+ )
63
+ }
64
+
65
+ export default RcSesLoader
@@ -0,0 +1,48 @@
1
+ import { render, screen } from '@testing-library/react'
2
+ import { describe, expect, it } from 'vitest'
3
+
4
+ import RcSesLoadingSpinner from './index'
5
+
6
+ describe('RcSesLoadingSpinner', () => {
7
+ it('should render a progress bar', () => {
8
+ render(<RcSesLoadingSpinner />)
9
+
10
+ const progressbar = screen.getByRole('progressbar')
11
+ expect(progressbar).toBeInTheDocument()
12
+ })
13
+
14
+ it('should render with default color inherit', () => {
15
+ render(<RcSesLoadingSpinner />)
16
+
17
+ const progressbar = screen.getByRole('progressbar')
18
+ expect(progressbar).toHaveClass('MuiCircularProgress-colorInherit')
19
+ })
20
+
21
+ it('should render with custom color', () => {
22
+ render(<RcSesLoadingSpinner color='primary' />)
23
+
24
+ const progressbar = screen.getByRole('progressbar')
25
+ expect(progressbar).toHaveClass('MuiCircularProgress-colorPrimary')
26
+ })
27
+
28
+ it('should render with custom size', () => {
29
+ render(<RcSesLoadingSpinner size='small' />)
30
+
31
+ const progressbar = screen.getByRole('progressbar')
32
+ expect(progressbar).toHaveStyle({ width: '16px', height: '16px' })
33
+ })
34
+
35
+ it('should render with medium size by default', () => {
36
+ render(<RcSesLoadingSpinner />)
37
+
38
+ const progressbar = screen.getByRole('progressbar')
39
+ expect(progressbar).toHaveStyle({ width: '20px', height: '20px' })
40
+ })
41
+
42
+ it('should support custom pixel size string', () => {
43
+ render(<RcSesLoadingSpinner size='32px' />)
44
+
45
+ const progressbar = screen.getByRole('progressbar')
46
+ expect(progressbar).toHaveStyle({ width: '32px', height: '32px' })
47
+ })
48
+ })
@@ -0,0 +1,70 @@
1
+ import { ButtonOwnProps, CircularProgress } from '@mui/material'
2
+
3
+ const VALID_SPINNER_COLORS = [
4
+ 'primary',
5
+ 'secondary',
6
+ 'error',
7
+ 'warning',
8
+ 'info',
9
+ 'success',
10
+ 'inherit',
11
+ ] as const
12
+
13
+ export type RcSesSpinnerColor = (typeof VALID_SPINNER_COLORS)[number]
14
+
15
+ const SPINNER_SIZE_MAP = {
16
+ small: '16px',
17
+ medium: '20px',
18
+ large: '24px',
19
+ } as const
20
+
21
+ // Custom colors that aren't MUI standard map to inherit (uses parent color)
22
+ const CUSTOM_COLOR_MAP: Record<string, RcSesSpinnerColor> = {
23
+ light: 'inherit',
24
+ ghost: 'inherit',
25
+ dark: 'inherit',
26
+ }
27
+
28
+ export function getSpinnerColor(color: ButtonOwnProps['color']): RcSesSpinnerColor {
29
+ if (color && VALID_SPINNER_COLORS.includes(color as RcSesSpinnerColor)) {
30
+ return color as RcSesSpinnerColor
31
+ }
32
+ return CUSTOM_COLOR_MAP[color as string] ?? 'inherit'
33
+ }
34
+
35
+ export interface RcSesLoadingSpinnerProps {
36
+ color?: RcSesSpinnerColor
37
+ size?: 'small' | 'medium' | 'large' | string
38
+ }
39
+
40
+ function RcSesLoadingSpinner({
41
+ color = 'inherit',
42
+ size = 'medium',
43
+ }: RcSesLoadingSpinnerProps) {
44
+ const spinnerSize = SPINNER_SIZE_MAP[size as keyof typeof SPINNER_SIZE_MAP] ?? size
45
+
46
+ return (
47
+ <CircularProgress
48
+ size={spinnerSize}
49
+ color={color}
50
+ variant='determinate'
51
+ value={75}
52
+ sx={{
53
+ animation: 'spin 1s linear infinite',
54
+ '@keyframes spin': {
55
+ from: {
56
+ transform: 'rotate(0deg)',
57
+ },
58
+ to: {
59
+ transform: 'rotate(360deg)',
60
+ },
61
+ },
62
+ '@media (prefers-reduced-motion: reduce)': {
63
+ animation: 'none',
64
+ },
65
+ }}
66
+ />
67
+ )
68
+ }
69
+
70
+ export default RcSesLoadingSpinner
@@ -0,0 +1,85 @@
1
+ import { Button } from '@mui/material'
2
+ import { render, screen } from '@testing-library/react'
3
+ import { describe, expect, it } from 'vitest'
4
+
5
+ import RcSesDialog from './index'
6
+
7
+ describe('RcSesDialog', () => {
8
+ it('should render dialog title', () => {
9
+ render(<RcSesDialog open dialogTitle='Test Title' actions={<Button>Close</Button>} />)
10
+
11
+ expect(screen.getByText('Test Title')).toBeInTheDocument()
12
+ })
13
+
14
+ it('should render children when provided', () => {
15
+ render(
16
+ <RcSesDialog open dialogTitle='Test Title' actions={<Button>Close</Button>}>
17
+ Test Content
18
+ </RcSesDialog>,
19
+ )
20
+
21
+ expect(screen.getByText('Test Content')).toBeInTheDocument()
22
+ })
23
+
24
+ it('should not render DialogContent when children are not provided', () => {
25
+ render(<RcSesDialog open dialogTitle='Test Title' actions={<Button>Close</Button>} />)
26
+
27
+ const dialogContent = document.querySelector('.MuiDialogContent-root')
28
+ expect(dialogContent).not.toBeInTheDocument()
29
+ })
30
+
31
+ it('should render actions', () => {
32
+ render(
33
+ <RcSesDialog open dialogTitle='Test Title' actions={<Button>Submit</Button>} />,
34
+ )
35
+
36
+ expect(screen.getByText('Submit')).toBeInTheDocument()
37
+ })
38
+
39
+ it('should apply medium size by default', () => {
40
+ render(<RcSesDialog open dialogTitle='Test Title' actions={<Button>Close</Button>} />)
41
+
42
+ const paper = document.querySelector('.MuiDialog-paper')
43
+ expect(paper).toHaveStyle({ width: '600px' })
44
+ })
45
+
46
+ it('should apply small size (480px)', () => {
47
+ render(
48
+ <RcSesDialog
49
+ open
50
+ size='sm'
51
+ dialogTitle='Test Title'
52
+ actions={<Button>Close</Button>}
53
+ />,
54
+ )
55
+
56
+ const paper = document.querySelector('.MuiDialog-paper')
57
+ expect(paper).toHaveStyle({ width: '480px' })
58
+ })
59
+
60
+ it('should apply large size (800px)', () => {
61
+ render(
62
+ <RcSesDialog
63
+ open
64
+ size='lg'
65
+ dialogTitle='Test Title'
66
+ actions={<Button>Close</Button>}
67
+ />,
68
+ )
69
+
70
+ const paper = document.querySelector('.MuiDialog-paper')
71
+ expect(paper).toHaveStyle({ width: '800px' })
72
+ })
73
+
74
+ it('should render ReactNode as title', () => {
75
+ render(
76
+ <RcSesDialog
77
+ open
78
+ dialogTitle={<span>Custom Title Element</span>}
79
+ actions={<Button>Close</Button>}
80
+ />,
81
+ )
82
+
83
+ expect(screen.getByText('Custom Title Element')).toBeInTheDocument()
84
+ })
85
+ })
@@ -0,0 +1,85 @@
1
+ import {
2
+ DialogActions,
3
+ DialogContent,
4
+ DialogTitle,
5
+ Dialog as MuiDialog,
6
+ DialogProps as MuiDialogProps,
7
+ } from '@mui/material'
8
+ import { ReactNode, useId } from 'react'
9
+
10
+ export type DialogSize = 'sm' | 'md' | 'lg'
11
+
12
+ const SIZE_MAP: Record<DialogSize, string> = {
13
+ sm: '480px',
14
+ md: '600px',
15
+ lg: '800px',
16
+ }
17
+
18
+ export interface RcSesDialogProps
19
+ extends Omit<MuiDialogProps, 'children' | 'title' | 'PaperProps' | 'maxWidth'> {
20
+ dialogTitle: string | ReactNode
21
+ children?: ReactNode
22
+ actions: ReactNode
23
+ size?: DialogSize
24
+ }
25
+
26
+ function RcSesDialog({
27
+ dialogTitle,
28
+ children,
29
+ actions,
30
+ onClose,
31
+ size = 'md',
32
+ ...props
33
+ }: RcSesDialogProps) {
34
+ const dialogWidth = SIZE_MAP[size]
35
+ const titleId = useId()
36
+ const contentId = useId()
37
+
38
+ return (
39
+ <MuiDialog
40
+ onClose={onClose}
41
+ {...props}
42
+ maxWidth={false}
43
+ PaperProps={{ sx: { width: dialogWidth, borderRadius: '16px' } }}
44
+ aria-labelledby={titleId}
45
+ aria-describedby={children ? contentId : undefined}
46
+ >
47
+ <DialogTitle
48
+ id={titleId}
49
+ sx={{
50
+ display: 'flex',
51
+ justifyContent: 'space-between',
52
+ alignItems: 'flex-start',
53
+ fontSize: '24px',
54
+ lineHeight: '32px',
55
+ padding: '2rem 2rem 1rem !important',
56
+ }}
57
+ >
58
+ {dialogTitle}
59
+ </DialogTitle>
60
+
61
+ {children && (
62
+ <DialogContent
63
+ id={contentId}
64
+ sx={{
65
+ padding: '0 2rem !important',
66
+ }}
67
+ >
68
+ {children}
69
+ </DialogContent>
70
+ )}
71
+
72
+ {actions && (
73
+ <DialogActions
74
+ sx={{
75
+ padding: '1.25rem 2rem 2rem !important',
76
+ }}
77
+ >
78
+ {actions}
79
+ </DialogActions>
80
+ )}
81
+ </MuiDialog>
82
+ )
83
+ }
84
+
85
+ export default RcSesDialog
@@ -0,0 +1,94 @@
1
+ import { render, screen } from '@testing-library/react'
2
+ import i18n from 'i18next'
3
+ import { I18nextProvider } from 'react-i18next'
4
+ import { beforeAll, describe, expect, it, vi } from 'vitest'
5
+
6
+ import inputEn from '@/i18n/namespaces/input/en.json'
7
+ import inputLt from '@/i18n/namespaces/input/lt.json'
8
+
9
+ import RcSesModal from './index'
10
+
11
+ beforeAll(() => {
12
+ if (!i18n.isInitialized) {
13
+ i18n.init({
14
+ lng: 'lt',
15
+ resources: {
16
+ lt: { input: inputLt },
17
+ en: { input: inputEn },
18
+ },
19
+ })
20
+ }
21
+ })
22
+
23
+ describe('RcSesModal', () => {
24
+ it('renders title and message', () => {
25
+ render(
26
+ <I18nextProvider i18n={i18n}>
27
+ <RcSesModal
28
+ open
29
+ onClose={vi.fn()}
30
+ title='Test Title'
31
+ message='Test Message'
32
+ onPrimaryAction={vi.fn()}
33
+ />
34
+ </I18nextProvider>,
35
+ )
36
+
37
+ expect(screen.getByText('Test Title')).toBeInTheDocument()
38
+ expect(screen.getByText('Test Message')).toBeInTheDocument()
39
+ })
40
+
41
+ it('renders success variant with only primary button', () => {
42
+ const onPrimary = vi.fn()
43
+
44
+ render(
45
+ <I18nextProvider i18n={i18n}>
46
+ <RcSesModal
47
+ open
48
+ onClose={vi.fn()}
49
+ title='Success!'
50
+ message='Operation complete'
51
+ variant='success'
52
+ onPrimaryAction={onPrimary}
53
+ />
54
+ </I18nextProvider>,
55
+ )
56
+
57
+ const buttons = screen.getAllByRole('button')
58
+ expect(buttons.length).toBe(1)
59
+ })
60
+
61
+ it('uses custom primary label when provided', () => {
62
+ render(
63
+ <I18nextProvider i18n={i18n}>
64
+ <RcSesModal
65
+ open
66
+ onClose={vi.fn()}
67
+ title='Test'
68
+ message='Test Message'
69
+ primaryActionLabel='Custom Label'
70
+ onPrimaryAction={vi.fn()}
71
+ />
72
+ </I18nextProvider>,
73
+ )
74
+
75
+ expect(screen.getByText('Custom Label')).toBeInTheDocument()
76
+ })
77
+
78
+ it('renders custom actions when provided', () => {
79
+ render(
80
+ <I18nextProvider i18n={i18n}>
81
+ <RcSesModal
82
+ open
83
+ onClose={vi.fn()}
84
+ title='Test'
85
+ message='Test Message'
86
+ actions={<button type='button'>Custom Action</button>}
87
+ onPrimaryAction={vi.fn()}
88
+ />
89
+ </I18nextProvider>,
90
+ )
91
+
92
+ expect(screen.getByText('Custom Action')).toBeInTheDocument()
93
+ })
94
+ })