This repository has been archived by the owner on Feb 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
application.spec.js
184 lines (158 loc) · 6.43 KB
/
application.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
var app = require("../../../server");
var PORT = process.env.FUNC_PORT || 3003;
var HOST = process.env.TEST_HOST || "http://127.0.0.1:" + PORT;
// WD helpers.
// https://github.com/admc/wd/blob/master/lib/special-keys.js
var wd = require("wd");
var ENTER_KEY = wd.SPECIAL_KEYS.Enter;
// Rowdy helpers and adapter.
var rowdy = require("rowdy");
var adapter = rowdy.adapters.mocha;
var helpers = rowdy.helpers;
describe("func/application", function () {
var client;
var server;
// --------------------------------------------------------------------------
// Mocha
// --------------------------------------------------------------------------
// Set a Mocha global timeout of 10 seconds to allow for test wonkiness.
this.timeout(10000);
// --------------------------------------------------------------------------
// Selenium (WD.js/Rowdy) initialization
// --------------------------------------------------------------------------
// We use WD.js to get a client to Selenium, and Rowdy to help configure our
// client, start a local selenium server if specified and provide a Mocha
// adater.
//
// For multi-file tests this setup should be extracted to a `base.spec.js`
// file and executed **once** for the entire test suite.
adapter.before();
adapter.beforeEach();
adapter.afterEach();
adapter.after();
before(function (done) {
// The `adapter.before();` call has the side effect of instantiating a
// Selenium / WD.js client that we can extract here.
client = adapter.client;
// Set a global Selenium timeout that is _before_ our test timeout.
client
.setImplicitWaitTimeout(200)
.nodeify(done);
});
// --------------------------------------------------------------------------
// Dev. Server
// --------------------------------------------------------------------------
// Start up (and later stop) a single instance of the server so that we can
// interact with the web application via our tests.
//
// An alternative to this approach is to hit a live running staging or
// production server for "smoke" tests.
//
// For multi-file tests this setup should be extracted to a `base.spec.js`
// file and executed **once** for the entire test suite.
before(function (done) {
// Start the dev. server.
app.serveRoot();
server = app.listen(PORT, done);
});
after(function (done) {
if (!server) { return done(); }
server.close(done);
});
// --------------------------------------------------------------------------
// Suites
// --------------------------------------------------------------------------
describe("camel", function () {
it("should convert complex input w/ extra spaces + click", function (done) {
client
// Get the web application page.
.get(HOST)
// Check we start with empty text.
// **Note**: _Could_ do this in all tests, but we'll just do it 1x here.
.waitForElementByCss(".js-input")
.text()
.then(function (text) {
expect(text).to.equal("");
})
// Type a complex string.
.waitForElementByCss(".js-input")
.type(" my new-string_rocks")
// Select the "Convert" button and click it.
.waitForElementByCss(".js-submit")
.click()
// Verify the conversion
.waitForElementByCss(".panel-body")
.text()
.then(function (text) {
expect(text).to.equal("myNewStringRocks");
})
// ... and we're done!
.nodeify(done);
});
// ------------------------------------------------------------------------
// WORKSHOP: IMPLEMENT_TESTS
// ------------------------------------------------------------------------
it("should display result for empty input");
it("should convert simple input 'hi there' to 'hiThere'");
});
describe("snake", function () {
// ------------------------------------------------------------------------
// WORKSHOP: IMPLEMENT_TESTS
// ------------------------------------------------------------------------
it("should display result for empty input");
it("should convert simple input 'hi there' to 'hi_there'");
});
describe("dash", function () {
// ------------------------------------------------------------------------
// WORKSHOP: IMPLEMENT_TESTS
// ------------------------------------------------------------------------
it("should display result for empty input");
it("should convert simple input 'hi there' to 'hi-there'");
});
describe("all the things", function () {
it("should convert complex input w/ enter key", function (done) {
client
// Get the web application page.
.get(HOST)
// Click the conversion types drowpdown.
.waitForElementByCss(".js-convert-label")
.click()
// Click the "all the things" option.
.waitForElementByCss(
".js-convert-types[data-convert='camel,snake,dash']")
.click()
// Type a complex string and the "enter key" to invoke a conversion.
.waitForElementByCss(".js-input")
.type(" all_the things!" + ENTER_KEY)
// Get all of the result panels using JavaScript!
.safeEval(helpers.js.fn(function () {
/*global $*/
// This is a **client-side** JavaScript function, returning values
// from the web application page.
//
// Here, we're going to extract the three values from converting to
// all the different types.
return $(".panel-body")
.map(function () { return $(this).text(); })
.toArray();
}))
.then(function (values) {
// Here's a tricky part -- our conversion results can come back in
// any order. So, we either have to sort on the array, or check that
// the array contains values in any position.
expect(values)
.to.have.length(3).and
.to.contain("allTheThings!").and
.to.contain("all-the-things!").and
.to.contain("all_the_things!");
})
// ... and we're done!
.nodeify(done);
});
// ------------------------------------------------------------------------
// WORKSHOP: IMPLEMENT_TESTS
// ------------------------------------------------------------------------
it("should display three empty results for empty input");
it("should convert simple input 'hi there' using a click on 'Convert'");
});
});