|
15 | 15 | */ |
16 | 16 | package com.vaadin.flow.webcomponent; |
17 | 17 |
|
| 18 | +import java.util.List; |
| 19 | +import java.util.stream.Collectors; |
| 20 | + |
18 | 21 | import org.junit.Assert; |
19 | 22 | import org.junit.Ignore; |
20 | 23 | import org.junit.Test; |
@@ -172,4 +175,50 @@ public void documentCssFonts_fromLocalCssFile_fontNotAppliedToEmbeddedComponent( |
172 | 175 | "Expected no Ostrich font to be applied to embedded component", |
173 | 176 | (Boolean) ostrichFontStylesFoundForEmbedded); |
174 | 177 | } |
| 178 | + |
| 179 | + @Test |
| 180 | + public void documentCssImport_onlyExternalAddedToHeadAsLink() { |
| 181 | + open(); |
| 182 | + checkLogsForErrors(); |
| 183 | + |
| 184 | + final WebElement documentHead = getDriver() |
| 185 | + .findElement(By.xpath("/html/head")); |
| 186 | + final List<WebElement> links = documentHead |
| 187 | + .findElements(By.tagName("link")); |
| 188 | + |
| 189 | + List<String> linkUrls = links.stream() |
| 190 | + .map(link -> link.getAttribute("href")) |
| 191 | + .collect(Collectors.toList()); |
| 192 | + Assert.assertTrue("Missing link for external url", linkUrls |
| 193 | + .contains("https://fonts.googleapis.com/css?family=Poppins")); |
| 194 | + Assert.assertTrue("Link with media query was not found", linkUrls |
| 195 | + .contains("https://fonts.googleapis.com/css?family=Oswald")); |
| 196 | + Assert.assertFalse("Found import that webpack should have resolved", |
| 197 | + linkUrls.contains("docImport.css")); |
| 198 | + |
| 199 | + final List<WebElement> mediaLinks = links.stream() |
| 200 | + .filter(link -> link.getAttribute("href").equals( |
| 201 | + "https://fonts.googleapis.com/css?family=Oswald")) |
| 202 | + .collect(Collectors.toList()); |
| 203 | + Assert.assertFalse("No expected media link found", |
| 204 | + mediaLinks.isEmpty()); |
| 205 | + Assert.assertEquals("Wrong media attribute contents", |
| 206 | + "screen and (orientation:landscape)", |
| 207 | + mediaLinks.get(0).getAttribute("media")); |
| 208 | + } |
| 209 | + |
| 210 | + @Test |
| 211 | + public void stylesCssImport_externalLinkAddedToShadowroot() { |
| 212 | + open(); |
| 213 | + checkLogsForErrors(); |
| 214 | + final TestBenchElement themedComponent = $("themed-component").first(); |
| 215 | + final List<WebElement> links = findInShadowRoot(themedComponent, |
| 216 | + By.tagName("link")); |
| 217 | + |
| 218 | + List<String> linkUrls = links.stream() |
| 219 | + .map(link -> link.getAttribute("href")) |
| 220 | + .collect(Collectors.toList()); |
| 221 | + Assert.assertTrue("Missing link for external url", linkUrls |
| 222 | + .contains("https://fonts.googleapis.com/css?family=Itim")); |
| 223 | + } |
175 | 224 | } |
0 commit comments