1-
21import { waitFor } from '@folio/jest-config-stripes/testing-library/react' ;
2+
33import { Button , Dropdown , MultiColumnList , renderWithIntl } from '@folio/stripes-erm-testing' ;
4- import { MemoryRouter } from 'react-router-dom' ;
4+
55import translationsProperties from '../../../../test/helpers' ;
66import CoveredEResourcesList from './CoveredEResourcesList' ;
77import agreement from './testResources' ;
88
9- jest . mock ( '../../IfEResourcesEnabled' , ( ) => ( { children } ) => {
10- return typeof children === 'function' ? children ( { isEnabled : true } ) : children ;
11- } ) ;
12-
13- // Use manual mocks set up in hooks/__mocks__ folder
14- jest . mock ( '../../../hooks' ) ;
9+ // Use manual mocks set up in hooks/__mocks__ folder (small correction to the way this was done before)
10+ jest . mock ( '../../../hooks/useAgreementsSettings' ) ;
11+ jest . mock ( '../../../hooks/useEresourcesEnabled' ) ;
1512
1613const handlers = {
1714 onFilterEResources : jest . fn ( ) ,
1815 onExportEResourcesAsJSON : jest . fn ( ) . mockImplementation ( ( ) => Promise . resolve ( ) ) ,
1916 onExportEResourcesAsKBART : jest . fn ( ) . mockImplementation ( ( ) => Promise . resolve ( ) ) ,
2017} ;
2118
19+ // TODO there are 2 warnings when running this test... contentData ends up as a boolean not an array --
20+ // maybe needs mocking fetchMultiplePages
21+ // received NaN for the children attribute within PrevNextPagination, better mocking needed there too?
2222describe ( 'CoveredEResourcesList' , ( ) => {
23- beforeEach ( ( ) => {
24- renderWithIntl (
25- < MemoryRouter >
23+ beforeEach ( async ( ) => {
24+ // This is blowing my mind... I do not understand why this needs to be wrapped in a waitFor
25+ await waitFor ( ( ) => {
26+ renderWithIntl (
2627 < CoveredEResourcesList
2728 agreement = { agreement }
2829 eresourcesFilterPath = "current"
2930 { ...handlers }
30- />
31- </ MemoryRouter > ,
32- translationsProperties
33- ) ;
34- } ) ;
35-
36- test ( 'renders the expected filter buttons' , async ( ) => {
37- await Button ( 'Current' ) . exists ( ) ;
38- await Button ( 'Future' ) . exists ( ) ;
39- await Button ( 'Dropped' ) . exists ( ) ;
40- await Button ( 'All' ) . exists ( ) ;
31+ /> ,
32+ translationsProperties
33+ ) ;
34+ } ) ;
4135 } ) ;
4236
43- test ( 'clicking the filter buttons should call the onFilterEResources callback' , async ( ) => {
44- await waitFor ( async ( ) => {
45- await Button ( 'Future' ) . click ( ) ;
37+ describe . each ( [ 'Future' , 'Current' , 'Dropped' , 'All' ] ) ( '%s filter button' , ( filterLabel ) => {
38+ test ( `renders the ${ filterLabel } button` , async ( ) => {
39+ await waitFor ( async ( ) => {
40+ await Button ( filterLabel ) . exists ( ) ;
41+ } ) ;
4642 } ) ;
4743
48- await waitFor ( async ( ) => {
49- expect ( handlers . onFilterEResources . mock . calls . length ) . toBe ( 1 ) ;
50- } ) ;
51-
52- await waitFor ( async ( ) => {
53- await Button ( 'Dropped' ) . click ( ) ;
54- } ) ;
44+ describe ( `clicking the ${ filterLabel } button` , ( ) => {
45+ beforeEach ( async ( ) => {
46+ handlers . onFilterEResources . mockClear ( ) ;
5547
56- await waitFor ( async ( ) => {
57- expect ( handlers . onFilterEResources . mock . calls . length ) . toBe ( 2 ) ;
58- } ) ;
48+ expect ( handlers . onFilterEResources . mock . calls . length ) . toBe ( 0 ) ;
5949
60- await waitFor ( async ( ) => {
61- await Button ( 'All' ) . click ( ) ;
62- } ) ;
50+ await waitFor ( async ( ) => {
51+ await Button ( filterLabel ) . click ( ) ;
52+ } ) ;
53+ } ) ;
6354
64- await waitFor ( async ( ) => {
65- expect ( handlers . onFilterEResources . mock . calls . length ) . toBe ( 3 ) ;
55+ test ( 'onFilterEResources callback called' , async ( ) => {
56+ await waitFor ( async ( ) => {
57+ expect ( handlers . onFilterEResources . mock . calls . length ) . toBe ( 1 ) ;
58+ } ) ;
59+ } ) ;
6660 } ) ;
6761 } ) ;
6862
6963 test ( 'renders the Export dropdown' , async ( ) => {
70- await Dropdown ( 'Export as...' ) . exists ( ) ;
71- } ) ;
72-
73- test ( 'choosing the dropdown options' , async ( ) => {
7464 await waitFor ( async ( ) => {
75- await Dropdown ( 'Export as...' ) . choose ( 'JSON' ) ;
65+ await Dropdown ( 'Export as...' ) . exists ( ) ;
7666 } ) ;
67+ } ) ;
7768
78- await waitFor ( async ( ) => {
79- expect ( handlers . onExportEResourcesAsJSON . mock . calls . length ) . toBe ( 1 ) ;
69+ describe . each ( [
70+ { dropdownChoice : 'JSON' , mockHandler : handlers . onExportEResourcesAsJSON } ,
71+ { dropdownChoice : 'KBART' , mockHandler : handlers . onExportEResourcesAsKBART }
72+ ] ) ( 'choosing export as $dropdownChoice' , ( { dropdownChoice, mockHandler } ) => {
73+ beforeEach ( async ( ) => {
74+ await waitFor ( async ( ) => {
75+ await Dropdown ( 'Export as...' ) . choose ( dropdownChoice ) ;
76+ } ) ;
8077 } ) ;
8178
82- await waitFor ( async ( ) => {
83- await Dropdown ( 'Export as...' ) . choose ( 'KBART' ) ;
84- } ) ;
85-
86- await waitFor ( async ( ) => {
87- expect ( handlers . onExportEResourcesAsKBART . mock . calls . length ) . toBe ( 1 ) ;
79+ test ( 'correct onExportResources handler called' , async ( ) => {
80+ await waitFor ( async ( ) => {
81+ expect ( mockHandler . mock . calls . length ) . toBe ( 1 ) ;
82+ } ) ;
8883 } ) ;
8984 } ) ;
9085
@@ -100,4 +95,3 @@ describe('CoveredEResourcesList', () => {
10095 await MultiColumnList ( { columns : [ 'Name' , 'eISSN/ISSN' , 'Platform' , 'Package' , 'Coverage' , ' ' , 'Access start' , 'Access end' ] } ) . exists ( ) ;
10196 } ) ;
10297} ) ;
103-
0 commit comments