test(device-utils): add unit tests for pickByDeviceModel

This commit is contained in:
Jan Komarek
2024-07-02 19:24:46 +02:00
committed by Jan Komárek
parent 340a39d1a7
commit cc6a036954
3 changed files with 42 additions and 1 deletions

View File

@@ -8,7 +8,8 @@
"scripts": {
"lint:js": "yarn g:eslint '**/*.{ts,tsx,js}'",
"depcheck": "yarn g:depcheck",
"type-check": "yarn g:tsc --build"
"type-check": "yarn g:tsc --build",
"test:unit": "yarn g:jest -c ../../jest.config.base.js"
},
"dependencies": {
"@trezor/connect": "workspace:*"

View File

@@ -0,0 +1,30 @@
import { DeviceModelInternal } from '@trezor/connect';
export const OPTIONS = {
default: 'default',
[DeviceModelInternal.T1B1]: null,
[DeviceModelInternal.T3T1]: 'T3T1',
};
export const fixtures = [
{
description: 'should return correct value for a given device',
deviceModelInternal: DeviceModelInternal.T3T1,
expectedResult: 'T3T1',
},
{
description: 'should return null when the value for the picked device is null',
deviceModelInternal: DeviceModelInternal.T1B1,
expectedResult: null,
},
{
description: 'should return default when deviceModelInternal is undefined',
deviceModelInternal: undefined,
expectedResult: 'default',
},
{
description: 'should return default when deviceModelInternal is not among options',
deviceModelInternal: DeviceModelInternal.T2B1,
expectedResult: 'default',
},
];

View File

@@ -0,0 +1,10 @@
import { OPTIONS, fixtures } from './__fixtures__/modelUtils';
import { pickByDeviceModel } from '../src';
describe('pickByDeviceModel', () => {
fixtures.forEach(f => {
it(f.description, () => {
expect(pickByDeviceModel(f.deviceModelInternal, OPTIONS)).toBe(f.expectedResult);
});
});
});