Refactor BaseDevice constructor

Summary: OS must always be defined.

Reviewed By: jknoxville

Differential Revision: D17204398

fbshipit-source-id: 0d84111c382af623843a41360bcb472394daf3f1
This commit is contained in:
Pascal Hartig
2019-09-09 07:03:00 -07:00
committed by Facebook Github Bot
parent dbab2d1d6d
commit 4d7e776672
7 changed files with 8 additions and 12 deletions

View File

@@ -21,9 +21,8 @@ export default class AndroidDevice extends BaseDevice {
title: string, title: string,
adb: ADBClient, adb: ADBClient,
) { ) {
super(serial, deviceType, title); super(serial, deviceType, title, 'Android');
this.adb = adb; this.adb = adb;
this.os = 'Android';
this.icon = 'icons/android.svg'; this.icon = 'icons/android.svg';
this.adb.openLogcat(this.serial).then(reader => { this.adb.openLogcat(this.serial).then(reader => {
reader.on('entry', entry => { reader.on('entry', entry => {

View File

@@ -22,8 +22,7 @@ export default class ArchivedDevice extends BaseDevice {
} else if (archivedDeviceType === 'physical') { } else if (archivedDeviceType === 'physical') {
archivedDeviceType = 'archivedPhysical'; archivedDeviceType = 'archivedPhysical';
} }
super(serial, archivedDeviceType, title); super(serial, archivedDeviceType, title, os);
this.os = os;
this.logs = logEntries; this.logs = logEntries;
} }

View File

@@ -51,10 +51,11 @@ export type DeviceExport = {
export type OS = 'iOS' | 'Android' | 'Windows' | 'MacOS'; export type OS = 'iOS' | 'Android' | 'Windows' | 'MacOS';
export default class BaseDevice { export default class BaseDevice {
constructor(serial: string, deviceType: DeviceType, title: string) { constructor(serial: string, deviceType: DeviceType, title: string, os: OS) {
this.serial = serial; this.serial = serial;
this.title = title; this.title = title;
this.deviceType = deviceType; this.deviceType = deviceType;
this.os = os;
} }
// operating system of this device // operating system of this device

View File

@@ -41,9 +41,8 @@ export default class IOSDevice extends BaseDevice {
buffer: string; buffer: string;
constructor(serial: string, deviceType: DeviceType, title: string) { constructor(serial: string, deviceType: DeviceType, title: string) {
super(serial, deviceType, title); super(serial, deviceType, title, 'iOS');
this.icon = 'icons/ios.svg'; this.icon = 'icons/ios.svg';
this.os = 'iOS';
this.buffer = ''; this.buffer = '';
this.log = this.startLogListener(); this.log = this.startLogListener();
} }

View File

@@ -9,8 +9,7 @@ import BaseDevice from './BaseDevice';
export default class MacDevice extends BaseDevice { export default class MacDevice extends BaseDevice {
constructor() { constructor() {
super('', 'physical', 'Mac'); super('', 'physical', 'Mac', 'MacOS');
this.os = 'MacOS';
} }
teardown() {} teardown() {}

View File

@@ -9,8 +9,7 @@ import BaseDevice from './BaseDevice';
export default class WindowsDevice extends BaseDevice { export default class WindowsDevice extends BaseDevice {
constructor() { constructor() {
super('', 'physical', 'Windows'); super('', 'physical', 'Windows', 'Windows');
this.os = 'Windows';
} }
teardown() {} teardown() {}

View File

@@ -20,7 +20,7 @@ test('REGISTER_DEVICE doesnt remove error', () => {
const endState = reducer(initialState, { const endState = reducer(initialState, {
type: 'REGISTER_DEVICE', type: 'REGISTER_DEVICE',
payload: new BaseDevice('serial', 'physical', 'title'), payload: new BaseDevice('serial', 'physical', 'title', 'Android'),
}); });
expect(endState.error).toEqual('something went wrong'); expect(endState.error).toEqual('something went wrong');