@@ -2,12 +2,17 @@ import { renderWithAllProviders, initializeMocks } from '@src/testUtils';
22import { screen } from '@testing-library/react' ;
33import userEvent from '@testing-library/user-event' ;
44
5+ import { getUrlByRouteRole } from '@openedx/frontend-base' ;
56import { instructorDashboardUrl } from '@src/data/services/lms/urls' ;
67
78import { GradebookHeader } from './index' ;
89import useGradebookHeaderData from './hooks' ;
910import messages from './messages' ;
1011
12+ jest . mock ( '@openedx/frontend-base' , ( ) => ( {
13+ ...jest . requireActual ( '@openedx/frontend-base' ) ,
14+ getUrlByRouteRole : jest . fn ( ) ,
15+ } ) ) ;
1116jest . mock ( '@src/data/services/lms/urls' , ( ) => ( {
1217 instructorDashboardUrl : jest . fn ( ) ,
1318} ) ) ;
@@ -20,6 +25,7 @@ describe('GradebookHeader', () => {
2025
2126 beforeEach ( ( ) => {
2227 jest . clearAllMocks ( ) ;
28+ getUrlByRouteRole . mockReturnValue ( null ) ;
2329 instructorDashboardUrl . mockReturnValue ( 'https://example.com/dashboard' ) ;
2430 } ) ;
2531
@@ -83,6 +89,28 @@ describe('GradebookHeader', () => {
8389 expect ( instructorDashboardUrl ) . toHaveBeenCalled ( ) ;
8490 } ) ;
8591
92+ it ( 'renders an SPA link when the site provides an instructor dashboard route' , ( ) => {
93+ getUrlByRouteRole . mockReturnValue ( '/instructor-dashboard/:courseId' ) ;
94+ renderWithAllProviders ( < GradebookHeader /> ) ;
95+ const dashboardLink = screen . getByRole ( 'link' ) ;
96+ expect ( dashboardLink ) . toHaveAttribute (
97+ 'href' ,
98+ '/instructor-dashboard/course-v1:TestU+CS101+2024' ,
99+ ) ;
100+ expect ( instructorDashboardUrl ) . not . toHaveBeenCalled ( ) ;
101+ } ) ;
102+
103+ it ( 'renders a plain anchor when the instructor dashboard route is external' , ( ) => {
104+ getUrlByRouteRole . mockReturnValue ( 'https://other.example.com/dashboard' ) ;
105+ renderWithAllProviders ( < GradebookHeader /> ) ;
106+ const dashboardLink = screen . getByRole ( 'link' ) ;
107+ expect ( dashboardLink ) . toHaveAttribute (
108+ 'href' ,
109+ 'https://other.example.com/dashboard' ,
110+ ) ;
111+ expect ( instructorDashboardUrl ) . not . toHaveBeenCalled ( ) ;
112+ } ) ;
113+
86114 it ( 'calls useGradebookHeaderData hook' , ( ) => {
87115 renderWithAllProviders ( < GradebookHeader /> ) ;
88116 expect ( useGradebookHeaderData ) . toHaveBeenCalled ( ) ;
0 commit comments