package ru.kovbasa.tests;

import org.junit.jupiter.api.Test;
import ru.kovbasa.pages.CatalogPage;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class CatalogFiltersTest extends BaseTest {

    @Test
    void catalogFilters() {
        CatalogPage catalog = new CatalogPage(page(), config);
        catalog.open();

        assertTrue(catalog.isDefaultDirectionSelected(),
                "Default direction should be selected");
        assertTrue(catalog.isDefaultLevelSelected(),
                "Default level should be selected");

        var titlesBefore = catalog.getCourseTitles(5);

        catalog.setDurationRange(3, 10);

        var durations = catalog.getVisibleCourseDurations();
        assertFalse(durations.isEmpty(), "Durations should be present");
        for (Integer duration : durations) {
            assertTrue(duration > 0, "Each course should have a duration");
            assertTrue(duration >= 3 && duration <= 10,
                    "Duration should be within selected range");
        }

        catalog.selectDirection("Архитектура");
        var titlesAfterDirection = catalog.getCourseTitles(5);
        assertNotEquals(titlesBefore, titlesAfterDirection,
                "Course cards should change after selecting direction");
        assertTrue(catalog.isDirectionSelected("Архитектура"),
                "Selected direction should be visible in filter");

        catalog.resetFilters();
        page().reload();
        assertTrue(catalog.isDefaultDirectionSelected(),
                "Direction should be reset to default");
        var titlesAfterReset = catalog.getCourseTitles(5);
        assertNotEquals(titlesAfterDirection, titlesAfterReset,
                "Course cards should change after reset");
    }
}
