-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Modularization and refactors in adb-actions class
- Added tests for listed devices
- Loading branch information
1 parent
0bb05c1
commit fc3f131
Showing
7 changed files
with
102 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,31 @@ | ||
import { ADBInterface, ADBResultState, ADBResult } from './../adb-actions' | ||
import { ConsoleInterfaceMock } from '../console-interface/console-interface-mock' | ||
// import { ConsoleInterface } from './../console-interface/console-interface' | ||
|
||
// Mocked ConsoleInterface | ||
const cimock = new ConsoleInterfaceMock() | ||
const adbInterfaceInstance = new ADBInterface(cimock) | ||
|
||
test('Test ADB Server has killed', async () => { | ||
cimock.setConsoleOutput('') | ||
let result = await adbInterfaceInstance.KillADBServer() | ||
|
||
test('Kill ADB Server', async () => { | ||
let result = await ADBInterface.KillADBServer() | ||
let expected = await new ADBResult( | ||
ADBResultState.Success, | ||
'ADB Server killed' | ||
) | ||
expect(result).toStrictEqual(expected) | ||
|
||
expect(JSON.stringify(result)).toBe(JSON.stringify(expected)) | ||
}) | ||
|
||
test('Test ADB Listed Devices', async () => { | ||
const str = `* daemon not running; starting now at tcp:5037 | ||
* daemon started successfully | ||
List of devices attached | ||
` | ||
cimock.setConsoleOutput(str) | ||
let result = await adbInterfaceInstance.GetConnectedDevices() | ||
|
||
expect(typeof result).toStrictEqual(typeof Array()) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export default { | ||
/** | ||
* Kills ADB Server needing some command to restart | ||
*/ | ||
ADB_KILL_SERVER: 'adb kill-server', | ||
/** | ||
* Shows an list of devices attached to adb and restart adb server if it as killed before | ||
*/ | ||
ADB_DEVICES: 'adb devices' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
import { execSync } from 'child_process' | ||
import { IConsoleInterface } from './iconsole-interface' | ||
|
||
export class ConsoleInterface implements IConsoleInterface { | ||
_output: Buffer | ||
export class ConsoleInterfaceMock implements IConsoleInterface { | ||
private _output: Buffer | ||
|
||
setConsoleOutput(output: string): void { | ||
this._output = Buffer.from(output, 'utf8') | ||
setConsoleOutput(value: string): void { | ||
if (value) { | ||
this._output = Buffer.from(value, 'utf8') | ||
} else { | ||
this._output = Buffer.from('', 'utf8') | ||
} | ||
} | ||
|
||
sendConsoleSync(command: string): Buffer { | ||
execConsoleSync(command: string): Buffer { | ||
return this._output | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export interface IConsoleInterface { | ||
sendConsoleSync(command: string): Buffer | ||
execConsoleSync(command: string): Buffer | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters