Device tests simplified

pull/395/head
Vladimir Volek 5 years ago
parent 4a39276693
commit f8f6609f3f

@ -1,67 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`device utils get status 1`] = `"disconnected"`;
exports[`device utils get status 2`] = `"unavailable"`;
exports[`device utils get status 3`] = `"unavailable"`;
exports[`device utils get status 4`] = `"connected"`;
exports[`device utils get status 5`] = `"unacquired"`;
exports[`device utils get status 6`] = `"used-in-other-window"`;
exports[`device utils get status color 1`] = `"#494949"`;
exports[`device utils get status color 2`] = `"#494949"`;
exports[`device utils get status color 3`] = `"#494949"`;
exports[`device utils get status color 4`] = `"#EB8A00"`;
exports[`device utils get status color 5`] = `"#01B757"`;
exports[`device utils get status color 6`] = `"#EB8A00"`;
exports[`device utils get status color 7`] = `"#ED1212"`;
exports[`device utils get status color 8`] = `"#ED1212"`;
exports[`device utils get status name 1`] = `"Status unknown"`;
exports[`device utils get status name 2`] = `"Status unknown"`;
exports[`device utils get status name 3`] = `"Status unknown"`;
exports[`device utils get status name 4`] = `"Used in other window"`;
exports[`device utils get status name 5`] = `"Connected"`;
exports[`device utils get status name 6`] = `"Used in other window"`;
exports[`device utils get status name 7`] = `"Disconnected"`;
exports[`device utils get status name 8`] = `"Unavailable"`;
exports[`device utils get version 1`] = `"One"`;
exports[`device utils get version 2`] = `"One"`;
exports[`device utils get version 3`] = `"One"`;
exports[`device utils get version 4`] = `"One"`;
exports[`device utils get version 5`] = `"One"`;
exports[`device utils get version 6`] = `"T"`;
exports[`device utils isDisabled 1`] = `false`;
exports[`device utils isDisabled 2`] = `true`;
exports[`device utils isWebUSB 1`] = `true`;
exports[`device utils isWebUSB 2`] = `false`;
exports[`device utils isWebUSB 3`] = `true`;

@ -1,112 +1,87 @@
import * as dUtils from 'utils/device'; import * as utils from 'utils/device';
describe('device utils', () => { describe('device utils', () => {
it('get status', () => { it('get status', () => {
const deviceMock = [ expect(utils.getStatus({ connected: false }))
{ .toBe('disconnected');
connected: false,
}, expect(utils.getStatus({ connected: true, available: false }))
{ .toBe('unavailable');
connected: true,
available: false, expect(utils.getStatus({
}, connected: true,
{ available: false,
connected: true, type: null,
available: false, })).toBe('unavailable');
type: null,
},
{
connected: true,
available: true,
type: 'acquired',
},
{
connected: true,
available: true,
type: 'unacquired',
},
{
connected: true,
available: true,
type: 'acquired',
status: 'occupied',
},
];
deviceMock.forEach((device) => { expect(utils.getStatus({
expect(dUtils.getStatus(device)).toMatchSnapshot(); connected: true,
}); available: true,
type: 'acquired',
})).toBe('connected');
expect(utils.getStatus({
connected: true,
available: true,
type: 'unacquired',
})).toBe('unacquired');
expect(utils.getStatus({
connected: true,
available: true,
type: 'acquired',
status: 'occupied',
})).toBe('used-in-other-window');
}); });
it('isWebUSB', () => { it('isWebUSB', () => {
const data = [ expect(utils.isWebUSB({ type: 'webusb', version: '1.6.0' })).toBe(true);
{ transport: { type: 'webusb', version: '1.6.0' } }, expect(utils.isWebUSB({ type: 'aaaa', version: 'aaaaaa' })).toBe(false);
{ transport: { type: null, version: 'aaaaaa' } }, expect(utils.isWebUSB({ type: 'webusb' })).toBe(true);
{ transport: { type: 'webusb' } },
];
data.forEach((item) => {
expect(dUtils.isWebUSB(item.transport)).toMatchSnapshot();
});
}); });
it('isDisabled', () => { it('isDisabled', () => {
const data = [ expect(utils.isDisabled(
{ selectedDevice: { features: null }, devices: [1, 2, 3], transport: { version: 'webusb' } }, { selectedDevice: { features: null } },
{ selectedDevice: { features: null }, devices: [], transport: { version: 'test' } }, [1, 2, 3],
]; {
version: 'webusb',
},
)).toBe(false);
data.forEach((item) => { expect(utils.isDisabled(
expect(dUtils.isDisabled(item.selectedDevice, item.devices, item.transport)).toMatchSnapshot(); { features: null }, [], { version: 'test' },
}); )).toBe(true);
}); });
it('get version', () => { it('get version', () => {
const deviceMock = [ expect(utils.getVersion({})).toBe('One');
{ }, expect(utils.getVersion({ features: {} })).toBe('One');
{ features: {} }, expect(utils.getVersion({ features: { major_version: null } })).toBe('One');
{ features: { major_version: null } }, expect(utils.getVersion({ features: { major_version: 0 } })).toBe('One');
{ features: { major_version: 0 } }, expect(utils.getVersion({ features: { major_version: 1 } })).toBe('One');
{ features: { major_version: 1 } }, expect(utils.getVersion({ features: { major_version: 2 } })).toBe('T');
{ features: { major_version: 2 } },
];
deviceMock.forEach((device) => {
expect(dUtils.getVersion(device)).toMatchSnapshot();
});
}); });
it('get status color', () => { it('get status color', () => {
const entry = [ expect(utils.getStatusColor(0)).toBe('#494949');
0, expect(utils.getStatusColor(null)).toBe('#494949');
null, expect(utils.getStatusColor('sdsdsdsd')).toBe('#494949');
'sdsdsdsd', expect(utils.getStatusColor('used-in-other-window')).toBe('#EB8A00');
'used-in-other-window', expect(utils.getStatusColor('connected')).toBe('#01B757');
'connected', expect(utils.getStatusColor('unacquired')).toBe('#EB8A00');
'unacquired', expect(utils.getStatusColor('disconnected')).toBe('#ED1212');
'disconnected', expect(utils.getStatusColor('unavailable')).toBe('#ED1212');
'unavailable',
];
entry.forEach((status) => {
expect(dUtils.getStatusColor(status)).toMatchSnapshot();
});
}); });
it('get status name', () => { it('get status name', () => {
const entry = [ expect(utils.getStatusName(0)).toBe('Status unknown');
0, expect(utils.getStatusName(null)).toBe('Status unknown');
null, expect(utils.getStatusName('sdsdsdsd')).toBe('Status unknown');
'sdsdsdsd', expect(utils.getStatusName('used-in-other-window')).toBe('Used in other window');
'used-in-other-window', expect(utils.getStatusName('connected')).toBe('Connected');
'connected', expect(utils.getStatusName('unacquired')).toBe('Used in other window');
'unacquired', expect(utils.getStatusName('disconnected')).toBe('Disconnected');
'disconnected', expect(utils.getStatusName('unavailable')).toBe('Unavailable');
'unavailable',
];
entry.forEach((status) => {
expect(dUtils.getStatusName(status)).toMatchSnapshot();
});
}); });
}); });
Loading…
Cancel
Save