-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fdb1b3d
commit 72e9e3f
Showing
1 changed file
with
176 additions
and
0 deletions.
There are no files selected for viewing
176 changes: 176 additions & 0 deletions
176
src/test/__tests__/common/helpers/search/formatters/authorities.test.ts
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,176 @@ | ||
import { formatAuthorityItem } from '@common/helpers/search/formatters/authorities'; | ||
|
||
describe('formatAuthorityItem', () => { | ||
const authoritiesList = [ | ||
{ | ||
authority: { | ||
id: '1', | ||
authRefType: 'testType_1', | ||
headingRef: 'testHeading_1', | ||
headingType: 'testHeadingType_1', | ||
sourceFileId: 'testSource_1', | ||
}, | ||
isAnchor: true, | ||
}, | ||
]; | ||
|
||
it('returns an empty array when authoritiesList is empty', () => { | ||
const result = formatAuthorityItem([]); | ||
|
||
expect(result).toEqual([]); | ||
}); | ||
|
||
it('formats authority items correctly when authority is present', () => { | ||
const testResult = [ | ||
{ | ||
__meta: { | ||
id: '1', | ||
key: expect.any(String), | ||
isAnchor: true, | ||
}, | ||
authorized: { | ||
label: 'testType_1', | ||
}, | ||
title: { | ||
label: 'testHeading_1', | ||
className: 'title', | ||
}, | ||
subclass: { | ||
label: 'testHeadingType_1', | ||
className: 'heading-type', | ||
}, | ||
authoritySource: { | ||
label: 'testSource_1', | ||
className: 'authority-source', | ||
}, | ||
}, | ||
]; | ||
|
||
const result = formatAuthorityItem(authoritiesList as unknown as AuthorityAsBrowseResultDTO[]); | ||
|
||
expect(result).toEqual(testResult); | ||
}); | ||
|
||
it('formats authority items correctly when authority is not present', () => { | ||
const authoritiesList = [ | ||
{ | ||
id: '2', | ||
authRefType: 'testType_2', | ||
headingRef: 'testHeading_2', | ||
headingType: 'testHeadingType_2', | ||
sourceFileId: 'testSource_2', | ||
isAnchor: false, | ||
}, | ||
]; | ||
const testResult = [ | ||
{ | ||
__meta: { | ||
id: '2', | ||
key: expect.any(String), | ||
isAnchor: false, | ||
}, | ||
authorized: { | ||
label: 'testType_2', | ||
}, | ||
title: { | ||
label: 'testHeading_2', | ||
className: 'title', | ||
}, | ||
subclass: { | ||
label: 'testHeadingType_2', | ||
className: 'heading-type', | ||
}, | ||
authoritySource: { | ||
label: 'testSource_2', | ||
className: 'authority-source', | ||
}, | ||
}, | ||
]; | ||
|
||
const result = formatAuthorityItem(authoritiesList); | ||
|
||
expect(result).toEqual(testResult); | ||
}); | ||
|
||
it('uses sourceData to find source label', () => { | ||
const sourceData = [{ id: 'testSource_1', name: 'Source Name 1' }]; | ||
const testResult = [ | ||
{ | ||
__meta: { | ||
id: '1', | ||
key: expect.any(String), | ||
isAnchor: true, | ||
}, | ||
authorized: { | ||
label: 'testType_1', | ||
}, | ||
title: { | ||
label: 'testHeading_1', | ||
className: 'title', | ||
}, | ||
subclass: { | ||
label: 'testHeadingType_1', | ||
className: 'heading-type', | ||
}, | ||
authoritySource: { | ||
label: 'Source Name 1', | ||
className: 'authority-source', | ||
}, | ||
}, | ||
]; | ||
|
||
const result = formatAuthorityItem( | ||
authoritiesList as unknown as AuthorityAsBrowseResultDTO[], | ||
sourceData as SourceDataDTO, | ||
); | ||
|
||
expect(result).toEqual(testResult); | ||
}); | ||
|
||
it('uses sourceFileId as source label when sourceData does not match', () => { | ||
const authoritiesList = [ | ||
{ | ||
authority: { | ||
id: '3', | ||
authRefType: 'testType_3', | ||
headingRef: 'testHeading_3', | ||
headingType: 'testHeadingType_3', | ||
sourceFileId: 'testSource_3', | ||
}, | ||
isAnchor: false, | ||
}, | ||
]; | ||
const sourceData = [{ id: 'testSource_4', name: 'Source Name 4' }]; | ||
const testResult = [ | ||
{ | ||
__meta: { | ||
id: '3', | ||
key: expect.any(String), | ||
isAnchor: false, | ||
}, | ||
authorized: { | ||
label: 'testType_3', | ||
}, | ||
title: { | ||
label: 'testHeading_3', | ||
className: 'title', | ||
}, | ||
subclass: { | ||
label: 'testHeadingType_3', | ||
className: 'heading-type', | ||
}, | ||
authoritySource: { | ||
label: 'testSource_3', | ||
className: 'authority-source', | ||
}, | ||
}, | ||
]; | ||
|
||
const result = formatAuthorityItem( | ||
authoritiesList as unknown as AuthorityAsBrowseResultDTO[], | ||
sourceData as SourceDataDTO, | ||
); | ||
|
||
expect(result).toEqual(testResult); | ||
}); | ||
}); |