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

Properly placed pages tests #8303

Merged
merged 12 commits into from
Sep 18, 2018
Merged

Properly placed pages tests #8303

merged 12 commits into from
Sep 18, 2018

Conversation

planarvoid
Copy link
Contributor

I'm using injected uiContext and commonPoolContext in view models in SearchListViewModel and PagesViewModel. I've separated the tests for these two to become truly unit tests. I've removed the _pageMap which was unnecessary because you can keep the value in pageMap. I've made it immutable because immutable collections are much easier to maintain and much less error-prone. I've added some test coverage but I feel like there are too many changes in this PR already so I'll add more in a separate PR.

I'm removing LiveDataUtils because it's not necessary any more since we're using synchronous liveData.setValue instead of async liveData.postValue.

To test: Go through the new Pages activity and check that everything still works as expected.

@0nko 0nko self-assigned this Sep 14, 2018
Copy link
Contributor

@0nko 0nko left a comment

Choose a reason for hiding this comment

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

There is a problem with the refactoring, please see the code comments.

Also, onPageEditFinishedReloadSite() test is throwing a NPE.

set(value) {
_pageMap = value
_pages.postValue(pageMap.values.toList())
field = value
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

@@ -194,16 +190,16 @@ class PagesViewModel
_isNewPageButtonVisible.postOnUi(isNotEmpty && currentPageType != TRASHED && _isSearchExpanded.value != true)
}

fun onSearch(searchQuery: String) {
fun onSearch(searchQuery: String, delay: Long = 200) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We could extract the number literal into a constant.

@@ -226,7 +222,7 @@ class PagesViewModel
_isSearchExpanded.value = false
clearSearch()

launch {
launch(uiContext) {
delay(500)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, this can be a constant (I know it's my code 🙃).


pageStore.uploadPageToServer(changed)
}
}
}
action.onSuccess = {
launch(CommonPool) {
launch(commonPoolContext) {
reloadPages()

delay(100)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same, constant.


checkIfNewPageButtonShouldBeVisible()

pageStore.deletePageFromServer(page)
}
}
action.onSuccess = {
launch(CommonPool) {
launch(commonPoolContext) {
delay(100)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same, constant.

pageStore.updatePageInDb(page)
refreshPages()

pageStore.uploadPageToServer(page)
}
}
action.onSuccess = {
launch(CommonPool) {
launch(commonPoolContext) {
delay(100)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same, constant.

if (page.parent?.remoteId != parentId) {
page.parent = _pageMap[parentId]
pageMap = _pageMap
Copy link
Contributor

Choose a reason for hiding this comment

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

By removing this line, the logic in the setter is not called and we lost the instant updates. We could just extract that code and call it from here explicitly.

Copy link
Contributor Author

@planarvoid planarvoid Sep 17, 2018

Choose a reason for hiding this comment

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

you're right! I missed that. I'll call the setter explicitly 👍
edit: Actually I noticed that the PageModel object is being modified directly and I don't think that's a good practice so I changed it to use the copy editing instead of setters and I'm doing the same for the pageMap

Copy link
Contributor

Choose a reason for hiding this comment

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

Perfect!

pageMap[page.remoteId]?.let { changed ->
changed.parent = _pageMap[oldParent]
pageMap = _pageMap
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, lost instant updates.

}

@Test
fun onPageEditFinishedReloadSite() = runBlocking<Unit> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you planning to add the test() function as you did in FluxC?

@0nko 0nko mentioned this pull request Sep 17, 2018
@planarvoid
Copy link
Contributor Author

@0nko Everything should be fixed now 👍

@0nko
Copy link
Contributor

0nko commented Sep 18, 2018

Looking great! :shipit:

@0nko 0nko merged commit 1d6b2d6 into develop Sep 18, 2018
@oguzkocer oguzkocer deleted the feature/pages_tests branch April 15, 2020 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants