@@ -6,15 +6,13 @@ import { Provider } from 'react-redux';
66import { mount } from 'enzyme' ;
77
88import LearnerActivityTable from '.' ;
9- import useCourseEnrollments from './data /hooks/useCourseEnrollments ' ;
10- import mockUseCourseEnrollments from './data/tests/constants' ;
9+ import usePaginatedTableData from '../.. /hooks/usePaginatedTableData ' ;
10+ import { mockUseCourseEnrollments , mockEmptyCourseEnrollmentsData } from './data/tests/constants' ;
1111
1212const enterpriseId = 'test-enterprise' ;
1313const mockStore = configureMockStore ( [ thunk ] ) ;
1414
15- jest . mock ( './data/hooks/useCourseEnrollments.js' , ( ) => (
16- jest . fn ( ) . mockReturnValue ( { } )
17- ) ) ;
15+ jest . mock ( '../../hooks/usePaginatedTableData' , ( ) => jest . fn ( ) ) ;
1816
1917const store = mockStore ( {
2018 portalConfiguration : {
@@ -26,33 +24,26 @@ const LearnerActivityTableWrapper = props => (
2624 < MemoryRouter >
2725 < IntlProvider locale = "en" >
2826 < Provider store = { store } >
29- < LearnerActivityTable
30- { ...props }
31- />
27+ < LearnerActivityTable { ...props } />
3228 </ Provider >
3329 </ IntlProvider >
3430 </ MemoryRouter >
3531) ;
3632
3733const verifyLearnerActivityTableRendered = ( tableId , activity , columnTitles , rowsData ) => {
3834 const wrapper = mount ( < LearnerActivityTableWrapper id = { tableId } activity = { activity } /> ) ;
39-
4035 const table = wrapper . find ( '[role="table"]' ) ;
4136 const headerColumns = table . find ( 'thead th' ) ;
4237 const tableRows = table . find ( 'tbody tr' ) ;
4338
44- // Verify the number of columns
4539 expect ( headerColumns ) . toHaveLength ( columnTitles . length ) ;
4640
47- // Verify column titles
4841 headerColumns . forEach ( ( column , index ) => {
4942 expect ( column . text ( ) ) . toContain ( columnTitles [ index ] ) ;
5043 } ) ;
5144
52- // Verify the number of rows
5345 expect ( tableRows ) . toHaveLength ( rowsData . length ) ;
5446
55- // Verify row data
5647 tableRows . forEach ( ( row , rowIndex ) => {
5748 const cells = row . find ( 'td' ) ;
5849 cells . forEach ( ( cell , colIndex ) => {
@@ -63,32 +54,19 @@ const verifyLearnerActivityTableRendered = (tableId, activity, columnTitles, row
6354
6455describe ( 'LearnerActivityTable' , ( ) => {
6556 beforeEach ( ( ) => {
66- useCourseEnrollments . mockReturnValue ( mockUseCourseEnrollments ) ;
57+ usePaginatedTableData . mockReturnValue ( mockUseCourseEnrollments ) ;
6758 } ) ;
6859
6960 afterEach ( ( ) => jest . clearAllMocks ( ) ) ;
7061
71- // Replacing the snapshot tests with explicit assertions
7262 it ( 'renders empty table correctly' , ( ) => {
73- useCourseEnrollments . mockReturnValue ( {
74- isLoading : false ,
75- courseEnrollments : {
76- itemCount : 0 ,
77- pageCount : 0 ,
78- results : [ ] ,
79- } ,
80- fetchCourseEnrollments : jest . fn ( ) ,
81- hasData : false ,
82- } ) ;
63+ usePaginatedTableData . mockReturnValue ( mockEmptyCourseEnrollmentsData ) ;
8364
8465 const wrapper = mount (
8566 < LearnerActivityTableWrapper id = "active-week" activity = "active_past_week" /> ,
8667 ) ;
8768
88- // Verify the table exists
8969 expect ( wrapper . find ( '[role="table"]' ) . exists ( ) ) . toBe ( true ) ;
90-
91- // Verify no data rows are displayed
9270 expect ( wrapper . find ( 'tbody tr' ) . length ) . toBe ( 0 ) ;
9371 } ) ;
9472
@@ -108,21 +86,15 @@ describe('LearnerActivityTable', () => {
10886 ] ;
10987
11088 const wrapper = mount ( < LearnerActivityTableWrapper id = { tableId } activity = { activity } /> ) ;
111-
112- // Verify the table exists
11389 const table = wrapper . find ( '[role="table"]' ) ;
114- expect ( table . exists ( ) ) . toBe ( true ) ;
115-
116- // Verify correct columns are displayed
11790 const headerColumns = table . find ( 'thead th' ) ;
118- expect ( headerColumns ) . toHaveLength ( columnTitles . length ) ;
11991
120- // Verify column titles
92+ expect ( table . exists ( ) ) . toBe ( true ) ;
93+ expect ( headerColumns ) . toHaveLength ( columnTitles . length ) ;
12194 headerColumns . forEach ( ( column , index ) => {
12295 expect ( column . text ( ) ) . toContain ( columnTitles [ index ] ) ;
12396 } ) ;
12497
125- // Verify data is rendered
12698 expect ( wrapper . find ( 'tbody tr' ) . length ) . toBeGreaterThan ( 0 ) ;
12799 } ) ;
128100
@@ -141,25 +113,17 @@ describe('LearnerActivityTable', () => {
141113 ] ;
142114
143115 const wrapper = mount ( < LearnerActivityTableWrapper id = { tableId } activity = { activity } /> ) ;
144-
145- // Verify the table exists
146116 const table = wrapper . find ( '[role="table"]' ) ;
147- expect ( table . exists ( ) ) . toBe ( true ) ;
148-
149- // Verify correct columns are displayed (should not include Passed Date)
150117 const headerColumns = table . find ( 'thead th' ) ;
151- expect ( headerColumns ) . toHaveLength ( columnTitles . length ) ;
152118
153- // Verify column titles
119+ expect ( table . exists ( ) ) . toBe ( true ) ;
120+ expect ( headerColumns ) . toHaveLength ( columnTitles . length ) ;
154121 headerColumns . forEach ( ( column , index ) => {
155122 expect ( column . text ( ) ) . toContain ( columnTitles [ index ] ) ;
156123 } ) ;
157124
158- // Verify "Passed Date" column is not present
159125 const columnHeaders = headerColumns . map ( col => col . text ( ) ) ;
160126 expect ( columnHeaders . includes ( 'Passed Date' ) ) . toBe ( false ) ;
161-
162- // Verify data is rendered
163127 expect ( wrapper . find ( 'tbody tr' ) . length ) . toBeGreaterThan ( 0 ) ;
164128 } ) ;
165129
@@ -178,25 +142,17 @@ describe('LearnerActivityTable', () => {
178142 ] ;
179143
180144 const wrapper = mount ( < LearnerActivityTableWrapper id = { tableId } activity = { activity } /> ) ;
181-
182- // Verify the table exists
183145 const table = wrapper . find ( '[role="table"]' ) ;
184- expect ( table . exists ( ) ) . toBe ( true ) ;
185-
186- // Verify correct columns are displayed (should not include Passed Date)
187146 const headerColumns = table . find ( 'thead th' ) ;
188- expect ( headerColumns ) . toHaveLength ( columnTitles . length ) ;
189147
190- // Verify column titles
148+ expect ( table . exists ( ) ) . toBe ( true ) ;
149+ expect ( headerColumns ) . toHaveLength ( columnTitles . length ) ;
191150 headerColumns . forEach ( ( column , index ) => {
192151 expect ( column . text ( ) ) . toContain ( columnTitles [ index ] ) ;
193152 } ) ;
194153
195- // Verify "Passed Date" column is not present
196154 const columnHeaders = headerColumns . map ( col => col . text ( ) ) ;
197155 expect ( columnHeaders . includes ( 'Passed Date' ) ) . toBe ( false ) ;
198-
199- // Verify data is rendered
200156 expect ( wrapper . find ( 'tbody tr' ) . length ) . toBeGreaterThan ( 0 ) ;
201157 } ) ;
202158
0 commit comments