Search in sources :

Example 11 with PwaConfiguration

use of com.vaadin.flow.server.PwaConfiguration in project flow by vaadin.

the class TaskUpdateViteTest method usedSettings_matchThoseCreatedToSettingsFile.

@Test
public void usedSettings_matchThoseCreatedToSettingsFile() throws IOException {
    TaskUpdateVite task = new TaskUpdateVite(temporaryFolder.getRoot(), "build");
    task.execute();
    File generatedConfigFile = new File(temporaryFolder.getRoot(), FrontendUtils.VITE_GENERATED_CONFIG);
    String template = IOUtils.toString(generatedConfigFile.toURI(), StandardCharsets.UTF_8);
    NodeTasks.Builder builder = new NodeTasks.Builder(Mockito.mock(Lookup.class), temporaryFolder.getRoot(), temporaryFolder.newFolder("generated"), temporaryFolder.newFolder("frontend"), "target");
    TaskUpdateSettingsFile updateSettings = new TaskUpdateSettingsFile(builder, "theme", new PwaConfiguration());
    updateSettings.execute();
    File settings = new File(temporaryFolder.getRoot(), "target/" + DEV_SETTINGS_FILE);
    JsonObject settingsJson = Json.parse(IOUtils.toString(settings.toURI(), StandardCharsets.UTF_8));
    final Matcher matcher = Pattern.compile("settings\\.(?!json)([a-zA-z]*)").matcher(template);
    StringBuilder faulty = new StringBuilder();
    while (matcher.find()) {
        if (!settingsJson.hasKey(matcher.group(1))) {
            faulty.append(matcher.group(1)).append('\n');
        }
    }
    Assert.assertTrue("Configuration uses settings keys\n" + faulty + "that are not generated in settings file.", faulty.toString().isEmpty());
}
Also used : PwaConfiguration(com.vaadin.flow.server.PwaConfiguration) Matcher(java.util.regex.Matcher) JsonObject(elemental.json.JsonObject) Lookup(com.vaadin.flow.di.Lookup) File(java.io.File) Test(org.junit.Test)

Example 12 with PwaConfiguration

use of com.vaadin.flow.server.PwaConfiguration in project flow by vaadin.

the class AbstractScannerPwaTest method should_findPwaOnAppShell.

@Test
public void should_findPwaOnAppShell() throws Exception {
    PwaConfiguration pwaConfiguration = getPwaConfiguration(AppShellWithPwa.class);
    assertEquals("PWA Application", pwaConfiguration.getAppName());
    assertEquals("PWA", pwaConfiguration.getShortName());
    assertEquals("Testing PWA", pwaConfiguration.getDescription());
    assertEquals("minimal-ui", pwaConfiguration.getDisplay());
    assertEquals("#eee", pwaConfiguration.getBackgroundColor());
    assertEquals("#369", pwaConfiguration.getThemeColor());
    assertEquals("pwa.png", pwaConfiguration.getIconPath());
    assertEquals("appmanifest.json", pwaConfiguration.getManifestPath());
    assertEquals("pwa.html", pwaConfiguration.getOfflinePath());
    String[] expectedOfflineResources = { "pwa.js", "pwa.css" };
    assertArrayEquals(expectedOfflineResources, pwaConfiguration.getOfflineResources().toArray());
}
Also used : PwaConfiguration(com.vaadin.flow.server.PwaConfiguration) Test(org.junit.Test)

Example 13 with PwaConfiguration

use of com.vaadin.flow.server.PwaConfiguration in project flow by vaadin.

the class AbstractScannerPwaTest method should_returnDefaultConfiguration_When_NoAppShell.

@Test
public void should_returnDefaultConfiguration_When_NoAppShell() throws Exception {
    PwaConfiguration pwaConfiguration = getPwaConfiguration(this.getClass());
    assertEquals(PwaConfiguration.DEFAULT_NAME, pwaConfiguration.getAppName());
    assertEquals("Flow PWA", pwaConfiguration.getShortName());
    assertEquals("", pwaConfiguration.getDescription());
    assertEquals(PwaConfiguration.DEFAULT_DISPLAY, pwaConfiguration.getDisplay());
    assertEquals(PwaConfiguration.DEFAULT_BACKGROUND_COLOR, pwaConfiguration.getBackgroundColor());
    assertEquals(PwaConfiguration.DEFAULT_THEME_COLOR, pwaConfiguration.getThemeColor());
    assertEquals(PwaConfiguration.DEFAULT_ICON, pwaConfiguration.getIconPath());
    assertEquals(PwaConfiguration.DEFAULT_PATH, pwaConfiguration.getManifestPath());
    assertEquals(PwaConfiguration.DEFAULT_OFFLINE_PATH, pwaConfiguration.getOfflinePath());
    String[] defaultOfflineResources = {};
    assertArrayEquals(defaultOfflineResources, pwaConfiguration.getOfflineResources().toArray());
}
Also used : PwaConfiguration(com.vaadin.flow.server.PwaConfiguration) Test(org.junit.Test)

Aggregations

PwaConfiguration (com.vaadin.flow.server.PwaConfiguration)13 Test (org.junit.Test)10 PwaRegistry (com.vaadin.flow.server.PwaRegistry)3 AppShellConfigurator (com.vaadin.flow.component.page.AppShellConfigurator)2 PWA (com.vaadin.flow.server.PWA)2 File (java.io.File)2 Lookup (com.vaadin.flow.di.Lookup)1 MockVaadinServletService (com.vaadin.flow.server.MockVaadinServletService)1 MockVaadinSession (com.vaadin.flow.server.MockVaadinSession)1 PwaIcon (com.vaadin.flow.server.PwaIcon)1 VaadinResponse (com.vaadin.flow.server.VaadinResponse)1 VaadinServletRequest (com.vaadin.flow.server.VaadinServletRequest)1 VaadinServletService (com.vaadin.flow.server.VaadinServletService)1 VaadinSession (com.vaadin.flow.server.VaadinSession)1 MockDeploymentConfiguration (com.vaadin.tests.util.MockDeploymentConfiguration)1 JsonObject (elemental.json.JsonObject)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 Annotation (java.lang.annotation.Annotation)1