package eu.livotov.labs.android.d3s;

import org.junit.Test;

import static com.google.common.truth.Truth.assertThat;

public class D3SRegexUtilsTest {

    @Test
    public void given_empty_html_when_PaRes_match_attempted_then_should_return_null() {
        // Given
        String html = "";

        // When
        String paRes = D3SRegexUtils.findPaRes(html);

        // Then
        assertThat(paRes)
                .isNull();
    }

    @Test
    public void given_blank_html_when_PaRes_match_attempted_then_should_return_null() {
        // Given
        String html = "               ";

        // When
        String paRes = D3SRegexUtils.findPaRes(html);

        // Then
        assertThat(paRes)
                .isNull();
    }

    @Test
    public void given_html_with_no_pares_when_PaRes_match_attempted_then_should_return_null() {
        // Given
        String html = "<html>" +
                "<head>\n" +
                "</head>\n" +
                "<body>\n" +
                "<div class=\"threeds-one\">" +
                "</html>";

        // When
        String paRes = D3SRegexUtils.findPaRes(html);

        // Then
        assertThat(paRes)
                .isNull();
    }

    @Test
    public void given_html_with_empty_pares_when_PaRes_match_attempted_then_should_return_null() {
        // https://github.com/LivotovLabs/3DSView/issues/30
        // Given
        String html = "<html>" +
                "<head>\n" +
                "</head>\n" +
                "<body>\n" +
                "<form method=\"POST\" id=\"TermForm\">\n" +
                "  <input type=\"hidden\" id=\"PaRes\" name=\"PaRes\" value=\"\">\n" +
                "  <input type=\"hidden\" id=\"MD\" name=\"MD\" value=\"\">\n" +
                "</form>" +
                "</html>";

        // When
        String paRes = D3SRegexUtils.findPaRes(html);

        // Then
        assertThat(paRes)
                .isNull();
    }

    @Test
    public void given_html_with_valid_pares_when_PaRes_match_attempted_then_should_return_null() {
        // Given
        String html = "<html>" +
                "<head>\n" +
                "</head>\n" +
                "<body>\n" +
                "<form method=\"POST\" id=\"TermForm\">\n" +
                "  <input type=\"hidden\" id=\"PaRes\" name=\"PaRes\" value=\"pares_value\">\n" +
                "  <input type=\"hidden\" id=\"MD\" name=\"MD\" value=\"\">\n" +
                "</form>" +
                "</html>";

        // When
        String paRes = D3SRegexUtils.findPaRes(html);

        // Then
        assertThat(paRes)
                .isEqualTo("pares_value");
    }
}
@@ -2551,32 +2551,755 @@
 ndPaRes(html);%0A%0A
+        // Then%0A        assertThat(paRes)%0A                .isEqualTo(%22pares_value%22);%0A    %7D%0A%0A    @Test%0A    public void given_html_with_valid_pares_case_insensitive_when_PaRes_match_attempted_then_should_return_null() %7B%0A        // Given%0A        String html = %22%3Chtml%3E%22 +%0A                %22%3Chead%3E%5Cn%22 +%0A                %22%3C/head%3E%5Cn%22 +%0A                %22%3Cbody%3E%5Cn%22 +%0A                %22%3Cform method=%5C%22POST%5C%22 id=%5C%22TermForm%5C%22%3E%5Cn%22 +%0A                %22  %3Cinput type=%5C%22hidden%5C%22 id=%5C%22PaRes%5C%22 name=%5C%22pares%5C%22 value=%5C%22pares_value%5C%22%3E%5Cn%22 +%0A                %22  %3Cinput type=%5C%22hidden%5C%22 id=%5C%22MD%5C%22 name=%5C%22MD%5C%22 value=%5C%22%5C%22%3E%5Cn%22 +%0A                %22%3C/form%3E%22 +%0A                %22%3C/html%3E%22;%0A%0A        // When%0A        String paRes = D3SRegexUtils.findPaRes(html);%0A%0A
         // Then%0A

Add test for case insensitivity for PaRes