
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;

/**
 * Tests for the Frontend implementation
 */
public class FrontendTests {

  /**
   * Test that verifies the frontend can generate the prompt HTML for shortest path and that it
   * contains all required elements (input fields with correct IDs and button)
   */
  @Test
  public void roleTest1() {
    // Create placeholder GraphADT and Backend
    GraphADT<String, Double> graph = new Graph_Placeholder();
    BackendInterface backend = new Backend_Placeholder(graph);

    // Create frontend with the backend
    Frontend frontend = new Frontend(backend);

    // Get the HTML for the shortest path prompt
    String html = frontend.generateShortestPathPromptHTML();

    // Check that HTML contains required elements
    assertTrue(html.contains("input") && html.contains("id=\"start\""),
        "HTML should contain an input field with id=\"start\"");
    assertTrue(html.contains("input") && html.contains("id=\"end\""),
        "HTML should contain an input field with id=\"end\"");
    assertTrue(html.contains("button") && html.contains("Find Shortest Path"),
        "HTML should contain a button labeled 'Find Shortest Path'");
  }

  /**
   * Test that verifies the frontend can generate the response HTML for shortest path and that it
   * contains all required elements (paragraph with locations, ordered list, and paragraph with
   * total time)
   */
  @Test
  public void roleTest2() {
    // Create placeholder GraphADT and Backend
    GraphADT<String, Double> graph = new Graph_Placeholder();
    BackendInterface backend = new Backend_Placeholder(graph);

    // Create frontend with the backend
    Frontend frontend = new Frontend(backend);

    // Get the HTML for the shortest path response
    // Using locations from the placeholder graph
    String html = frontend.generateShortestPathResponseHTML("Union South",
        "Weeks Hall for Geological Sciences");

    // Check that HTML contains required elements
    assertTrue(
        html.contains("<p") && html.contains("Union South")
            && html.contains("Weeks Hall for Geological Sciences"),
        "HTML should contain a paragraph describing start and end locations");
    assertTrue(html.contains("<ol>") && html.contains("</ol>"),
        "HTML should contain an ordered list");
    assertTrue(html.contains("<li>"), "HTML should contain list items");
    assertTrue(html.contains("Total travel time"), "HTML should contain total travel time");
  }

  /**
   * Test that verifies the frontend can generate both prompt and response HTML for the longest
   * location list functionality
   */
  @Test
  public void roleTest3() {
    // Create placeholder GraphADT and Backend
    GraphADT<String, Double> graph = new Graph_Placeholder();
    BackendInterface backend = new Backend_Placeholder(graph);

    // Create frontend with the backend
    Frontend frontend = new Frontend(backend);

    // Test longest location list prompt HTML
    String promptHtml = frontend.generateLongestLocationListFromPromptHTML();
    assertTrue(promptHtml.contains("input") && promptHtml.contains("id=\"from\""),
        "Prompt HTML should contain an input field with id=\"from\"");
    assertTrue(promptHtml.contains("button") && promptHtml.contains("Longest Location List From"),
        "Prompt HTML should contain a button labeled 'Longest Location List From'");

    // Test longest location list response HTML
    String responseHtml = frontend.generateLongestLocationListFromResponseHTML("Union South");
    assertTrue(responseHtml.contains("<ol>") && responseHtml.contains("</ol>"),
        "Response HTML should contain an ordered list");
    assertTrue(responseHtml.contains("Total number of locations"),
        "Response HTML should contain the total number of locations");
  }
}
