1- import React from 'react' ;
2- import { shallow } from '@edx/react-unit-test-utils' ;
3-
4- import { Hyperlink } from '@openedx/paragon' ;
5-
6- import * as constants from 'data/constants/app' ;
7- import urls from 'data/services/lms/urls' ;
1+ import { render } from '@testing-library/react' ;
2+ import { IntlProvider } from '@edx/frontend-platform/i18n' ;
83import { selectors } from 'data/redux' ;
9-
104import {
115 ListViewBreadcrumb ,
126 mapStateToProps ,
137} from './ListViewBreadcrumb' ;
148
9+ jest . unmock ( '@openedx/paragon' ) ;
10+ jest . unmock ( 'react' ) ;
11+ jest . unmock ( '@edx/frontend-platform/i18n' ) ;
12+
1513jest . mock ( 'data/redux' , ( ) => ( {
1614 selectors : {
1715 app : {
18- courseId : ( ... args ) => ( { courseId : args } ) ,
16+ courseId : jest . fn ( ( state ) => state . courseId || 'test-course-id' ) ,
1917 ora : {
20- name : ( ... args ) => ( { oraName : args } ) ,
18+ name : jest . fn ( ( state ) => state . oraName || 'test-ora-name' ) ,
2119 } ,
2220 } ,
2321 } ,
@@ -28,41 +26,64 @@ jest.mock('data/services/lms/urls', () => ({
2826 ora : ( courseId , locationId ) => `oraUrl(${ courseId } , ${ locationId } )` ,
2927} ) ) ;
3028
31- let el ;
29+ jest . mock ( 'data/constants/app' , ( ) => ( {
30+ locationId : ( ) => 'test-location-id' ,
31+ } ) ) ;
3232
3333describe ( 'ListViewBreadcrumb component' , ( ) => {
34- describe ( 'component' , ( ) => {
35- const props = {
36- courseId : 'test-course-id' ,
37- oraName : 'fake-ora-name' ,
38- } ;
39- beforeEach ( ( ) => {
40- el = shallow ( < ListViewBreadcrumb { ...props } /> ) ;
34+ const props = {
35+ courseId : 'test-course-id' ,
36+ oraName : 'fake-ora-name' ,
37+ } ;
38+
39+ const renderWithIntl = ( component ) => render (
40+ < IntlProvider locale = "en" messages = { { } } >
41+ { component }
42+ </ IntlProvider > ,
43+ ) ;
44+
45+ beforeEach ( ( ) => {
46+ jest . clearAllMocks ( ) ;
47+ } ) ;
48+
49+ describe ( 'behavior' , ( ) => {
50+ it ( 'renders back to responses link with correct destination' , ( ) => {
51+ const { container } = renderWithIntl ( < ListViewBreadcrumb { ...props } /> ) ;
52+ const backLink = container . querySelector ( 'a[href*="openResponseUrl"]' ) ;
53+ expect ( backLink ) . toBeInTheDocument ( ) ;
54+ expect ( backLink ) . toHaveAttribute ( 'href' , `openResponseUrl(${ props . courseId } )` ) ;
4155 } ) ;
42- test ( 'snapshot: empty (no list data)' , ( ) => {
43- expect ( el . snapshot ) . toMatchSnapshot ( ) ;
56+
57+ it ( 'displays ORA name in heading' , ( ) => {
58+ const { getByText } = renderWithIntl ( < ListViewBreadcrumb { ...props } /> ) ;
59+ const heading = getByText ( props . oraName ) ;
60+ expect ( heading ) . toBeInTheDocument ( ) ;
61+ expect ( heading ) . toHaveClass ( 'h3' ) ;
4462 } ) ;
45- test ( 'openResponse destination' , ( ) => {
46- expect (
47- el . instance . findByType ( Hyperlink ) [ 0 ] . props . destination ,
48- ) . toEqual ( urls . openResponse ( props . courseId ) ) ;
63+
64+ it ( 'renders ORA link with correct destination' , ( ) => {
65+ const { container } = renderWithIntl ( < ListViewBreadcrumb { ...props } /> ) ;
66+ const oraLink = container . querySelector ( 'a[href*="oraUrl"]' ) ;
67+ expect ( oraLink ) . toBeInTheDocument ( ) ;
68+ expect ( oraLink ) . toHaveAttribute ( 'href' , `oraUrl(${ props . courseId } , test-location-id)` ) ;
4969 } ) ;
50- test ( 'ora destination' , ( ) => {
51- expect (
52- el . instance . findByType ( Hyperlink ) [ 1 ] . props . destination ,
53- ) . toEqual ( urls . ora ( props . courseId , constants . locationId ( ) ) ) ;
70+
71+ it ( 'displays back to responses text' , ( ) => {
72+ const { getByText } = renderWithIntl ( < ListViewBreadcrumb { .. .props } /> ) ;
73+ expect ( getByText ( 'Back to all open responses' ) ) . toBeInTheDocument ( ) ;
5474 } ) ;
5575 } ) ;
76+
5677 describe ( 'mapStateToProps' , ( ) => {
57- let mapped ;
5878 const testState = { some : 'test-state' } ;
59- beforeEach ( ( ) => {
60- mapped = mapStateToProps ( testState ) ;
61- } ) ;
62- test ( 'courseId loads from app.courseId' , ( ) => {
79+
80+ it ( 'maps courseId from app.courseId selector' , ( ) => {
81+ const mapped = mapStateToProps ( testState ) ;
6382 expect ( mapped . courseId ) . toEqual ( selectors . app . courseId ( testState ) ) ;
6483 } ) ;
65- test ( 'oraName loads from app.ora.name' , ( ) => {
84+
85+ it ( 'maps oraName from app.ora.name selector' , ( ) => {
86+ const mapped = mapStateToProps ( testState ) ;
6687 expect ( mapped . oraName ) . toEqual ( selectors . app . ora . name ( testState ) ) ;
6788 } ) ;
6889 } ) ;
0 commit comments