Skip to content

Commit 9a7a615

Browse files
committed
Implemented MC code conflict dialog.
1 parent 22a7527 commit 9a7a615

File tree

13 files changed

+761
-6
lines changed

13 files changed

+761
-6
lines changed
Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
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+
existingFile,
87+
newFile,
88+
UserAccountManagerImpl
89+
.fromContext(targetContext)
90+
.user
91+
)
92+
dialog.showDialog(sut)
93+
94+
sut.listener = OnConflictDecisionMadeListener { decision: Decision? ->
95+
Assert.assertEquals(decision, Decision.KEEP_LOCAL)
96+
returnCode = true
97+
}
98+
99+
InstrumentationRegistry.getInstrumentation().waitForIdleSync()
100+
101+
Espresso.onView(ViewMatchers.withId(R.id.replace_btn)).perform(ViewActions.click())
102+
103+
TestCase.assertTrue(returnCode)
104+
}
105+
106+
@Test
107+
fun keepBothFiles() {
108+
returnCode = false
109+
110+
val newUpload = OCUpload(
111+
FileStorageUtils.getSavePath(user.accountName) + "/nonEmpty.txt",
112+
"/newFile.txt",
113+
user.accountName
114+
)
115+
116+
val existingFile = OCFile("/newFile.txt")
117+
existingFile.fileLength = 1024000
118+
existingFile.modificationTimestamp = 1582019340
119+
120+
val newFile = OCFile("/newFile.txt")
121+
newFile.fileLength = 56000
122+
newFile.modificationTimestamp = 1522019340
123+
newFile.storagePath = FileStorageUtils.getSavePath(user.accountName) + "/nonEmpty.txt"
124+
125+
val storageManager = FileDataStorageManager(user, targetContext.contentResolver)
126+
storageManager.saveNewFile(existingFile)
127+
128+
val intent = Intent(targetContext, ConflictsResolveActivity::class.java)
129+
intent.putExtra(FileActivity.EXTRA_FILE, newFile)
130+
intent.putExtra(ConflictsResolveActivity.EXTRA_EXISTING_FILE, existingFile)
131+
intent.putExtra(FileActivity.EXTRA_USER, user)
132+
intent.putExtra(ConflictsResolveActivity.EXTRA_CONFLICT_UPLOAD_ID, newUpload.uploadId)
133+
intent.putExtra(ConflictsResolveActivity.EXTRA_LAUNCHED_FROM_TEST, true)
134+
135+
val sut = activityRule.launchActivity(intent)
136+
137+
val dialog = newInstance(
138+
existingFile,
139+
newFile,
140+
UserAccountManagerImpl
141+
.fromContext(targetContext)
142+
.user
143+
)
144+
dialog.showDialog(sut)
145+
146+
sut.listener = OnConflictDecisionMadeListener { decision: Decision? ->
147+
Assert.assertEquals(decision, Decision.KEEP_BOTH)
148+
returnCode = true
149+
}
150+
151+
InstrumentationRegistry.getInstrumentation().waitForIdleSync()
152+
153+
Espresso.onView(ViewMatchers.withId(R.id.keep_both_btn)).perform(ViewActions.click())
154+
155+
TestCase.assertTrue(returnCode)
156+
}
157+
158+
@Test
159+
fun keepExistingFile() {
160+
returnCode = false
161+
162+
val newUpload = OCUpload(
163+
FileStorageUtils.getSavePath(user.accountName) + "/nonEmpty.txt",
164+
"/newFile.txt",
165+
user.accountName
166+
)
167+
168+
val existingFile = OCFile("/newFile.txt")
169+
existingFile.fileLength = 1024000
170+
existingFile.modificationTimestamp = 1582019340
171+
172+
val newFile = OCFile("/newFile.txt")
173+
newFile.fileLength = 56000
174+
newFile.modificationTimestamp = 1522019340
175+
newFile.storagePath = FileStorageUtils.getSavePath(user.accountName) + "/nonEmpty.txt"
176+
177+
val storageManager = FileDataStorageManager(user, targetContext.contentResolver)
178+
storageManager.saveNewFile(existingFile)
179+
180+
val intent = Intent(targetContext, ConflictsResolveActivity::class.java)
181+
intent.putExtra(FileActivity.EXTRA_FILE, newFile)
182+
intent.putExtra(ConflictsResolveActivity.EXTRA_EXISTING_FILE, existingFile)
183+
intent.putExtra(FileActivity.EXTRA_USER, user)
184+
intent.putExtra(ConflictsResolveActivity.EXTRA_CONFLICT_UPLOAD_ID, newUpload.uploadId)
185+
intent.putExtra(ConflictsResolveActivity.EXTRA_LAUNCHED_FROM_TEST, true)
186+
187+
val sut = activityRule.launchActivity(intent)
188+
189+
val dialog = newInstance(
190+
existingFile,
191+
newFile,
192+
UserAccountManagerImpl
193+
.fromContext(targetContext)
194+
.user
195+
)
196+
dialog.showDialog(sut)
197+
198+
sut.listener = OnConflictDecisionMadeListener { decision: Decision? ->
199+
Assert.assertEquals(decision, Decision.KEEP_SERVER)
200+
returnCode = true
201+
}
202+
203+
InstrumentationRegistry.getInstrumentation().waitForIdleSync()
204+
205+
Espresso.onView(ViewMatchers.withId(R.id.cancel_keep_existing_btn)).perform(ViewActions.click())
206+
207+
TestCase.assertTrue(returnCode)
208+
}
209+
210+
@After
211+
override fun after() {
212+
storageManager.deleteAllFiles()
213+
}
214+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.nextcloud.ui.SetStatusDialogFragment;
3030
import com.nextcloud.ui.composeActivity.ComposeActivity;
3131
import com.nextcloud.ui.fileactions.FileActionsBottomSheet;
32+
import com.nmc.android.ui.conflict.ConflictsResolveConsentDialog;
3233
import com.nmc.android.ui.LauncherActivity;
3334
import com.owncloud.android.MainApp;
3435
import com.owncloud.android.authentication.AuthenticatorActivity;
@@ -366,6 +367,9 @@ abstract class ComponentsModule {
366367
@ContributesAndroidInjector
367368
abstract ConflictsResolveDialog conflictsResolveDialog();
368369

370+
@ContributesAndroidInjector
371+
abstract ConflictsResolveConsentDialog conflictsResolveConsentDialog();
372+
369373
@ContributesAndroidInjector
370374
abstract CreateFolderDialogFragment createFolderDialogFragment();
371375

0 commit comments

Comments
 (0)