import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;

/**
 * JUnit tests for Frontend
 */
public class FrontendTests {
    /**
     * Tests if the HTML for the prompts are correct
     */
    @Test
    public void FrontendTest1() {
        //setup
        GraphADT<String, Double> graph = new Graph_Placeholder();
        BackendInterface backend = new Backend_Placeholder(graph);
        FrontendInterface frontend = new Frontend(backend);

        String expectedPath = """
                <label for="start">Start Location:</label>
                <input type="text" id="start"></input>
                <label for="end">End Location:</label>
                <input type="text" id="end"></input>
                <input type="button" value="Find Shortest Path"></input>
                """;

        //Check if the output is as expected
        Assertions.assertEquals(expectedPath, frontend.generateShortestPathPromptHTML(), "Incorrect shortest path prompt HTML");

        String expectedReach = """
                <label for="from">From:</label>
                <input type="text" id="from"></input>
                <label for="time">Max Time:</label>
                <input type="text" id="time"></input>
                <input type="button" value="Reachable From Within"></input>
                """;

        //Check if the output is as expected
        Assertions.assertEquals(expectedReach, frontend.generateReachableFromWithinPromptHTML(), "Incorrect reachable from within prompt HTML");
    }

    /**
     * Tests generateShortestPathResponseHTML() if it outputs as expected
     */
    @Test
    public void FrontendTest2() {
        GraphADT<String, Double> graph = new Graph_Placeholder();
        BackendInterface backend = new Backend_Placeholder(graph);
        FrontendInterface frontend = new Frontend(backend);

        String outputPath1 = frontend.generateShortestPathResponseHTML("Union South", "Computer Sciences and Statistics");
        //This is the expected output with the placeholder Graph and Backend
        String expectedPath1 = "<p>This path starts at Union South and ends at Computer Sciences and Statistics with the following locations along the path:</p>"
        +"<ol><li>Union South</li><li>Computer Sciences and Statistics</li></ol><p>The total travel time is: 3.0</p>";
        
        Assertions.assertEquals(expectedPath1, outputPath1, "Incorrect shortest path response");
        
        String outputPath2 = frontend.generateShortestPathResponseHTML("Doesn't Exists", "Union South");
        //Since "Doesn't exist" is the startLocation and it doesn't exist in the graph, graph placeholder will return an empty list, so so will the backend placeholder 
        String expectedPath2 = "<p>There is no such path or some other problem occured.</p>";

        Assertions.assertEquals(expectedPath2, outputPath2, "Incorrect shortest path response");
    }

    /**
     * Tests generateReachableFromWithinResponseHTML() method if it outputs as expected
     */
    @Test
    public void FrontendTest3() {
        GraphADT<String, Double> graph = new Graph_Placeholder();
        BackendInterface backend = new Backend_Placeholder(graph);
        FrontendInterface frontend = new Frontend(backend);

        String outputReachCorrect = frontend.generateReachableFromWithinResponseHTML("Union South", 5);
        //This is the expected output with the placeholder Graph and Backend
        String expectedReachCorrect = "<p>Starting from Union South and reachable within the time limit 5.0 seconds are the following:</p>"
        +"<ul><li>Union South</li><li>Computer Sciences and Statistics</li><li>Weeks Hall for Geological Sciences</li></ul>";
        
        Assertions.assertEquals(expectedReachCorrect, outputReachCorrect, "Incorrect reachable from within response");
    }
}
