package com.workfusion.odf;

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

import io.webfolder.cdp.Launcher;
import io.webfolder.cdp.session.SessionFactory;
import mockit.Mock;
import mockit.MockUp;
import mockit.Mocked;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import static com.workfusion.odf.HtmlToPdfPrinter.COMPLETION_SUCCESS_MESSAGE;
class HtmlToPdfPrinterTest {

    @Test
    void testSuccessMain(@Mocked  SessionFactory sessionFactory) throws Exception {
        new MockUp<Launcher>(){
            @Mock
            public SessionFactory launch(List<String> arguments){
                return sessionFactory;
            }
        };

        final Path tempFile = Files.createTempFile("delete", "delete");
        java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream();
        System.setOut(new java.io.PrintStream(out));
        HtmlToPdfPrinter.main( "tut.by",   tempFile.toFile().getCanonicalPath() );
        assertTrue(out.toString().contains(tempFile.toFile().getCanonicalPath()));
        assertTrue(out.toString().contains(COMPLETION_SUCCESS_MESSAGE));

        Files.delete(tempFile);
    }

    @Test
    void testFailMain() throws Exception {
        assertThrows(IllegalArgumentException.class, () -> HtmlToPdfPrinter.main( "g "));
        assertThrows(IllegalArgumentException.class, () -> HtmlToPdfPrinter.main( "fdgsb", " k", ""));
        assertThrows(IllegalArgumentException.class, () -> HtmlToPdfPrinter.main( "", ""));
        assertThrows(IllegalArgumentException.class, () -> HtmlToPdfPrinter.main( "", "dzsfh"));
        assertThrows(IllegalArgumentException.class, () -> HtmlToPdfPrinter.main( "dsg", ""));
        assertThrows(IllegalArgumentException.class, () -> HtmlToPdfPrinter.main( "dsg", null));
        assertThrows(IllegalArgumentException.class, () -> HtmlToPdfPrinter.main( null, "dsg"));
    }


    void list() {
        List<String> websitesForTest = new ArrayList<>();
        websitesForTest.add("https://www.tut.by/");
        websitesForTest.add("https://www.yahoo.com/");
        websitesForTest.add("https://www.alibaba.com/");
        websitesForTest.add("https://www.ebay.com/");
        websitesForTest.add("https://www.amazon.com/");
        websitesForTest.add("https://yandex.by/");
        websitesForTest.add("https://www.reddit.com/");
        websitesForTest.add("https://www.bing.com/news");
        websitesForTest.add("https://www.dx.com/");
        websitesForTest.add("https://wccftech.com/");
        websitesForTest.add("https://3dnews.ru/");
        websitesForTest.add("http://www.bbc.com/");
        websitesForTest.add("https://www.euronews.com/");
        websitesForTest.add("https://www.booking.com/");
        websitesForTest.add("https://www.hotels.com/");
        websitesForTest.add("https://news.yahoo.com/");
        websitesForTest.add("https://news.google.com/");
        websitesForTest.add("https://www.huffingtonpost.com/");
        websitesForTest.add("https://cnn.com/");
        websitesForTest.add("https://www.nytimes.com/");
        websitesForTest.add("https://www.foxnews.com/");
        websitesForTest.add("https://www.nbcnews.com/");
        websitesForTest.add("https://www.dailymail.co.uk/");
        websitesForTest.add("https://www.washingtonpost.com");
        websitesForTest.add("https://www.theguardian.com/");
        websitesForTest.add("https://www.wsj.com/");
        websitesForTest.add("https://abcnews.go.com/");
        websitesForTest.add("https://www.bbc.com/news");
        websitesForTest.add("https://www.usatoday.com/");
        websitesForTest.add("https://www.latimes.com/");
    }
}