-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(feo): add search index interceptor
- Loading branch information
1 parent
0bf16ff
commit c228b19
Showing
4 changed files
with
84 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { ChromeStaticSearchEntry, FrontendCRD } from './feo-types'; | ||
import searchInterceptor from './search-interceptor'; | ||
|
||
describe('SearchInterceptor', () => { | ||
it('should replace search entries with the ones from the frontendCRD', () => { | ||
const frontendName = 'frontendName'; | ||
const frontendCRD: FrontendCRD = { | ||
objects: [ | ||
{ | ||
metadata: { | ||
name: frontendName, | ||
}, | ||
spec: { | ||
module: { | ||
manifestLocation: 'location', | ||
}, | ||
searchEntries: [ | ||
{ | ||
frontendRef: frontendName, | ||
id: 'id-1', | ||
href: 'href-1', | ||
title: 'title-1', | ||
description: 'description-1', | ||
}, | ||
{ | ||
frontendRef: frontendName, | ||
id: 'id-1', | ||
href: 'href-1', | ||
title: 'title-1', | ||
description: 'description-1', | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
}; | ||
const remoteSearchEntries: ChromeStaticSearchEntry[] = [ | ||
{ | ||
frontendRef: 'otherFrontend', | ||
id: 'otherFrontend', | ||
href: 'otherFrontend', | ||
title: 'otherFrontend', | ||
description: 'otherFrontend', | ||
}, | ||
{ | ||
frontendRef: frontendName, | ||
id: frontendName, | ||
href: frontendName, | ||
title: frontendName, | ||
description: frontendName, | ||
}, | ||
]; | ||
|
||
const expectedSearchEntries: ChromeStaticSearchEntry[] = [remoteSearchEntries[0], ...(frontendCRD.objects[0].spec.searchEntries ?? [])]; | ||
const result = searchInterceptor(remoteSearchEntries, frontendCRD); | ||
expect(result).toEqual(expectedSearchEntries); | ||
}); | ||
}); |
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,9 @@ | ||
import { ChromeStaticSearchEntry, FrontendCRD } from './feo-types'; | ||
|
||
function searchInterceptor(staticSearchIndex: ChromeStaticSearchEntry[], frontendCRD: FrontendCRD): ChromeStaticSearchEntry[] { | ||
const frontendRef = frontendCRD.objects[0].metadata.name; | ||
const result = staticSearchIndex.filter((entry) => entry.frontendRef !== frontendRef); | ||
return [...result, ...(frontendCRD.objects[0].spec.searchEntries ?? [])]; | ||
} | ||
|
||
export default searchInterceptor; |