Skip to content

Commit

Permalink
Don't automatically update form from text, instead wait for enter etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpoole committed Jul 25, 2021
1 parent 49eaac6 commit b9cb53d
Show file tree
Hide file tree
Showing 4 changed files with 204 additions and 169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,23 @@

package ch.poole.openinghoursfragment;

import static org.junit.Assert.assertNotNull;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.rule.ActivityTestRule;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.UiObject;
import androidx.test.uiautomator.UiObjectNotFoundException;
import androidx.test.uiautomator.UiSelector;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

@RunWith(AndroidJUnit4.class)
@LargeTest
Expand Down Expand Up @@ -186,7 +184,8 @@ public void addYearRange() {
TestUtils.clickOverflowButton();
Assert.assertTrue(TestUtils.clickText(device, false, "Delete", true));
TestUtils.clickOverflowButton();
Assert.assertTrue(TestUtils.clickText(device, false, "Add year range", true));
Assert.assertTrue(TestUtils.clickText(device, false, fragment.getString(R.string.spd_ohf_year_range_menu), true));
Assert.assertTrue(TestUtils.clickTextExact(device, false, fragment.getString(R.string.add_year_range), true));
UiSelector uiSelector = new UiSelector().description("More options").instance(1);
UiObject overflowButton = device.findObject(uiSelector);
try {
Expand Down Expand Up @@ -284,8 +283,9 @@ public void addTimeRange4() {
public void addTimeRange5() {
deleteTimeBars();
clickAddTimeSpan();
TestUtils.scrollTo("Variable time-open end");
Assert.assertTrue(TestUtils.clickText(device, false, "Variable time-open end", true));
String text = fragment.getString(R.string.variable_time_open_end);
TestUtils.scrollTo(text);
Assert.assertTrue(TestUtils.clickText(device, false, text, true));
Assert.assertTrue(TestUtils.clickText(device, false, "Save", true));
Assert.assertEquals("Mo-Fr dawn+; Sa 09:00-17:00; PH closed", mActivityRule.getActivity().getResult());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ public class TestActivity extends AppCompatActivity implements OnSaveListener {

@Override
public void save(String key, String openingHours) {
System.out.println("save got " + openingHours + " for key " + key);
result = openingHours;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public static boolean clickText(UiDevice device, boolean clickable, String text,
return false;
}
}

/**
* Click a text on screen (exact)
*
Expand Down Expand Up @@ -354,19 +354,19 @@ public static void doubleClick(@NonNull UiDevice device, @NonNull UiObject2 obje
object.click();
cc.setActionAcknowledgmentTimeout(defaultAckTimeout);
}

/**
* Scroll to a specific text
*
* @param text the text
* @throws UiObjectNotFoundException if the UiScrollable couldn't be found
*/
public static void scrollTo(@NonNull String text) {
UiScrollable appView = new UiScrollable(new UiSelector().scrollable(true));
UiScrollable scrollable = new UiScrollable(new UiSelector().scrollable(true));
try {
appView.scrollIntoView(new UiSelector().textStartsWith(text));
scrollable.scrollIntoView(new UiSelector().textStartsWith(text));
} catch (UiObjectNotFoundException e) {
Assert.fail(text + " not found");
// Assert.fail(text + " not found"); seems to fail if text already in view ....
}
}
}
Loading

0 comments on commit b9cb53d

Please sign in to comment.