Commit 5ce8c5e8 authored by Jean-Baptiste Nizet's avatar Jean-Baptiste Nizet
Browse files

fix: fix template error when germplasm collector is null

also fix the error page, which was used veen for template errors and thus embedded the error page inside the partially rendered requested page. A custom error page is now only used for 4xx and 5xx errors.

fix #85
parent cea7d291
<!DOCTYPE html>
<html
xmlns:th="http://www.thymeleaf.org"
th:replace="~{layout/main :: layout(title=~{::title}, content=~{::main}, script=~{})}"
>
<head>
<title>Error</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<main>
<h1 class="display-1" th:text="${status}">404</h1>
<p class="lead">Unexpected error: <span th:text="${error}">.</span></p>
</main>
</body>
</html>
......@@ -347,49 +347,51 @@
</div>
</th:block>
<div
th:replace="fragments/row::text-row(label='Material type', text=${model.germplasm.collector.materialType})"
></div>
<div
th:replace="fragments/row::text-row(label='Collectors', text=${model.germplasm.collector.collectors})"
></div>
<th:block
th:if="${!#strings.isEmpty(model.germplasm.acquisitionDate) && model.germplasm.collector.accessionCreationDate == null}"
>
<th:block th:if="${model.germplasm.collector != null}">
<div
th:replace="fragments/row::text-row(label='Acquisition / Creation date', text=${model.germplasm.acquisitionDate})"
th:replace="fragments/row::text-row(label='Material type', text=${model.germplasm.collector.materialType})"
></div>
<div
th:replace="fragments/row::text-row(label='Collectors', text=${model.germplasm.collector.collectors})"
></div>
</th:block>
<th:block
th:if="${model.germplasm.collector.institute != null && !#strings.isEmpty(model.germplasm.collector.institute.instituteName)}"
>
<template id="collector-institute-popover">
<th:block
th:if="${!#strings.isEmpty(model.germplasm.acquisitionDate) && model.germplasm.collector.accessionCreationDate == null}"
>
<div
th:replace="fragments/institute::institute(institute=${model.germplasm.collector.institute})"
th:replace="fragments/row::text-row(label='Acquisition / Creation date', text=${model.germplasm.acquisitionDate})"
></div>
</template>
<div
th:replace="fragments/row::row(label='Institution', content=~{::#collecting-institution})"
</th:block>
<th:block
th:if="${model.germplasm.collector.institute != null && !#strings.isEmpty(model.germplasm.collector.institute.instituteName)}"
>
<a
id="collecting-institution"
role="button"
tabindex="0"
data-bs-toggle="popover"
th:data-bs-title="${model.germplasm.collector.institute.instituteName}"
data-bs-element="#collector-institute-popover"
data-bs-container="body"
data-bs-trigger="focus"
th:text="${model.germplasm.collector.institute.instituteName}"
></a>
</div>
</th:block>
<template id="collector-institute-popover">
<div
th:replace="fragments/institute::institute(institute=${model.germplasm.collector.institute})"
></div>
</template>
<div
th:replace="fragments/row::row(label='Institution', content=~{::#collecting-institution})"
>
<a
id="collecting-institution"
role="button"
tabindex="0"
data-bs-toggle="popover"
th:data-bs-title="${model.germplasm.collector.institute.instituteName}"
data-bs-element="#collector-institute-popover"
data-bs-container="body"
data-bs-trigger="focus"
th:text="${model.germplasm.collector.institute.instituteName}"
></a>
</div>
</th:block>
<div
th:replace="fragments/row::text-row(label='Accession number', text=${model.germplasm.collector.accessionNumber})"
></div>
<div
th:replace="fragments/row::text-row(label='Accession number', text=${model.germplasm.collector.accessionNumber})"
></div>
</th:block>
</div>
</div>
......@@ -441,9 +443,7 @@
<div class="f-card-body">
<div class="scroll-table-container">
<table
class="
table table-sm table-striped table-sticky table-responsive-sm
"
class="table table-sm table-striped table-sticky table-responsive-sm"
>
<thead>
<tr>
......@@ -494,9 +494,7 @@
<div class="f-card-body">
<div class="scroll-table-container">
<table
class="
table table-sm table-striped table-sticky table-responsive-sm
"
class="table table-sm table-striped table-sticky table-responsive-sm"
>
<thead>
<tr>
......
......@@ -109,6 +109,29 @@ public class GermplasmControllerTest {
.andExpect(htmlContent().endsCorrectly());
}
@Test
void shouldDisplayGermplasmWithNullCollector() throws Exception {
germplasm.setCollector(null);
mockMvc.perform(get("/germplasms/{id}", germplasm.getGermplasmDbId()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.TEXT_HTML))
.andExpect(htmlContent().hasTitle("Germplasm: BLE BARBU DU ROUSSILLON"))
.andExpect(htmlContent().containsH2s("Identification",
"Depositary",
"Collector",
"Breeder",
"Donors",
"Distributors",
"Evaluation Data",
"Genealogy",
"Population",
"Collection",
"Panel",
"Cross references"))
.andExpect(htmlContent().endsCorrectly());
}
@Test
void shouldDisplayGermplasmWithIdAsParameter() throws Exception {
mockMvc.perform(get("/germplasms").param("id", germplasm.getGermplasmDbId()))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment