Skip to content

Commit b89bf2f

Browse files
committed
Implemented MC code conflict dialog.
1 parent 8f42be4 commit b89bf2f

File tree

13 files changed

+844
-8
lines changed

13 files changed

+844
-8
lines changed
Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
/*
2+
*
3+
* Nextcloud Android client application
4+
*
5+
* @author Tobias Kaminsky
6+
* Copyright (C) 2020 Tobias Kaminsky
7+
* Copyright (C) 2020 Nextcloud GmbH
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as published by
11+
* the Free Software Foundation, either version 3 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
21+
*/
22+
package com.nmc.android.ui.conflict
23+
24+
import android.content.Intent
25+
import androidx.test.espresso.Espresso
26+
import androidx.test.espresso.action.ViewActions
27+
import androidx.test.espresso.intent.rule.IntentsTestRule
28+
import androidx.test.espresso.matcher.ViewMatchers
29+
import androidx.test.platform.app.InstrumentationRegistry
30+
import com.nextcloud.client.account.UserAccountManagerImpl
31+
import com.nmc.android.ui.conflict.ConflictsResolveConsentDialog.Companion.newInstance
32+
import com.owncloud.android.AbstractIT
33+
import com.owncloud.android.R
34+
import com.owncloud.android.datamodel.FileDataStorageManager
35+
import com.owncloud.android.datamodel.OCFile
36+
import com.owncloud.android.db.OCUpload
37+
import com.owncloud.android.ui.activity.ConflictsResolveActivity
38+
import com.owncloud.android.ui.activity.FileActivity
39+
import com.owncloud.android.ui.dialog.ConflictsResolveDialog.Decision
40+
import com.owncloud.android.ui.dialog.ConflictsResolveDialog.OnConflictDecisionMadeListener
41+
import com.owncloud.android.utils.FileStorageUtils
42+
import junit.framework.TestCase
43+
import org.junit.After
44+
import org.junit.Assert
45+
import org.junit.Rule
46+
import org.junit.Test
47+
48+
class ConflictsResolveConsentDialogIT : AbstractIT() {
49+
@get:Rule
50+
val activityRule = IntentsTestRule(ConflictsResolveActivity::class.java, true, false)
51+
52+
private var returnCode = false
53+
54+
@Test
55+
fun replaceWithNewFile() {
56+
returnCode = false
57+
58+
val newUpload = OCUpload(
59+
FileStorageUtils.getSavePath(user.accountName) + "/nonEmpty.txt",
60+
"/newFile.txt",
61+
user.accountName
62+
)
63+
64+
val existingFile = OCFile("/newFile.txt")
65+
existingFile.fileLength = 1024000
66+
existingFile.modificationTimestamp = 1582019340
67+
existingFile.remoteId = "00000123abc"
68+
69+
val newFile = OCFile("/newFile.txt")
70+
newFile.fileLength = 56000
71+
newFile.modificationTimestamp = 1522019340
72+
newFile.storagePath = FileStorageUtils.getSavePath(user.accountName) + "/nonEmpty.txt"
73+
74+
val storageManager = FileDataStorageManager(user, targetContext.contentResolver)
75+
storageManager.saveNewFile(existingFile)
76+
77+
val intent = Intent(targetContext, ConflictsResolveActivity::class.java)
78+
intent.putExtra(FileActivity.EXTRA_FILE, newFile)
79+
intent.putExtra(ConflictsResolveActivity.EXTRA_EXISTING_FILE, existingFile)
80+
intent.putExtra(ConflictsResolveActivity.EXTRA_CONFLICT_UPLOAD_ID, newUpload.uploadId)
81+
intent.putExtra(ConflictsResolveActivity.EXTRA_LAUNCHED_FROM_TEST, true)
82+
83+
val sut = activityRule.launchActivity(intent)
84+
85+
val dialog = newInstance(
86+
targetContext,
87+
existingFile,
88+
newFile,
89+
UserAccountManagerImpl
90+
.fromContext(targetContext)
91+
.user
92+
)
93+
dialog.showDialog(sut)
94+
95+
sut.listener = OnConflictDecisionMadeListener { decision: Decision? ->
96+
Assert.assertEquals(decision, Decision.KEEP_LOCAL)
97+
returnCode = true
98+
}
99+
100+
InstrumentationRegistry.getInstrumentation().waitForIdleSync()
101+
102+
Espresso.onView(ViewMatchers.withId(R.id.replace_btn)).perform(ViewActions.click())
103+
104+
TestCase.assertTrue(returnCode)
105+
}
106+
107+
@Test
108+
fun keepBothFiles() {
109+
returnCode = false
110+
111+
val newUpload = OCUpload(
112+
FileStorageUtils.getSavePath(user.accountName) + "/nonEmpty.txt",
113+
"/newFile.txt",
114+
user.accountName
115+
)
116+
117+
val existingFile = OCFile("/newFile.txt")
118+
existingFile.fileLength = 1024000
119+
existingFile.modificationTimestamp = 1582019340
120+
121+
val newFile = OCFile("/newFile.txt")
122+
newFile.fileLength = 56000
123+
newFile.modificationTimestamp = 1522019340
124+
newFile.storagePath = FileStorageUtils.getSavePath(user.accountName) + "/nonEmpty.txt"
125+
126+
val storageManager = FileDataStorageManager(user, targetContext.contentResolver)
127+
storageManager.saveNewFile(existingFile)
128+
129+
val intent = Intent(targetContext, ConflictsResolveActivity::class.java)
130+
intent.putExtra(FileActivity.EXTRA_FILE, newFile)
131+
intent.putExtra(ConflictsResolveActivity.EXTRA_EXISTING_FILE, existingFile)
132+
intent.putExtra(FileActivity.EXTRA_USER, user)
133+
intent.putExtra(ConflictsResolveActivity.EXTRA_CONFLICT_UPLOAD_ID, newUpload.uploadId)
134+
intent.putExtra(ConflictsResolveActivity.EXTRA_LAUNCHED_FROM_TEST, true)
135+
136+
val sut = activityRule.launchActivity(intent)
137+
138+
val dialog = newInstance(
139+
targetContext,
140+
existingFile,
141+
newFile,
142+
UserAccountManagerImpl
143+
.fromContext(targetContext)
144+
.user
145+
)
146+
dialog.showDialog(sut)
147+
148+
sut.listener = OnConflictDecisionMadeListener { decision: Decision? ->
149+
Assert.assertEquals(decision, Decision.KEEP_BOTH)
150+
returnCode = true
151+
}
152+
153+
InstrumentationRegistry.getInstrumentation().waitForIdleSync()
154+
155+
Espresso.onView(ViewMatchers.withId(R.id.keep_both_btn)).perform(ViewActions.click())
156+
157+
TestCase.assertTrue(returnCode)
158+
}
159+
160+
@Test
161+
fun keepExistingFile() {
162+
returnCode = false
163+
164+
val newUpload = OCUpload(
165+
FileStorageUtils.getSavePath(user.accountName) + "/nonEmpty.txt",
166+
"/newFile.txt",
167+
user.accountName
168+
)
169+
170+
val existingFile = OCFile("/newFile.txt")
171+
existingFile.fileLength = 1024000
172+
existingFile.modificationTimestamp = 1582019340
173+
174+
val newFile = OCFile("/newFile.txt")
175+
newFile.fileLength = 56000
176+
newFile.modificationTimestamp = 1522019340
177+
newFile.storagePath = FileStorageUtils.getSavePath(user.accountName) + "/nonEmpty.txt"
178+
179+
val storageManager = FileDataStorageManager(user, targetContext.contentResolver)
180+
storageManager.saveNewFile(existingFile)
181+
182+
val intent = Intent(targetContext, ConflictsResolveActivity::class.java)
183+
intent.putExtra(FileActivity.EXTRA_FILE, newFile)
184+
intent.putExtra(ConflictsResolveActivity.EXTRA_EXISTING_FILE, existingFile)
185+
intent.putExtra(FileActivity.EXTRA_USER, user)
186+
intent.putExtra(ConflictsResolveActivity.EXTRA_CONFLICT_UPLOAD_ID, newUpload.uploadId)
187+
intent.putExtra(ConflictsResolveActivity.EXTRA_LAUNCHED_FROM_TEST, true)
188+
189+
val sut = activityRule.launchActivity(intent)
190+
191+
val dialog = newInstance(
192+
targetContext,
193+
existingFile,
194+
newFile,
195+
UserAccountManagerImpl
196+
.fromContext(targetContext)
197+
.user
198+
)
199+
dialog.showDialog(sut)
200+
201+
sut.listener = OnConflictDecisionMadeListener { decision: Decision? ->
202+
Assert.assertEquals(decision, Decision.KEEP_SERVER)
203+
returnCode = true
204+
}
205+
206+
InstrumentationRegistry.getInstrumentation().waitForIdleSync()
207+
208+
Espresso.onView(ViewMatchers.withId(R.id.cancel_keep_existing_btn)).perform(ViewActions.click())
209+
210+
TestCase.assertTrue(returnCode)
211+
}
212+
213+
@After
214+
override fun after() {
215+
storageManager.deleteAllFiles()
216+
}
217+
}

app/src/main/java/com/nextcloud/client/di/ComponentsModule.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.nextcloud.ui.SetStatusDialogFragment;
3131
import com.nextcloud.ui.composeActivity.ComposeActivity;
3232
import com.nextcloud.ui.fileactions.FileActionsBottomSheet;
33+
import com.nmc.android.ui.conflict.ConflictsResolveConsentDialog;
3334
import com.nmc.android.ui.LauncherActivity;
3435
import com.owncloud.android.MainApp;
3536
import com.owncloud.android.authentication.AuthenticatorActivity;
@@ -371,6 +372,9 @@ abstract class ComponentsModule {
371372
@ContributesAndroidInjector
372373
abstract ConflictsResolveDialog conflictsResolveDialog();
373374

375+
@ContributesAndroidInjector
376+
abstract ConflictsResolveConsentDialog conflictsResolveConsentDialog();
377+
374378
@ContributesAndroidInjector
375379
abstract CreateFolderDialogFragment createFolderDialogFragment();
376380

0 commit comments

Comments
 (0)