package pl.matsuo.gitlab.controller;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import pl.matsuo.gitlab.file.YamlFileConverterProvider;
import pl.matsuo.gitlab.hook.PushEvent;
import pl.matsuo.gitlab.hook.Repository;
import pl.matsuo.gitlab.service.build.BuildServiceImpl;
import pl.matsuo.gitlab.service.build.jekyll.JekyllPartialBuilder;
import pl.matsuo.gitlab.service.db.MapDbDatabase;
import pl.matsuo.gitlab.service.git.GitRepositoryServiceImpl;
import pl.matsuo.gitlab.service.mustashe.GenerateContentServiceImpl;

import static org.junit.Assert.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;


/**
 * Created by marek on 04.07.15.
 */
@ContextConfiguration(classes = { BuildServiceImpl.class, MapDbDatabase.class, GitRepositoryServiceImpl.class,
                                  JekyllPartialBuilder.class, YamlFileConverterProvider.class, WebViewController.class,
                                  GenerateContentServiceImpl.class})
public class TestWebViewController extends AbstractControllerRequestTest {


  @Autowired
  BuildServiceImpl buildService;
  @Autowired
  WebViewController controller;


  @Test
  public void testGetRequest() throws Exception {
    PushEvent pushEvent = new PushEvent();
    pushEvent.setRepository(new Repository());
    pushEvent.getRepository().setUrl("ssh://github.com/tunguski/kosher.git");
    pushEvent.getRepository().setGit_http_url("http://github.com/tunguski/kosher.git");
    pushEvent.getRepository().setGit_ssh_url("git@github.com:tunguski/kosher.git");
    pushEvent.setRef("refs/heads/master");
    pushEvent.setAfter("78af4d73667e3ef4bbb06e82270e0015a1f251ea");

    buildService.pushEvent(pushEvent);

    performAndCheckStatus(get("/tunguski/kosher/master/index.html"), status().isOk(),
        html -> System.out.println("----\n" + html + "\n----"),
        html -> assertTrue(html.contains("<h1>Test!</h1>")));

//    performAndCheckStatus(get("/tunguski/kosher/master/markdown.html"), status().isOk(),
//        html -> System.out.println("----\n" + html + "\n----"),
//        // link relativeness
//        html -> assertTrue(html.contains("<link rel=\"stylesheet\" type=\"text/css\" href=\"./css/main.css\">")),
//        // link relativeness
//        html -> assertTrue(html.contains("window.base_mustache = './';")),
//        // lists and bold
//        html -> assertTrue(html.contains("<li><strong>two</strong></li>")),
//        // headers
//        html -> assertTrue(html.contains("<h2>Complex table with strong and italic</h2>")),
//        // conditional parts
//        html -> assertTrue(html.contains("<div class=\"col-sm-12 col-md-4 col-lg-4 page-menu\">")),
//        // conditional parts
//        html -> assertTrue(html.contains("<div class=\"col-sm-12 col-md-8 col-lg-8 project-description\">")),
//        // tables
//        html -> assertTrue(html.contains("<th>col3</th>")),
//        // minus sign in table
//        html -> assertTrue(html.contains("<td>- </td>")),
//        // links
//        html -> assertTrue(html.contains("<a href=\"tunguski.github.io\">Some link</a>"))
//    );

    performAndCheckStatus(get("/tunguski/kosher/master/branch_master.html"), status().isOk(),
        html -> System.out.println("----\n" + html + "\n----"),
        html -> assertTrue(html.contains("tunguski - kosher - master")));
  }
}


@@ -2099,18 +2099,16 @@
 %3E%22)));%0A%0A
-//
     perf
@@ -2188,18 +2188,16 @@
 isOk(),%0A
-//
         
@@ -2252,18 +2252,16 @@
 ----%22),%0A
-//
         
@@ -2273,34 +2273,32 @@
 nk relativeness%0A
-//
         html -%3E 
@@ -2387,34 +2387,32 @@
 main.css%5C%22%3E%22)),%0A
-//
         // link 
@@ -2424,18 +2424,16 @@
 iveness%0A
-//
         
@@ -2495,26 +2495,24 @@
 = './';%22)),%0A
-//
         // l
@@ -2525,18 +2525,16 @@
 nd bold%0A
-//
         
@@ -2597,26 +2597,24 @@
 g%3E%3C/li%3E%22)),%0A
-//
         // h
@@ -2620,18 +2620,16 @@
 headers%0A
-//
         
@@ -2708,26 +2708,24 @@
 ic%3C/h2%3E%22)),%0A
-//
         // c
@@ -2733,34 +2733,32 @@
 nditional parts%0A
-//
         html -%3E 
@@ -2833,34 +2833,32 @@
 age-menu%5C%22%3E%22)),%0A
-//
         // condi
@@ -2870,18 +2870,16 @@
 l parts%0A
-//
         
@@ -2974,24 +2974,21 @@
 iption%5C%22
-%3E
 %22)),%0A
-//
         
@@ -2997,18 +2997,16 @@
  tables%0A
-//
         
@@ -3053,26 +3053,24 @@
 l3%3C/th%3E%22)),%0A
-//
         // m
@@ -3088,18 +3088,16 @@
 n table%0A
-//
         
@@ -3146,18 +3146,16 @@
 td%3E%22)),%0A
-//
         
@@ -3163,18 +3163,16 @@
 / links%0A
-//
         
@@ -3253,18 +3253,16 @@
 %3C/a%3E%22))%0A
-//
     );%0A%0A

Fix test