Skip to content

Commit a7159c1

Browse files
Added recorder for text fill in, record initial route.
1 parent 3415f78 commit a7159c1

File tree

3 files changed

+109
-32
lines changed

3 files changed

+109
-32
lines changed

app/components/test-recorder.js

Lines changed: 71 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ export default Ember.Component.extend({
6464
*/
6565
didInsertElement: function () {
6666

67+
var route = this.get("currentRouteName") === 'index' ? '/' : this.get("currentRouteName");
68+
this.set("generatedScript", 'visit("' + route + '");<br>');
69+
6770
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
6871

6972
//listen to clicks on ember items, apart from
@@ -74,42 +77,44 @@ export default Ember.Component.extend({
7477
var currentNestedLevel = 0; //tracks the nesting level for mutations
7578

7679
/**
77-
* This is a helper function extension of jquery to give us a dynamic path incase the user hasn't given an
78-
* interactive element an ID. We then use this path to repeat the user action in a test case.
80+
* this is used for capturing text input fill-ins
7981
*/
80-
Ember.$.fn.extend({
81-
path: function () {
82-
83-
if (this.length !== 1) {
84-
throw 'Requires one element.';
85-
}
86-
87-
var path, node = this;
88-
//this is just to get the path if the user interacts with a non user given id object
89-
//we stop at body as qunit tests find statement is relative to the #ember-testing div
90-
while (node.length && node[0].localName !== 'body') {
91-
var realNode = node[0], name = realNode.localName;
92-
if (!name) {
93-
break;
94-
}
95-
name = name.toLowerCase();
96-
97-
var parent = node.parent();
98-
99-
var siblings = parent.children(name);
100-
if (siblings.length > 1) {
101-
name += ':eq(' + siblings.index(realNode) + ')';
82+
Ember.$('input').on('focusout', function (e) {
83+
84+
if (e.target.localName === 'input' && e.target.type === 'text') {
85+
86+
var $target = $(e.target);
87+
var $emberTarget = $target.is(emberSelector) ? $target : $target.parent(emberSelector);
88+
if ($emberTarget.length) {
89+
// we don't want to output a click (#ember123) as this is not reliable
90+
var hasEmberIdRegex = /ember[\d]+/;
91+
if (e.target.id && !hasEmberIdRegex.test(e.target.id)) {
92+
var pathPrint = "#" + e.target.id;
93+
} else {
94+
//print the nasty DOM path instead, to avoid give your element its own id
95+
var pathPrint = $emberTarget.path();
96+
}
97+
98+
var newTestPrint = 'fillIn("' + pathPrint + '", " ' + e.target.value + '");<br/>'
99+
100+
//add to existing tests
101+
self.set("generatedScript", self.get("generatedScript") + newTestPrint);
102+
103+
//wrap in <pre> block to make code well formatted
104+
self.set("renderedScript", '<pre>' + self.get("generatedScript") + '</pre>');
105+
} else {
106+
return;
102107
}
103-
104-
path = name + (path ? '>' + path : '');
105-
node = parent;
106108
}
107-
108-
return path;
109109
}
110-
});
110+
);
111+
111112
Ember.$(document).on('click', function (e) {
112113

114+
if (e.target.localName === 'input' && e.target.type === 'text') {
115+
return; //for text inputs we capture mouse out and use this to generate a fillIn test helper
116+
}
117+
113118
//clear this if not DOM mutations happen ()
114119
var cleanText = self.get("generatedScript").replace(self.get("MUTATIONS_PLACEHOLDER"), "");
115120
self.set("generatedScript", cleanText);
@@ -270,3 +275,39 @@ function filterDoNotRecordAndWhiteSpace(node) {
270275
var hasDoNotRecordClass = classListArray ? (classListArray.indexOf("doNotRecord") !== -1) : false;
271276
return node.nodeType !== 3 && !hasDoNotRecordClass;
272277
}
278+
279+
/**
280+
* This is a helper function extension of jquery to give us a dynamic path incase the user hasn't given an
281+
* interactive element an ID. We then use this path to repeat the user action in a test case.
282+
*/
283+
Ember.$.fn.extend({
284+
path: function () {
285+
286+
if (this.length !== 1) {
287+
throw 'Requires one element.';
288+
}
289+
290+
var path, node = this;
291+
//this is just to get the path if the user interacts with a non user given id object
292+
//we stop at body as qunit tests find statement is relative to the #ember-testing div
293+
while (node.length && node[0].localName !== 'body') {
294+
var realNode = node[0], name = realNode.localName;
295+
if (!name) {
296+
break;
297+
}
298+
name = name.toLowerCase();
299+
300+
var parent = node.parent();
301+
302+
var siblings = parent.children(name);
303+
if (siblings.length > 1) {
304+
name += ':eq(' + siblings.index(realNode) + ')';
305+
}
306+
307+
path = name + (path ? '>' + path : '');
308+
node = parent;
309+
}
310+
311+
return path;
312+
}
313+
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ember-cli-test-recorder",
3-
"version": "0.0.8",
3+
"version": "0.1.0",
44
"description": "The default blueprint for ember-cli addons.",
55
"directories": {
66
"doc": "doc",

tests/acceptance/test-playback-test.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,18 @@ module('Acceptance: TestPlayback', {
2424
*/
2525
test('Playback code', function (assert) {
2626
//assume that the user starts on index
27-
visit('/');
27+
visit("/");
28+
fillIn("#register-input-1", " wd");
29+
click("div:eq(0)>form>input:eq(0)");
30+
andThen(function () {
31+
32+
});
33+
34+
click("div:eq(0)>form>input:eq(1)");
35+
andThen(function () {
36+
37+
});
38+
2839
click("div:eq(0)>header>button:eq(1)");
2940
andThen(function () {
3041
assert.equal(currentRouteName(), "foo", "The page navigates to foo on button click");
@@ -33,6 +44,17 @@ test('Playback code', function (assert) {
3344

3445
});
3546

47+
click("#foobtn");
48+
andThen(function () {
49+
assert.equal(find("#toggle-component-login-p").length, 0, "toggle-component-login-p removed AFTER user [INSERT REASON]");
50+
51+
});
52+
53+
click("div:eq(0)");
54+
andThen(function () {
55+
56+
});
57+
3658
click("div:eq(0)>header>button:eq(0)");
3759
andThen(function () {
3860
assert.equal(currentRouteName(), "index", "The page navigates to index on button click");
@@ -41,5 +63,19 @@ test('Playback code', function (assert) {
4163

4264
});
4365

66+
click("div:eq(0)");
67+
andThen(function () {
68+
69+
});
70+
71+
click("div:eq(0)");
72+
andThen(function () {
73+
74+
});
75+
76+
click("div:eq(0)");
77+
andThen(function () {
78+
79+
});
4480

4581
});

0 commit comments

Comments
 (0)