package kr.iotdoor.boot.web;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@SpringBootTest
@AutoConfigureMockMvc
class AdminPageControllerTest {

    @Autowired
    private MockMvc mockMvc;

    @Test
    @WithMockUser(username = "admin", roles = "ADMIN")
    void dashboardRendersWithNewAdminLayout() throws Exception {
        mockMvc.perform(get("/mfuc/index.do"))
            .andExpect(status().isOk())
            .andExpect(content().string(org.hamcrest.Matchers.containsString("Admin Menu")))
            .andExpect(content().string(org.hamcrest.Matchers.containsString("최근 문의")));
    }

    @Test
    @WithMockUser(username = "admin", roles = "ADMIN")
    void userManagementPageRenders() throws Exception {
        mockMvc.perform(get("/mfuc/user/list.do"))
            .andExpect(status().isOk())
            .andExpect(content().string(org.hamcrest.Matchers.containsString("신규 사용자 등록")));
    }

    @Test
    @WithMockUser(username = "admin", roles = "ADMIN")
    void portfolioManagementPagesRender() throws Exception {
        mockMvc.perform(get("/mfuc/portfolio/list.do"))
            .andExpect(status().isOk())
            .andExpect(content().string(org.hamcrest.Matchers.containsString("포트폴리오 관리")));

        mockMvc.perform(get("/mfuc/portfolio/form.do"))
            .andExpect(status().isOk())
            .andExpect(content().string(org.hamcrest.Matchers.containsString("대표 이미지 지정")));
    }

    @Test
    @WithMockUser(username = "admin", roles = "ADMIN")
    void contactManagementPageRenders() throws Exception {
        mockMvc.perform(get("/mfuc/contact/list.do"))
            .andExpect(status().isOk())
            .andExpect(content().string(org.hamcrest.Matchers.containsString("문의 접수 목록")));
    }
}
