Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 43 additions & 32 deletions src/main/resources/freemarker/new-study-digest.ftl
Original file line number Diff line number Diff line change
@@ -1,45 +1,56 @@
<#assign pageTitle="DUOS - New data in DUOS today!">
<#assign greetingHtml="Dear ${userName},">
<#-- Email clients require inline CSS, so the shared declarations are defined once and reused. -->
<#assign bodyTextStyle="font-family: 'Montserrat', sans-serif; font-size: 16px; color: #1F3B50; line-height: 25px;">
<#assign headerCellStyle="font-family: 'Montserrat', sans-serif; font-style: italic; font-size: 15px; color: #00609f; border-bottom: 1px solid #cccccc; padding: 5px;">
<#assign dataCellStyle="font-family: 'Montserrat', sans-serif; color: #1F3B50; border-bottom: 1px solid #cccccc; padding: 5px; vertical-align: top;">
<#assign linkStyle="text-decoration: none; font-family: 'Montserrat', sans-serif; color: #00609F; font-weight: 600;">
<#assign badgeStyle="display: inline-block; padding: 1px 10px; border: 1px solid #cde1f0; border-radius: 12px; background-color: #eaf2f9; font-family: 'Montserrat', sans-serif; font-size: 13px; line-height: 20px; color: #00609F; white-space: nowrap;">
Comment on lines +3 to +8

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not for this PR, but it would be really nice to have these as base/reusable styles in the header template.

<#include "/freemarker/header.ftl">
<tr>
<td style="padding: 15px 15px 0px; font-family: 'Montserrat', sans-serif; font-size: 16px; color: #1F3B50; text-align: justify; line-height: 25px;">
The studies below were registered in DUOS today! Click the Study link to view the study and its datasets, or go to the <a href="${serverUrl}datalibrary">DUOS Data Library</a> to view all studies.
<td style="${bodyTextStyle} padding: 15px 15px 0px; text-align: justify;">
The studies below were registered in DUOS today! Click the Study link to view the study and its datasets, or go to the <a style="${linkStyle}" href="${serverUrl}datalibrary">DUOS Data Library</a> to view all studies.
</td>
</tr>
<#if newStudies?has_content>
<tr>
<td>
<#if newStudies?has_content>
<table style="padding: 15px 15px 0px; font-family: 'Montserrat', sans-serif; font-size: 16px; color: #1F3B50; text-align: justify; line-height: 25px;">
<thead style="padding: 15px 15px 0px; font-family: 'Montserrat', sans-serif; font-size: 16px; color: #1F3B50; text-align: justify; line-height: 25px;">
<tr>
<th style="padding: 15px 15px 0px; font-family: 'Montserrat', sans-serif; font-size: 16px; color: #1F3B50; text-align: justify; line-height: 25px;">Study Name</th>
<th style="padding: 15px 15px 0px; font-family: 'Montserrat', sans-serif; font-size: 16px; color: #1F3B50; text-align: justify; line-height: 25px;">Access Type(s)</th>
<th style="padding: 15px 15px 0px; font-family: 'Montserrat', sans-serif; font-size: 16px; color: #1F3B50; text-align: justify; line-height: 25px;">Number of Datasets</th>
</tr>
</thead>
<tbody>
<#list newStudies as item>
<tr>
<td style="padding: 15px 15px 0px; font-family: 'Montserrat', sans-serif; font-size: 16px; color: #1F3B50; text-align: justify; line-height: 25px;">
<a href="${serverUrl}studies/${item.id()?c}">${item.name()}</a>
</td>
<td style="padding: 15px 15px 0px; font-family: 'Montserrat', sans-serif; font-size: 16px; color: #1F3B50; text-align: justify; line-height: 25px;">
<#list item.accessTypes()?split(",") as accessType>${accessType?trim?cap_first}<#sep>, </#list>
</td>
<td style="padding: 15px 15px 0px; font-family: 'Montserrat', sans-serif; font-size: 16px; color: #1F3B50; text-align: justify; line-height: 25px;">
${item.datasetCount()}
</td>
</tr>
</#list>
</tbody>
</table>
</#if>
<td id="newStudyCount" style="${bodyTextStyle} padding: 15px 15px 0px; text-align: left; font-weight: 600;">
<#if newStudies?size == 1>1 new study was<#else>${newStudies?size} new studies were</#if> registered today.
</td>
</tr>
<tr>
<td style="padding: 15px 15px 0px; font-family: 'Montserrat', sans-serif; font-size: 16px; color: #1F3B50; text-align: left; line-height: 25px; display: block; font-weight: 500;">
</br>
</br>
<td style="padding: 10px 15px 0px;">
<table style="width: 100%; border-collapse: collapse;">
<thead>
<tr>
<th style="${headerCellStyle} text-align: left;">Study Name</th>
<th style="${headerCellStyle} text-align: left;">Access Type(s)</th>
<th style="${headerCellStyle} text-align: right;">Number of Datasets</th>
</tr>
</thead>
<tbody>
<#list newStudies as item>
<tr>
<td style="${dataCellStyle} text-align: left;">
<a style="${linkStyle}" href="${serverUrl}studies/${item.id()?c}">${item.name()}</a>
</td>
<td class="access-types" style="${dataCellStyle} text-align: left;">
<#list item.accessTypes()?split(",") as accessType>
<span class="access-type-badge" style="${badgeStyle}">${accessType?trim?cap_first}</span>
</#list>
</td>
<td class="dataset-count" style="${dataCellStyle} text-align: right; white-space: nowrap;">
${item.datasetCount()}
</td>
</tr>
</#list>
</tbody>
</table>
</td>
</tr>
</#if>
<tr>
<td style="${bodyTextStyle} padding: 25px 15px 0px; text-align: left; font-weight: 500;">
The DUOS team
</td>
</tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,36 @@ void testNewStudyDigestMessage() throws Exception {
rendered.document().body().html(),
containsString(urlStringPattern.formatted(serverUrl, record2.id(), record2.name())));

// Assert display-formatted access types from template
assertThat(rendered.document().body().html(), containsString("Controlled, External"));
assertThat(rendered.document().body().html(), containsString("Open"));
// Assert display-formatted access types from template, rendered as one badge per type
assertEquals(
List.of("Controlled", "External", "Open"),
rendered.document().select(".access-type-badge").eachText());

// Assert the summary count line is present and pluralized for multiple studies
assertEquals(
"2 new studies were registered today.",
getElementTextById(rendered.document(), "newStudyCount"));

// Assert dataset counts are bare numbers, right-aligned under the column heading
var datasetCounts = rendered.document().select(".dataset-count");
assertEquals(List.of("1", "2"), datasetCounts.eachText());
datasetCounts.forEach(
cell -> assertThat(cell.attr("style"), containsString("text-align: right")));
}

@Test
void testNewStudyDigestMessage_SingleStudyCountIsSingular() throws Exception {
List<StudyDatasetCountRecord> newStudies =
List.of(new StudyDatasetCountRecord("My only new study", 3, "open", 1));
User user = new User();
user.setDisplayName("Test User");
var message = new NewStudyDigestMessage(user, newStudies, "My reference id");

var rendered = renderTemplate(message, "http://localhost:8080/");

assertEquals(
"1 new study was registered today.",
getElementTextById(rendered.document(), "newStudyCount"));
assertEquals(List.of("1"), rendered.document().select(".dataset-count").eachText());
}
}
Loading