fix(ui): complete reviewed desktop integration

This commit is contained in:
sechmachine
2026-08-15 04:03:19 +07:00
parent 1f6454ae53
commit c81c0dfe65
19 changed files with 148 additions and 43 deletions
@@ -26,6 +26,7 @@ import com.lab.labtimesheet.feature.attendance.model.dto.GlobalCalendarEvent;
import com.lab.labtimesheet.feature.attendance.service.AttendanceApplicationService;
import com.lab.labtimesheet.feature.attendance.service.AttendanceCurrentUserService;
import com.lab.labtimesheet.feature.attendance.service.CalendarApplicationService;
import com.lab.labtimesheet.feature.integration.service.SmtpConfigurationService;
import java.time.Instant;
import java.time.LocalDate;
import java.util.List;
@@ -50,6 +51,9 @@ class AttendanceControllerTest {
@MockitoBean
private AttendanceCurrentUserService currentUsers;
@MockitoBean
private SmtpConfigurationService smtpConfiguration;
@Test
void internPunchesOnlyForAuthenticatedSelf() throws Exception {
AttendanceActor actor = new AttendanceActor(42L, AttendanceRole.INTERN);
@@ -25,6 +25,7 @@ import com.lab.labtimesheet.feature.project.model.dto.ProjectLeadershipTermView;
import com.lab.labtimesheet.feature.project.model.dto.ProjectMemberView;
import com.lab.labtimesheet.feature.project.service.ProjectQueryService;
import com.lab.labtimesheet.feature.project.service.ProjectService;
import com.lab.labtimesheet.feature.integration.service.SmtpConfigurationService;
import java.time.Instant;
import java.time.LocalDate;
import java.util.List;
@@ -49,6 +50,9 @@ class ProjectControllerTest {
@MockitoBean
private ProjectService projects;
@MockitoBean
private SmtpConfigurationService smtpConfiguration;
@Test
@WithMockUser(username = "mentor@example.test")
void listsOnlyTheAuthenticatedUsersAuthorizedProjects() throws Exception {
@@ -6,11 +6,16 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import com.lab.labtimesheet.feature.account.model.dto.ActivationForm;
import com.lab.labtimesheet.feature.account.model.dto.BootstrapForm;
import com.lab.labtimesheet.feature.account.model.dto.CreateAccountForm;
import com.lab.labtimesheet.feature.integration.service.SmtpConfigurationService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest;
import org.springframework.context.annotation.Import;
import org.springframework.stereotype.Controller;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@@ -21,6 +26,9 @@ class AccountTemplateIntegrationTest {
private final MockMvc mvc;
@MockitoBean
private SmtpConfigurationService smtpConfiguration;
@Autowired
AccountTemplateIntegrationTest(MockMvc mvc) {
this.mvc = mvc;
@@ -80,13 +88,16 @@ class AccountTemplateIntegrationTest {
public static class TemplateController {
@GetMapping("/template-contract/accounts/new")
String accountCreation() {
String accountCreation(Model model) {
model.addAttribute("accountForm", new CreateAccountForm());
return "accounts/new";
}
@GetMapping("/template-contract/accounts/activate")
String activation(Model model) {
model.addAttribute("token", "raw-token");
ActivationForm form = new ActivationForm();
form.setToken("raw-token");
model.addAttribute("activationForm", form);
return "accounts/activate";
}
@@ -96,7 +107,8 @@ class AccountTemplateIntegrationTest {
}
@GetMapping("/template-contract/bootstrap")
String bootstrap() {
String bootstrap(Model model) {
model.addAttribute("bootstrapForm", new BootstrapForm());
return "bootstrap/form";
}
}
@@ -6,9 +6,10 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import com.lab.labtimesheet.feature.attendance.model.AttendancePolicy;
import com.lab.labtimesheet.feature.attendance.model.AttendancePolicyFixtures;
import com.lab.labtimesheet.feature.attendance.model.AttendanceViolations;
import com.lab.labtimesheet.feature.attendance.model.dto.AttendanceHistoryItem;
import com.lab.labtimesheet.feature.integration.service.SmtpConfigurationService;
import java.time.Instant;
import java.time.LocalDate;
import java.util.List;
@@ -17,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest;
import org.springframework.context.annotation.Import;
import org.springframework.stereotype.Controller;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@@ -27,6 +29,9 @@ class AttendanceTemplateIntegrationTest {
private final MockMvc mvc;
@MockitoBean
private SmtpConfigurationService smtpConfiguration;
@Autowired
AttendanceTemplateIntegrationTest(MockMvc mvc) {
this.mvc = mvc;
@@ -91,13 +96,13 @@ class AttendanceTemplateIntegrationTest {
LocalDate.of(2026, 8, 14),
Instant.parse("2026-08-14T02:05:00Z"),
Instant.parse("2026-08-14T09:00:00Z"),
AttendancePolicy.seeded(1L),
AttendancePolicyFixtures.seeded(1L),
new AttendanceViolations(true, true, false)),
new AttendanceHistoryItem(
LocalDate.of(2026, 8, 13),
Instant.parse("2026-08-13T01:30:00Z"),
null,
AttendancePolicy.seeded(1L),
AttendancePolicyFixtures.seeded(1L),
new AttendanceViolations(true, false, true))));
return "attendance/history";
}
@@ -9,6 +9,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
import com.lab.labtimesheet.feature.integration.service.SmtpConfigurationService;
import com.lab.labtimesheet.feature.reporting.model.dto.DashboardView;
import com.lab.labtimesheet.feature.reporting.service.DashboardService;
import java.util.List;
@@ -27,6 +28,9 @@ class DashboardControllerWebTest {
@MockitoBean
private DashboardService dashboards;
@MockitoBean
private SmtpConfigurationService smtpConfiguration;
@Test
void adminRendersAdminDashboardForAuthenticatedIdentity() throws Exception {
var dashboard = new DashboardView.Admin(2, 1, 1, 3);
@@ -6,6 +6,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import com.lab.labtimesheet.feature.integration.service.SmtpConfigurationService;
import com.lab.labtimesheet.feature.reporting.model.dto.DashboardView;
import java.time.LocalDate;
import java.util.List;
@@ -15,6 +16,7 @@ import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest;
import org.springframework.context.annotation.Import;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.stereotype.Controller;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@@ -25,6 +27,9 @@ class DashboardTemplateWebTest {
private final MockMvc mvc;
@MockitoBean
private SmtpConfigurationService smtpConfiguration;
@Autowired
DashboardTemplateWebTest(MockMvc mvc) {
this.mvc = mvc;
@@ -8,6 +8,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import com.lab.labtimesheet.feature.integration.service.SmtpConfigurationService;
import com.lab.labtimesheet.feature.project.controller.ProjectController;
import com.lab.labtimesheet.feature.project.service.ProjectQueryService;
import com.lab.labtimesheet.feature.project.service.ProjectService;
@@ -36,6 +37,9 @@ class ProjectTaskFormAccessibilityWebTest {
@MockitoBean
private TaskService tasks;
@MockitoBean
private SmtpConfigurationService smtpConfiguration;
@Test
void projectFieldErrorsHaveStableIdsAndInputAssociations() throws Exception {
mvc.perform(post("/projects")
@@ -6,6 +6,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import com.lab.labtimesheet.feature.integration.service.SmtpConfigurationService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest;
@@ -13,6 +14,7 @@ import org.springframework.context.annotation.Import;
import org.springframework.http.HttpStatus;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.stereotype.Controller;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@@ -25,6 +27,9 @@ class SharedErrorTemplateWebTest {
@Autowired
private MockMvc mvc;
@MockitoBean
private SmtpConfigurationService smtpConfiguration;
@Test
@WithMockUser(username = "intern@example.test", roles = "INTERN")
void notFoundPageUsesSharedShellWithoutDisclosingRecordDetails() throws Exception {
@@ -26,6 +26,7 @@ import com.lab.labtimesheet.feature.task.model.dto.TaskDetails;
import com.lab.labtimesheet.feature.task.model.dto.TaskListView;
import com.lab.labtimesheet.feature.task.model.dto.TaskView;
import com.lab.labtimesheet.feature.task.service.TaskService;
import com.lab.labtimesheet.feature.integration.service.SmtpConfigurationService;
import java.time.Instant;
import java.time.LocalDate;
import java.util.List;
@@ -51,6 +52,9 @@ class TaskControllerTest {
@MockitoBean
private TaskService taskService;
@MockitoBean
private SmtpConfigurationService smtpConfiguration;
@Test
void taskListRequiresAuthentication() throws Exception {
mockMvc.perform(get("/projects/10/tasks"))
@@ -5,6 +5,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import com.lab.labtimesheet.feature.integration.service.SmtpConfigurationService;
import java.nio.charset.StandardCharsets;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -15,6 +16,7 @@ import org.springframework.core.io.ClassPathResource;
import org.springframework.context.annotation.Import;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.stereotype.Controller;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.web.bind.annotation.GetMapping;
@@ -25,6 +27,9 @@ class UiContractWebTest {
private final MockMvc mvc;
@MockitoBean
private SmtpConfigurationService smtpConfiguration;
@Autowired
UiContractWebTest(MockMvc mvc) {
this.mvc = mvc;
@@ -49,6 +54,7 @@ class UiContractWebTest {
assertFalse(html.contains("href=\"/profile\""));
assertFalse(html.contains("href=\"/notifications\""));
assertTrue(html.indexOf("/assets/theme.js") < html.indexOf("/assets/app.css"));
assertTrue(html.contains("rel=\"icon\" href=\"/assets/icons.svg\""));
assertTrue(html.contains("href=\"/assets/icons.svg#panel-left\""));
}
@@ -91,6 +97,29 @@ class UiContractWebTest {
assertTrue(themeBootstrap.contains("matchMedia('(prefers-color-scheme: dark)')"));
}
@Test
@WithMockUser(username = "admin@example.test", roles = "ADMIN")
void collapsedSidebarExposesStateAndKeyboardVisibleControlNames() throws Exception {
String html = mvc.perform(get("/ui-contract"))
.andExpect(status().isOk())
.andReturn()
.getResponse()
.getContentAsString(StandardCharsets.UTF_8);
String script = new ClassPathResource("static/assets/app.js")
.getContentAsString(StandardCharsets.UTF_8);
String css = new ClassPathResource("static/assets/app.css")
.getContentAsString(StandardCharsets.UTF_8);
assertTrue(html.contains("data-sidebar-toggle aria-expanded=\"true\""));
assertTrue(html.contains("data-tooltip=\"Overview\""));
assertTrue(html.contains("data-tooltip=\"Accounts\""));
assertTrue(html.contains("data-tooltip=\"Global calendar\""));
assertTrue(html.contains("data-tooltip=\"Logout\""));
assertTrue(html.contains("title=\"Theme preference\""));
assertTrue(script.contains("setAttribute('aria-expanded', String(!collapsed))"));
assertTrue(css.contains("content:attr(data-tooltip)"));
}
@Test
void themeTokensMeetTextFocusAndMeaningfulBoundaryContrast() throws Exception {
String css = new ClassPathResource("static/assets/app.css")
@@ -1,10 +0,0 @@
<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head><meta charset="utf-8"><title th:text="${errorTitle}">Request unavailable</title></head>
<body>
<main>
<h1 th:text="${errorTitle}">Request unavailable</h1>
<p th:text="${errorMessage}">The request could not be completed.</p>
</main>
</body>
</html>