Skip to content

Commit af02f2b

Browse files
committed
fix(e2e): adds events to hello world static.
Extends e2e test to cover events.
1 parent bf609f0 commit af02f2b

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

modules/examples/e2e_test/hello_world/hello_world_spec.es6

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@ describe('hello world', function () {
99
it('should greet', function() {
1010
browser.get(URL);
1111

12-
expect(getGreetingText('hello-app')).toBe('hello world!');
12+
expect(getComponentText('hello-app', '.greeting')).toBe('hello world!');
13+
});
14+
15+
it('should change greeting', function() {
16+
browser.get(URL);
17+
18+
clickComponentButton('hello-app', '.changeButton');
19+
expect(getComponentText('hello-app', '.greeting')).toBe('howdy world!');
1320
});
1421
});
1522

@@ -19,12 +26,23 @@ describe('hello world', function () {
1926
it('should greet', function() {
2027
browser.get(URL);
2128

22-
expect(getGreetingText('hello-app')).toBe('hello world!');
29+
expect(getComponentText('hello-app', '.greeting')).toBe('hello world!');
30+
});
31+
32+
it('should change greeting', function() {
33+
browser.get(URL);
34+
35+
clickComponentButton('hello-app', '.changeButton');
36+
expect(getComponentText('hello-app', '.greeting')).toBe('howdy world!');
2337
});
2438
});
2539

2640
});
2741

28-
function getGreetingText(selector) {
29-
return browser.executeScript('return document.querySelector("'+selector+'").shadowRoot.firstChild.textContent');
42+
function getComponentText(selector, innerSelector) {
43+
return browser.executeScript('return document.querySelector("'+selector+'").shadowRoot.querySelector("'+innerSelector+'").textContent');
44+
}
45+
46+
function clickComponentButton(selector, innerSelector) {
47+
return browser.executeScript('return document.querySelector("'+selector+'").shadowRoot.querySelector("'+innerSelector+'").click()');
3048
}

modules/examples/src/hello_world/index_common.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import {bootstrap, Component, Decorator, TemplateConfig, NgElement} from 'core/c
2020
// The template for the component.
2121
// Expressions in the template (like {{greeting}}) are evaluated in the
2222
// context of the HelloCmp class below.
23-
inline: `<div>{{greeting}} <span red>world</span>!</div>
24-
<button (click)="changeGreeting()">change greeting</button>`,
23+
inline: `<div class="greeting">{{greeting}} <span red>world</span>!</div>
24+
<button class="changeButton" (click)="changeGreeting()">change greeting</button>`,
2525
// All directives used in the template need to be specified. This allows for
2626
// modularity (RedDec can only be used in this template)
2727
// and better tooling (the template can be invalidated if the attribute is

modules/examples/src/hello_world/index_static.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ function setup() {
1919
componentServices: [app.GreetingService],
2020
template: new TemplateConfig({
2121
directives: [app.RedDec],
22-
inline: `{{greeting}} <span red>world</span>!`})
22+
inline: `<div class="greeting">{{greeting}} <span red>world</span>!</div>
23+
<button class="changeButton" (click)="changeGreeting()">change greeting</button>`})
2324
})]
2425
});
2526

@@ -84,6 +85,10 @@ function setup() {
8485
reflector.registerSetters({
8586
"greeting": (a,v) => a.greeting = v
8687
});
88+
89+
reflector.registerMethods({
90+
"changeGreeting": (obj, args) => obj.changeGreeting()
91+
});
8792
}
8893

8994
export function main() {

0 commit comments

Comments
 (0)