@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
@@ -48,6 +48,16 @@ declare const meta: {
48
48
  defaultValue: {};
49
49
  };
50
50
  };
51
+ loading: {
52
+ control: {
53
+ type: "boolean";
54
+ };
55
+ table: {
56
+ defaultValue: {
57
+ summary: string;
58
+ };
59
+ };
60
+ };
51
61
  };
52
62
  tags: string[];
53
63
  args: {
@@ -78,3 +88,19 @@ export declare const LightOutlinedWithIcon: Story;
78
88
  export declare const LightOutlinedDisabled: Story;
79
89
  export declare const GhostOutlinedIconOnly: Story;
80
90
  export declare const GhostOutlinedIconOnlyDisabled: Story;
91
+ export declare const PrimaryContainedLoading: Story;
92
+ export declare const PrimaryContainedLoadingWithIcon: Story;
93
+ export declare const PrimaryContainedLoadingWithEndIcon: Story;
94
+ export declare const PrimaryContainedIconOnlyLoading: Story;
95
+ export declare const PrimaryOutlinedLoading: Story;
96
+ export declare const SecondaryContainedLoading: Story;
97
+ export declare const SecondaryOutlinedLoading: Story;
98
+ export declare const GreyContainedLoading: Story;
99
+ export declare const GreyOutlinedLoading: Story;
100
+ export declare const WarningContainedLoading: Story;
101
+ export declare const WarningOutlinedLoading: Story;
102
+ export declare const ErrorContainedLoading: Story;
103
+ export declare const ErrorOutlinedLoading: Story;
104
+ export declare const LightOutlinedLoading: Story;
105
+ export declare const LightOutlinedWithIconLoading: Story;
106
+ export declare const GhostOutlinedIconOnlyLoading: Story;
@@ -0,0 +1,37 @@
1
+ import { StoryObj } from '@storybook/react';
2
+ import { default as RcSesFullPageLoader } from '../../../components/loaders/FullPageLoader';
3
+ declare const meta: {
4
+ title: string;
5
+ component: typeof RcSesFullPageLoader;
6
+ tags: string[];
7
+ parameters: {
8
+ controls: {
9
+ include: string[];
10
+ };
11
+ docs: {
12
+ story: {
13
+ inline: boolean;
14
+ height: number;
15
+ };
16
+ description: {
17
+ component: string;
18
+ };
19
+ };
20
+ };
21
+ argTypes: {
22
+ backdrop: {
23
+ control: "radio";
24
+ options: string[];
25
+ };
26
+ label: {
27
+ control: "text";
28
+ };
29
+ showLabel: {
30
+ control: "boolean";
31
+ };
32
+ };
33
+ };
34
+ export default meta;
35
+ type Story = StoryObj<typeof meta>;
36
+ export declare const Default: Story;
37
+ export declare const DarkBackdrop: Story;
@@ -0,0 +1,36 @@
1
+ import { StoryObj } from '@storybook/react';
2
+ import { default as RcSesLoader } from '../../../components/loaders/Loader';
3
+ declare const meta: {
4
+ title: string;
5
+ component: typeof RcSesLoader;
6
+ tags: string[];
7
+ parameters: {
8
+ controls: {
9
+ include: string[];
10
+ };
11
+ docs: {
12
+ description: {
13
+ component: string;
14
+ };
15
+ };
16
+ };
17
+ argTypes: {
18
+ label: {
19
+ control: "text";
20
+ };
21
+ showLabel: {
22
+ control: "boolean";
23
+ };
24
+ size: {
25
+ control: "radio";
26
+ options: string[];
27
+ };
28
+ };
29
+ };
30
+ export default meta;
31
+ type Story = StoryObj<typeof meta>;
32
+ export declare const Default: Story;
33
+ export declare const Small: Story;
34
+ export declare const Medium: Story;
35
+ export declare const Large: Story;
36
+ export declare const WithoutLabel: Story;
@@ -0,0 +1,62 @@
1
+ import { StoryObj } from '@storybook/react';
2
+ import { default as RcSesLoadingSpinner } from '../../../components/loaders/LoadingSpinner';
3
+ declare const meta: {
4
+ title: string;
5
+ component: typeof RcSesLoadingSpinner;
6
+ parameters: {
7
+ layout: string;
8
+ docs: {
9
+ description: {
10
+ component: string;
11
+ };
12
+ };
13
+ };
14
+ argTypes: {
15
+ color: {
16
+ description: string;
17
+ options: ("inherit" | "success" | "info" | "warning" | "error" | "primary" | "secondary")[];
18
+ mapping: ("inherit" | "success" | "info" | "warning" | "error" | "primary" | "secondary")[];
19
+ control: {
20
+ type: "select";
21
+ labels: ("inherit" | "success" | "info" | "warning" | "error" | "primary" | "secondary")[];
22
+ };
23
+ table: {
24
+ defaultValue: {
25
+ summary: string;
26
+ };
27
+ type: {
28
+ summary: string;
29
+ };
30
+ };
31
+ };
32
+ size: {
33
+ description: string;
34
+ options: string[];
35
+ mapping: string[];
36
+ control: {
37
+ type: "select";
38
+ labels: string[];
39
+ };
40
+ table: {
41
+ defaultValue: {
42
+ summary: string;
43
+ };
44
+ type: {
45
+ summary: string;
46
+ };
47
+ };
48
+ };
49
+ };
50
+ tags: string[];
51
+ };
52
+ export default meta;
53
+ type Story = StoryObj<typeof meta>;
54
+ export declare const Default: Story;
55
+ export declare const Small: Story;
56
+ export declare const Large: Story;
57
+ export declare const Primary: Story;
58
+ export declare const Secondary: Story;
59
+ export declare const Error: Story;
60
+ export declare const Success: Story;
61
+ export declare const Warning: Story;
62
+ export declare const Info: Story;
@@ -0,0 +1,9 @@
1
+ import { Meta, StoryObj } from '@storybook/react';
2
+ import { default as RcSesDialog } from '../../../components/overlays/Dialog';
3
+ declare const meta: Meta<typeof RcSesDialog>;
4
+ export default meta;
5
+ type Story = StoryObj<typeof RcSesDialog>;
6
+ export declare const Basic: Story;
7
+ export declare const SmallDialog: Story;
8
+ export declare const MediumDialog: Story;
9
+ export declare const LargeDialog: Story;
@@ -0,0 +1,10 @@
1
+ import { Meta, StoryObj } from '@storybook/react';
2
+ import { default as RcSesModal } from '../../../components/overlays/Modal';
3
+ declare const meta: Meta<typeof RcSesModal>;
4
+ export default meta;
5
+ type Story = StoryObj<typeof RcSesModal>;
6
+ export declare const Destructive: Story;
7
+ export declare const Confirm: Story;
8
+ export declare const Success: Story;
9
+ export declare const Info: Story;
10
+ export declare const WithoutIcon: Story;
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.7.1",
4
+ "version": "1.9.0",
5
5
  "description": "RC SES React komponentų biblioteka",
6
6
  "type": "module",
7
7
  "private": false,
@@ -2,13 +2,19 @@ import { CheckCircleIcon as CheckCircleFillIcon } from '@phosphor-icons/react'
2
2
 
3
3
  import IconProps from '../IconProps'
4
4
 
5
- function CheckCircleIcon({ className, fillColor, size = 24, ...rest }: IconProps) {
5
+ function CheckCircleIcon({
6
+ className,
7
+ fillColor,
8
+ size = 24,
9
+ weight = 'fill',
10
+ ...rest
11
+ }: IconProps) {
6
12
  return (
7
13
  <CheckCircleFillIcon
8
14
  {...rest}
9
15
  className={className}
10
16
  size={size}
11
- weight='fill'
17
+ weight={weight}
12
18
  color={fillColor}
13
19
  />
14
20
  )
@@ -0,0 +1,23 @@
1
+ import { CopyIcon as CopyFillIcon } from '@phosphor-icons/react'
2
+
3
+ import IconProps from '../IconProps'
4
+
5
+ function CopyIcon({
6
+ className,
7
+ fillColor,
8
+ size = 24,
9
+ weight = 'regular',
10
+ ...rest
11
+ }: IconProps) {
12
+ return (
13
+ <CopyFillIcon
14
+ {...rest}
15
+ className={className}
16
+ size={size}
17
+ weight={weight}
18
+ color={fillColor}
19
+ />
20
+ )
21
+ }
22
+
23
+ export default CopyIcon
@@ -2,9 +2,15 @@ import { InfoIcon as Info } from '@phosphor-icons/react'
2
2
 
3
3
  import IconProps from '../IconProps'
4
4
 
5
- function InfoFillIcon({ className, size = 24, fillColor, ...rest }: IconProps) {
5
+ function InfoFillIcon({
6
+ className,
7
+ size = 24,
8
+ fillColor,
9
+ weight = 'fill',
10
+ ...rest
11
+ }: IconProps) {
6
12
  return (
7
- <Info {...rest} className={className} size={size} weight='fill' color={fillColor} />
13
+ <Info {...rest} className={className} size={size} weight={weight} color={fillColor} />
8
14
  )
9
15
  }
10
16
 
@@ -2,13 +2,19 @@ import { QuestionIcon as Question } from '@phosphor-icons/react'
2
2
 
3
3
  import IconProps from '../IconProps'
4
4
 
5
- function QuestionFillIcon({ className, size = 16, fillColor, ...rest }: IconProps) {
5
+ function QuestionFillIcon({
6
+ className,
7
+ size = 16,
8
+ fillColor,
9
+ weight = 'fill',
10
+ ...rest
11
+ }: IconProps) {
6
12
  return (
7
13
  <Question
8
14
  {...rest}
9
15
  className={className}
10
16
  size={size}
11
- weight='fill'
17
+ weight={weight}
12
18
  color={fillColor}
13
19
  />
14
20
  )
@@ -2,13 +2,19 @@ import { WarningIcon as Warning } from '@phosphor-icons/react'
2
2
 
3
3
  import IconProps from '../IconProps'
4
4
 
5
- function WarningFillIcon({ className, size = 24, fillColor, ...rest }: IconProps) {
5
+ function WarningFillIcon({
6
+ className,
7
+ size = 24,
8
+ fillColor,
9
+ weight = 'fill',
10
+ ...rest
11
+ }: IconProps) {
6
12
  return (
7
13
  <Warning
8
14
  {...rest}
9
15
  className={className}
10
16
  size={size}
11
- weight='fill'
17
+ weight={weight}
12
18
  color={fillColor}
13
19
  />
14
20
  )
@@ -0,0 +1,175 @@
1
+ import { fireEvent, render, screen } from '@testing-library/react'
2
+ import { describe, expect, it, vi } from 'vitest'
3
+
4
+ import Button from './index'
5
+
6
+ describe('Button Component', () => {
7
+ describe('Loading State', () => {
8
+ it('should render loading spinner when loading is true', () => {
9
+ render(<Button loading>Save</Button>)
10
+
11
+ const spinner = screen.getByRole('progressbar')
12
+ expect(spinner).toBeInTheDocument()
13
+ })
14
+
15
+ it('should set aria-busy attribute when loading', () => {
16
+ render(<Button loading>Save</Button>)
17
+
18
+ const button = screen.getByRole('button')
19
+ expect(button).toHaveAttribute('aria-busy', 'true')
20
+ })
21
+
22
+ it('should disable button when loading=true', () => {
23
+ render(<Button loading>Save</Button>)
24
+
25
+ const button = screen.getByRole('button')
26
+ expect(button).toBeDisabled()
27
+ })
28
+
29
+ it('should show spinner instead of children when loading', () => {
30
+ render(<Button loading>Save</Button>)
31
+
32
+ expect(screen.queryByText('Save')).not.toBeInTheDocument()
33
+ expect(screen.getByRole('progressbar')).toBeInTheDocument()
34
+ })
35
+
36
+ it('should replace startIcon with spinner when loading', () => {
37
+ render(
38
+ <Button loading startIcon={<span data-testid='start-icon'>+</span>}>
39
+ Add
40
+ </Button>,
41
+ )
42
+
43
+ expect(screen.queryByTestId('start-icon')).not.toBeInTheDocument()
44
+ expect(screen.getByRole('progressbar')).toBeInTheDocument()
45
+ })
46
+
47
+ it('should replace endIcon with spinner when loading', () => {
48
+ render(
49
+ <Button loading endIcon={<span data-testid='end-icon'>→</span>}>
50
+ Next
51
+ </Button>,
52
+ )
53
+
54
+ expect(screen.queryByTestId('end-icon')).not.toBeInTheDocument()
55
+ expect(screen.getByRole('progressbar')).toBeInTheDocument()
56
+ })
57
+
58
+ it('should prevent click when loading=true', () => {
59
+ const handleClick = vi.fn()
60
+ render(
61
+ <Button loading onClick={handleClick}>
62
+ Save
63
+ </Button>,
64
+ )
65
+
66
+ const button = screen.getByRole('button')
67
+ fireEvent.click(button)
68
+
69
+ expect(handleClick).not.toHaveBeenCalled()
70
+ })
71
+ })
72
+
73
+ describe('Disabled State', () => {
74
+ it('should disable button when disabled=true', () => {
75
+ render(<Button disabled>Save</Button>)
76
+
77
+ const button = screen.getByRole('button')
78
+ expect(button).toBeDisabled()
79
+ })
80
+
81
+ it('should prevent click when disabled=true', () => {
82
+ const handleClick = vi.fn()
83
+ render(
84
+ <Button disabled onClick={handleClick}>
85
+ Save
86
+ </Button>,
87
+ )
88
+
89
+ const button = screen.getByRole('button')
90
+ fireEvent.click(button)
91
+
92
+ expect(handleClick).not.toHaveBeenCalled()
93
+ })
94
+ })
95
+
96
+ describe('Loading + Disabled States', () => {
97
+ it('should show spinner and be disabled when both loading and disabled are true', () => {
98
+ const handleClick = vi.fn()
99
+ render(
100
+ <Button loading disabled onClick={handleClick}>
101
+ Save
102
+ </Button>,
103
+ )
104
+
105
+ const button = screen.getByRole('button')
106
+ expect(button).toBeDisabled()
107
+ expect(button).toHaveAttribute('aria-busy', 'true')
108
+ expect(screen.getByRole('progressbar')).toBeInTheDocument()
109
+ })
110
+ })
111
+
112
+ describe('Variants', () => {
113
+ it('should render contained variant by default', () => {
114
+ render(<Button>Save</Button>)
115
+
116
+ const button = screen.getByRole('button')
117
+ expect(button).toHaveClass('MuiButton-contained')
118
+ })
119
+
120
+ it('should render outlined variant when specified', () => {
121
+ render(<Button variant='outlined'>Save</Button>)
122
+
123
+ const button = screen.getByRole('button')
124
+ expect(button).toHaveClass('MuiButton-outlined')
125
+ })
126
+
127
+ it('should render text variant when specified', () => {
128
+ render(<Button variant='text'>Save</Button>)
129
+
130
+ const button = screen.getByRole('button')
131
+ expect(button).toHaveClass('MuiButton-textPrimary')
132
+ })
133
+ })
134
+
135
+ describe('Icon Only Buttons', () => {
136
+ it('should show spinner in place of icon when loading and iconOnly', () => {
137
+ render(
138
+ <Button
139
+ loading
140
+ iconOnly
141
+ variant='contained'
142
+ startIcon={<span data-testid='icon'>+</span>}
143
+ >
144
+ Add
145
+ </Button>,
146
+ )
147
+
148
+ expect(screen.queryByTestId('icon')).not.toBeInTheDocument()
149
+ expect(screen.getByRole('progressbar')).toBeInTheDocument()
150
+ })
151
+ })
152
+
153
+ describe('Size Props', () => {
154
+ it('should render small button', () => {
155
+ render(<Button size='small'>Save</Button>)
156
+
157
+ const button = screen.getByRole('button')
158
+ expect(button).toHaveClass('MuiButton-sizeSmall')
159
+ })
160
+
161
+ it('should render medium button by default', () => {
162
+ render(<Button>Save</Button>)
163
+
164
+ const button = screen.getByRole('button')
165
+ expect(button).toHaveClass('MuiButton-sizeMedium')
166
+ })
167
+
168
+ it('should render large button', () => {
169
+ render(<Button size='large'>Save</Button>)
170
+
171
+ const button = screen.getByRole('button')
172
+ expect(button).toHaveClass('MuiButton-sizeLarge')
173
+ })
174
+ })
175
+ })
@@ -1,5 +1,7 @@
1
1
  import { Button as MuiButton, ButtonProps as MuiButtonProps } from '@mui/material'
2
+ import { useTranslation } from 'react-i18next'
2
3
 
4
+ import RcSesLoadingSpinner, { getSpinnerColor } from '@/components/loaders/LoadingSpinner'
3
5
  import { ButtonProps } from '@/types/buttons/ButtonProps'
4
6
 
5
7
  const defaultProps: Partial<MuiButtonProps> = {
@@ -14,21 +16,61 @@ const ICON_ONLY_SIZE_MAP = {
14
16
  large: '3rem',
15
17
  } as const
16
18
 
17
- type Props = ButtonProps & { to?: string }
19
+ // TODO: use MUI's loading prop when MUI lib upgrade is done
20
+ type Props = ButtonProps & {
21
+ loading?: boolean
22
+ }
18
23
 
19
24
  function RcSesButton(props: Props) {
20
- const { children, iconOnly, size = 'medium', sx, variant, ...rest } = props
25
+ const { t } = useTranslation('common')
26
+ const {
27
+ children,
28
+ iconOnly,
29
+ loading = false,
30
+ size = 'medium',
31
+ sx,
32
+ variant,
33
+ ...rest
34
+ } = props
21
35
 
22
36
  const currentVariant = variant ?? defaultProps.variant
23
37
  const isIconOnly =
24
38
  !!iconOnly && (currentVariant === 'contained' || currentVariant === 'outlined')
25
39
 
40
+ const showSpinnerInContent = loading && !isIconOnly && !rest.startIcon && !rest.endIcon
41
+ const showSpinnerAsIcon = loading && isIconOnly
42
+
43
+ const spinnerColor = getSpinnerColor(rest.color)
44
+ const spinner = <RcSesLoadingSpinner color={spinnerColor} size={size} />
45
+
46
+ const getIconDisplay = (icon: React.ReactNode) => {
47
+ if (showSpinnerAsIcon) return undefined
48
+ if (loading && !isIconOnly && icon) return spinner
49
+ return icon
50
+ }
51
+
52
+ const displayIcon = getIconDisplay(rest.startIcon)
53
+ const displayEndIcon = getIconDisplay(rest.endIcon)
54
+
55
+ let displayContent = children
56
+ if (showSpinnerInContent || showSpinnerAsIcon) displayContent = spinner
57
+
26
58
  return (
27
59
  <MuiButton
28
60
  {...defaultProps}
29
61
  {...rest}
62
+ // TODO: use loading prop when MUI lib upgrade is done
63
+ disabled={loading || rest.disabled}
30
64
  size={size}
31
- variant={variant}
65
+ variant={currentVariant}
66
+ aria-busy={loading || undefined}
67
+ aria-label={
68
+ loading && rest['aria-label']
69
+ ? `${rest['aria-label']} – ${t('components.Button.loading')}`
70
+ : rest['aria-label']
71
+ }
72
+ startIcon={displayIcon}
73
+ endIcon={displayEndIcon}
32
74
  sx={[
33
75
  ...(Array.isArray(sx) ? sx : [sx]),
34
76
  isIconOnly
@@ -44,7 +86,7 @@ function RcSesButton(props: Props) {
44
86
  : undefined,
45
87
  ]}
46
88
  >
47
- {children}
89
+ {displayContent}
48
90
  </MuiButton>
49
91
  )
50
92
  }
@@ -1,5 +1,5 @@
1
1
  import { ThemeProvider } from '@mui/material/styles'
2
- import { fireEvent, render, screen } from '@testing-library/react'
2
+ import { act, fireEvent, render, screen } from '@testing-library/react'
3
3
  import { ReactNode } from 'react'
4
4
  import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
5
5
 
@@ -20,7 +20,9 @@ describe('RcSesSnackbar', () => {
20
20
  })
21
21
 
22
22
  afterEach(() => {
23
- vi.runOnlyPendingTimers()
23
+ act(() => {
24
+ vi.runOnlyPendingTimers()
25
+ })
24
26
  vi.useRealTimers()
25
27
  })
26
28
 
@@ -67,7 +69,9 @@ describe('RcSesSnackbar', () => {
67
69
  const statusElement = screen.getByText('Test')
68
70
  expect(statusElement).toBeInTheDocument()
69
71
 
70
- vi.advanceTimersByTime(1000)
72
+ act(() => {
73
+ vi.advanceTimersByTime(1000)
74
+ })
71
75
 
72
76
  expect(handleClose).toHaveBeenCalled()
73
77
  })
@@ -78,7 +82,9 @@ describe('RcSesSnackbar', () => {
78
82
  <RcSesSnackbar {...DEFAULT_PROPS} onClose={handleClose} persist duration={1000} />,
79
83
  )
80
84
 
81
- vi.advanceTimersByTime(2000)
85
+ act(() => {
86
+ vi.advanceTimersByTime(2000)
87
+ })
82
88
 
83
89
  expect(handleClose).not.toHaveBeenCalled()
84
90
  })
@@ -1,5 +1,5 @@
1
1
  import { ThemeProvider } from '@mui/material/styles'
2
- import { render } from '@testing-library/react'
2
+ import { fireEvent, render, waitFor } from '@testing-library/react'
3
3
  import { useForm } from 'react-hook-form'
4
4
  import { describe, expect, test, vi } from 'vitest'
5
5
 
@@ -40,7 +40,7 @@ describe('RcSesCheckboxFormControl - Indeterminate State', () => {
40
40
  expect(checkbox.checked).toBe(false)
41
41
  })
42
42
 
43
- test('should call onChildValuesChange with [true, true, true] when clicking parent in indeterminate state', () => {
43
+ test('should call onChildValuesChange with [true, true, true] when clicking parent in indeterminate state', async () => {
44
44
  const onChildValuesChange = vi.fn()
45
45
  const { container } = render(
46
46
  <TestWrapper
@@ -49,11 +49,13 @@ describe('RcSesCheckboxFormControl - Indeterminate State', () => {
49
49
  />,
50
50
  )
51
51
  const checkbox = container.querySelector('input#checkbox') as HTMLInputElement
52
- checkbox.click()
53
- expect(onChildValuesChange).toHaveBeenCalledWith([true, true, true])
52
+ fireEvent.click(checkbox)
53
+ await waitFor(() => {
54
+ expect(onChildValuesChange).toHaveBeenCalledWith([true, true, true])
55
+ })
54
56
  })
55
57
 
56
- test('should call onChildValuesChange with [false, false, false] when clicking checked parent', () => {
58
+ test('should call onChildValuesChange with [false, false, false] when clicking checked parent', async () => {
57
59
  const onChildValuesChange = vi.fn()
58
60
  const { container } = render(
59
61
  <TestWrapper
@@ -62,7 +64,9 @@ describe('RcSesCheckboxFormControl - Indeterminate State', () => {
62
64
  />,
63
65
  )
64
66
  const checkbox = container.querySelector('input#checkbox') as HTMLInputElement
65
- checkbox.click()
66
- expect(onChildValuesChange).toHaveBeenCalledWith([false, false, false])
67
+ fireEvent.click(checkbox)
68
+ await waitFor(() => {
69
+ expect(onChildValuesChange).toHaveBeenCalledWith([false, false, false])
70
+ })
67
71
  })
68
72
  })