-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2137 from Hyperkid123/feo-modules-spec-merging
Feo modules spec merging
- Loading branch information
Showing
12 changed files
with
555 additions
and
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
export type SupportCaseData = { | ||
version: string; | ||
product: string; | ||
}; | ||
|
||
export type ChromeGlobalModuleConfig = { | ||
supportCaseData?: SupportCaseData; | ||
ssoScopes?: string[]; | ||
}; | ||
|
||
export type ChromePermissions = { | ||
method: string; | ||
apps?: string[]; | ||
args?: unknown[]; | ||
}; | ||
|
||
export type ChromeEntryModuleRoute = { | ||
pathname: string; | ||
exact?: boolean; | ||
props?: object; | ||
supportCaseData?: SupportCaseData; | ||
permissions?: ChromePermissions; | ||
}; | ||
|
||
export type ChromeEntryModule = { | ||
id: string; | ||
module: string; | ||
routes: ChromeEntryModuleRoute[]; | ||
}; | ||
|
||
type ChromeModuleAnalytics = { | ||
APIKey: string; | ||
}; | ||
|
||
export type ChromeModule = { | ||
manifestLocation: string; | ||
defaultDocumentTitle?: string; | ||
/** | ||
* @deprecated | ||
* use `moduleConfig` instead | ||
*/ | ||
config?: object; | ||
moduleConfig?: ChromeGlobalModuleConfig; | ||
modules?: ChromeEntryModule[]; | ||
/** | ||
* @deprecated | ||
* Use feo generated resources to get permitted modules | ||
*/ | ||
isFedramp?: boolean; | ||
analytics?: ChromeModuleAnalytics; | ||
}; | ||
|
||
export type ChromeModuleRegistry = { | ||
[moduleName: string]: ChromeModule; | ||
}; | ||
|
||
export type ChromeStaticSearchEntry = { | ||
frontendRef: string; | ||
id: string; | ||
href: string; | ||
title: string; | ||
description: string; | ||
alt_title?: string[]; | ||
isExternal?: boolean; | ||
}; | ||
|
||
export type SegmentRef = { | ||
segmentId: string; | ||
frontendName: string; | ||
}; | ||
|
||
export type DirectNavItem = { | ||
id?: string; | ||
frontendRef?: string; | ||
href?: string; | ||
title?: string; | ||
expandable?: boolean; | ||
// should be removed | ||
appId?: string; | ||
routes?: DirectNavItem[]; | ||
navItems?: DirectNavItem[]; | ||
bundleSegmentRef?: string; | ||
segmentRef?: SegmentRef; | ||
segmentId?: string; | ||
}; | ||
|
||
export type Nav = { | ||
title?: string; | ||
id: string; | ||
navItems: DirectNavItem[]; | ||
}; | ||
|
||
export type BundleSegment = { | ||
segmentId: string; | ||
bundleId: string; | ||
position: number; | ||
navItems: DirectNavItem[]; | ||
}; | ||
|
||
export type ServiceTile = { | ||
section: string; | ||
group: string; | ||
id: string; | ||
frontendRef: string; | ||
}; | ||
|
||
export type ServiceGroup = { | ||
id: string; | ||
tiles: ServiceTile[]; | ||
}; | ||
|
||
export type ServiceCategory = { | ||
id: string; | ||
groups: ServiceGroup[]; | ||
}; | ||
|
||
export type ChromeWidgetEntry = { | ||
scope: string; | ||
module: string; | ||
frontendRef: string; | ||
}; | ||
|
||
export type CRDObject = { | ||
metadata: { | ||
name: string; | ||
}; | ||
spec: { | ||
bundleSegments?: BundleSegment[]; | ||
navigationSegments?: DirectNavItem[]; | ||
module: ChromeModule; | ||
searchEntries?: ChromeStaticSearchEntry[]; | ||
serviceTiles?: ServiceTile[]; | ||
widgetRegistry?: ChromeWidgetEntry[]; | ||
}; | ||
}; | ||
|
||
export type FrontendCRD = { | ||
objects: CRDObject[]; | ||
}; |
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,61 @@ | ||
import { ChromeModule, ChromeModuleRegistry, FrontendCRD } from './feo-types'; | ||
import moduleInterceptor from './module-interceptor'; | ||
|
||
describe('module-interceptor', () => { | ||
it('should replace existing entry in moduleRegistry with new entry', () => { | ||
const moduleName = 'module-name'; | ||
const newEntry: ChromeModule = { | ||
manifestLocation: 'new-location', | ||
}; | ||
const frontendCRD: FrontendCRD = { | ||
objects: [ | ||
{ | ||
metadata: { | ||
name: moduleName, | ||
}, | ||
spec: { | ||
module: newEntry, | ||
}, | ||
}, | ||
], | ||
}; | ||
const remoteModuleRegistry: ChromeModuleRegistry = { | ||
[moduleName]: { | ||
manifestLocation: 'old-location', | ||
}, | ||
}; | ||
const expectedResult: ChromeModuleRegistry = { | ||
[moduleName]: newEntry, | ||
}; | ||
|
||
const result = moduleInterceptor(remoteModuleRegistry, frontendCRD); | ||
expect(result).toEqual(expectedResult); | ||
}); | ||
|
||
it('should add new entry to moduleRegistry', () => { | ||
const moduleName = 'module-name'; | ||
const newEntry: ChromeModule = { | ||
manifestLocation: 'new-location', | ||
}; | ||
const frontendCRD: FrontendCRD = { | ||
objects: [ | ||
{ | ||
metadata: { | ||
name: moduleName, | ||
}, | ||
spec: { | ||
module: newEntry, | ||
}, | ||
}, | ||
], | ||
}; | ||
const remoteModuleRegistry: ChromeModuleRegistry = {}; | ||
|
||
const expectedResult: ChromeModuleRegistry = { | ||
[moduleName]: newEntry, | ||
}; | ||
|
||
const result = moduleInterceptor(remoteModuleRegistry, frontendCRD); | ||
expect(result).toEqual(expectedResult); | ||
}); | ||
}); |
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,11 @@ | ||
import { ChromeModuleRegistry, FrontendCRD } from './feo-types'; | ||
|
||
function moduleInterceptor(moduleRegistry: ChromeModuleRegistry, frontendCRD: FrontendCRD): ChromeModuleRegistry { | ||
const moduleName = frontendCRD.objects[0].metadata.name; | ||
return { | ||
...moduleRegistry, | ||
[moduleName]: frontendCRD.objects[0].spec.module, | ||
}; | ||
} | ||
|
||
export default moduleInterceptor; |
Oops, something went wrong.