///////////////////////////////////////////
///
/// File: FrontendTests.java
/// Author: Evan Gaul
/// Email: eagaul@wisc.edu
/// Date: 9/17/25
/// Assignment: P103.RoleCode
/// Course: CS400 Lec004 Fall 2025
/// Professor: Ashley Samuelson
///
///////////////////////////////////////////
///
/// Assistance: None
///
///////////////////////////////////////////

import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import java.util.Scanner;

/**
 * Tests the Frontend class
 * Checks every command is correct
 */
public class FrontendTests {

    /**
     * This test checks the load command and the correct output is outputted from the outputter :)
     */
    @Test
    public void frontendTest1() {
        // load songs.csv, then quit
        TextUITester tester = new TextUITester("load songs.csv\nquit\n");

        Scanner sc = new Scanner(System.in);
        IterableSortedCollection<Song> tree = new Tree_Placeholder();
        BackendInterface backend = new Backend_Placeholder(tree);
        Frontend frontend = new Frontend(sc, backend);

        frontend.runCommandLoop();

        String output = tester.checkOutput();

        // check for filename or the word "loaded"
        assertTrue(output.contains("songs.csv"),
                "Frontend should say the filename");
        assertTrue(output.toLowerCase().contains("loaded"),
                "Frontend should say data was loaded");
    }

    /**
     * This test checks the year MIN to MAX and loudness MAX commands are parsed good and give correct output
     */
    @Test
    public void frontendTest2() {
        // year 1990 to 2000, loudness 50, then quit
        TextUITester tester = new TextUITester("year 1990 to 2000\nloudness 50\nquit\n");

        Scanner sc = new Scanner(System.in);
        IterableSortedCollection<Song> tree = new Tree_Placeholder();
        BackendInterface backend = new Backend_Placeholder(tree);
        Frontend frontend = new Frontend(sc, backend);

        frontend.runCommandLoop();

        String output = tester.checkOutput();

        assertTrue(output.contains("1990") && output.contains("2000"),
                "Frontend should say both years");
        assertTrue(output.toLowerCase().contains("range set"),
                "Frontend should say 'range set'");
        assertTrue(output.toLowerCase().contains("loudness set"),
                "Frontend should confirm loudness");
    }

    /**
     * This test checks the show most dancable and show commands
     */
    @Test
    public void frontendTest3() {
        // show most danceable, show 3, then quit
        TextUITester tester = new TextUITester("show most danceable\nshow 3\nquit\n");

        Scanner sc = new Scanner(System.in);
        IterableSortedCollection<Song> tree = new Tree_Placeholder();
        BackendInterface backend = new Backend_Placeholder(tree);
        Frontend frontend = new Frontend(sc, backend);

        frontend.runCommandLoop();


        String output = tester.checkOutput();

        assertTrue(output.toLowerCase().contains("most danceable"),
                "Frontend should print correct results for 'show most danceable'");
        // check that correct 3 message is there
        assertTrue(output.contains("Showing 3 songs:"),
                "Frontend should show right results for 'show 3'");
    }
}

