Skip to content

Commit a65b3dd

Browse files
committed
test: add new tests for OCRemoteSpacesDataSourceTest and OCSpacesRepositoryTest
1 parent d549b07 commit a65b3dd

File tree

3 files changed

+98
-3
lines changed

3 files changed

+98
-3
lines changed

owncloudApp/src/main/java/com/owncloud/android/presentation/spaces/SpacesListFragment.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class SpacesListFragment :
139139
collectLatestLifecycleFlow(spacesListViewModel.spacesList) { uiState ->
140140
if (uiState.searchFilter != "") {
141141
var spacesToListFiltered =
142-
uiState.spaces.filter { it.name.lowercase().contains(uiState.searchFilter.lowercase()) && !it.isPersonal && !it.isDisabled }
142+
uiState.spaces.filter { it.name.lowercase().contains(uiState.searchFilter.lowercase()) && !it.isPersonal }
143143
val personalSpace = uiState.spaces.find { it.isPersonal }
144144
personalSpace?.let {
145145
spacesToListFiltered = spacesToListFiltered.toMutableList().apply {
@@ -150,7 +150,7 @@ class SpacesListFragment :
150150
spacesListAdapter.setData(spacesToListFiltered, isMultiPersonal)
151151
} else {
152152
showOrHideEmptyView(uiState.spaces)
153-
spacesListAdapter.setData(uiState.spaces.filter { !it.isDisabled }, isMultiPersonal)
153+
spacesListAdapter.setData(uiState.spaces, isMultiPersonal)
154154
}
155155
binding.swipeRefreshSpacesList.isRefreshing = uiState.refreshing
156156
uiState.error?.let { showErrorInSnackbar(R.string.spaces_sync_failed, it) }

owncloudData/src/test/java/com/owncloud/android/data/spaces/datasources/implementation/OCRemoteSpacesDataSourceTest.kt

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,72 @@ class OCRemoteSpacesDataSourceTest {
150150
}
151151
}
152152

153+
@Test
154+
fun `disableSpace disables a project space correctly when delete mode is false`() {
155+
val disableSpaceResult = createRemoteOperationResultMock(Unit, isSuccess = true)
156+
157+
every {
158+
ocSpaceService.disableSpace(
159+
spaceId = OC_SPACE_PROJECT_WITH_IMAGE.id,
160+
deleteMode = false
161+
)
162+
} returns disableSpaceResult
163+
164+
ocRemoteSpacesDataSource.disableSpace(
165+
accountName = OC_ACCOUNT_NAME,
166+
spaceId = OC_SPACE_PROJECT_WITH_IMAGE.id,
167+
deleteMode = false
168+
)
169+
170+
verify(exactly = 1) {
171+
clientManager.getSpacesService(OC_ACCOUNT_NAME)
172+
ocSpaceService.disableSpace(
173+
spaceId = OC_SPACE_PROJECT_WITH_IMAGE.id,
174+
deleteMode = false
175+
)
176+
}
177+
}
178+
179+
@Test
180+
fun `disableSpace deletes a project space correctly when delete mode is true`() {
181+
val disableSpaceResult = createRemoteOperationResultMock(Unit, isSuccess = true)
182+
183+
every {
184+
ocSpaceService.disableSpace(
185+
spaceId = OC_SPACE_PROJECT_WITH_IMAGE.id,
186+
deleteMode = true
187+
)
188+
} returns disableSpaceResult
189+
190+
ocRemoteSpacesDataSource.disableSpace(
191+
accountName = OC_ACCOUNT_NAME,
192+
spaceId = OC_SPACE_PROJECT_WITH_IMAGE.id,
193+
deleteMode = true
194+
)
195+
196+
verify(exactly = 1) {
197+
clientManager.getSpacesService(OC_ACCOUNT_NAME)
198+
ocSpaceService.disableSpace(
199+
spaceId = OC_SPACE_PROJECT_WITH_IMAGE.id,
200+
deleteMode = true
201+
)
202+
}
203+
}
204+
205+
@Test
206+
fun `enableSpace enables a project space correctly`() {
207+
val enableSpaceResult = createRemoteOperationResultMock(SPACE_RESPONSE, isSuccess = true)
208+
209+
every {
210+
ocSpaceService.enableSpace(OC_SPACE_PROJECT_WITH_IMAGE.id)
211+
} returns enableSpaceResult
212+
213+
ocRemoteSpacesDataSource.enableSpace(OC_ACCOUNT_NAME, OC_SPACE_PROJECT_WITH_IMAGE.id)
214+
215+
verify(exactly = 1) {
216+
clientManager.getSpacesService(OC_ACCOUNT_NAME)
217+
ocSpaceService.enableSpace(OC_SPACE_PROJECT_WITH_IMAGE.id)
218+
}
219+
}
220+
153221
}

owncloudData/src/test/java/com/owncloud/android/data/spaces/repository/OCSpacesRepositoryTest.kt

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class OCSpacesRepositoryTest {
5151

5252
private val localSpacesDataSource = mockk<LocalSpacesDataSource>(relaxUnitFun = true)
5353
private val localUserDataSource = mockk<LocalUserDataSource>(relaxUnitFun = true)
54-
private val remoteSpacesDataSource = mockk<RemoteSpacesDataSource>()
54+
private val remoteSpacesDataSource = mockk<RemoteSpacesDataSource>(relaxUnitFun = true)
5555
private val localCapabilitiesDataSource = mockk<LocalCapabilitiesDataSource>(relaxUnitFun = true)
5656
private val ocSpacesRepository = OCSpacesRepository(localSpacesDataSource, localUserDataSource, remoteSpacesDataSource,
5757
localCapabilitiesDataSource)
@@ -350,4 +350,31 @@ class OCSpacesRepositoryTest {
350350
}
351351
}
352352

353+
@Test
354+
fun `disableSpace disables a space correctly when delete mode is false`() {
355+
ocSpacesRepository.disableSpace(OC_ACCOUNT_NAME, OC_SPACE_PROJECT_WITH_IMAGE.id, false)
356+
357+
verify(exactly = 1) {
358+
remoteSpacesDataSource.disableSpace(OC_ACCOUNT_NAME, OC_SPACE_PROJECT_WITH_IMAGE.id, false)
359+
}
360+
}
361+
362+
@Test
363+
fun `disableSpace deletes a space correctly when delete mode is true`() {
364+
ocSpacesRepository.disableSpace(OC_ACCOUNT_NAME, OC_SPACE_PROJECT_WITH_IMAGE.id, true)
365+
366+
verify(exactly = 1) {
367+
remoteSpacesDataSource.disableSpace(OC_ACCOUNT_NAME, OC_SPACE_PROJECT_WITH_IMAGE.id, true)
368+
}
369+
}
370+
371+
@Test
372+
fun `enableSpace enables a space correctly`() {
373+
ocSpacesRepository.enableSpace(OC_ACCOUNT_NAME, OC_SPACE_PROJECT_WITH_IMAGE.id)
374+
375+
verify(exactly = 1) {
376+
remoteSpacesDataSource.enableSpace(OC_ACCOUNT_NAME, OC_SPACE_PROJECT_WITH_IMAGE.id)
377+
}
378+
}
379+
353380
}

0 commit comments

Comments
 (0)