package seedu.address.logic.parser;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static seedu.address.testutil.TestUtil.assertThrows;

import java.util.Optional;

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

import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.EditFloatingTaskCommand;
import seedu.address.model.task.Name;
import seedu.address.model.task.Priority;

public class EditFloatingTaskParserTest {

    private EditFloatingTaskParser parser;

    @Before
    public void setupParser() {
        parser = new EditFloatingTaskParser();
    }

    @Test
    public void parse() throws ParseException, IllegalValueException {
        // No modification
        assertParse("f1", 1, null, null);

        // name
        assertParse("f1 n-new name", 1, new Name("new name"), null);

        // priority
        assertParse("f1 p-2", 1, null, new Priority("2"));

        // All arguments
        assertParse("f3 n-thisname p-5", 3, new Name("thisname"), new Priority("5"));

        // Invalid flags
        assertIncorrect("f5 invalid-flag");
    }

    private void assertParse(String args, int targetIndex, Name name, Priority priority)
            throws ParseException {
        final Command command = parser.parse(args);
        assertTrue(command instanceof EditFloatingTaskCommand);

        assertEquals(targetIndex, ((EditFloatingTaskCommand)command).getTargetIndex());
        assertEquals(Optional.ofNullable(name), ((EditFloatingTaskCommand)command).getNewName());
        assertEquals(Optional.ofNullable(priority), ((EditFloatingTaskCommand)command).getNewPriority());
    }

    private void assertIncorrect(String args) {
        assertThrows(ParseException.class, () -> parser.parse(args));
    }

}

@@ -179,16 +179,71 @@
 hrows;%0A%0A
+import java.util.Arrays;%0Aimport java.util.Collections;%0A
 import j
@@ -472,32 +472,73 @@
 ingTaskCommand;%0A
+import seedu.address.model.ModelManager;%0A
 import seedu.add
@@ -600,16 +600,70 @@
 riority;
+%0Aimport seedu.address.model.task.TypicalFloatingTasks;
 %0A%0Apublic
@@ -715,37 +715,202 @@
 ate 
-EditFloatingTaskParser parser
+final TypicalFloatingTasks tft = new TypicalFloatingTasks();%0A%0A    private final ModelManager model = new ModelManager();%0A%0A    private EditFloatingTaskParser parser = new EditFloatingTaskParser()
 ;%0A%0A 
@@ -999,16 +999,84 @@
 rser();%0A
+        assertEquals(1, model.addFloatingTask(tft.buyAHelicopter));%0A
     %7D%0A%0A 
@@ -2245,10 +2245,879 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void autocompleteName_returnsFloatingTaskName() %7B%0A        assertEquals(Arrays.asList(%22buy A Helicopter%22), parser.autocomplete(model, %22f1 n- %22, 5));%0A        assertEquals(Collections.emptyList(), parser.autocomplete(model, %22f2 n- %22, 5));%0A        assertEquals(Collections.emptyList(), parser.autocomplete(model, %22f1 n-a%22, 5));%0A        assertEquals(Collections.emptyList(), parser.autocomplete(model, %221 n-%22, 4));%0A    %7D%0A%0A    @Test%0A    public void autocompletePriority_returnsFloatingTaskPriority() %7B%0A        assertEquals(Arrays.asList(%224%22), parser.autocomplete(model, %22f1 p- %22, 5));%0A        assertEquals(Collections.emptyList(), parser.autocomplete(model, %22f2 p- %22, 5));%0A        assertEquals(Collections.emptyList(), parser.autocomplete(model, %22f1 p-3%22, 5));%0A        assertEquals(Collections.emptyList(), parser.autocomplete(model, %221 p-%22, 4));%0A    %7D%0A%0A
 %7D%0A

improve test coverage