Skip to content

Commit

Permalink
add clearing of input
Browse files Browse the repository at this point in the history
  • Loading branch information
hannojg committed Oct 27, 2023
1 parent 602bdbd commit 8152008
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 11 deletions.
13 changes: 9 additions & 4 deletions src/libs/E2E/tests/reportTypingTest.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ const test = () => {

// Wait until keyboard is visible (so we are focused on the input):
waitForKeyboard().then(() => {
resetRerenderCount();
console.debug(`[E2E] Keyboard visible, typing…`);
E2EClient.sendNativeCommand(NativeCommands.makeTypeTextCommand('A'))
E2EClient.sendNativeCommand(NativeCommands.makeBackspaceCommand())
.then(() => {
resetRerenderCount();
return Promise.resolve();
})
.then(() => E2EClient.sendNativeCommand(NativeCommands.makeTypeTextCommand('A')))
.then(() => {
setTimeout(() => {
const rerenderCount = getRerenderCount();
Expand All @@ -43,8 +47,9 @@ const test = () => {
}).then(E2EClient.submitTestDone);
}, 3000);
})
.catch(() => {
// TODO: error handling
.catch((error) => {
console.error('[E2E] Error while test', error);
E2EClient.submitTestDone();
});
});
});
Expand Down
6 changes: 6 additions & 0 deletions tests/e2e/nativeCommands/NativeCommandsAction.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const NativeCommandsAction = {
scroll: 'scroll',
type: 'type',
backspace: 'backspace',
};

const makeTypeTextCommand = (text) => ({
Expand All @@ -10,7 +11,12 @@ const makeTypeTextCommand = (text) => ({
},
});

const makeBackspaceCommand = () => ({
actionName: NativeCommandsAction.backspace,
});

module.exports = {
NativeCommandsAction,
makeTypeTextCommand,
makeBackspaceCommand,
};
10 changes: 10 additions & 0 deletions tests/e2e/nativeCommands/adbBackspace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const execAsync = require('../utils/execAsync');
const Logger = require('../utils/logger');

const adbBackspace = async () => {
Logger.log(`🔙 Pressing backspace`);
execAsync(`adb shell input keyevent KEYCODE_DEL`);
return true;
};

module.exports = adbBackspace;
3 changes: 3 additions & 0 deletions tests/e2e/nativeCommands/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const adbBackspace = require('./adbBackspace');
const adbTypeText = require('./adbTypeText');
const {NativeCommandsAction} = require('./NativeCommandsAction');

Expand All @@ -7,6 +8,8 @@ const executeFromPayload = (actionName, payload) => {
throw new Error('Not implemented yet');
case NativeCommandsAction.type:
return adbTypeText(payload.text);
case NativeCommandsAction.backspace:
return adbBackspace();
default:
throw new Error(`Unknown action: ${actionName}`);
}
Expand Down
20 changes: 13 additions & 7 deletions tests/e2e/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,21 @@ const createServerInstance = () => {
}

case Routes.testNativeCommand: {
getPostJSONRequestData(req, res).then((data) =>
executeFromPayload(data.actionName, data.payload).then((status) => {
if (status) {
return res.end('ok');
}
getPostJSONRequestData(req, res)
.then((data) =>
executeFromPayload(data.actionName, data.payload).then((status) => {
if (status) {
return res.end('ok');
}
res.statusCode = 500;
res.end('Error executing command');
}),
)
.catch((error) => {
Logger.error('Error executing command', error);
res.statusCode = 500;
res.end('Error executing command');
}),
);
});
break;
}

Expand Down

0 comments on commit 8152008

Please sign in to comment.