Skip to content

Commit

Permalink
test(TypeScript): add tests for endpoint class-like wrappers (#718)
Browse files Browse the repository at this point in the history
* test(TypeScript): add tests for endpoint class-like wrappers

Connected to vaadin/flow#7176
Depends on vaadin/flow#9972

* fix: uncomment import line for missing AppEndpoint
  • Loading branch information
platosha authored Feb 15, 2021
1 parent 9715ea2 commit 6db5bbf
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { css, customElement, html, LitElement, property } from 'lit-element';

import * as appEndpoint from './generated/AppEndpoint';
import {AppEndpoint} from "./generated/AppEndpoint";

@customElement('main-view')
export class MainView extends LitElement {
Expand All @@ -11,6 +12,7 @@ export class MainView extends LitElement {
render() {
return html`
<button id="helloAnonymous" @click="${this.helloAnonymous}">endpoint helloAnonymous</button><br/>
<button id="helloAnonymousWrapper" @click="${this.helloAnonymousWrapper}">endpoint AppEndpoint.helloAnonymous</button><br/>
<div id="content">${this.content}</div>
`;
}
Expand All @@ -23,6 +25,14 @@ export class MainView extends LitElement {
}
}

async helloAnonymousWrapper() {
try {
this.content = await AppEndpoint.helloAnonymous();
} catch (error) {
this.content = 'Error:' + error;
}
}

static get styles() {
return [
css`
Expand All @@ -34,3 +44,4 @@ export class MainView extends LitElement {
];
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,24 @@ public void should_requestAnonymously_connect_service() {
25);
}

@Test
public void should_requestAnonymously_endpoint_wrapper() {
TestBenchElement button = mainView.$(TestBenchElement.class)
.id("helloAnonymousWrapper");
button.click();

// Wait for the server connect response
waitUntil(ExpectedConditions.textToBePresentInElement(
mainView.$(TestBenchElement.class).id("content"),
"Hello, stranger!"), 25);

// verify that the custom Connect client works
waitUntil(
ExpectedConditions.textMatches(By.id("log"), Pattern.compile(
"\\[LOG] AppEndpoint/helloAnonymous took \\d+ ms")),
25);
}

@Test
public void should_requestAnonymously_after_logout() throws Exception {
String originalCsrfToken = executeScript(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import { PolymerElement } from '@polymer/polymer/polymer-element.js';
import { html } from '@polymer/polymer/lib/utils/html-tag.js';
import * as appEndpoint from '../generated/AppEndpoint';
import * as packagePrivateEndpoint from '../generated/PackagePrivateEndpoint';
import {AppEndpoint} from "../generated/AppEndpoint";

class TestComponent extends PolymerElement {
static get template() {
return html`
<button id="button">vaadin hello</button><br/>
<button id="hello" on-click="hello">endpoint hello</button><br/>
<button id="helloAnonymous" on-click="helloAnonymous">endpoint helloAnonymous</button><br/>
<button id="helloAnonymousWrapper" on-click="helloAnonymousWrapper">endpoint AppEndpoint.helloAnonymous</button><br/>
<button id="echoWithOptional" on-click="echoWithOptional">endpoint echoWithOptional</button><br/>
<button id="helloAdmin" on-click="helloAdmin">endpoint helloAdmin</button><br/>
<button id="checkUser" on-click="checkUser">endpoint checkUser</button><br/>
Expand Down Expand Up @@ -47,6 +49,13 @@ class TestComponent extends PolymerElement {
.catch(error => this.$.content.textContent = 'Error:' + error);
}

helloAnonymousWrapper(e) {
AppEndpoint
.helloAnonymous()
.then(response => this.$.content.textContent = response)
.catch(error => this.$.content.textContent = 'Error:' + error);
}

helloAnonymousFromPackagePrivateEndpoint(e) {
packagePrivateEndpoint
.helloAnonymous()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void should_load_web_component() {

/**
* Just a control test that assures that webcomponents is working.
*
*
* @throws Exception
*/
@Test
Expand Down Expand Up @@ -96,6 +96,16 @@ public void should_requestAnonymously_connect_service() throws Exception {
verifyContent("Hello, stranger!");
}

@Test
public void should_requestAnonymously_endpoint_wrapper() throws Exception {
WebElement button = testComponent.$(TestBenchElement.class)
.id("helloAnonymousWrapper");
button.click();

// Wait for the server connect response
verifyContent("Hello, stranger!");
}

@Test
public void should_requestAnonymously_packagePrivate_connect_service()
throws Exception {
Expand Down

0 comments on commit 6db5bbf

Please sign in to comment.