package guitests;

import static org.junit.Assert.assertTrue;

import org.junit.Test;

import seedu.tasklist.commons.core.Messages;
import seedu.tasklist.logic.commands.SortCommand;
import seedu.tasklist.testutil.TestTask;

public class SortCommandTest extends TaskListGuiTest {


    @Test
    public void sort_invalidParameter_errorMessageShown() {
        String command = "sort a";
        commandBox.runCommand(command);
        assertResultMessage(String.format(SortCommand.MESSAGE_FAILURE));
    }

    @Test
    public void sort_moreThanOneParameter_errorMessageShown() {
        String command = "sort n p";
        commandBox.runCommand(command);
        assertResultMessage(String.format(SortCommand.MESSAGE_FAILURE));
    }

    @Test
    public void sort_invalidCommand_errorMessageShown() {
        commandBox.runCommand("sorts newTask");
        assertResultMessage(Messages.MESSAGE_UNKNOWN_COMMAND);
    }

    @Test
    public void sort() {
        //sort by name
        TestTask[] expectedListName = {td.groceries, td.tutorial, td.homework, td.drink, td.cs2103T, td.java};
        String commandName = "sort n";
        commandBox.runCommand(commandName);
        assertSortSuccess(expectedListName);

        //sort by start date
        TestTask[] expectedListStartDate = {td.tutorial, td.cs2103T, td.groceries, td.homework, td.drink, td.java };
        String commandStartDate = "sort sd";
        commandBox.runCommand(commandStartDate);
        assertResultMessage(SortCommand.MESSAGE_SUCCESS);
        assertSortSuccess(expectedListStartDate);

        //sort by end date
        TestTask[] expectedListEndDate = {td.tutorial, td.cs2103T, td.groceries, td.homework, td.drink, td.java};
        String commandEndDate = "sort ed";
        commandBox.runCommand(commandEndDate);
        assertResultMessage(SortCommand.MESSAGE_SUCCESS);
        assertSortSuccess(expectedListEndDate);

        //sort by deadline date
        TestTask[] expectedListDeadline =  {td.cs2103T, td.tutorial, td.groceries, td.homework, td.drink, td.java};
        String commandDeadline = "sort d";
        commandBox.runCommand(commandDeadline);
        assertResultMessage(SortCommand.MESSAGE_SUCCESS);
        assertSortSuccess(expectedListDeadline);

        //sort by start priority
        TestTask[] expectedListPriority = {td.tutorial, td.drink, td.java, td.cs2103T, td.groceries, td.homework};
        String commandPriority = "sort p";
        commandBox.runCommand(commandPriority);
        assertResultMessage(SortCommand.MESSAGE_SUCCESS);
        assertSortSuccess(expectedListPriority);
    }

    private void assertSortSuccess(TestTask... expectedList) {
        //confirm list contains all tasks in the correct sorted order
        assertTrue(taskListPanel.isListMatching(expectedList));
    }

}

@@ -1232,22 +1232,16 @@
 sort by 
-start 
 date%0A   
@@ -1264,29 +1264,24 @@
 expectedList
-Start
 Date = %7Btd.t
@@ -1367,29 +1367,24 @@
 ring command
-Start
 Date = %22sort
@@ -1384,17 +1384,16 @@
 = %22sort 
-s
 d%22;%0A    
@@ -1425,21 +1425,16 @@
 (command
-Start
 Date);%0A 
@@ -1494,694 +1494,8 @@
 S);%0A
-        assertSortSuccess(expectedListStartDate);%0A%0A        //sort by end date%0A        TestTask%5B%5D expectedListEndDate = %7Btd.tutorial, td.cs2103T, td.groceries, td.homework, td.drink, td.java%7D;%0A        String commandEndDate = %22sort ed%22;%0A        commandBox.runCommand(commandEndDate);%0A        assertResultMessage(SortCommand.MESSAGE_SUCCESS);%0A        assertSortSuccess(expectedListEndDate);%0A%0A        //sort by deadline date%0A        TestTask%5B%5D expectedListDeadline =  %7Btd.cs2103T, td.tutorial, td.groceries, td.homework, td.drink, td.java%7D;%0A        String commandDeadline = %22sort d%22;%0A        commandBox.runCommand(commandDeadline);%0A        assertResultMessage(SortCommand.MESSAGE_SUCCESS);%0A
     
@@ -1533,14 +1533,10 @@
 istD
-eadlin
+at
 e);%0A

Remove irrelevant test cases