package seedu.todo.guitests;

import static org.junit.Assert.*;

import java.io.IOException;

import org.junit.Before;
import org.junit.Test;

import seedu.todo.commons.core.Config;
import seedu.todo.commons.core.ConfigCenter;
import seedu.todo.guitests.guihandles.AliasItemHandle;
import seedu.todo.models.Task;

// @@author A0139812A
public class AliasCommandTest extends GuiTest {
    
    @Before
    public void beforeTest() {
        try {
            ConfigCenter.getInstance().saveConfig(new Config());
        } catch (IOException e) {
            fail("Failed to reset config.");
        }
    }

    @Test
    public void alias_view_success() {
        console.runCommand("alias");
        assertTrue(aliasView.hasLoaded());
    }
    
    @Test
    public void alias_toList_success() {
        console.runCommand("alias list ls");
        assertAliasItemVisible("list", "ls");
        
        console.runCommand("add Buy milk");
        Task testTask = new Task();
        testTask.setName("Buy milk");
        assertTaskVisibleAfterCmd("ls", testTask);
    }
    
    /**
     * Helper function to assert that AliasItem is visible.
     */
    private void assertAliasItemVisible(String aliasKey, String aliasValue) {
        // Make sure we can see the Alias View.
        assertTrue(aliasView.hasLoaded());
        
        // Gets the matching AliasItem. Since it matches, if it's not null -> it definitely exists.
        AliasItemHandle aliasItem = aliasView.getAliasItem(aliasKey, aliasValue);
        assertNotNull(aliasItem);
    }

}

@@ -85,16 +85,48 @@
 ception;
+%0Aimport java.time.LocalDateTime;
 %0A%0Aimport
@@ -252,16 +252,57 @@
 Center;%0A
+import seedu.todo.commons.util.DateUtil;%0A
 import s
@@ -463,46 +463,274 @@
     
-@Before%0A    public void beforeTest() %7B
+// Fixtures%0A    private LocalDateTime twoDaysFromNow = LocalDateTime.now().plusDays(2);%0A    private String twoDaysFromNowIsoString = DateUtil.formatIsoDate(twoDaysFromNow);%0A    %0A    @Before%0A    public void beforeTest() %7B%0A        console.runCommand(%22clear%22);%0A        
 %0A   
@@ -1131,14 +1131,14 @@
 as l
+s l
 ist
- ls
 %22);%0A
@@ -1174,14 +1174,300 @@
 e(%22l
-ist%22, 
+s%22, %22list%22);%0A        %0A        console.runCommand(%22add Buy milk%22);%0A        console.runCommand(%22alias%22); // Move away from IndexView%0A        %0A        Task testTask = new Task();%0A        testTask.setName(%22Buy milk%22);%0A        assertTaskVisibleAfterCmd(%22ls%22, testTask);%0A        assertValidCommand(
 %22ls%22
@@ -1465,32 +1465,34 @@
 mand(%22ls%22);%0A    
+%7D%0A
     %0A        con
@@ -1488,170 +1488,1522 @@
     
-    console.runCommand(%22add Buy milk%22);%0A        Task testTask = new Task();%0A        testTask.setName(%22Buy milk%22);%0A        assertTaskVisibleAfterCmd(%22ls%22, testTask
+@Test%0A    public void alias_toAdd_success() %7B%0A        console.runCommand(%22alias a add%22);%0A        assertAliasItemVisible(%22a%22, %22add%22);%0A        %0A        Task testTask = new Task();%0A        testTask.setName(%22Buy milk%22);%0A        assertTaskVisibleAfterCmd(%22a Buy milk%22, testTask);%0A    %7D%0A%0A    @Test%0A    public void alias_toAddTaskDeadline_success() %7B%0A        console.runCommand(%22alias a add%22);%0A        assertAliasItemVisible(%22a%22, %22add%22);%0A        %0A        String command = String.format(%22a Buy milk by %25s 5pm%22, twoDaysFromNowIsoString);%0A        Task testTask = new Task();%0A        testTask.setName(%22Buy milk%22);%0A        testTask.setDueDate(DateUtil.parseDateTime(String.format(%22%25s 17:00:00%22, twoDaysFromNowIsoString)));%0A        assertTaskVisibleAfterCmd(command, testTask);%0A    %7D%0A    %0A    @Test%0A    public void alias_toInvalidCommand_isInvalid() %7B%0A        console.runCommand(%22alias invalidcommand ic%22);%0A        assertAliasItemVisible(%22invalidcommand%22, %22ic%22);%0A        console.runCommand(%22ic%22);%0A        assertInvalidCommand(%22ic%22);%0A    %7D%0A    %0A    @Test%0A    public void alias_missingValue_disambiguate() %7B%0A        console.runCommand(%22alias list%22);%0A        String disambiguation = %22alias list %3Calias value%3E%22;%0A        assertEquals(disambiguation, console.getConsoleInputText());%0A    %7D%0A    %0A    @Test%0A    public void alias_tooManyArgs_disambiguate() %7B%0A        console.runCommand(%22alias show me the money%22);%0A        String disambiguation = %22alias show methemoney%22;%0A        assertEquals(disambiguation, console.getConsoleInputText()
 );%0A 

Complete the rest of the alias test cases