Use named args for ArchivedDevice constructor

Summary: The constructor is getting quite a few args now, so to avoid string, string mistakes I'm making sure you pass objects with named params.

Reviewed By: passy, mweststrate

Differential Revision: D20034012

fbshipit-source-id: 4e0d23eeaa9100c6c19d3e36fee62649659ad261
This commit is contained in:
John Knox
2020-02-24 19:41:33 -08:00
committed by Facebook Github Bot
parent 609ca27eae
commit b3a6bf3dba
5 changed files with 176 additions and 171 deletions

View File

@@ -83,14 +83,14 @@ export default class AndroidDevice extends BaseDevice {
} }
archive(): ArchivedDevice { archive(): ArchivedDevice {
return new ArchivedDevice( return new ArchivedDevice({
this.serial, serial: this.serial,
this.deviceType, deviceType: this.deviceType,
this.title, title: this.title,
this.os, os: this.os,
[...this.logEntries], logEntries: [...this.logEntries],
null, screenshotHandle: null,
); });
} }
navigateToLocation(location: string) { navigateToLocation(location: string) {

View File

@@ -22,21 +22,26 @@ function normalizeArchivedDeviceType(deviceType: DeviceType): DeviceType {
} }
export default class ArchivedDevice extends BaseDevice { export default class ArchivedDevice extends BaseDevice {
constructor( constructor(options: {
serial: string, serial: string;
deviceType: DeviceType, deviceType: DeviceType;
title: string, title: string;
os: OS, os: OS;
logEntries: Array<DeviceLogEntry>, logEntries: Array<DeviceLogEntry>;
screenshotHandle: string | null, screenshotHandle: string | null;
source: string = '', source?: string;
supportRequestDetails?: SupportFormRequestDetailsState, supportRequestDetails?: SupportFormRequestDetailsState;
) { }) {
super(serial, normalizeArchivedDeviceType(deviceType), title, os); super(
this.logs = logEntries; options.serial,
this.source = source; normalizeArchivedDeviceType(options.deviceType),
this.supportRequestDetails = supportRequestDetails; options.title,
this.archivedScreenshotHandle = screenshotHandle; options.os,
);
this.logs = options.logEntries;
this.source = options.source || '';
this.supportRequestDetails = options.supportRequestDetails;
this.archivedScreenshotHandle = options.screenshotHandle;
} }
logs: Array<DeviceLogEntry>; logs: Array<DeviceLogEntry>;

View File

@@ -200,13 +200,13 @@ export default class MetroDevice extends BaseDevice {
} }
archive() { archive() {
return new ArchivedDevice( return new ArchivedDevice({
this.serial, serial: this.serial,
this.deviceType, deviceType: this.deviceType,
this.title, title: this.title,
this.os, os: this.os,
[...this.logEntries], logEntries: [...this.logEntries],
null, screenshotHandle: null,
); });
} }
} }

View File

@@ -71,14 +71,14 @@ function generateClientFromDevice(
} }
test('test generateClientIndentifierWithSalt helper function', () => { test('test generateClientIndentifierWithSalt helper function', () => {
const device = new ArchivedDevice( const device = new ArchivedDevice({
'serial', serial: 'serial',
'emulator', deviceType: 'emulator',
'TestiPhone', title: 'TestiPhone',
'iOS', os: 'iOS',
[], logEntries: [],
null, screenshotHandle: null,
); });
const identifier = generateClientIdentifier(device, 'app'); const identifier = generateClientIdentifier(device, 'app');
const saltIdentifier = generateClientIdentifierWithSalt(identifier, 'salt'); const saltIdentifier = generateClientIdentifierWithSalt(identifier, 'salt');
expect(saltIdentifier).toEqual('app#iOS#archivedEmulator#salt-serial'); expect(saltIdentifier).toEqual('app#iOS#archivedEmulator#salt-serial');
@@ -86,14 +86,14 @@ test('test generateClientIndentifierWithSalt helper function', () => {
}); });
test('test generateClientFromClientWithSalt helper function', () => { test('test generateClientFromClientWithSalt helper function', () => {
const device = new ArchivedDevice( const device = new ArchivedDevice({
'serial', serial: 'serial',
'emulator', deviceType: 'emulator',
'TestiPhone', title: 'TestiPhone',
'iOS', os: 'iOS',
[], logEntries: [],
null, screenshotHandle: null,
); });
const client = generateClientFromDevice(device, 'app'); const client = generateClientFromDevice(device, 'app');
const saltedClient = generateClientFromClientWithSalt(client, 'salt'); const saltedClient = generateClientFromClientWithSalt(client, 'salt');
expect(saltedClient).toEqual({ expect(saltedClient).toEqual({
@@ -117,14 +117,14 @@ test('test generateClientFromClientWithSalt helper function', () => {
}); });
test('test generateClientFromDevice helper function', () => { test('test generateClientFromDevice helper function', () => {
const device = new ArchivedDevice( const device = new ArchivedDevice({
'serial', serial: 'serial',
'emulator', deviceType: 'emulator',
'TestiPhone', title: 'TestiPhone',
'iOS', os: 'iOS',
[], logEntries: [],
null, screenshotHandle: null,
); });
const client = generateClientFromDevice(device, 'app'); const client = generateClientFromDevice(device, 'app');
expect(client).toEqual({ expect(client).toEqual({
id: 'app#iOS#archivedEmulator#serial', id: 'app#iOS#archivedEmulator#serial',
@@ -138,14 +138,14 @@ test('test generateClientFromDevice helper function', () => {
}); });
test('test generateClientIdentifier helper function', () => { test('test generateClientIdentifier helper function', () => {
const device = new ArchivedDevice( const device = new ArchivedDevice({
'serial', serial: 'serial',
'emulator', deviceType: 'emulator',
'TestiPhone', title: 'TestiPhone',
'iOS', os: 'iOS',
[], logEntries: [],
null, screenshotHandle: null,
); });
const identifier = generateClientIdentifier(device, 'app'); const identifier = generateClientIdentifier(device, 'app');
expect(identifier).toEqual('app#iOS#archivedEmulator#serial'); expect(identifier).toEqual('app#iOS#archivedEmulator#serial');
}); });
@@ -177,14 +177,14 @@ test('test processStore function for empty state', () => {
test('test processStore function for an iOS device connected', async () => { test('test processStore function for an iOS device connected', async () => {
const json = await processStore({ const json = await processStore({
activeNotifications: [], activeNotifications: [],
device: new ArchivedDevice( device: new ArchivedDevice({
'serial', serial: 'serial',
'emulator', deviceType: 'emulator',
'TestiPhone', title: 'TestiPhone',
'iOS', os: 'iOS',
[], logEntries: [],
null, screenshotHandle: null,
), }),
pluginStates: {}, pluginStates: {},
clients: [], clients: [],
devicePlugins: new Map(), devicePlugins: new Map(),
@@ -214,14 +214,14 @@ test('test processStore function for an iOS device connected', async () => {
}); });
test('test processStore function for an iOS device connected with client plugin data', async () => { test('test processStore function for an iOS device connected with client plugin data', async () => {
const device = new ArchivedDevice( const device = new ArchivedDevice({
'serial', serial: 'serial',
'emulator', deviceType: 'emulator',
'TestiPhone', title: 'TestiPhone',
'iOS', os: 'iOS',
[], logEntries: [],
null, screenshotHandle: null,
); });
const clientIdentifier = generateClientIdentifier(device, 'testapp'); const clientIdentifier = generateClientIdentifier(device, 'testapp');
const json = await processStore({ const json = await processStore({
activeNotifications: [], activeNotifications: [],
@@ -252,22 +252,22 @@ test('test processStore function for an iOS device connected with client plugin
}); });
test('test processStore function to have only the client for the selected device', async () => { test('test processStore function to have only the client for the selected device', async () => {
const selectedDevice = new ArchivedDevice( const selectedDevice = new ArchivedDevice({
'serial', serial: 'serial',
'emulator', deviceType: 'emulator',
'TestiPhone', title: 'TestiPhone',
'iOS', os: 'iOS',
[], logEntries: [],
null, screenshotHandle: null,
); });
const unselectedDevice = new ArchivedDevice( const unselectedDevice = new ArchivedDevice({
'identifier', serial: 'identifier',
'emulator', deviceType: 'emulator',
'TestiPhone', title: 'TestiPhone',
'iOS', os: 'iOS',
[], logEntries: [],
null, screenshotHandle: null,
); });
const unselectedDeviceClientIdentifier = generateClientIdentifier( const unselectedDeviceClientIdentifier = generateClientIdentifier(
unselectedDevice, unselectedDevice,
@@ -321,14 +321,14 @@ test('test processStore function to have only the client for the selected device
}); });
test('test processStore function to have multiple clients for the selected device', async () => { test('test processStore function to have multiple clients for the selected device', async () => {
const selectedDevice = new ArchivedDevice( const selectedDevice = new ArchivedDevice({
'serial', serial: 'serial',
'emulator', deviceType: 'emulator',
'TestiPhone', title: 'TestiPhone',
'iOS', os: 'iOS',
[], logEntries: [],
null, screenshotHandle: null,
); });
const clientIdentifierApp1 = generateClientIdentifier( const clientIdentifierApp1 = generateClientIdentifier(
selectedDevice, selectedDevice,
@@ -388,14 +388,14 @@ test('test processStore function to have multiple clients for the selected devic
test('test processStore function for device plugin state and no clients', async () => { test('test processStore function for device plugin state and no clients', async () => {
// Test case to verify that device plugin data is exported even if there are no clients // Test case to verify that device plugin data is exported even if there are no clients
const selectedDevice = new ArchivedDevice( const selectedDevice = new ArchivedDevice({
'serial', serial: 'serial',
'emulator', deviceType: 'emulator',
'TestiPhone', title: 'TestiPhone',
'iOS', os: 'iOS',
[], logEntries: [],
null, screenshotHandle: null,
); });
const json = await processStore({ const json = await processStore({
activeNotifications: [], activeNotifications: [],
device: selectedDevice, device: selectedDevice,
@@ -426,14 +426,14 @@ test('test processStore function for device plugin state and no clients', async
test('test processStore function for unselected device plugin state and no clients', async () => { test('test processStore function for unselected device plugin state and no clients', async () => {
// Test case to verify that device plugin data is exported even if there are no clients // Test case to verify that device plugin data is exported even if there are no clients
const selectedDevice = new ArchivedDevice( const selectedDevice = new ArchivedDevice({
'serial', serial: 'serial',
'emulator', deviceType: 'emulator',
'TestiPhone', title: 'TestiPhone',
'iOS', os: 'iOS',
[], logEntries: [],
null, screenshotHandle: null,
); });
const json = await processStore({ const json = await processStore({
activeNotifications: [], activeNotifications: [],
device: selectedDevice, device: selectedDevice,
@@ -460,14 +460,14 @@ test('test processStore function for unselected device plugin state and no clien
test('test processStore function for notifications for selected device', async () => { test('test processStore function for notifications for selected device', async () => {
// Test case to verify that device plugin data is exported even if there are no clients // Test case to verify that device plugin data is exported even if there are no clients
const selectedDevice = new ArchivedDevice( const selectedDevice = new ArchivedDevice({
'serial', serial: 'serial',
'emulator', deviceType: 'emulator',
'TestiPhone', title: 'TestiPhone',
'iOS', os: 'iOS',
[], logEntries: [],
null, screenshotHandle: null,
); });
const client = generateClientFromDevice(selectedDevice, 'testapp1'); const client = generateClientFromDevice(selectedDevice, 'testapp1');
const notification = generateNotifications( const notification = generateNotifications(
'notificationID', 'notificationID',
@@ -510,22 +510,22 @@ test('test processStore function for notifications for selected device', async (
test('test processStore function for notifications for unselected device', async () => { test('test processStore function for notifications for unselected device', async () => {
// Test case to verify that device plugin data is exported even if there are no clients // Test case to verify that device plugin data is exported even if there are no clients
const selectedDevice = new ArchivedDevice( const selectedDevice = new ArchivedDevice({
'serial', serial: 'serial',
'emulator', deviceType: 'emulator',
'TestiPhone', title: 'TestiPhone',
'iOS', os: 'iOS',
[], logEntries: [],
null, screenshotHandle: null,
); });
const unselectedDevice = new ArchivedDevice( const unselectedDevice = new ArchivedDevice({
'identifier', serial: 'identifier',
'emulator', deviceType: 'emulator',
'TestiPhone', title: 'TestiPhone',
'iOS', os: 'iOS',
[], logEntries: [],
null, screenshotHandle: null,
); });
const client = generateClientFromDevice(selectedDevice, 'testapp1'); const client = generateClientFromDevice(selectedDevice, 'testapp1');
const unselectedclient = generateClientFromDevice( const unselectedclient = generateClientFromDevice(
@@ -566,14 +566,14 @@ test('test processStore function for notifications for unselected device', async
}); });
test('test processStore function for selected plugins', async () => { test('test processStore function for selected plugins', async () => {
const selectedDevice = new ArchivedDevice( const selectedDevice = new ArchivedDevice({
'serial', serial: 'serial',
'emulator', deviceType: 'emulator',
'TestiPhone', title: 'TestiPhone',
'iOS', os: 'iOS',
[], logEntries: [],
null, screenshotHandle: null,
); });
const client = generateClientFromDevice(selectedDevice, 'app'); const client = generateClientFromDevice(selectedDevice, 'app');
const pluginstates = { const pluginstates = {
@@ -617,14 +617,14 @@ test('test processStore function for selected plugins', async () => {
}); });
test('test processStore function for no selected plugins', async () => { test('test processStore function for no selected plugins', async () => {
const selectedDevice = new ArchivedDevice( const selectedDevice = new ArchivedDevice({
'serial', serial: 'serial',
'emulator', deviceType: 'emulator',
'TestiPhone', title: 'TestiPhone',
'iOS', os: 'iOS',
[], logEntries: [],
null, screenshotHandle: null,
); });
const client = generateClientFromDevice(selectedDevice, 'app'); const client = generateClientFromDevice(selectedDevice, 'app');
const pluginstates = { const pluginstates = {
[generateClientIdentifier(selectedDevice, 'app') + '#TestDevicePlugin1']: { [generateClientIdentifier(selectedDevice, 'app') + '#TestDevicePlugin1']: {

View File

@@ -268,14 +268,14 @@ const addSaltToDeviceSerial = async (
} = options; } = options;
const {serial} = device; const {serial} = device;
const newSerial = salt + '-' + serial; const newSerial = salt + '-' + serial;
const newDevice = new ArchivedDevice( const newDevice = new ArchivedDevice({
newSerial, serial: newSerial,
device.deviceType, deviceType: device.deviceType,
device.title, title: device.title,
device.os, os: device.os,
selectedPlugins.includes('DeviceLogs') ? device.getLogs() : [], logEntries: selectedPlugins.includes('DeviceLogs') ? device.getLogs() : [],
deviceScreenshot, screenshotHandle: deviceScreenshot,
); });
statusUpdate && statusUpdate &&
statusUpdate('Adding salt to the selected device id in the client data...'); statusUpdate('Adding salt to the selected device id in the client data...');
const updatedClients = clients.map((client: ClientExport) => { const updatedClients = clients.map((client: ClientExport) => {
@@ -681,20 +681,20 @@ export function importDataToStore(source: string, data: string, store: Store) {
} }
const {serial, deviceType, title, os, logs} = device; const {serial, deviceType, title, os, logs} = device;
const archivedDevice = new ArchivedDevice( const archivedDevice = new ArchivedDevice({
serial, serial,
deviceType, deviceType,
title, title,
os, os,
logs logEntries: logs
? logs.map(l => { ? logs.map(l => {
return {...l, date: new Date(l.date)}; return {...l, date: new Date(l.date)};
}) })
: [], : [],
deviceScreenshot, screenshotHandle: deviceScreenshot,
source, source,
supportRequestDetails, supportRequestDetails,
); });
const devices = store.getState().connections.devices; const devices = store.getState().connections.devices;
const matchedDevices = devices.filter( const matchedDevices = devices.filter(
availableDevice => availableDevice.serial === serial, availableDevice => availableDevice.serial === serial,