| 
 | 1 | +/*  | 
 | 2 | + * Copyright (c) 2002-2025 Gargoyle Software Inc.  | 
 | 3 | + *  | 
 | 4 | + * Licensed under the Apache License, Version 2.0 (the "License");  | 
 | 5 | + * you may not use this file except in compliance with the License.  | 
 | 6 | + * You may obtain a copy of the License at  | 
 | 7 | + * https://www.apache.org/licenses/LICENSE-2.0  | 
 | 8 | + *  | 
 | 9 | + * Unless required by applicable law or agreed to in writing, software  | 
 | 10 | + * distributed under the License is distributed on an "AS IS" BASIS,  | 
 | 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  | 
 | 12 | + * See the License for the specific language governing permissions and  | 
 | 13 | + * limitations under the License.  | 
 | 14 | + */  | 
 | 15 | +package org.htmlunit.libraries;  | 
 | 16 | + | 
 | 17 | +import java.net.URL;  | 
 | 18 | + | 
 | 19 | +import org.eclipse.jetty.server.Server;  | 
 | 20 | +import org.htmlunit.WebDriverTestCase;  | 
 | 21 | +import org.htmlunit.WebServerTestCase;  | 
 | 22 | +import org.htmlunit.junit.BrowserRunner;  | 
 | 23 | +import org.htmlunit.junit.BrowserRunner.Alerts;  | 
 | 24 | +import org.htmlunit.junit.BrowserRunner.HtmlUnitNYI;  | 
 | 25 | +import org.junit.AfterClass;  | 
 | 26 | +import org.junit.BeforeClass;  | 
 | 27 | +import org.junit.Test;  | 
 | 28 | +import org.junit.runner.RunWith;  | 
 | 29 | +import org.openqa.selenium.By;  | 
 | 30 | +import org.openqa.selenium.WebDriver;  | 
 | 31 | + | 
 | 32 | +/**  | 
 | 33 | + * Tests for https://github.com/slab/quill.  | 
 | 34 | + *  | 
 | 35 | + * @author Ronald Brill  | 
 | 36 | + */  | 
 | 37 | +@RunWith(BrowserRunner.class)  | 
 | 38 | +public class QuillTest extends WebDriverTestCase {  | 
 | 39 | + | 
 | 40 | +    /** The server. */  | 
 | 41 | +    protected static Server SERVER_;  | 
 | 42 | + | 
 | 43 | +    /**  | 
 | 44 | +     * @throws Exception if an error occurs  | 
 | 45 | +     */  | 
 | 46 | +    @BeforeClass  | 
 | 47 | +    public static void startSesrver() throws Exception {  | 
 | 48 | +        SERVER_ = WebServerTestCase.createWebServer("src/test/resources/libraries/quill/", null);  | 
 | 49 | +    }  | 
 | 50 | + | 
 | 51 | +    /**  | 
 | 52 | +     * @throws Exception if an error occurs  | 
 | 53 | +     */  | 
 | 54 | +    @AfterClass  | 
 | 55 | +    public static void stopServer() throws Exception {  | 
 | 56 | +        if (SERVER_ != null) {  | 
 | 57 | +            SERVER_.stop();  | 
 | 58 | +            SERVER_.destroy();  | 
 | 59 | +            SERVER_ = null;  | 
 | 60 | +        }  | 
 | 61 | +    }  | 
 | 62 | + | 
 | 63 | +    /**  | 
 | 64 | +     * @return the resource base URL  | 
 | 65 | +     */  | 
 | 66 | +    protected URL getBaseUrl() {  | 
 | 67 | +        return URL_FIRST;  | 
 | 68 | +    }  | 
 | 69 | + | 
 | 70 | +    /**  | 
 | 71 | +     * @throws Exception if the test fails  | 
 | 72 | +     */  | 
 | 73 | +    @Test  | 
 | 74 | +    @Alerts("Bold Italic\\nHello World!\\nSome initial bold text")  | 
 | 75 | +    @HtmlUnitNYI  | 
 | 76 | +    public void basic() throws Exception {  | 
 | 77 | +        // fails because the lib uses classes  | 
 | 78 | +        doTest("QuillTest.html");  | 
 | 79 | +    }  | 
 | 80 | + | 
 | 81 | +    private void doTest(final String filename) throws Exception {  | 
 | 82 | +        final WebDriver driver = getWebDriver();  | 
 | 83 | +        driver.get(getBaseUrl() + filename);  | 
 | 84 | + | 
 | 85 | +        String content = driver.findElement(By.tagName("body")).getText();  | 
 | 86 | +        content = content.replace("\r", "").replace("\n", "\\n");  | 
 | 87 | +        assertEquals(getExpectedAlerts()[0], content);  | 
 | 88 | +    }  | 
 | 89 | +}  | 
0 commit comments