-
Notifications
You must be signed in to change notification settings - Fork 8
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
Basic test for lazy loading Case Lists #1513
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f61e793
Adds a test for detail with lazy loading set
shubham1g5 3f91868
BeforeAll doesn't get called for a kotlin test
shubham1g5 d749fc3
decouple Endpoint Actions test with base test class as it seems to re…
shubham1g5 d5b2028
clear up static state after test
shubham1g5 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/test/java/org/commcare/formplayer/tests/CaseListLazyLoadingTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package org.commcare.formplayer.tests | ||
|
||
import org.commcare.formplayer.application.MenuController | ||
import org.commcare.formplayer.beans.menus.BaseResponseBean | ||
import org.commcare.formplayer.beans.menus.EntityListResponse | ||
import org.commcare.formplayer.configuration.CacheConfiguration | ||
import org.commcare.formplayer.junit.* | ||
import org.commcare.formplayer.junit.Installer.Companion.getInstallReference | ||
import org.commcare.formplayer.junit.request.SessionNavigationRequest | ||
import org.commcare.formplayer.utils.TestContext | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.junit.jupiter.api.extension.RegisterExtension | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest | ||
import org.springframework.context.annotation.Import | ||
import org.springframework.test.context.ContextConfiguration | ||
import org.springframework.test.web.servlet.MockMvc | ||
|
||
@WebMvcTest | ||
@Import(MenuController::class) | ||
@ContextConfiguration(classes = [TestContext::class, CacheConfiguration::class]) | ||
@ExtendWith(InitializeStaticsExtension::class) | ||
class CaseListLazyLoadingTests { | ||
|
||
companion object { | ||
const val APP_NAME = "case_claim_with_multi_select" | ||
} | ||
|
||
@Autowired | ||
private lateinit var mockMvc: MockMvc | ||
|
||
@RegisterExtension | ||
var restoreFactoryExt = RestoreFactoryExtension.builder() | ||
.withUser("test").withDomain("test") | ||
.withRestorePath("restores/caseclaim.xml") | ||
.build() | ||
|
||
@RegisterExtension | ||
var storageExt = StorageFactoryExtension.builder() | ||
.withUser("test").withDomain("test").build() | ||
|
||
|
||
@Test | ||
fun testLazyLoadingDetail_PaginatesAsNormal() { | ||
val selections = arrayOf("5") | ||
var response = navigate(selections, EntityListResponse::class.java, 0, 2) | ||
var entitites = response.entities | ||
assertEquals(response.pageCount, 4) | ||
assertEquals(entitites.size, 2) | ||
|
||
// Ensure both sort and non sort fields are populated | ||
var singleEntity = entitites[1] | ||
assertEquals(singleEntity.data[0], "Batman Begins") | ||
assertEquals(singleEntity.data[1], "Batman Begins") | ||
assertEquals(singleEntity.groupKey, "Batman Begins") | ||
|
||
response = navigate(selections, EntityListResponse::class.java, 1, 3) | ||
entitites = response.entities | ||
assertEquals(response.pageCount, 3) | ||
assertEquals(entitites.size, 3) | ||
singleEntity = entitites[2] | ||
assertEquals(singleEntity.data[0], "Rudolph") | ||
assertEquals(singleEntity.data[1], "Rudolph") | ||
assertEquals(singleEntity.groupKey, "Rudolph") | ||
} | ||
|
||
private fun <T : BaseResponseBean> navigate( | ||
selections: Array<String>, responseClass: Class<T>, offset: Int, casesPerPage: Int | ||
): T { | ||
val installReference = getInstallReference(APP_NAME) | ||
val request = SessionNavigationRequest( | ||
mockMvc, responseClass, installReference | ||
) | ||
val bean = request.getNavigationBeanForPage(selections, offset, casesPerPage) | ||
return request.requestWithBean(bean).bean() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
changes here are not related to PR and I end up doing it under a wrong assumption, but keeping the changes since it's still a good change to make.