@@ -10,7 +10,6 @@ const gradedUnitLabel = messages.gradedUnitPagesLabel.defaultMessage;
1010const defaultProps = {
1111 onBlur : jest . fn ( ) ,
1212 onChange : jest . fn ( ) ,
13- setFieldValue : jest . fn ( ) ,
1413 values : {
1514 enableGradedUnits : false ,
1615 groupAtSubsection : false ,
@@ -36,18 +35,6 @@ describe('InContextDiscussionFields', () => {
3635 } ) ;
3736
3837 it ( 'renders without crashing' , ( ) => {
39- renderComponent ( ) ;
40- // Component renders - check for presence of expected text
41- 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 ( ) ;
42- } ) ;
43-
44- it ( 'renders with disabled prop' , ( ) => {
45- renderComponent ( { disabled : true } ) ;
46- 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 ( ) ;
47- } ) ;
48-
49- it ( 'renders with default disabled (false)' , ( ) => {
50- // Test default param - no disabled prop passed
5138 renderComponent ( ) ;
5239 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 ( ) ;
5340 } ) ;
@@ -59,62 +46,28 @@ describe('InContextDiscussionFields', () => {
5946 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 ( ) ;
6047 } ) ;
6148
62- it ( 'shows confirmation popup when toggling enableGradedUnits when not disabled' , ( ) => {
63- renderComponent ( { disabled : false } ) ;
64- // When not disabled, clicking the switch should trigger the onChange which sets showPopup
65- // The component should still render - we test via the callback behavior
66- const switchControl = screen . getByLabelText ( gradedUnitLabel ) ;
67- expect ( switchControl ) . not . toBeDisabled ( ) ;
68- } ) ;
69-
70- it ( 'does NOT show popup when disabled' , ( ) => {
71- renderComponent ( { disabled : true } ) ;
72- // When disabled, clicking should not trigger popup logic
73- // Verify the switch is disabled
74- const switchControl = screen . getByLabelText ( gradedUnitLabel ) ;
75- expect ( switchControl ) . toBeDisabled ( ) ;
76- } ) ;
77-
7849 it ( 'shows confirmation popup and handles confirm' , ( ) => {
79- renderComponent ( { disabled : false , setFieldValue : jest . fn ( ) } ) ;
80- // Click the switch to show popup
50+ renderComponent ( { setFieldValue : jest . fn ( ) } ) ;
8151 const switchControl = screen . getByLabelText ( gradedUnitLabel ) ;
8252 fireEvent . click ( switchControl ) ;
83- // Check popup appears with confirm button
8453 expect ( screen . getByText ( / C o n f i r m / i) ) . toBeInTheDocument ( ) ;
85- // Click confirm
8654 fireEvent . click ( screen . getByText ( / C o n f i r m / i) ) ;
87- // Popup should close (no longer visible)
8855 } ) ;
8956
9057 it ( 'shows popup with cancel labels when enableGradedUnits is already true' , ( ) => {
9158 renderComponent ( {
92- disabled : false ,
9359 values : { enableGradedUnits : true , groupAtSubsection : false } ,
9460 } ) ;
9561 const switchControl = screen . getByLabelText ( gradedUnitLabel ) ;
9662 fireEvent . click ( switchControl ) ;
97- // Popup shows cancel-related labels (enableGradedUnits=true branch)
9863 expect ( screen . getByText ( / C o n f i r m / i) ) . toBeInTheDocument ( ) ;
9964 } ) ;
10065
10166 it ( 'shows confirmation popup and handles cancel' , ( ) => {
102- renderComponent ( { disabled : false , setFieldValue : jest . fn ( ) } ) ;
103- // Click the switch to show popup
67+ renderComponent ( { setFieldValue : jest . fn ( ) } ) ;
10468 const switchControl = screen . getByLabelText ( gradedUnitLabel ) ;
10569 fireEvent . click ( switchControl ) ;
106- // Check popup appears with cancel button
10770 expect ( screen . getByText ( / C a n c e l / i) ) . toBeInTheDocument ( ) ;
108- // Click cancel
10971 fireEvent . click ( screen . getByText ( / C a n c e l / i) ) ;
110- // Popup should close (no longer visible)
111- } ) ;
112-
113- it ( 'does not show popup when onChange fires with disabled=true' , ( ) => {
114- renderComponent ( { disabled : true } ) ;
115- const switchControl = screen . getByLabelText ( gradedUnitLabel ) ;
116- // fireEvent bypasses browser disabled-input behavior, but the !disabled guard in onChange prevents the popup
117- fireEvent . click ( switchControl ) ;
118- expect ( screen . queryByText ( / C o n f i r m / i) ) . not . toBeInTheDocument ( ) ;
11972 } ) ;
12073} ) ;
0 commit comments