package org.jenkins.ci.plugins.jenkinslint;

import com.gargoylesoftware.htmlunit.WebAssert;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import hudson.model.FreeStyleProject;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.*;
import org.jvnet.hudson.test.JenkinsRule;

import static org.junit.Assert.*;

/**
 * @author victor.martinez.
 */
public class JenkinsLintActionTestCase {

    private static final String EMPTY_TABLE = "<tbody id=\"jenkinsLintTableBody\"></tbody></table>";
    private static final String URL = "jenkinslint";

    @Rule
    public JenkinsRule j = new JenkinsRule();
    @Test
    public void testEmptyJob() throws Exception {
        HtmlPage page = j.createWebClient().goTo(URL);
        WebAssert.assertTextPresent(page, "JenkinsLint");
        assertTrue(page.getWebResponse().getContentAsString().contains(EMPTY_TABLE));
    }
    //Issue("JENKINS-29418")
    @Test
    public void testJob() throws Exception {
        String jobName = "JOB";
        FreeStyleProject project = j.createFreeStyleProject(jobName);
        HtmlPage page = j.createWebClient().goTo(URL);
        //System.out.println(page.getWebResponse().getContentAsString());
        //System.out.println("URL " + j.getURL().toString() + project.getUrl());
        WebAssert.assertTextPresent(page, "JenkinsLint");
        assertFalse(page.getWebResponse().getContentAsString().contains(EMPTY_TABLE));
        assertTrue(page.getWebResponse().getContentAsString().contains(jobTable(j.getURL().toString() + project.getUrl(), jobName)));
    }

    private String jobTable (String url, String jobName){
        return "<tbody id=\"jenkinsLintTableBody\"><tr><td><a href=\""+ url +"\" target=\"_blank\">"+jobName+"</a></td>";
    }
}

@@ -1502,17 +1502,8 @@
 ins(
-jobTable(
 j.ge
@@ -1542,207 +1542,10 @@
 rl()
-, jobName)));%0A    %7D%0A%0A    private String jobTable (String url, String jobName)%7B%0A        return %22%3Ctbody id=%5C%22jenkinsLintTableBody%5C%22%3E%3Ctr%3E%3Ctd%3E%3Ca href=%5C%22%22+ url +%22%5C%22 target=%5C%22_blank%5C%22%3E%22+jobName+%22%3C/a%3E%3C/td%3E%22
+))
 ;%0A  

Check whether the Job is part of the table