Repository navigation
[New arch] Private shares: edition and deletion - #2603
Conversation
43249ba to
a5e728f
Compare
f59a586 to
21302cc
Compare
| } | ||
|
|
||
| /************************************************************************************************************** | ||
| *************************************************** COMMON *************************************************** |
There was a problem hiding this comment.
Common to private and public shares
|
|
||
| val textShares = getValue( | ||
| ocShareDao.getSharesAsLiveData( | ||
| "/Texts/text1.txt", "admin@server", listOf(ShareType.USER.value) |
There was a problem hiding this comment.
This is a bit difficult to read. How should I know that "/Texts/text1.txt", "admin@server", etc... correspond to the fields of the share returned by 'createDefaultPrivasteShare()' ?
I would save the value of createDefaultPrivateShare() in a variable at the beginning, then use the fields of that variable here to pass file, user, etc... That way it's clear that we are getting the same share that we inserted first.
| fun deletePrivateShare() { | ||
| ocShareDao.insert(createDefaultPrivateShare()) | ||
|
|
||
| ocShareDao.deleteShare(1) |
There was a problem hiding this comment.
Similar here, how do we know that the Share created by 'createDefaultPrivarteShare' is the one with id '1'?
| `when`(ocShareViewModel.getPrivateShares(file.remotePath)).thenReturn(privateSharesLiveData) | ||
| `when`(ocShareViewModel.getPublicShares(file.remotePath)).thenReturn(MutableLiveData()) | ||
|
|
||
| stopKoin() |
There was a problem hiding this comment.
I would create a method with annotation @after to put 'stopKoin()' there instead.
There was a problem hiding this comment.
I could create it to stop Koin for the last executed test but this line would be still needed because since instrumented tests are launched on a device, the android application class is instantiated and it causes Koin initialization as a side effect. Therefore, we need to stop it here before starting koin again, otherwise I get the exception below:
org.koin.core.error.KoinAppAlreadyStartedException: A Koin Application has already been started
There was a problem hiding this comment.
You can create a full Koin tree to be used only in tests and load it in the @Begin methods with StandAloneContext.loadKoinModules so that if overrides the full app module(s), then keep the @Begin/@After symmetry.
| ) | ||
| ).perform(click()) | ||
|
|
||
| privateSharesLiveData.postValue( |
There was a problem hiding this comment.
Sorry, I don't understand what is this for.
There was a problem hiding this comment.
We are mocking the viewmodel so the operation to delete the share from localShareDataSource, which takes place in the repository, is never executed. Therefore, privateSharesLiveData is not updated after the deletion so we have to do it here manually.
I know this makes these tests to be a little "fake", so I guess we would need to use mocks in layers below, i.e. datasources, to have the whole flow. Shares will not be released without #2523 so I've just created a new task there to face this change.
| } | ||
|
|
||
| if (sharesFromServer.isEmpty()) { | ||
| localShareDataSource.deleteSharesForFile(filePath, accountName) |
There was a problem hiding this comment.
Is this needed? Shouldn't be done inside 'replaceShares(...)' right below?
There was a problem hiding this comment.
The replaceShares method in OCShareDao.kt includes the code below and its aim is replacing the still existing shares, not deleting the shares that no longer exist in the server.
@Transaction
open fun replaceShares(ocShares: List<OCShare>): List<Long> {
for (ocShare in ocShares) {
deleteSharesForFile(ocShare.path, ocShare.accountOwner)
}
return insert(ocShares)
}|
|
||
| // Set back button | ||
| supportActionBar!!.setDisplayHomeAsUpEnabled(true) | ||
| supportActionBar?.setDisplayHomeAsUpEnabled(true) |
There was a problem hiding this comment.
What happens if supportActionBar is null?
There was a problem hiding this comment.
The arrow to go back would not appear in the action bar but you could still use the back button in the Android navigation bar.
Implements #2556
Bugs and improvements