-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[New arch] Private shares: edition and deletion #2603
[New arch] Private shares: edition and deletion #2603
Conversation
43249ba
to
a5e728f
Compare
f59a586
to
21302cc
Compare
@@ -236,8 +261,12 @@ class OCLocalDataSourceTest { | |||
assertEquals(8, updatedShareId) | |||
} | |||
|
|||
/************************************************************************************************************** | |||
*************************************************** COMMON *************************************************** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Common to what?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
fun deletePrivateShare() { | ||
ocShareDao.insert(createDefaultPrivateShare()) | ||
|
||
ocShareDao.deleteShare(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar here, how do we know that the Share created by 'createDefaultPrivarteShare' is the one with id '1'?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
`when`(ocShareViewModel.getPrivateShares(file.remotePath)).thenReturn(privateSharesLiveData) | ||
`when`(ocShareViewModel.getPublicShares(file.remotePath)).thenReturn(MutableLiveData()) | ||
|
||
stopKoin() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would create a method with annotation @after to put 'stopKoin()' there instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I don't understand what is this for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed? Shouldn't be done inside 'replaceShares(...)' right below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
}
@@ -114,7 +112,7 @@ class ShareActivity : FileActivity(), ShareFragmentListener { | |||
setContentView(R.layout.share_activity) | |||
|
|||
// Set back button | |||
supportActionBar!!.setDisplayHomeAsUpEnabled(true) | |||
supportActionBar?.setDisplayHomeAsUpEnabled(true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if supportActionBar is null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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