Skip to content

Commit

Permalink
UIIN-3162 use prefix+callnumber+suffix instead of fullCallNumber
Browse files Browse the repository at this point in the history
  • Loading branch information
BogdanDenis committed Jan 15, 2025
1 parent 1d1101a commit 6439b8b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
9 changes: 6 additions & 3 deletions src/components/BrowseResultsList/BrowseResultsList.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,18 @@ const defaultProps = {
browseData: [
{
fullCallNumber: 'Aaa',
callNumber: 'Aaa',
isAnchor: true,
totalRecords: 0,
},
{
fullCallNumber: 'A 1958 A 8050',
callNumber: 'A 1958 A 8050',
totalRecords: 1,
},
{
fullCallNumber: 'ABBA',
callNumber: 'ABBA',
totalRecords: 2,
},
],
Expand Down Expand Up @@ -127,13 +130,13 @@ describe('BrowseResultsList', () => {
it('should render browse data', () => {
renderBrowseResultsList();

expect(screen.getByText(defaultProps.browseData[1].fullCallNumber)).toBeInTheDocument();
expect(screen.getByText(defaultProps.browseData[1].callNumber)).toBeInTheDocument();
});

it('should navigate to instance Search page and show related instances', async () => {
renderBrowseResultsList();

await act(async () => fireEvent.click(screen.getByText(defaultProps.browseData[2].fullCallNumber)));
await act(async () => fireEvent.click(screen.getByText(defaultProps.browseData[2].callNumber)));

const { pathname, search } = history.location;

Expand Down Expand Up @@ -174,7 +177,7 @@ describe('BrowseResultsList', () => {
},
});

fireEvent.click(screen.getByText(defaultProps.browseData[2].fullCallNumber));
fireEvent.click(screen.getByText(defaultProps.browseData[2].callNumber));

expect(history.location.search).toContain('?filters=shared.true%2Cshared.false%2CtenantId.college');
});
Expand Down
5 changes: 3 additions & 2 deletions src/components/BrowseResultsList/getBrowseResultsFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
INVENTORY_ROUTE,
} from '../../constants';
import {
getFullCallNumber,
getSearchParams,
isRowPreventsClick,
} from './utils';
Expand Down Expand Up @@ -137,12 +138,12 @@ const getBrowseResultsFormatter = ({
return typeName || <NoValue />;
},
callNumber: r => {
const fullCallNumber = [r?.callNumberPrefix, r?.callNumber, r?.callNumberSuffix].filter(Boolean).join(' ');
const fullCallNumber = getFullCallNumber(r);

if (r?.totalRecords) {
return getTargetRecord(fullCallNumber, r, ...commonTargetRecordArgs);
}
return <MissedMatchItem query={fullCallNumber} />;
return <MissedMatchItem query={r.fullCallNumber} />;
},
classificationNumber: r => {
if (r?.totalRecords) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,21 @@ describe('getBrowseResultsFormatter', () => {
const missedMatchRecord = {
isAnchor: true,
fullCallNumber: 'bla bla',
callNumber: 'bla bla',
totalRecords: 0,
};
const contentData = [
{
fullCallNumber: 'A 1958 A 8050',
callNumber: 'A 1958 A 8050',
shelfKey: '41958 A 48050',
isAnchor: true,
totalRecords: 1,
instance: { id: 'ce9dd893-c812-49d5-8973-d55d018894c4', title: 'Test title' },
},
{
fullCallNumber: 'AAA',
callNumber: 'AAA',
shelfKey: '123456',
totalRecords: 2,
instance: { id: 'ce9dd893-c812-49d5-8973-d55d018894c4', title: 'Test title 2' },
Expand All @@ -117,17 +120,17 @@ describe('getBrowseResultsFormatter', () => {
renderCallNumberList();

// Anchor row
expect(screen.getByText(anchorRecord.fullCallNumber).tagName.toLowerCase()).toBe('strong');
expect(screen.getByText(anchorRecord.callNumber).tagName.toLowerCase()).toBe('strong');
expect(screen.getByText(anchorRecord.totalRecords).tagName.toLowerCase()).toBe('strong');
// Default row
expect(screen.getByText(nonAnchorRecord.fullCallNumber).tagName.toLowerCase()).not.toBe('strong');
expect(screen.getByText(nonAnchorRecord.callNumber).tagName.toLowerCase()).not.toBe('strong');
expect(screen.getByText(nonAnchorRecord.totalRecords).tagName.toLowerCase()).not.toBe('strong');
});

it('should render \'Missed match item\' row', () => {
renderCallNumberList({ contentData: [missedMatchRecord] });

expect(screen.getByText(missedMatchRecord.fullCallNumber)).toBeInTheDocument();
expect(screen.getByText(missedMatchRecord.callNumber)).toBeInTheDocument();
expect(screen.getByText(missedMatchText)).toBeInTheDocument();
});

Expand All @@ -136,7 +139,7 @@ describe('getBrowseResultsFormatter', () => {

expect(history.location.pathname).toEqual(BROWSE_INVENTORY_ROUTE);

await act(async () => fireEvent.click(screen.getByText(anchorRecord.fullCallNumber)));
await act(async () => fireEvent.click(screen.getByText(anchorRecord.callNumber)));

expect(history.location.pathname).toEqual(INVENTORY_ROUTE);
});
Expand Down
22 changes: 15 additions & 7 deletions src/components/BrowseResultsList/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ const getClassificationQuery = (qindex, data, row) => {
return query;
};

export const getFullCallNumber = (row) => {
const fullCallNumber = [row.callNumberPrefix, row.callNumber, row.callNumberSuffix].filter(Boolean).join(' ');

return fullCallNumber;
};

export const getSearchParams = (row, qindex, allFilters, data) => {
const filters = getExtraFilters(row, qindex, allFilters);
const classificationQuery = getClassificationQuery(qindex, data, row);
Expand All @@ -107,46 +113,48 @@ export const getSearchParams = (row, qindex, allFilters, data) => {
...filters,
};

const fullCallNumber = getFullCallNumber(row);

const optionsMap = {
[browseModeOptions.CALL_NUMBERS]: {
qindex: queryIndexes.ITEM_NORMALIZED_CALL_NUMBERS,
query: row.fullCallNumber,
query: fullCallNumber,
segment: segments.items,
...filters,
},
[browseModeOptions.DEWEY]: {
qindex: queryIndexes.ITEM_NORMALIZED_CALL_NUMBERS,
query: row.fullCallNumber,
query: fullCallNumber,
segment: segments.items,
...filters,
},
[browseModeOptions.LIBRARY_OF_CONGRESS]: {
qindex: queryIndexes.ITEM_NORMALIZED_CALL_NUMBERS,
query: row.fullCallNumber,
query: fullCallNumber,
segment: segments.items,
...filters,
},
[browseModeOptions.LOCAL]: {
qindex: queryIndexes.ITEM_NORMALIZED_CALL_NUMBERS,
query: row.fullCallNumber,
query: fullCallNumber,
segment: segments.items,
...filters,
},
[browseModeOptions.NATIONAL_LIBRARY_OF_MEDICINE]: {
qindex: queryIndexes.ITEM_NORMALIZED_CALL_NUMBERS,
query: row.fullCallNumber,
query: fullCallNumber,
segment: segments.items,
...filters,
},
[browseModeOptions.OTHER]: {
qindex: queryIndexes.ITEM_NORMALIZED_CALL_NUMBERS,
query: row.fullCallNumber,
query: fullCallNumber,
segment: segments.items,
...filters,
},
[browseModeOptions.SUPERINTENDENT]: {
qindex: queryIndexes.ITEM_NORMALIZED_CALL_NUMBERS,
query: row.fullCallNumber,
query: fullCallNumber,
segment: segments.items,
...filters,
},
Expand Down

0 comments on commit 6439b8b

Please sign in to comment.