Detox: typeText space in string - detox

I'm trying to enter text in TextInput field using detox. My test case looks like this:
it('should create company', async () => {
await element(by.id('addCompany')).tap();
await expect(element(by.id('companyForm'))).toBeVisible();
const companyName = element(by.id('formCompanyName'))
companyName.typeText('Test');
companyName.typeText(" ");
companyName.typeText('Company');
});
According to the Earlgrey docs: https://github.com/google/EarlGrey/blob/master/EarlGrey/Core/GREYKeyboard.m#L81 the space identifier is " ", but this doesn't seem to work? Other things such as backspace companyName.typeText("\b"); - work fine.
Is there a trick on how to show enter text with space in it? Or should I use the replaceText() function instead?

Related

VS Code API:How to insert text in the bottom of line

I started to create an extension of VS Code and am facing a problem.
As you see in the title, I want to insert the certain text in the bottom of line. To realize this, I tried this:
let moveBy = {to: 'wrappedLineEnd', by: 'line'};
vscode.commands.executeCommand('cursorMove', moveBy);
editor.edit(editBuilder =>{
if (editor !== undefined){
editBuilder.insert(editor.selection.active, "test");
}
});
However, it does not work well; it resulted in this:
//Before: this is the text.
//cursor is between 'h' and 'i'(from 'this')
//After: thtestis is the text
//Omg 'test' is inserted here
It seems to me that the cursor did not move and it ended up inserting the string there.
Is there any solution to this?
While you can await the cursorMove command, I think it is better practice to simply compute the range at the end of the line yourself. You do not have to await moving a cursor to where you want to make an edit.
You just have to know where you want to make an edit (in case you didn't know you can make an edit anywhere in the document, there doesn't need to be a cursor there already).
const editor = vscode.window.activeTextEditor;
// let moveBy = {to: 'wrappedLineEnd', by: 'line'};
// await vscode.commands.executeCommand('cursorMove', moveBy);
// get range at end of line
const editRange = editor.document.lineAt(editor.selection.end.line).range.end;
editor.edit(editBuilder =>{
if (editor !== undefined){
// editBuilder.insert(editor.selection.active, "test");
editBuilder.insert(editRange, "test");
}
});

How to Add Google Map Places "textSearch()" api in React Native

I have a tourist App, and i have made a tab i.e ATM onPress it will display List of ATM's in nearby defined Radius.
I have tried Different modules which available in NPM website, but didn't figured it out the use case for my specific result
The problem i have facing is when reading '''textSearch()''' documentation's is uses
'''google.maps.places.PlacesService(map);''' from where this .object should i import
if any relevant sources welcome
const handleSearch = async () => {
const url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?";
const fulllocation = `location=${location.latitude},${location.longitude}`;
const radius = `&radius=2000`;
const type = `&keyword=ATM`;
const key = "&key=xyz";
const restaurantSearchUrl = url + fulllocation + radius + type + key;
await fetch(restaurantSearchUrl)
.then((response) => response.json())
.then((result) => setPlaceData(result))
.catch((e) => console.log(e));
I have used placeSearch to get result - but it needed to click few times to get the result, on first click it shows empty array then on second click it shows result with "status" : "ZERO_RESULTS" then after few clicks it shows the results.
I have tried to use async/await to get result, but it gives empty array or ZERO_RESULTS. How can i fix that
Every array of object is a result after click

Flutter - how to get Text widget on widget test

I'm trying to create a simple widget test in Flutter. I have a custom widget that receives some values, composes a string and shows a Text with that string. I got to create the widget and it works, but I'm having trouble reading the value of the Text component to assert that the generated text is correct.
I created a simple test that illustrates the issue. I want to get the text value, which is "text". I tried several ways, if I get the finder asString() I could interpret the string to get the value, but I don't consider that a good solution. I wanted to read the component as a Text so that I have access to all the properties.
So, how would I read the Text widget so that I can access the data property?
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('my first widget test', (WidgetTester tester) async {
await tester
.pumpWidget(MaterialApp(home: Text("text", key: Key('unit_text'))));
// This works and prints: (Text-[<'unit_text'>]("text"))
var finder = find.byKey(Key("unit_text"));
print(finder.evaluate().first);
// This also works and prints: (Text-[<'unit_text'>]("text"))
var finderByType = find.byType(Text);
print(finderByType.evaluate().first);
// This returns empty
print(finder.first.evaluate().whereType<Text>());
// This throws: type 'StatelessElement' is not a subtype of type 'Text' in type cast
print(finder.first.evaluate().cast<Text>().first);
});
}
I got it working. I had to access the widget property of the Element, and then cast it as text:
var text = finder.evaluate().single.widget as Text;
print(text.data);
Please check this simple example.
testWidgets('Test name', (WidgetTester tester) async {
// findig the widget
var textFind = find.text("text_of_field");
// checking widget present or not
expect(textFind, findsOneWidget);
//getting Text object
Text text = tester.firstWidget(textFind);
// validating properies
expect(text.style.color, Colors.black);
...
...
}
You can use find.text
https://flutter.io/docs/cookbook/testing/widget/finders#1-find-a-text-widget
testWidgets('finds a Text Widget', (WidgetTester tester) async {
// Build an App with a Text Widget that displays the letter 'H'
await tester.pumpWidget(MaterialApp(
home: Scaffold(
body: Text('H'),
),
));
// Find a Widget that displays the letter 'H'
expect(find.text('H'), findsOneWidget);
});

Detox - Tap a button when it becomes enabled

I have a problem performing a tap() on a button when testing with Detox.
<Button style={this._loginButtonDisabled() ? {} : styles.loginButtonActive}
disabled={this._loginButtonDisabled()}
onPress={this.logInClick}
testID='logInButton'>
<Text style={styles.loginButtonText}>Log In</Text>
</Button>
Our test looks like this:
const emailInput = element(by.id('emailInput'));
await emailInput.replaceText('idontexist#myeatclub.com');
const passwordInput = element(by.id('passwordInput'));
await passwordInput.replaceText('password');
await element(by.id('logInButton')).tap();
The button is visible all the time, but becomes enabled ('tappable') only after typing in the text in the form fields. So the code above taps the button before it's enabled, resulting in no real action. What I'd like to do is wait until button is enabled, and then perform the tap.
What's the suggested way of handling this type of scenario? I couldn't find any good examples in the docs.
I think it's because you are using replaceText
Instead try using typeText
Like this:
const emailInput = element(by.id('emailInput'));
await emailInput.replaceText('idontexist#myeatclub.com');
const passwordInput = element(by.id('passwordInput'));
// \n is used to press the return key on keyboard
await passwordInput.typeText('password\n');
await element(by.id('logInButton')).tap();

react-native I do not understand the sentences

I just do not know how the code works in below, mind if any one can tell me how its working this?? I do not understand especially "=>" what does this do?
React.Children.map(this.props.children, (child) => {};
This is an arrow expression. It creates a function. There's nothing in the curly braces, so no code will execute. It's part of JavaScript, not React Native-related.
For example, you could write a function named myFunction like this:
var myFunction = (name) => {
console.log("Hello, " + name);
}
See the MDN docs for more info: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions