package com.njcn.rdms.module.project.service.status;

import com.njcn.rdms.framework.test.core.ut.BaseMockitoUnitTest;
import com.njcn.rdms.module.project.dal.dataobject.status.ObjectStatusModelDO;
import com.njcn.rdms.module.project.dal.mysql.status.ObjectStatusModelMapper;
import com.njcn.rdms.module.project.dal.mysql.status.ObjectStatusTransitionMapper;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.when;

class StatusActionTextResolverTest extends BaseMockitoUnitTest {

    @InjectMocks
    private StatusActionTextResolver resolver;
    @Mock
    private ObjectStatusTransitionMapper transitionMapper;
    @Mock
    private ObjectStatusModelMapper statusModelMapper;

    @Test
    void actionName_hit_returnsChineseName() {
        when(transitionMapper.selectActionNameByObjectTypeAndAction("task", "complete")).thenReturn("完成");
        assertEquals("完成", resolver.actionName("task", "complete"));
    }

    @Test
    void actionName_miss_fallsBackToCode() {
        when(transitionMapper.selectActionNameByObjectTypeAndAction("task", "weird")).thenReturn(null);
        assertEquals("weird", resolver.actionName("task", "weird"));
    }

    @Test
    void actionName_blankInput_returnsInput() {
        assertEquals("", resolver.actionName("task", ""));
    }

    @Test
    void statusName_hit_returnsChineseName() {
        ObjectStatusModelDO model = new ObjectStatusModelDO();
        model.setStatusName("已完成");
        when(statusModelMapper.selectByObjectTypeAndStatusCode("task", "completed")).thenReturn(model);
        assertEquals("已完成", resolver.statusName("task", "completed"));
    }

    @Test
    void statusName_miss_fallsBackToCode() {
        when(statusModelMapper.selectByObjectTypeAndStatusCode("task", "ghost")).thenReturn(null);
        assertEquals("ghost", resolver.statusName("task", "ghost"));
    }
}
