File tree Expand file tree Collapse file tree 4 files changed +81
-2
lines changed
packages/ui-client/src/components/Modal/GenericModal Expand file tree Collapse file tree 4 files changed +81
-2
lines changed Original file line number Diff line number Diff line change 11import { useSetModal } from '@rocket.chat/ui-contexts' ;
22import { act , screen , renderHook } from '@testing-library/react' ;
33import userEvent from '@testing-library/user-event' ;
4+ import { axe } from 'jest-axe' ;
45import type { ReactElement } from 'react' ;
56import { Suspense } from 'react' ;
67
@@ -25,6 +26,21 @@ const renderModal = (modalElement: ReactElement) => {
2526 return { setModal } ;
2627} ;
2728
29+ describe ( 'renders' , ( ) => {
30+ it ( 'should render a modal without crashing' , async ( ) => {
31+ renderModal ( < GenericModal title = 'Modal' /> ) ;
32+
33+ expect ( await screen . findByRole ( 'dialog' , { name : 'Modal' } ) ) . toMatchSnapshot ( ) ;
34+ } ) ;
35+
36+ it ( 'should have no accessibility violations when rendered' , async ( ) => {
37+ renderModal ( < GenericModal title = 'Modal' /> ) ;
38+
39+ const results = await axe ( screen . getByRole ( 'dialog' , { name : 'Modal' } ) ) ;
40+ expect ( results ) . toHaveNoViolations ( ) ;
41+ } ) ;
42+ } ) ;
43+
2844describe ( 'callbacks' , ( ) => {
2945 it ( 'should call onClose callback when dismissed' , async ( ) => {
3046 const handleClose = jest . fn ( ) ;
Original file line number Diff line number Diff line change @@ -46,6 +46,9 @@ Warning.args = { variant: 'warning' };
4646export const Success = Template . bind ( { } ) ;
4747Success . args = { variant : 'success' } ;
4848
49+ export const DangerSecondary = Template . bind ( { } ) ;
50+ DangerSecondary . args = { variant : 'secondary-danger' } ;
51+
4952export const WithDontAskAgain : StoryFn < typeof GenericModalDoNotAskAgain > = ( args ) => < GenericModalDoNotAskAgain { ...args } /> ;
5053WithDontAskAgain . args = {
5154 dontAskAgain : {
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ import type { RequiredModalProps } from './withDoNotAskAgain';
2222import { withDoNotAskAgain } from './withDoNotAskAgain' ;
2323import { modalStore } from '../../../providers/ModalProvider/ModalStore' ;
2424
25- type VariantType = 'danger' | 'warning' | 'info' | 'success' | 'upsell' ;
25+ type VariantType = 'danger' | 'secondary-danger' | ' warning' | 'info' | 'success' | 'upsell' ;
2626
2727type GenericModalProps = RequiredModalProps & {
2828 variant ?: VariantType ;
@@ -50,6 +50,8 @@ const getButtonProps = (variant: VariantType): ComponentProps<typeof Button> =>
5050 switch ( variant ) {
5151 case 'danger' :
5252 return { danger : true } ;
53+ case 'secondary-danger' :
54+ return { secondary : true , danger : true } ;
5355 case 'warning' :
5456 case 'upsell' :
5557 return { primary : true } ;
@@ -59,7 +61,7 @@ const getButtonProps = (variant: VariantType): ComponentProps<typeof Button> =>
5961} ;
6062
6163const renderIcon = ( icon : GenericModalProps [ 'icon' ] , variant : VariantType ) : ReactNode => {
62- if ( icon === null ) {
64+ if ( icon === null || iconMap [ variant ] === undefined ) {
6365 return null ;
6466 }
6567
Original file line number Diff line number Diff line change 1+ // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2+
3+ exports [` renders should render a modal without crashing 1` ] = `
4+ <dialog
5+ aria-labelledby = " :r0:-title"
6+ aria-modal = " true"
7+ class = " rcx-box rcx-box--full rcx-modal"
8+ open = " "
9+ >
10+ <div
11+ class = " rcx-box rcx-box--full rcx-modal__inner rcx-css-1e2ego0"
12+ >
13+ <header
14+ class = " rcx-box rcx-box--full rcx-modal__header"
15+ >
16+ <div
17+ class = " rcx-box rcx-box--full rcx-modal__header-inner"
18+ >
19+ <div
20+ class = " rcx-box rcx-box--full rcx-css-trljwa rcx-css-3k19uf"
21+ >
22+ <i
23+ aria-hidden = " true"
24+ class = " rcx-box rcx-box--full rcx-icon--name-info rcx-icon rcx-css-zozvgz"
25+ >
26+
27+ </i >
28+ </div >
29+ <div
30+ class = " rcx-box rcx-box--full rcx-modal__header-text rcx-css-trljwa rcx-css-lma364"
31+ >
32+ <h2
33+ class = " rcx-box rcx-box--full rcx-modal__title"
34+ id = " :r0:-title"
35+ >
36+ Modal
37+ </h2 >
38+ </div >
39+ </div >
40+ </header >
41+ <div
42+ class = " rcx-box rcx-box--full rcx-modal__content rcx-css-1vw7itl"
43+ >
44+ <div
45+ class = " rcx-box rcx-box--full rcx-modal__content-wrapper rcx-css-r1bpeb"
46+ />
47+ </div >
48+ <div
49+ class = " rcx-box rcx-box--full rcx-modal__footer rcx-css-17mu816"
50+ >
51+ <div
52+ class = " rcx-button-group rcx-button-group--align-end"
53+ role = " group"
54+ />
55+ </div >
56+ </div >
57+ </dialog >
58+ ` ;
You can’t perform that action at this time.
0 commit comments