-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NAS-123538: Adding tests to helpers (#8598)
- Loading branch information
Showing
74 changed files
with
191 additions
and
228 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
export const officialCatalog = 'TRUENAS'; | ||
export const ixChartApp = 'ix-chart'; | ||
export const chartsTrain = 'charts'; | ||
export const latestVersion = 'latest'; | ||
export const appImagePlaceholder = 'assets/images/truenas_scale_ondark_favicon.png'; |
This file was deleted.
Oops, something went wrong.
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,65 @@ | ||
import { lastValueFrom, of } from 'rxjs'; | ||
import { | ||
arrayToOptions, | ||
choicesToOptions, | ||
idNameArrayToOptions, | ||
singleArrayToOptions, | ||
} from 'app/helpers/operators/options.operators'; | ||
|
||
describe('choicesToOptions', () => { | ||
it('converts key-value objects to an array of options', async () => { | ||
const choices = { | ||
key1: 'label1', | ||
key2: 'label2', | ||
}; | ||
|
||
const options = await lastValueFrom(of(choices).pipe(choicesToOptions())); | ||
|
||
expect(options).toEqual([ | ||
{ label: 'label1', value: 'key1' }, | ||
{ label: 'label2', value: 'key2' }, | ||
]); | ||
}); | ||
}); | ||
|
||
describe('arrayToOptions', () => { | ||
it('converts array of labels and values to array of options', async () => { | ||
const array = [['value1', 'label1'], ['value2', 'label2']]; | ||
|
||
const options = await lastValueFrom(of(array).pipe(arrayToOptions())); | ||
|
||
expect(options).toEqual([ | ||
{ label: 'label1', value: 'value1' }, | ||
{ label: 'label2', value: 'value2' }, | ||
]); | ||
}); | ||
}); | ||
|
||
describe('singleArrayToOptions', () => { | ||
it('converts array of strings to an array of options', async () => { | ||
const array = ['value1', 'value2']; | ||
|
||
const options = await lastValueFrom(of(array).pipe(singleArrayToOptions())); | ||
|
||
expect(options).toEqual([ | ||
{ label: 'value1', value: 'value1' }, | ||
{ label: 'value2', value: 'value2' }, | ||
]); | ||
}); | ||
}); | ||
|
||
describe('idNameArrayToOptions', () => { | ||
it('converts array of objects with id and name to an array of options', async () => { | ||
const array = [ | ||
{ id: 1, name: 'name1' }, | ||
{ id: 2, name: 'name2' }, | ||
]; | ||
|
||
const options = await lastValueFrom(of(array).pipe(idNameArrayToOptions())); | ||
|
||
expect(options).toEqual([ | ||
{ label: 'name1', value: 1 }, | ||
{ label: 'name2', value: 2 }, | ||
]); | ||
}); | ||
}); |
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,32 @@ | ||
import { OperatorFunction } from 'rxjs'; | ||
import { map } from 'rxjs/operators'; | ||
import { Choices } from 'app/interfaces/choices.interface'; | ||
import { MapOption, Option } from 'app/interfaces/option.interface'; | ||
|
||
/** | ||
* Convert choices to options | ||
* @returns Option[] | ||
*/ | ||
export function choicesToOptions(): OperatorFunction<Choices, Option[]> { | ||
return map((choices) => { | ||
return Object.entries(choices).map(([value, label]) => ({ label, value })); | ||
}); | ||
} | ||
|
||
export function arrayToOptions(): OperatorFunction<MapOption[], Option[]> { | ||
return map((choices) => { | ||
return choices.map(([value, label]) => ({ label, value })); | ||
}); | ||
} | ||
|
||
export function singleArrayToOptions(): OperatorFunction<(string | number)[], Option[]> { | ||
return map((choices) => { | ||
return choices.map((choice) => ({ label: String(choice), value: choice })); | ||
}); | ||
} | ||
|
||
export function idNameArrayToOptions(): OperatorFunction<{ id: number; name: string }[], Option[]> { | ||
return map((options) => { | ||
return options.map((option) => ({ label: option.name, value: option.id })); | ||
}); | ||
} |
File renamed without changes.
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,23 @@ | ||
import { TranslateService } from '@ngx-translate/core'; | ||
import { mapToOptions } from 'app/helpers/options.helper'; | ||
|
||
describe('mapToOptions', () => { | ||
it('converts JS Map to an array of options while invoking translation on labels', () => { | ||
const translate = { | ||
instant: jest.fn((label) => label) as TranslateService['instant'], | ||
} as TranslateService; | ||
|
||
const map = new Map([ | ||
['key1', 'label1'], | ||
['key2', 'label2'], | ||
]); | ||
|
||
const options = mapToOptions(map, translate); | ||
|
||
expect(options).toEqual([ | ||
{ label: 'label1', value: 'key1' }, | ||
{ label: 'label2', value: 'key2' }, | ||
]); | ||
expect(translate.instant).toHaveBeenCalledTimes(2); | ||
}); | ||
}); |
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
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
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
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
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
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
Oops, something went wrong.