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.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.redirectedUrl;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@SpringBootTest
@AutoConfigureMockMvc
class PublicPageControllerTest {

    @Autowired
    private MockMvc mockMvc;

    @Test
    void homePageRendersFully() throws Exception {
        mockMvc.perform(get("/"))
            .andExpect(status().isOk())
            .andExpect(content().string(org.hamcrest.Matchers.containsString("Footer Start")));
    }

    @Test
    void loginEntryRedirectsToLoginPage() throws Exception {
        mockMvc.perform(get("/comn/user/login/login.do"))
            .andExpect(status().isFound())
            .andExpect(redirectedUrl("/comn/user/login/loginUser.do"));
    }

    @Test
    void loginPageRendersFully() throws Exception {
        mockMvc.perform(get("/comn/user/login/loginUser.do"))
            .andExpect(status().isOk())
            .andExpect(content().string(org.hamcrest.Matchers.containsString("관리자 로그인")));
    }
}
