11// @ts -check
2- import { render , screen } from '@testing-library/react' ;
2+ import { render , screen , fireEvent } from '@testing-library/react' ;
33import { IntlProvider } from '@edx/frontend-platform/i18n' ;
44import { Formik , Form } from 'formik' ;
55import InContextDiscussionFields from './InContextDiscussionFields' ;
66
77const defaultProps = {
88 onBlur : jest . fn ( ) ,
99 onChange : jest . fn ( ) ,
10+ setFieldValue : jest . fn ( ) ,
1011 values : {
1112 enableGradedUnits : false ,
1213 groupAtSubsection : false ,
@@ -17,9 +18,11 @@ const renderComponent = (props = {}) =>
1718 render (
1819 < IntlProvider locale = "en" >
1920 < Formik initialValues = { defaultProps . values } onSubmit = { jest . fn ( ) } >
20- < Form >
21- < InContextDiscussionFields { ...defaultProps } { ...props } />
22- </ Form >
21+ { ( ) => (
22+ < Form >
23+ < InContextDiscussionFields { ...defaultProps } { ...props } />
24+ </ Form >
25+ ) }
2326 </ Formik >
2427 </ IntlProvider > ,
2528 ) ;
@@ -40,12 +43,15 @@ describe('InContextDiscussionFields', () => {
4043 expect ( screen . getByText ( / V i s i b i l i t y o f i n - c o n t e x t d i s c u s s i o n s / ) ) . toBeInTheDocument ( ) ;
4144 } ) ;
4245
43- it ( 'accepts different values' , ( ) => {
46+ it ( 'renders with default disabled (false)' , ( ) => {
47+ // Test default param - no disabled prop passed
48+ renderComponent ( ) ;
49+ expect ( screen . getByText ( / V i s i b i l i t y o f i n - c o n t e x t d i s c u s s i o n s / ) ) . toBeInTheDocument ( ) ;
50+ } ) ;
51+
52+ it ( 'renders with enableGradedUnits true (shows cancel labels)' , ( ) => {
4453 renderComponent ( {
45- values : {
46- enableGradedUnits : true ,
47- groupAtSubsection : true ,
48- } ,
54+ values : { enableGradedUnits : true , groupAtSubsection : false } ,
4955 } ) ;
5056 expect ( screen . getByText ( / V i s i b i l i t y o f i n - c o n t e x t d i s c u s s i o n s / ) ) . toBeInTheDocument ( ) ;
5157 } ) ;
@@ -65,4 +71,28 @@ describe('InContextDiscussionFields', () => {
6571 const switchControl = screen . getByLabelText ( / e n a b l e d i s c u s s i o n s / i) ;
6672 expect ( switchControl ) . toBeDisabled ( ) ;
6773 } ) ;
74+
75+ it ( 'shows confirmation popup and handles confirm' , ( ) => {
76+ renderComponent ( { disabled : false , setFieldValue : jest . fn ( ) } ) ;
77+ // Click the switch to show popup
78+ const switchControl = screen . getByLabelText ( / e n a b l e d i s c u s s i o n s / i) ;
79+ fireEvent . click ( switchControl ) ;
80+ // Check popup appears with confirm button
81+ expect ( screen . getByText ( / C o n f i r m / i) ) . toBeInTheDocument ( ) ;
82+ // Click confirm
83+ fireEvent . click ( screen . getByText ( / C o n f i r m / i) ) ;
84+ // Popup should close (no longer visible)
85+ } ) ;
86+
87+ it ( 'shows confirmation popup and handles cancel' , ( ) => {
88+ renderComponent ( { disabled : false , setFieldValue : jest . fn ( ) } ) ;
89+ // Click the switch to show popup
90+ const switchControl = screen . getByLabelText ( / e n a b l e d i s c u s s i o n s / i) ;
91+ fireEvent . click ( switchControl ) ;
92+ // Check popup appears with cancel button
93+ expect ( screen . getByText ( / C a n c e l / i) ) . toBeInTheDocument ( ) ;
94+ // Click cancel
95+ fireEvent . click ( screen . getByText ( / C a n c e l / i) ) ;
96+ // Popup should close (no longer visible)
97+ } ) ;
6898} ) ;
0 commit comments