-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add function to get relevant app titles to display as input fie…
…ld (#14521)
- Loading branch information
Showing
3 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
...ubHeader/SettingsModalButton/SettingsModal/components/Tabs/AboutTab/types/ServiceNames.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,3 @@ | ||
export type ServiceNames = { | ||
[key: string]: string | undefined; | ||
}; |
76 changes: 76 additions & 0 deletions
76
...ngsModalButton/SettingsModal/components/Tabs/AboutTab/utils/getAppTitlesToDisplay.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,76 @@ | ||
import type { KeyValuePairs } from 'app-shared/types/KeyValuePairs'; | ||
import { getAppTitlesToDisplay } from './getAppTitlesToDisplay'; | ||
import type { ServiceNames } from '../types/ServiceNames'; | ||
|
||
const nb: string = 'nb'; | ||
const nn: string = 'nn'; | ||
const en: string = 'en'; | ||
const se: string = 'se'; | ||
const da: string = 'da'; | ||
|
||
describe('getAppTitlesToDisplay', () => { | ||
it('returns empty recommended app titles if appMetadataTitles and appLangCodes are empty', () => { | ||
const appMetadataTitles: KeyValuePairs<string> = {}; | ||
const appLangCodesData: string[] = []; | ||
const appTitles: ServiceNames = getAppTitlesToDisplay(appMetadataTitles, appLangCodesData); | ||
expect(appTitles).toEqual({ nb: undefined, nn: undefined, en: undefined }); | ||
}); | ||
|
||
it('returns empty recommended app titles if appMetadataTitles is empty and appLangCodes contains them', () => { | ||
const appMetadataTitles: KeyValuePairs<string> = {}; | ||
const appLangCodesData: string[] = [nb, nn, en]; | ||
const appTitles: ServiceNames = getAppTitlesToDisplay(appMetadataTitles, appLangCodesData); | ||
expect(appTitles).toEqual({ nb: undefined, nn: undefined, en: undefined }); | ||
}); | ||
|
||
it('returns the recommended app titles with values if present in appMetadataTitles', () => { | ||
const appNameNb: string = 'appNameNb'; | ||
const appMetadataTitles: KeyValuePairs<string> = { nb: appNameNb }; | ||
const appLangCodesData: string[] = []; | ||
const appTitles: ServiceNames = getAppTitlesToDisplay(appMetadataTitles, appLangCodesData); | ||
expect(appTitles).toEqual({ nb: appNameNb, nn: undefined, en: undefined }); | ||
}); | ||
|
||
it('returns the recommended app titles with values if present in appMetadataTitles and if languages are present in appLangCodesData', () => { | ||
const appNameNb: string = 'appNameNb'; | ||
const appMetadataTitles: KeyValuePairs<string> = { nb: appNameNb }; | ||
const appLangCodesData: string[] = [nb, nn, en]; | ||
const appTitles: ServiceNames = getAppTitlesToDisplay(appMetadataTitles, appLangCodesData); | ||
expect(appTitles).toEqual({ nb: appNameNb, nn: undefined, en: undefined }); | ||
}); | ||
|
||
it('returns additional empty app titles if languages are present in appLangCodesData', () => { | ||
const appMetadataTitles: KeyValuePairs<string> = {}; | ||
const appLangCodesData: string[] = [se, da]; | ||
const appTitles: ServiceNames = getAppTitlesToDisplay(appMetadataTitles, appLangCodesData); | ||
expect(appTitles).toEqual({ | ||
nb: undefined, | ||
nn: undefined, | ||
en: undefined, | ||
se: undefined, | ||
da: undefined, | ||
}); | ||
}); | ||
|
||
it('returns additional app titles with values if languages are present in appLangCodesData and appMetadataTitles', () => { | ||
const appNameSe: string = 'appNameSe'; | ||
const appMetadataTitles: KeyValuePairs<string> = { se: appNameSe }; | ||
const appLangCodesData: string[] = [se, da]; | ||
const appTitles: ServiceNames = getAppTitlesToDisplay(appMetadataTitles, appLangCodesData); | ||
expect(appTitles).toEqual({ | ||
nb: undefined, | ||
nn: undefined, | ||
en: undefined, | ||
se: appNameSe, | ||
da: undefined, | ||
}); | ||
}); | ||
|
||
it('return additional app title for language if language is not recommended and not in appLangCodes, but in appMetadataTitles', () => { | ||
const appNameSe: string = 'appNameSe'; | ||
const appMetadataTitles: KeyValuePairs<string> = { se: appNameSe }; | ||
const appLangCodesData: string[] = []; | ||
const appTitles: ServiceNames = getAppTitlesToDisplay(appMetadataTitles, appLangCodesData); | ||
expect(appTitles).toEqual({ nb: undefined, nn: undefined, en: undefined, se: appNameSe }); | ||
}); | ||
}); |
16 changes: 16 additions & 0 deletions
16
...SettingsModalButton/SettingsModal/components/Tabs/AboutTab/utils/getAppTitlesToDisplay.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,16 @@ | ||
import type { ServiceNames } from '../types/ServiceNames'; | ||
import { ArrayUtils } from '@studio/pure-functions'; | ||
|
||
export const recommendedLanguages: string[] = ['nb', 'nn', 'en']; | ||
|
||
export const getAppTitlesToDisplay = ( | ||
appMetadataTitles: ServiceNames, | ||
appLangCodesData: string[], | ||
): ServiceNames => { | ||
const appLangCodesIncludingRecommended: string[] = ArrayUtils.removeDuplicates( | ||
recommendedLanguages.concat(Object.keys(appMetadataTitles)).concat(appLangCodesData), | ||
); | ||
return Object.fromEntries( | ||
appLangCodesIncludingRecommended.map((lang) => [lang, appMetadataTitles[lang]]), | ||
); | ||
}; |