Skip to content

Commit

Permalink
CCDM: add IT for Flow start() API
Browse files Browse the repository at this point in the history
  • Loading branch information
manolo committed Aug 9, 2019
1 parent e6cfb8b commit 5f12d72
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 21 deletions.
9 changes: 6 additions & 3 deletions flow-tests/test-ccdm/frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
in the browsers that do not support these APIs natively (e.g. IE11) -->
<script src="./VAADIN/build/webcomponentsjs/webcomponents-loader.js"></script>

<div id="content">index.html content</div>
<button onclick="loadContent()">Load content from other bundle</button>
<div id="contentFromOtherBundle"></div>
<button id="button1">Load content from other bundle</button>
<button id="button2">Load flow</button>
<button id="button3">Navigate flow</button>

<div id="div0">index.html content</div>

<!-- index.ts is included here automatically (either by the dev server or during the build) -->
</body>
</html>
37 changes: 32 additions & 5 deletions flow-tests/test-ccdm/frontend/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
window.loadContent = async function() {
import { Flow } from '@vaadin/flow-frontend/Flow';

document.getElementById("button1").addEventListener('click', async e => {
await import('./another-bundle.js');
const label = document.createElement('label');
label.textContent = window.anotherBundle;
document.getElementById('contentFromOtherBundle').appendChild(label);
}
const div = document.createElement('div');
div.id = 'div1';
div.textContent = window.anotherBundle;
document.body.appendChild(div);
});

const flow = new Flow({
imports: () => import('../target/frontend/generated-flow-imports')
});

document.getElementById("button2").addEventListener('click', async e => {
await flow.start();
const bootstrapLoaded = !!window.Vaadin.Flow.initApplication;
const clientLoaded = !!window.Vaadin.Flow.resolveUri;
const remoteMethod = !!document.body.$server.connectClient;
const div = document.createElement('div');
div.id = 'div2';
div.textContent = bootstrapLoaded + " " + clientLoaded + " " + remoteMethod;
document.body.appendChild(div);
});

document.getElementById("button3").addEventListener('click', async e => {
const view = await flow.navigate('my/foo view');
const div = document.createElement('div');
div.id = 'div3';
div.appendChild(view);
document.body.appendChild(div);
});

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import com.vaadin.flow.testutil.ChromeBrowserTest;

Expand All @@ -31,24 +30,24 @@ private void openTestUrl(String url) {
@Test
public void indexHtmlRequestHandler_openRootURL_shouldResponseIndexHtml() {
openTestUrl("/");
waitForElementPresent(By.tagName("div"));
String content = findElement(By.id("content")).getText();
waitForElementPresent(By.id("div0"));
String content = findElement(By.id("div0")).getText();
Assert.assertEquals("index.html content", content);
}

@Test
public void indexHtmlRequestHandler_openRandomRoute_shouldResponseIndexHtml() {
openTestUrl("/abc");
waitForElementPresent(By.tagName("div"));
String content = findElement(By.id("content")).getText();
waitForElementPresent(By.id("div0"));
String content = findElement(By.id("div0")).getText();
Assert.assertEquals("index.html content", content);
}

@Test
public void indexHtmlRequestHandler_openURLHasParameterWithExtension_shouldResponseIndexHtml() {
openTestUrl("/someroute?myparam=picture.png");
waitForElementPresent(By.tagName("div"));
String content = findElement(By.id("content")).getText();
waitForElementPresent(By.id("div0"));
String content = findElement(By.id("div0")).getText();
Assert.assertEquals("index.html content", content);
}

Expand All @@ -62,16 +61,19 @@ public void indexHtmlRequestHandler_openURLWithExtension_shouldNotResponseIndexH
@Test
public void indexHtmlRequestHandler_importDynamically_shouldLoadBundleCorrectly() {
openTestUrl("/");
findElement(By.tagName("button")).click();
WebElement contentFromJs = findElement(By.id("contentFromOtherBundle"));
Assert.assertEquals("Content from other bundle",
contentFromJs.getText());
waitForElementPresent(By.id("button1"));

findElement(By.id("button1")).click();
waitForElementPresent(By.id("div1"));

String content = findElement(By.id("div1")).getText();
Assert.assertEquals("Content from other bundle", content);
}

@Test
public void indexHtmlRequestHandler_openRootURL_shouldAddBaseHref() {
openTestUrl("/");
waitForElementPresent(By.tagName("div"));
waitForElementPresent(By.id("div0"));
// In Selenium, getAttribute('href') won't return the exact value of
// 'href'.
// https://stackoverflow.com/questions/35494519/how-to-get-the-exact-text-of-href-attribute-of-tag-a
Expand All @@ -83,9 +85,35 @@ public void indexHtmlRequestHandler_openRootURL_shouldAddBaseHref() {
@Test
public void indexHtmlRequestHandler_openTwoSlashesURL_shouldAddBaseHrefCorrectly() {
openTestUrl("/abc/xyz");
waitForElementPresent(By.tagName("div"));
waitForElementPresent(By.id("div0"));
String outerHTML = findElement(By.tagName("head"))
.findElement(By.tagName("base")).getAttribute("outerHTML");
Assert.assertTrue(outerHTML.contains("href=\"./..\""));
}

@Test
public void should_startFlow() {
openTestUrl("/");
waitForElementPresent(By.id("button2"));

findElement(By.id("button2")).click();
waitForElementPresent(By.id("div2"));

String content = findElement(By.id("div2")).getText();
Assert.assertEquals("true true true", content);
}

@Test
public void should_connectFlowServerSide() {
openTestUrl("/");
waitForElementPresent(By.id("button3"));


findElement(By.id("button3")).click();
waitForElementPresent(By.id("div3"));

String content = findElement(By.id("div3")).getText();
Assert.assertTrue(content.length() > 0);
}

}
21 changes: 21 additions & 0 deletions flow-tests/test-ccdm/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"sourceMap": true,
"inlineSources": true,
"module": "esNext",
"target": "es2017",
"moduleResolution": "node",
"strict": true,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"noImplicitAny": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"experimentalDecorators": true
},
"include": [
"frontend/**/*.ts", "frontend/index.js"
],
"exclude": []
}

0 comments on commit 5f12d72

Please sign in to comment.