Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test cases relate to BluetoothControl Plugin - Scan, Pair, Unpair #20

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/commonMethods/commonFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,3 +495,45 @@ export const stopWPEFramework = function() {
stopProcess('WPEFramework')
return true
}

/**
* This function is used to scan Info of Bluetooth Control Plugin
* @param type , timeout
* @returns {Promise<AxiosResponse<any>>}
*/
export const scanDevices = function(type, timeout) {
return this.$thunder.api.BluetoothControl.scan(type, timeout)
.then(result => result)
.catch(err => err)
}
/**
* This function is used to get available Bluetooth devices
* @returns {Promise<AxiosResponse<any>>}
*/
export const getBluetoothDevices = function() {
return this.$thunder.api.BluetoothControl.devices()
.then(result => result)
.catch(err => err)
}

/**
* This function is used to pair with the available Bluetooth devices
* @param address
* @returns {Promise<AxiosResponse<any>>}
*/
export const pairBTDevice = function(address) {
return this.$thunder.api.BluetoothControl.pair(address)
.then(result => result)
.catch(err => err)
}

/**
* This function is used to disconnect with the available Bluetooth devices
* @param address
* @returns {Promise<AxiosResponse<any>>}
*/
export const unpairBTDevice = function(address) {
return this.$thunder.api.BluetoothControl.unpair(address)
.then(result => result)
.catch(err => err)
}
3 changes: 2 additions & 1 deletion src/commonMethods/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default {
monitorPlugin: 'Monitor',
controllerPlugin: 'Controller',
webKitBrowserPlugin: 'WebKitBrowser',
bluetoothControlPlugin: 'BluetoothControl',
webKitImplementation: 'WebKitImplementation',
deviceInfo: 'DeviceInfo',
youTubePlugin: 'Cobalt',
Expand All @@ -19,6 +20,7 @@ export default {
provisioningPlugin: 'Provisioning',
WPEProcess: 'WPEProcess',
remoteControlPlugin: 'RemoteControl',
invalidAddress: 'invalidstring',

//Plugin states
activate: 'activate',
Expand All @@ -29,4 +31,3 @@ export default {
blankUrl: 'about:blank',
host: config.thunder.host,
}

68 changes: 68 additions & 0 deletions src/tests/bluetoothcontrol/BluetoothControl_Pair_001.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { pairBTDevice } from '../../commonMethods/commonFunctions'

import baseTest from './BluetoothControl_Scan_001.test'

let btdevicelist
let scanCompleteListener
let deviceStateChangeListener

export default {
title: 'Bluetooth Control - Pair 001',
description: 'Check the Pair Functionality of Bluetooth Control Module',
setup() {
scanCompleteListener = this.$thunder.api.BluetoothControl.on('scancomplete', () => {
this.$data.write('scancompleted', 'scancompleted')
})
deviceStateChangeListener = this.$thunder.api.BluetoothControl.on('devicestatechange', data => {
this.$data.write('address', data.address)
this.$data.write('state', data.state)
})
},
teardown() {
scanCompleteListener.dispose()
deviceStateChangeListener.dispose()
},
steps: [
baseTest,
{
description: 'Pair with the device',
sleep: 5,
test() {
//TODO - Prompt the user to select the device that need to be paired
// and input(instead of btdevicelist[0]) that to the 'pairBTDevice'
return pairBTDevice.call(this, btdevicelist[0])
},
validate(res) {
if (res == null) {
return true
} else {
this.$log('Pairing not started')
return false
}
},
},
{
description: 'Check whether pairing is success',
sleep: 60,
test() {
//TODO - Prompt the user to press on the button in the Bluetooth Device to pair with 1 minute timeout
return new Promise((resolve, reject) => {
let attempts = 0
const interval = setInterval(() => {
attempts++
if (
this.$data.read('address') === btdevicelist[0] && //TODO - btdevicelist[0] need to be replaced with the user input given in previous step
this.$data.read('state') === 'Paired'
) {
clearInterval(interval)
resolve()
} else if (attempts > 10) {
clearInterval(interval)
reject('Pairing does not happen')
}
}, 1000)
})
},
},
],
}
36 changes: 36 additions & 0 deletions src/tests/bluetoothcontrol/BluetoothControl_Pair_002.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { pluginDeactivate, pluginActivate, pairBTDevice } from '../../commonMethods/commonFunctions'
import constants from '../../commonMethods/constants'

export default {
title: 'Bluetooth Control - Pair 002',
description: 'Check the Pair Functionality of Bluetooth Control Module with Invalid MAC',
steps: [
{
description: 'Check if Bluetooth Control Plugin is stopped correctly',
test: pluginDeactivate,
params: constants.bluetoothControlPlugin,
assert: 'deactivated',
},
{
description: 'Check if Bluetooth Control Plugin is started correctly',
test: pluginActivate,
params: constants.bluetoothControlPlugin,
assert: 'activated',
},
{
description: 'Pair with the device',
sleep: 5,
test() {
return pairBTDevice.call(this, constants.invalidAddress)
},
validate(res) {
if (res.code === 22 && res.message === 'ERROR_UNKNOWN_KEY') {
return true
} else {
this.$log('Proper error message is not shown')
return false
}
},
},
],
}
44 changes: 44 additions & 0 deletions src/tests/bluetoothcontrol/BluetoothControl_Pair_003.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { pairBTDevice } from '../../commonMethods/commonFunctions'

import baseTest from './BluetoothControl_Pair_001.test'

let btdevicelist
let scanCompleteListener
let deviceStateChangeListener

export default {
title: 'Bluetooth Control - Pair 003',
description:
'Check the Pair Functionality of Bluetooth Control Module with the device which is already paired',
setup() {
scanCompleteListener = this.$thunder.api.BluetoothControl.on('scancomplete', () => {
this.$data.write('scancompleted', 'scancompleted')
})
deviceStateChangeListener = this.$thunder.api.BluetoothControl.on('devicestatechange', data => {
this.$data.write('address', data.address)
this.$data.write('state', data.state)
})
},
teardown() {
scanCompleteListener.dispose()
deviceStateChangeListener.dispose()
},
steps: [
baseTest,
{
description: 'Pair with the device',
sleep: 5,
test() {
return pairBTDevice.call(this, btdevicelist[0]) //TODO - btdevicelist[0] need to be replaced with the user input given in previous testcase
},
validate(res) {
if (res.code === 9 && res.message === 'ERROR_ALREADY_CONNECTED') {
return true
} else {
this.$log('Proper error message is not shown')
return false
}
},
},
],
}
96 changes: 96 additions & 0 deletions src/tests/bluetoothcontrol/BluetoothControl_Scan_001.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import {
pluginDeactivate,
pluginActivate,
scanDevices,
getBluetoothDevices,
} from '../../commonMethods/commonFunctions'
import constants from '../../commonMethods/constants'

let scanCompleteListener

export default {
title: 'Bluetooth Control - Scan 001',
description: 'Check the Scan Functionality of Bluetooth Control Module for Low Energy devices',
context: {
deviceType: 'Low Energy',
timeOut: 10,
},
setup() {
scanCompleteListener = this.$thunder.api.BluetoothControl.on('scancomplete', () => {
this.$data.write('scancompleted', 'scancompleted')
})
},
teardown() {
scanCompleteListener.dispose()
},
steps: [
{
description: 'Check if Bluetooth Control Plugin is stopped correctly',
test: pluginDeactivate,
params: constants.bluetoothControlPlugin,
assert: 'deactivated',
},
{
description: 'Check if Bluetooth Control Plugin is started correctly',
test: pluginActivate,
params: constants.bluetoothControlPlugin,
assert: 'activated',
},
{
description: 'Invoke Scan',
sleep: 5,
test() {
this.$log('devicetype is ', this.$context.read('deviceType'), this.$context.read('timeOut'))
return scanDevices.call(
this,
this.$context.read('deviceType'),
this.$context.read('timeOut')
)
},
validate(res) {
if (res == null) {
return true
} else {
this.$log('Scan does not start')
return false
}
},
},
{
description: 'Check whether scanning is success',
sleep: 5,
test() {
return new Promise((resolve, reject) => {
let attempts = 0
const interval = setInterval(() => {
attempts++
if (this.$data.read('scancompleted') === 'scancompleted') {
clearInterval(interval)
resolve()
} else if (attempts > 10) {
clearInterval(interval)
reject('Scanning not completed')
}
}, 1000)
})
},
},
{
description: 'Get scan results',
sleep: 10,
test() {
return getBluetoothDevices.call(this)
},
validate(result) {
//TODO - Prompt the user with result and ask him to confirm the Low Energy devices available in the list.
// If user says yes pass the test case.
if (result === undefined || result.length === 0) {
this.$log('Result does not have device list')
return false
} else {
return true
}
},
},
],
}
49 changes: 49 additions & 0 deletions src/tests/bluetoothcontrol/BluetoothControl_Scan_002.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { pluginDeactivate, pluginActivate, scanDevices } from '../../commonMethods/commonFunctions'
import constants from '../../commonMethods/constants'

export default {
title: 'Bluetooth Control - Scan 002',
description: 'Check error message when scanning is performed while previous scan is in progress',
steps: [
{
description: 'Check if Bluetooth Control Plugin is stopped correctly',
test: pluginDeactivate,
params: constants.bluetoothControlPlugin,
assert: 'deactivated',
},
{
description: 'Check if Bluetooth Control Plugin is started correctly',
test: pluginActivate,
params: constants.bluetoothControlPlugin,
assert: 'activated',
},
{
description: 'Invoke Scan',
test() {
return scanDevices.call(this, 'LowEnergy', 10)
},
validate(res) {
if (res == null) {
return true
} else {
this.$log('Scan does not start')
return false
}
},
},
{
description: 'Invoke Scan',
test() {
return scanDevices.call(this, 'LowEnergy', 10)
},
validate(res) {
if (res.code == 12 && res.message == 'ERROR_INPROGRESS') {
return true
} else {
this.$log('Proper error message is not shown')
return false
}
},
},
],
}
17 changes: 17 additions & 0 deletions src/tests/bluetoothcontrol/BluetoothControl_Scan_003.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import baseTest from './BluetoothControl_Scan_001.test'

export default {
...baseTest,
...{
context: {
deviceType: 'Classic',
timeOut: 10,
},

title: 'Bluetooth Control - Scan 003',
description: 'Check the Scan Functionality of Bluetooth Control Module for Classic devices',
steps: baseTest.steps.map((step, index) => {
return step
}),
},
}
16 changes: 16 additions & 0 deletions src/tests/bluetoothcontrol/BluetoothControl_Scan_004.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import baseTest from './BluetoothControl_Scan_001.test'

export default {
...baseTest,
...{
context: {
deviceType: 'Low Energy',
timeOut: 20,
},
title: 'Bluetooth Control - Scan 004',
description: 'Check the Scan Functionality of Bluetooth Control Module with modified timeout',
steps: baseTest.steps.map((step, index) => {
return step
}),
},
}
Loading