Skip to content
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

Merged
merged 10 commits into from
Jul 15, 2019

Conversation

davigonz
Copy link
Contributor

@davigonz davigonz commented Jul 8, 2019

Implements #2556

Bugs and improvements

  • (1) Loading dialog stuck when trying to create an already existing private share [FIXED]

@davigonz davigonz changed the base branch from master to new_arch/shares July 8, 2019 13:19
@davigonz davigonz force-pushed the new_arch/private_shares_edit_remove branch from 43249ba to a5e728f Compare July 9, 2019 14:34
@davigonz davigonz force-pushed the new_arch/private_shares_edit_remove branch from f59a586 to 21302cc Compare July 10, 2019 08:12
@davigonz davigonz changed the title [New arch] Private shares: edition and deletion [WIP] [New arch] Private shares: edition and deletion Jul 10, 2019
@@ -236,8 +261,12 @@ class OCLocalDataSourceTest {
assertEquals(8, updatedShareId)
}

/**************************************************************************************************************
*************************************************** COMMON ***************************************************
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Common to what?

Copy link
Contributor Author

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)
Copy link
Contributor

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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'?

Copy link
Contributor Author

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()
Copy link
Contributor

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.

Copy link
Contributor Author

@davigonz davigonz Jul 12, 2019

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

Copy link
Contributor

@davivel davivel Jul 15, 2019

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(
Copy link
Contributor

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.

Copy link
Contributor Author

@davigonz davigonz Jul 12, 2019

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants