From 829a2ab62072da57feca389a2bedc4773a22a7e2 Mon Sep 17 00:00:00 2001 From: simonpoole Date: Sun, 8 Sep 2024 12:55:29 +0200 Subject: [PATCH] Add test for selection upload --- .../blau/android/osm/UploadConflictTest.java | 103 +++++++++++++----- 1 file changed, 77 insertions(+), 26 deletions(-) diff --git a/src/androidTest/java/de/blau/android/osm/UploadConflictTest.java b/src/androidTest/java/de/blau/android/osm/UploadConflictTest.java index 0c8178af37..6edbd56048 100644 --- a/src/androidTest/java/de/blau/android/osm/UploadConflictTest.java +++ b/src/androidTest/java/de/blau/android/osm/UploadConflictTest.java @@ -111,7 +111,7 @@ public void teardown() { */ @Test public void versionConflictUseLocal() { - versionConflict("conflict1", new String[] { "conflictdownload1" }, false, R.string.upload_conflict_message_version); + conflict("conflict1", new String[] { "conflictdownload1" }, false, R.string.upload_conflict_message_version); assertTrue(TestUtils.clickText(device, false, main.getString(R.string.resolve), true)); assertTrue(TestUtils.clickText(device, false, main.getString(R.string.use_local_version), true)); assertTrue(TestUtils.findText(device, false, main.getString(R.string.confirm_upload_title), 5000)); @@ -119,12 +119,42 @@ public void versionConflictUseLocal() { assertEquals(7, n.getOsmVersion()); // version should now be the same as the server } + /** + * Version conflict use the local element, just uploading a selection + */ + @Test + public void versionConflictUseLocalSelection() { + loadDataAndFixtures("conflict1", new String[] { "conflictdownload1" }, false); + + UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); + + TestUtils.unlock(device); + Node n = (Node) App.getDelegator().getOsmElement(Node.NAME, 101792984L); + TestUtils.clickAtCoordinates(device, main.getMap(), n.getLon(), n.getLat()); + + assertTrue(TestUtils.findText(device, false, main.getString(R.string.actionmode_nodeselect), 1000)); + + assertTrue(TestUtils.clickOverflowButton(device)); + TestUtils.scrollTo(main.getString(R.string.menu_upload_element), false); + assertTrue(TestUtils.clickText(device, false, main.getString(R.string.menu_upload_element), true)); + + + uploadDialog(R.string.upload_conflict_message_version, device); + + assertTrue(TestUtils.clickText(device, false, main.getString(R.string.resolve), true)); + assertTrue(TestUtils.clickText(device, false, main.getString(R.string.use_local_version), true)); + assertTrue(TestUtils.findText(device, false, main.getString(R.string.confirm_upload_title), 5000)); + assertFalse(TestUtils.findText(device, false, "Kindhauserstrasse")); + n = (Node) App.getDelegator().getOsmElement(Node.NAME, 101792984L); + assertEquals(7, n.getOsmVersion()); // version should now be the same as the server + } + /** * Version conflict use the server element */ @Test public void versionConflictUseServer() { - versionConflict("conflict1", new String[] { "conflictdownload1" }, false, R.string.upload_conflict_message_version); + conflict("conflict1", new String[] { "conflictdownload1" }, false, R.string.upload_conflict_message_version); Node n = (Node) App.getDelegator().getOsmElement(Node.NAME, 101792984L); assertNotNull(n); assertEquals(6, n.getOsmVersion()); // version should now be server and not in the API @@ -151,7 +181,7 @@ public void versionConflictUseServer() { */ @Test public void severElementAlreadyDeleted() { - versionConflict("conflict2", new String[] { "410", "200" }, false, -1); + conflict("conflict2", new String[] { "410", "200" }, false, -1); try { final MockWebServer server = mockServer.server(); server.takeRequest(10L, TimeUnit.SECONDS); @@ -171,7 +201,7 @@ public void severElementAlreadyDeleted() { */ @Test public void severElementInUse() { - versionConflict("conflict3", new String[] { "way-210461100", "way-210461100-nodes", "relation-12345", "relation-12345", "empty" }, false, -1); + conflict("conflict3", new String[] { "way-210461100", "way-210461100-nodes", "relation-12345", "relation-12345", "empty" }, false, -1); Way w = App.getDelegator().getApiStorage().getWay(210461100L); assertNotNull(w); assertEquals(OsmElement.STATE_DELETED, w.getState()); @@ -191,45 +221,38 @@ public void severElementInUse() { */ @Test public void referencesMissing() { - versionConflict("conflict4", new String[] { "way-27009604", "way-27009604-nodes", "nodes-deleted" }, false, + conflict("conflict4", new String[] { "way-27009604", "way-27009604-nodes", "nodes-deleted" }, false, R.string.upload_conflict_message_missing_references); Way w = App.getDelegator().getApiStorage().getWay(27009604L); assertTrue(TestUtils.clickText(device, false, main.getString(R.string.cancel), true)); } /** - * Upload to changes (mock-)server and wait for version conflict dialog + * Upload to changes (mock-)server and wait for conflict dialog * * @param conflictReponse the response * @param fixtures name of additional fixtures with the response to the upload * @param userDetails if true enqueue user details - * @param waitForDialog wait for the conflict dialog if true + * @param titleRes title to expect */ - private void versionConflict(@NonNull String conflictReponse, @NonNull String[] fixtures, boolean userDetails, int titleRes) { - final CountDownLatch signal = new CountDownLatch(1); - Logic logic = App.getLogic(); - - ClassLoader loader = Thread.currentThread().getContextClassLoader(); - InputStream is = loader.getResourceAsStream("test1.osm"); - logic.readOsmFile(main, is, false, new SignalHandler(signal)); - SignalUtils.signalAwait(signal, TIMEOUT); - - mockServer.enqueue("capabilities1"); // for whatever reason this gets asked for twice - mockServer.enqueue("capabilities1"); - mockServer.enqueue("changeset1"); - mockServer.enqueue(conflictReponse); - if (userDetails) { - mockServer.enqueue("userdetails"); - } - for (String fixture : fixtures) { - mockServer.enqueue(fixture); - } + private void conflict(@NonNull String conflictReponse, @NonNull String[] fixtures, boolean userDetails, int titleRes) { + loadDataAndFixtures(conflictReponse, fixtures, userDetails); TestUtils.clickMenuButton(device, main.getString(R.string.menu_transfer), false, true); UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); TestUtils.clickText(device, false, main.getString(R.string.menu_transfer_upload), true, false); // menu item + uploadDialog(titleRes, device); + } + + /** + * FIllout comment and source fields and upload + * + * @param titleRes title to expect + * @param device UiDevice + */ + private void uploadDialog(int titleRes, UiDevice device) { UiSelector uiSelector = new UiSelector().className("android.widget.Button").instance(1); // dialog upload button UiObject button = device.findObject(uiSelector); try { @@ -248,6 +271,34 @@ private void versionConflict(@NonNull String conflictReponse, @NonNull String[] } } + /** + * Load the data and fixtures + * + * @param conflictReponse the response + * @param fixtures name of additional fixtures with the response to the upload + * @param userDetails if true enqueue user details + */ + private void loadDataAndFixtures(String conflictReponse, String[] fixtures, boolean userDetails) { + final CountDownLatch signal = new CountDownLatch(1); + Logic logic = App.getLogic(); + + ClassLoader loader = Thread.currentThread().getContextClassLoader(); + InputStream is = loader.getResourceAsStream("test1.osm"); + logic.readOsmFile(main, is, false, new SignalHandler(signal)); + SignalUtils.signalAwait(signal, TIMEOUT); + + mockServer.enqueue("capabilities1"); // for whatever reason this gets asked for twice + mockServer.enqueue("capabilities1"); + mockServer.enqueue("changeset1"); + mockServer.enqueue(conflictReponse); + if (userDetails) { + mockServer.enqueue("userdetails"); + } + for (String fixture : fixtures) { + mockServer.enqueue(fixture); + } + } + /** * Fill our comment and source fields *