-
Notifications
You must be signed in to change notification settings - Fork 39
/
add-complete-delete.js
79 lines (59 loc) · 1.31 KB
/
add-complete-delete.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
var suite = function() {
// FACTS
function getFacts(doc)
{
var input = doc.getElementsByClassName('new-todo')[0];
return input ? { doc: doc, input: input } : undefined;
}
// STEPS
function addCompleteDeleteSteps(numItems)
{
var steps = [];
for (var i = 0; i < numItems; i++)
{
steps.push({ name: 'Inputing ' + i, work: inputTodo(i) });
steps.push({ name: 'Entering ' + i, work: pressEnter });
}
for (var i = 0; i < numItems; i++)
{
steps.push({ name: 'Checking ' + i, work: click('toggle', i) });
}
for (var i = 0; i < numItems; i++)
{
steps.push({ name: 'Removing ' + i, work: click('destroy', 0) });
}
return steps;
}
function inputTodo(number)
{
return function(facts)
{
var node = facts.input;
var inputEvent = document.createEvent('Event');
inputEvent.initEvent('input', true, true);
node.value = 'Do task ' + number;
node.dispatchEvent(inputEvent);
};
}
function pressEnter(facts)
{
var event = document.createEvent('Event');
event.initEvent('keydown', true, true);
event.key = 'Enter';
event.keyCode = 13;
event.which = 13;
facts.input.dispatchEvent(event);
}
function click(className, index)
{
return function(facts)
{
facts.doc.getElementsByClassName(className)[index].click();
};
}
// SUITE
return {
getFacts: getFacts,
steps: addCompleteDeleteSteps(100)
};
}();