Fixed behaviour when no images or tags have been added.
Added test for this case.
This commit is contained in:
parent
0b1bb099df
commit
71fcbd5ef0
@ -162,7 +162,7 @@ class ImageController
|
|||||||
}
|
}
|
||||||
} ?: return "gallery"
|
} ?: return "gallery"
|
||||||
model.addAttribute("pageNumber", pageNumber)
|
model.addAttribute("pageNumber", pageNumber)
|
||||||
val commonTags: List<Tag> = tagRepository.find20TagsOnImages(images.content.map { it.id })
|
val commonTags: List<Tag> = try { tagRepository.find20TagsOnImages(images.content.map { it.id }) } catch (e: Exception) {listOf()}
|
||||||
model.addAttribute("commonTags", commonTags)
|
model.addAttribute("commonTags", commonTags)
|
||||||
model.addAttribute("imagePage", images)
|
model.addAttribute("imagePage", images)
|
||||||
return "gallery"
|
return "gallery"
|
||||||
|
@ -6,9 +6,9 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div th:replace="fragments :: navbar"></div>
|
<div th:replace="fragments :: navbar"></div>
|
||||||
<div class="container-fluid">
|
<div class="container-fluid" th:with="validPage = ${imagePage != null && !imagePage.isEmpty()}">
|
||||||
<div th:replace="fragments :: searchBarRow"></div>
|
<div th:replace="fragments :: searchBarRow"></div>
|
||||||
<div class="row mt-3" th:if="${imagePage != null}">
|
<div class="row mt-3" th:if="${validPage}">
|
||||||
<div class="col-xl-2 col-md-3 col-4">
|
<div class="col-xl-2 col-md-3 col-4">
|
||||||
<div class="list-group w-75">
|
<div class="list-group w-75">
|
||||||
<a class="list-group-item d-flex justify-content-between align-items-center text-decoration-none" th:each="tag : ${commonTags}" th:href="${#mvc.url('IC#getGalleryPage').arg(1, tag.tag).build()}">
|
<a class="list-group-item d-flex justify-content-between align-items-center text-decoration-none" th:each="tag : ${commonTags}" th:href="${#mvc.url('IC#getGalleryPage').arg(1, tag.tag).build()}">
|
||||||
@ -30,12 +30,12 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row" th:if="${imagePage == null}">
|
<div class="row" th:if="${!validPage}">
|
||||||
<div class="col text-center mt-3">
|
<div class="col text-center mt-3">
|
||||||
<p class="lead">No images found with all the specified tags.</p>
|
<p class="lead">No images found with all the specified tags.</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row justify-content-center mt-3" th:if="${imagePage != null}">
|
<div class="row justify-content-center mt-3" th:if="${validPage}">
|
||||||
<div class="col d-flex justify-content-center">
|
<div class="col d-flex justify-content-center">
|
||||||
<ul class="pagination">
|
<ul class="pagination">
|
||||||
<li class="page-item" th:classappend="${imagePage.isFirst() ? 'disabled' : ''}">
|
<li class="page-item" th:classappend="${imagePage.isFirst() ? 'disabled' : ''}">
|
||||||
|
@ -26,6 +26,9 @@ internal class ImageControllerTest {
|
|||||||
@MockBean
|
@MockBean
|
||||||
lateinit var imageRepository: ImageRepository
|
lateinit var imageRepository: ImageRepository
|
||||||
|
|
||||||
|
@MockBean
|
||||||
|
lateinit var tagRepository: TagRepository
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `get an empty gallery page`() {
|
fun `get an empty gallery page`() {
|
||||||
mockMvc.perform(MockMvcRequestBuilders.get("/gallery"))
|
mockMvc.perform(MockMvcRequestBuilders.get("/gallery"))
|
||||||
@ -75,4 +78,24 @@ internal class ImageControllerTest {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `get a gallery page but no images exist`() {
|
||||||
|
val page = PageImpl<Image>(listOf())
|
||||||
|
doReturn(page).`when`(imageRepository).findAll(Mockito.any(PageRequest::class.java))
|
||||||
|
doReturn(listOf<Tag>()).`when`(tagRepository).findAllByTagIn(Mockito.anyList())
|
||||||
|
println(listOf<Tag>().isEmpty())
|
||||||
|
mockMvc.perform(MockMvcRequestBuilders.get("/gallery"))
|
||||||
|
.andExpect(MockMvcResultMatchers.status().isOk)
|
||||||
|
.andExpect(MockMvcResultMatchers.view().name("gallery"))
|
||||||
|
.andExpect(MockMvcResultMatchers.model().attribute("imagePage", page))
|
||||||
|
.andExpect(MockMvcResultMatchers.model().attribute("pageNumber", 1))
|
||||||
|
.andExpect(
|
||||||
|
MockMvcResultMatchers.model().attribute(
|
||||||
|
"imagePage",
|
||||||
|
Matchers.hasProperty<Int>("totalPages", Matchers.equalTo(1))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.andExpect(MockMvcResultMatchers.content().string(Matchers.containsString("No images found with all the specified tags.")))
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user