forked from tastejs/todomvc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testOperations.js
103 lines (84 loc) · 3.82 KB
/
testOperations.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
'use strict';
function TestOperations(page) {
this.assertItemInputFocused = function () {
return page.waitForFocusedElement(page.getEditingListItemInputCss(), 'Expected the item input to be focused');
};
this.assertNewInputFocused = function () {
return page.waitForFocusedElement(page.getNewInputCss());
};
this.assertNewInputBlurred = function () {
return page.waitForBlurredElement(page.getNewInputCss());
};
this.assertItemCount = function (itemCount) {
return itemCount === 0 ?
page.waitForMainSectionRemovedOrEmpty() :
page.waitForListItemCount(itemCount);
};
this.assertClearCompleteButtonText = function (buttonText) {
return page.waitForClearCompleteButton()
.then(page.waitForTextContent.bind(page, buttonText, 'Expected clear button text to be ' + buttonText));
};
this.assertClearCompleteButtonVisibility = function (shouldBeVisible) {
var failMsg = 'Expected the clear completed items button to be ' + (shouldBeVisible ? 'visible' : 'hidden');
return page.waitForVisibility(shouldBeVisible, page.getClearCompletedButtonCss(), failMsg);
};
this.assertMainSectionVisibility = function (shouldBeVisible) {
var failMsg = 'Expected main section to be ' + (shouldBeVisible ? 'visible' : 'hidden');
return page.waitForVisibility(shouldBeVisible, page.getMainSectionCss(), failMsg);
};
this.assertFooterVisibility = function (shouldBeVisible) {
var failMsg = 'Expected footer to be ' + (shouldBeVisible ? 'visible' : 'hidden');
return page.waitForVisibility(shouldBeVisible, page.getFooterSectionCss(), failMsg);
};
this.assertItemToggleIsHidden = function (index) {
return page.waitForVisibility(false, page.getListItemToggleCss(index),
'Expected the item toggle button to be hidden');
};
this.assertItemLabelIsHidden = function (index) {
return page.waitForVisibility(false, page.getListItemLabelCss(index), 'Expected the item label to be hidden');
};
this.assertNewItemInputFieldText = function (text) {
return page.waitForNewItemInputField()
.then(page.waitForTextContent.bind(page, text,
'Expected the new item input text field contents to be ' + text));
};
this.assertItemText = function (itemIndex, text) {
return page.waitForItemLabel(itemIndex)
.then(page.waitForTextContent.bind(page, text, 'Expected the item label to be ' + text));
};
this.assertItems = function (textArray) {
return page.getListItems().then(function (items) {
if (items.length < textArray.length) {
// This means that the framework removes rather than hides list items
textArray = textArray.filter(function (item) { return item !== page.ITEM_HIDDEN_OR_REMOVED; });
}
var ret;
textArray.forEach(function (text, i) {
if (text === page.ITEM_HIDDEN_OR_REMOVED) { return; }
var promise = page.waitForTextContent(text, 'Expected item text to be ' + text, items[i]);
ret = ret ? ret.then(promise) : promise;
});
return ret;
});
};
this.assertItemCountText = function (text) {
return page.waitForElement(page.getItemCountCss())
.then(page.waitForTextContent.bind(page, text, 'Expected item count text to be ' + text));
};
this.assertItemCompletedStates = function (completedStates) {
return page.waitForElement(
page.getListItemsWithCompletedStatesCss(completedStates),
'Item completed states were incorrect');
};
this.assertFilterAtIndexIsSelected = function (selectedIndex) {
return page.waitForElement(
page.getSelectedFilterCss(selectedIndex),
'Expexted the filter / route at index ' + selectedIndex + ' to be selected');
};
this.assertCompleteAllCheckedStatus = function (shouldBeChecked) {
var failMsg = 'Expected the mark-all-completed checkbox to be ' + shouldBeChecked ? 'checked' : 'unchecked';
return page.waitForMarkAllCompletedCheckBox()
.then(page.waitForCheckedStatus.bind(page, shouldBeChecked, failMsg));
};
}
module.exports = TestOperations;