package id.ac.tazkia.dosen.controller;

import com.github.javafaker.Faker;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;

import java.text.SimpleDateFormat;

import static org.assertj.core.api.Assertions.assertThat;

public class SuratTugasTests extends BaseSeleniumTests {

    private WebDriver webDriver = new HtmlUnitDriver();

    private Faker faker = new Faker();
    private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

    @Test
    public void testListView() throws Exception {
        webDriver.get(baseUrl + "/surattugas/list");
        assertThat(webDriver.getTitle()).isEqualTo("Aplikasi Dosen :: Surat Tugas");
    }

    @Test
    public void testSubmitFormGagal() throws Exception {
        webDriver.get(baseUrl + "/surattugas/form");
        assertThat(webDriver.getTitle()).isEqualTo("Aplikasi Dosen :: Edit Surat Tugas");

        webDriver.findElement(By.name("noSurat")).submit();
        assertThat(webDriver.getTitle()).isEqualTo("Aplikasi Dosen :: Edit Surat Tugas");
        assertThat(webDriver.getPageSource())
                .contains("may not be null")
                .contains("may not be empty")
                .contains("size must be between 3 and 255");

    }
}

@@ -216,41 +216,150 @@
 er;%0A
-%0Aimport java.text.SimpleDateForma
+import org.openqa.selenium.support.ui.Select;%0A%0Aimport java.text.SimpleDateFormat;%0Aimport java.util.Locale;%0Aimport java.util.concurrent.TimeUni
 t;%0A%0A
@@ -568,16 +568,35 @@
 w Faker(
+new Locale(%22in-ID%22)
 );%0A    p
@@ -1439,11 +1439,945 @@
 ;%0A%0A    %7D
+%0A%0A    @Test%0A    public void testSubmitFormSukses() throws Exception %7B%0A        webDriver.get(baseUrl + %22/surattugas/form%22);%0A        assertThat(webDriver.getTitle()).isEqualTo(%22Aplikasi Dosen :: Edit Surat Tugas%22);%0A%0A        webDriver.findElement(By.name(%22noSurat%22)).sendKeys(faker.letterify(%22SK-???%22));%0A        webDriver.findElement(By.name(%22tanggalMulai%22)).sendKeys(dateFormat.format(faker.date().future(1, TimeUnit.DAYS)));%0A        webDriver.findElement(By.name(%22tanggalSelesai%22)).sendKeys(dateFormat.format(faker.date().future(100, TimeUnit.DAYS)));%0A        new Select(webDriver.findElement(By.name(%22penerima%22)))%0A                .selectByVisibleText(%22Dosen 2%22);%0A        new Select(webDriver.findElement(By.name(%22jenisSurat%22)))%0A                .selectByVisibleText(%22Jenis Surat 1%22);%0A%0A        webDriver.findElement(By.name(%22noSurat%22)).submit();%0A        assertThat(webDriver.getTitle()).isEqualTo(%22Aplikasi Dosen :: Surat Tugas%22);%0A    %7D
 %0A%7D%0A

add test submit form sukses