Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit 35c4dab

Browse files
Foxandxsskapunahelewong
authored andcommitted
A few e2e tests to start
1 parent 5e1f352 commit 35c4dab

File tree

1 file changed

+150
-0
lines changed

1 file changed

+150
-0
lines changed
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
'use strict'; // necessary for es6 output in node
2+
3+
import { browser, element, by, ExpectedConditions } from 'protractor';
4+
5+
function finalDemoAddressForm(element: any, index: number) {
6+
let form = {
7+
street: element.all(by.css('input[formcontrolname=street]')).get(index).getAttribute('value'),
8+
city: element.all(by.css('input[formcontrolname=city]')).get(index).getAttribute('value'),
9+
state: element.all(by.css('select[formcontrolname=state]')).get(index).getAttribute('value'),
10+
zip: element.all(by.css('input[formcontrolname=zip]')).get(index).getAttribute('value')
11+
};
12+
return form;
13+
}
14+
15+
describe('Reactive forms', function() {
16+
let select: any;
17+
18+
beforeEach(function() {
19+
browser.get('');
20+
select = element(by.css('.container > h4 > select'));
21+
});
22+
23+
describe('navigation', function() {
24+
it('should display the title', function() {
25+
let title = element(by.css('.container > h1'));
26+
expect(title.getText()).toBe('Reactive Forms');
27+
});
28+
29+
it('should contain a dropdown with each example', function() {
30+
expect(select.isDisplayed()).toBe(true);
31+
});
32+
33+
it('should have 8 options for different demos', function() {
34+
let options = select.all(by.tagName('option'));
35+
expect(options.count()).toBe(8);
36+
});
37+
38+
it('should start with Final Demo', function() {
39+
select.getAttribute('value').then(function(demo: string) {
40+
expect(demo).toBe('Final Demo');
41+
});
42+
});
43+
});
44+
45+
describe('final demo', function() {
46+
it('does not select any hero by default', function() {
47+
let heroSection = element(by.css('hero-list > div'));
48+
expect(heroSection.isPresent()).toBe(false);
49+
});
50+
51+
it('refresh the page upon button click', function() {
52+
// We move to another page...
53+
let whirlwindButton = element.all(by.css('nav a')).get(0);
54+
whirlwindButton.click();
55+
let refresh = element(by.css('button'));
56+
refresh.click();
57+
let heroSection = element(by.css('hero-list > div'));
58+
expect(heroSection.isPresent()).toBe(false);
59+
});
60+
61+
describe('Whirlwind form', function() {
62+
beforeEach(function() {
63+
let whirlwindButton = element.all(by.css('nav a')).get(0);
64+
whirlwindButton.click();
65+
});
66+
67+
it('should show a hero information when the button is click', function() {
68+
let editMessage = element(by.css('hero-list > div > h3'));
69+
expect(editMessage.getText()).toBe('Editing: Whirlwind');
70+
});
71+
72+
it('should show a form with the selected hero information', function() {
73+
let nameInput = element(by.css('input[formcontrolname=name]'));
74+
// nameInput.getAttribute('value').then(function(name: string) {
75+
// expect(name).toBe('Whirlwind');
76+
// });
77+
expect(nameInput.getAttribute('value')).toBe('Whirlwind');
78+
let address1 = finalDemoAddressForm(element, 0);
79+
expect(address1.street).toBe('123 Main');
80+
expect(address1.state).toBe('CA');
81+
expect(address1.zip).toBe('94801');
82+
expect(address1.city).toBe('Anywhere');
83+
let address2 = finalDemoAddressForm(element, 1);
84+
expect(address2.street).toBe('456 Maple');
85+
// expect(address2.state).toBe('VA');
86+
expect(address2.zip).toBe('23226');
87+
expect(address2.city).toBe('Somewhere');
88+
});
89+
90+
it('shows a json output from the form', function() {
91+
let json = element(by.css('hero-detail > p'));
92+
expect(json.getText()).toContain('Whirlwind');
93+
expect(json.getText()).toContain('Anywhere');
94+
expect(json.getText()).toContain('Somewhere');
95+
expect(json.getText()).toContain('VA');
96+
});
97+
98+
it('has two disabled buttons by default', function() {
99+
let buttons = element.all(by.css('hero-detail > form > div > button'));
100+
expect(buttons.get(0).getAttribute('disabled')).toBe('true');
101+
expect(buttons.get(1).getAttribute('disabled')).toBe('true');
102+
});
103+
104+
it('enables the buttons after we edit the form', function() {
105+
let nameInput = element(by.css('input[formcontrolname=name]'));
106+
nameInput.sendKeys('a');
107+
let buttons = element.all(by.css('hero-detail > form > div > button'));
108+
expect(buttons.get(0).getAttribute('disabled')).toBeNull();
109+
expect(buttons.get(1).getAttribute('disabled')).toBeNull();
110+
});
111+
112+
it('saves the changes when the save button is click', function() {
113+
let nameInput = element(by.css('input[formcontrolname=name]'));
114+
nameInput.sendKeys('a');
115+
let save = element.all(by.css('hero-detail > form > div > button')).get(0);
116+
save.click();
117+
let editMessage = element(by.css('hero-list > div > h3'));
118+
expect(editMessage.getText()).toBe('Editing: Whirlwinda');
119+
});
120+
121+
it('reverts the changes when the revert button is click', function() {
122+
let nameInput = element(by.css('input[formcontrolname=name]'));
123+
nameInput.sendKeys('a');
124+
let revert = element.all(by.css('hero-detail > form > div > button')).get(1);
125+
revert.click();
126+
let editMessage = element(by.css('hero-list > div > h3'));
127+
expect(editMessage.getText()).toBe('Editing: Whirlwind');
128+
expect(nameInput.getAttribute('value')).toBe('Whirlwind');
129+
});
130+
131+
it('is able to add a new empty address', function() {
132+
let newLairButton = element.all(by.css('button')).get(3);
133+
newLairButton.click();
134+
let address3 = finalDemoAddressForm(element, 2);
135+
expect(address3.street).toBe('');
136+
expect(address3.state).toBe('CA');
137+
expect(address3.zip).toBe('');
138+
expect(address3.city).toBe('');
139+
});
140+
});
141+
142+
describe('Bombasta form', function() {
143+
144+
});
145+
146+
describe('Magneta form', function() {
147+
148+
});
149+
});
150+
});

0 commit comments

Comments
 (0)