mirror of
https://github.com/trezor/trezor-suite.git
synced 2026-03-09 08:48:15 +01:00
test(device-utils): add unit tests for pickByDeviceModel
This commit is contained in:
@@ -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:*"
|
||||
|
||||
30
packages/device-utils/tests/__fixtures__/modelUtils.ts
Normal file
30
packages/device-utils/tests/__fixtures__/modelUtils.ts
Normal 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',
|
||||
},
|
||||
];
|
||||
10
packages/device-utils/tests/modelUtils.test.ts
Normal file
10
packages/device-utils/tests/modelUtils.test.ts
Normal 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);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user