-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UISACQCOMP-208: ECS - clear Select location filters on change another…
… Affiliation (#799) * UISACQCOMP-208: ECS - clear Select location filters on change another Affiliation * fix holding selection issue * test: add unit test * test: add test coverage * refactor resetFilters function * reset filter on change affiliation * add initial value constanta
- Loading branch information
1 parent
d4faea1
commit f096bdf
Showing
6 changed files
with
218 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
import { useLocalStorage } from '@rehooks/local-storage'; | ||
import { render, screen } from '@testing-library/react'; | ||
import user from '@testing-library/user-event'; | ||
|
||
import { | ||
useCampusesQuery, | ||
useCurrentUserTenants, | ||
useInstitutionsQuery, | ||
useLibrariesQuery, | ||
} from '../hooks'; | ||
import { FindLocationLookup } from './FindLocationLookup'; | ||
import { | ||
useLocationsList, | ||
useLocationsRecords, | ||
} from './hooks'; | ||
|
||
jest.mock('@rehooks/local-storage', () => ({ | ||
useLocalStorage: jest.fn(), | ||
})); | ||
|
||
jest.mock('../AcqList', () => ({ | ||
...jest.requireActual('../AcqList'), | ||
useFiltersToogle: () => ({ isFiltersOpened: true, toggleFilters: jest.fn }), | ||
})); | ||
jest.mock('../hooks', () => ({ | ||
...jest.requireActual('../hooks'), | ||
useCampusesQuery: jest.fn(), | ||
useCurrentUserTenants: jest.fn(), | ||
useEventEmitter: jest.fn().mockReturnValue({ | ||
emit: jest.fn(), | ||
on: jest.fn(), | ||
off: jest.fn(), | ||
}), | ||
useInstitutionsQuery: jest.fn(), | ||
useLibrariesQuery: jest.fn(), | ||
})); | ||
jest.mock('./hooks', () => ({ | ||
useLocationsList: jest.fn(), | ||
useLocationsRecords: jest.fn(), | ||
})); | ||
|
||
const setItem = jest.fn(); | ||
const removeItem = jest.fn(); | ||
const mockTenants = [ | ||
{ | ||
id: 'central', | ||
name: 'Central Office', | ||
isPrimary: true, | ||
}, | ||
{ | ||
id: 'college', | ||
name: 'College', | ||
isPrimary: false, | ||
}, | ||
]; | ||
|
||
const renderFindLocationLookup = (props) => render( | ||
<FindLocationLookup | ||
affiliationsLabel="affiliationsLabel" | ||
crossTenant | ||
filterRecords={jest.fn()} | ||
idPrefix="idPrefix" | ||
isMultiSelect | ||
modalLabel="modalLabel" | ||
onRecordsSelect={jest.fn()} | ||
resultsPaneTitle="resultsPaneTitle" | ||
sortableColumns={['sortableColumns']} | ||
tenantId={mockTenants[0].id} | ||
visibleColumns={['visibleColumns']} | ||
{...props} | ||
/>, | ||
); | ||
|
||
describe('FindLocationLookup', () => { | ||
beforeEach(() => { | ||
useCampusesQuery.mockClear().mockReturnValue({ | ||
campuses: [], | ||
isLoading: false, | ||
}); | ||
useInstitutionsQuery.mockClear().mockReturnValue({ | ||
institutions: [], | ||
isLoading: false, | ||
}); | ||
useLibrariesQuery.mockClear().mockReturnValue({ | ||
libraries: [], | ||
isLoading: false, | ||
}); | ||
useLocationsList.mockClear().mockReturnValue({ locations: [] }); | ||
useLocationsRecords.mockClear().mockReturnValue({ | ||
locations: [], | ||
isLoading: false, | ||
}); | ||
useLocalStorage.mockReturnValue([ | ||
null, | ||
setItem, | ||
removeItem, | ||
]); | ||
useCurrentUserTenants.mockClear().mockReturnValue(mockTenants); | ||
}); | ||
it('should render FindRecords component', () => { | ||
const { getByText } = renderFindLocationLookup(); | ||
|
||
expect(getByText('resultsPaneTitle')).toBeDefined(); | ||
}); | ||
|
||
it('should clear filters on tenant change', async () => { | ||
const onTenantChange = jest.fn(); | ||
|
||
useInstitutionsQuery.mockClear().mockReturnValue({ | ||
institutions: [ | ||
{ | ||
'id': 'a0ba27d5-aa76-4bfb-904d-1ba9b80ab882', | ||
'tenantId': 'cs00000int', | ||
'name': 'Test 1', | ||
}, | ||
], | ||
isLoading: false, | ||
}); | ||
useCampusesQuery.mockClear().mockReturnValue({ | ||
campuses: [{ | ||
'id': '124da306-a838-40c4-812d-4e2d1e82ebdd', | ||
'tenantId': 'cs00000int', | ||
'name': 'Campus 1', | ||
'institutionId': '9d1b77e5-f02e-4b7f-b296-3f2042ddac54', | ||
}], | ||
isLoading: false, | ||
}); | ||
useLibrariesQuery.mockClear().mockReturnValue({ | ||
libraries: [{ | ||
'id': '563e0d8b-180d-45fb-abfe-5d0696ba4f60', | ||
'tenantId': 'cs00000int', | ||
'name': 'library', | ||
'campusId': '124da306-a838-40c4-812d-4e2d1e82ebdd', | ||
}], | ||
isLoading: false, | ||
}); | ||
useLocationsList.mockClear().mockReturnValue({ | ||
locations: [ | ||
{ | ||
'id': '65578bd8-0e87-472e-8579-9db5cfe846dc', | ||
'name': 'Folio name', | ||
'tenantId': 'cs00000int', | ||
'code': 'location-new', | ||
'discoveryDisplayName': 'Location new', | ||
'isActive': 'true', | ||
'institutionId': '9d1b77e5-f02e-4b7f-b296-3f2042ddac54', | ||
'campusId': '124da306-a838-40c4-812d-4e2d1e82ebdd', | ||
'libraryId': '563e0d8b-180d-45fb-abfe-5d0696ba4f60', | ||
'primaryServicePoint': '9d1b77e8-f02e-4b7f-b296-3f2042ddac54', | ||
'servicePointIds': [ | ||
'9d1b77e8-f02e-4b7f-b296-3f2042ddac54', | ||
], | ||
'campus': { | ||
'id': '124da306-a838-40c4-812d-4e2d1e82ebdd', | ||
'tenantId': 'cs00000int', | ||
'name': 'Campus 1', | ||
'institutionId': '9d1b77e5-f02e-4b7f-b296-3f2042ddac54', | ||
}, | ||
'library': { | ||
'id': '563e0d8b-180d-45fb-abfe-5d0696ba4f60', | ||
'tenantId': 'cs00000int', | ||
'name': 'library', | ||
'campusId': '124da306-a838-40c4-812d-4e2d1e82ebdd', | ||
}, | ||
}, | ||
], | ||
}); | ||
|
||
renderFindLocationLookup({ onTenantChange }); | ||
|
||
const affiliationSelection = await screen.findByText('affiliationsLabel'); | ||
|
||
expect(affiliationSelection).toBeInTheDocument(); | ||
await user.click(screen.getByText(mockTenants[1].name)); | ||
|
||
expect(onTenantChange).toHaveBeenCalledWith(mockTenants[1].id); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters