-
Notifications
You must be signed in to change notification settings - Fork 39
/
add-complete-delete-batched.js
76 lines (60 loc) · 1.19 KB
/
add-complete-delete-batched.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
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)
{
return [
{
name: 'Adding ' + numItems + ' Items',
work: add(numItems)
},
{
name: 'Completing All Items',
work: clickAll('.toggle')
},
{
name: 'Deleting All Items',
work: clickAll('.destroy')
}
];
}
function add(numItems)
{
return function(facts)
{
var node = facts.input;
for (var i = 0; i < numItems; i++)
{
var inputEvent = document.createEvent('Event');
inputEvent.initEvent('input', true, true);
node.value = 'Do task ' + i;
node.dispatchEvent(inputEvent);
var keydownEvent = document.createEvent('Event');
keydownEvent.initEvent('keydown', true, true);
keydownEvent.keyCode = 13;
node.dispatchEvent(keydownEvent);
}
};
}
function clickAll(selector)
{
return function(facts)
{
var checkboxes = facts.doc.querySelectorAll(selector);
for (var i = 0; i < checkboxes.length; i++)
{
checkboxes[i].click();
}
};
}
// SUITE
return {
getFacts: getFacts,
steps: addCompleteDeleteSteps(100)
};
}();