Limit max parameters + add Espresso tests

This commit is contained in:
serso
2016-02-26 14:35:25 +01:00
parent c002e7caf9
commit ea4d107b12
11 changed files with 150 additions and 24 deletions

View File

@@ -0,0 +1,58 @@
package org.solovyev.android.calculator.plot;
import android.support.annotation.NonNull;
import android.support.test.espresso.action.ViewActions;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import android.text.TextUtils;
import org.hamcrest.Matchers;
import org.junit.Rule;
import org.junit.runner.RunWith;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.functions.CppFunction;
import org.solovyev.android.calculator.functions.FunctionParamsView;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.typeText;
import static android.support.test.espresso.action.ViewActions.typeTextIntoFocusedView;
import static android.support.test.espresso.matcher.ViewMatchers.hasFocus;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withTagValue;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;
@RunWith(AndroidJUnit4.class)
@LargeTest
public class BasePlotTest {
@Rule
public ActivityTestRule<PlotActivity> rule = new ActivityTestRule<>(PlotActivity.class);
protected void addFunction(@NonNull CppFunction function) {
openFunctionEditor();
if (!TextUtils.isEmpty(function.getName())) {
onView(withId(R.id.function_name)).perform(typeText(function.getName()));
}
for (String parameter : function.getParameters()) {
onView(withId(R.id.function_params_add)).perform(click());
onView(allOf(hasFocus(), withTagValue(Matchers.<Object>equalTo(FunctionParamsView.PARAM_VIEW_TAG)))).perform(click(), typeTextIntoFocusedView(parameter));
}
onView(withId(R.id.function_body)).perform(typeText(function.getBody()));
onView(withText(R.string.ok)).perform(click());
}
protected final void openFunctionEditor() {
onView(withId(R.id.plot_view_frame)).perform(ViewActions.click());
onView(withId(R.id.plot_add_function)).perform(click());
}
protected final void openFunctionsList() {
onView(withId(R.id.plot_view_frame)).perform(ViewActions.click());
onView(withId(R.id.plot_functions)).perform(click());
}
}

View File

@@ -0,0 +1,22 @@
package org.solovyev.android.calculator.plot;
import org.junit.Test;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.functions.CppFunction;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
public class PlotEditFunctionFragmentTest extends BasePlotTest {
@Test
public void testShouldAddFunction() throws Exception {
final CppFunction function = CppFunction.builder("", "x + y").withParameters("x", "y").build();
addFunction(function);
openFunctionsList();
onView(withId(R.id.function_name)).check(matches(withText("x+y")));
}
}