@@ -175,11 +175,16 @@ vi.mock('@iblai/iblai-js/data-layer', () => ({
175175} ) ) ;
176176
177177// Mock web-utils — layout dispatches setAdvancedDisplayMonetizationCheckoutModal
178+ // and reads the tenant `enable_course_voice_autoplay` flag via useTenantMetadata.
179+ const mockTenantMetadata = vi . hoisted ( ( ) => ( {
180+ current : { enable_course_voice_autoplay : true } as Record < string , unknown > ,
181+ } ) ) ;
178182vi . mock ( '@iblai/iblai-js/web-utils' , ( ) => ( {
179183 setAdvancedDisplayMonetizationCheckoutModal : ( payload : unknown ) => ( {
180184 type : 'setAdvancedDisplayMonetizationCheckoutModal' ,
181185 payload,
182186 } ) ,
187+ useTenantMetadata : vi . fn ( ( ) => ( { metadata : mockTenantMetadata . current } ) ) ,
183188} ) ) ;
184189
185190// Mock react-redux — layout calls useDispatch + useSelector(selectMentorSpinnerHidden)
@@ -226,6 +231,7 @@ describe('CourseContentLayout', () => {
226231
227232 beforeEach ( ( ) => {
228233 vi . clearAllMocks ( ) ;
234+ mockTenantMetadata . current = { enable_course_voice_autoplay : true } ;
229235 vi . mocked ( useCourseDetail ) . mockReturnValue ( {
230236 handleFetchCourseInfo : mockHandleFetchCourseInfo ,
231237 handleFetchCourseSyllabus : mockHandleFetchCourseSyllabus ,
@@ -1145,10 +1151,85 @@ describe('CourseContentLayout', () => {
11451151 } ) ;
11461152
11471153 describe ( 'agent autoplay toggle' , ( ) => {
1148- // NOTE: layout.tsx temporarily hard-codes `autoplayToggleVisible = true`, so
1149- // the toggle currently renders regardless of `course.agent_autoplay`. Once
1150- // the proper gate is restored, hide-when-false / hide-when-null specs can
1151- // be added back here.
1154+ const renderWithCourse = ( course : any ) => {
1155+ vi . mocked ( useCourseDetail ) . mockReturnValue ( {
1156+ handleFetchCourseInfo : mockHandleFetchCourseInfo ,
1157+ handleFetchCourseSyllabus : mockHandleFetchCourseSyllabus ,
1158+ handleOpenLesson : mockHandleOpenLesson ,
1159+ handleFetchCourseProgress : mockHandleFetchCourseProgress ,
1160+ handleFetchCourseCompletion : mockHandleFetchCourseCompletion ,
1161+ handleCheckCourseMonetizationAccess : mockHandleCheckCourseMonetizationAccess ,
1162+ course,
1163+ courseInfoLoadingState : 'successful' ,
1164+ courseOutline : null ,
1165+ courseOutlineLoading : false ,
1166+ courseCompletion : null ,
1167+ courseGradingPolicyActive : false ,
1168+ } as any ) ;
1169+
1170+ return render (
1171+ < CourseContentLayout params = { defaultParams } >
1172+ < div > children</ div >
1173+ </ CourseContentLayout > ,
1174+ ) ;
1175+ } ;
1176+
1177+ it ( 'hides the autoplay toggle when course.agent_autoplay is false' , ( ) => {
1178+ renderWithCourse ( { agent_autoplay : false } ) ;
1179+ expect ( screen . queryByTestId ( 'agent-autoplay-toggle' ) ) . not . toBeInTheDocument ( ) ;
1180+ expect ( screen . queryByTestId ( 'agent-autoplay-popover-switch' ) ) . not . toBeInTheDocument ( ) ;
1181+ } ) ;
1182+
1183+ it ( 'hides the autoplay toggle when course.agent_autoplay is null' , ( ) => {
1184+ renderWithCourse ( { agent_autoplay : null } ) ;
1185+ expect ( screen . queryByTestId ( 'agent-autoplay-toggle' ) ) . not . toBeInTheDocument ( ) ;
1186+ expect ( screen . queryByTestId ( 'agent-autoplay-popover-switch' ) ) . not . toBeInTheDocument ( ) ;
1187+ } ) ;
1188+
1189+ it ( 'hides the autoplay toggle when course.agent_autoplay is missing' , ( ) => {
1190+ renderWithCourse ( { } ) ;
1191+ expect ( screen . queryByTestId ( 'agent-autoplay-toggle' ) ) . not . toBeInTheDocument ( ) ;
1192+ expect ( screen . queryByTestId ( 'agent-autoplay-popover-switch' ) ) . not . toBeInTheDocument ( ) ;
1193+ } ) ;
1194+
1195+ it ( 'hides the autoplay toggle when course is null (still loading)' , ( ) => {
1196+ renderWithCourse ( null ) ;
1197+ expect ( screen . queryByTestId ( 'agent-autoplay-toggle' ) ) . not . toBeInTheDocument ( ) ;
1198+ expect ( screen . queryByTestId ( 'agent-autoplay-popover-switch' ) ) . not . toBeInTheDocument ( ) ;
1199+ } ) ;
1200+
1201+ it ( 'hides the autoplay toggle for truthy-but-not-true values (e.g. 1)' , ( ) => {
1202+ renderWithCourse ( { agent_autoplay : 1 } ) ;
1203+ expect ( screen . queryByTestId ( 'agent-autoplay-toggle' ) ) . not . toBeInTheDocument ( ) ;
1204+ expect ( screen . queryByTestId ( 'agent-autoplay-popover-switch' ) ) . not . toBeInTheDocument ( ) ;
1205+ } ) ;
1206+
1207+ it ( 'hides the autoplay toggle when tenant enable_course_voice_autoplay is false (course flag on)' , ( ) => {
1208+ mockTenantMetadata . current = { enable_course_voice_autoplay : false } ;
1209+ renderWithCourse ( { agent_autoplay : true } ) ;
1210+ expect ( screen . queryByTestId ( 'agent-autoplay-toggle' ) ) . not . toBeInTheDocument ( ) ;
1211+ expect ( screen . queryByTestId ( 'agent-autoplay-popover-switch' ) ) . not . toBeInTheDocument ( ) ;
1212+ } ) ;
1213+
1214+ it ( 'hides the autoplay toggle when tenant enable_course_voice_autoplay is missing' , ( ) => {
1215+ mockTenantMetadata . current = { } ;
1216+ renderWithCourse ( { agent_autoplay : true } ) ;
1217+ expect ( screen . queryByTestId ( 'agent-autoplay-toggle' ) ) . not . toBeInTheDocument ( ) ;
1218+ expect ( screen . queryByTestId ( 'agent-autoplay-popover-switch' ) ) . not . toBeInTheDocument ( ) ;
1219+ } ) ;
1220+
1221+ it ( 'hides the autoplay toggle for tenant truthy-but-not-true values (e.g. "true")' , ( ) => {
1222+ mockTenantMetadata . current = { enable_course_voice_autoplay : 'true' } ;
1223+ renderWithCourse ( { agent_autoplay : true } ) ;
1224+ expect ( screen . queryByTestId ( 'agent-autoplay-toggle' ) ) . not . toBeInTheDocument ( ) ;
1225+ expect ( screen . queryByTestId ( 'agent-autoplay-popover-switch' ) ) . not . toBeInTheDocument ( ) ;
1226+ } ) ;
1227+
1228+ it ( 'shows the autoplay toggle only when BOTH course.agent_autoplay AND tenant flag are true' , ( ) => {
1229+ mockTenantMetadata . current = { enable_course_voice_autoplay : true } ;
1230+ renderWithCourse ( { agent_autoplay : true } ) ;
1231+ expect ( screen . getByTestId ( 'agent-autoplay-toggle' ) ) . toBeInTheDocument ( ) ;
1232+ } ) ;
11521233
11531234 it ( 'shows the autoplay toggle (defaults to off, play icon visible)' , ( ) => {
11541235 vi . mocked ( useCourseDetail ) . mockReturnValue ( {
0 commit comments