-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathtest.ts
More file actions
175 lines (148 loc) · 5.32 KB
/
test.ts
File metadata and controls
175 lines (148 loc) · 5.32 KB
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
/** @internal */
import { ElementFinder, ElementArrayFinder } from 'protractor';
import { BaseFragment, BaseArrayFragment } from './index';
let Jasmine = require('jasmine');
let jasmine = new Jasmine();
///////////////////////////////////////////////////
///////////////////////MOCKS///////////////////////
function $(locator: string) {
let browser = {} as any;
let actionResults_ = {} as any;
return new ElementFinder(browser, $$(locator));
}
function $$(locator: string) {
let browser = {} as any;
let getWebElements = () => {
return Promise.resolve([{}, {}, {}]) as any;
};
let actionResults_ = {} as any;
return new ElementArrayFinder(browser, getWebElements, locator, actionResults_);
}
class TestFragment extends BaseFragment {
constructor(elem) {
super(elem);
}
}
class TestArrayFragment extends BaseArrayFragment<TestFragment> {
constructor(elementArrayFinder) {
super(elementArrayFinder, TestFragment);
}
}
///////////////////////////////////////////////////
describe('BaseFragment', () => {
let testFrag;
beforeEach(function() {
testFrag = new TestFragment($('html'));
});
it('should still be ElementFinder', function() {
expect(testFrag instanceof ElementFinder).toBeTruthy('Fragment still should be ElementFinder');
});
});
describe('BaseArrayFragment', () => {
let arrayFrag;
beforeEach(function() {
arrayFrag = new TestArrayFragment($$('html'));
});
it('should still be ElementFinder', function() {
expect(arrayFrag instanceof ElementArrayFinder).toBeTruthy('BaseArrayFragment should still be ElementArrayFinder');
});
it(' ".map()" function must iterate thru your custom elements, not ElementFinders', () => {
arrayFrag.map((customel) => {
expect(customel instanceof TestFragment).toBeTruthy('You should get custom elements, not ElementFinder while iterating');
});
});
it(' ".each()" must iterate thru your custom elements, not ElementFinders', () => {
arrayFrag.each((customel) => {
expect(customel instanceof TestFragment).toBeTruthy('You should get custom elements, not ElementFinder while iterating');
});
});
it(' ".filter()" must iterate thru your custom elements, not ElementFinders', (done) => {
arrayFrag
.filter((customel) => {
expect(customel instanceof TestFragment).toBeTruthy('You should get custom elements, not ElementFinder while iterating');
})
.then(done);
});
it(' ".filter()" must return your extended from ElementArrayFinder type', (done) => {
let filteredRes = arrayFrag.filter(() => true);
expect(filteredRes instanceof TestArrayFragment).toBeTruthy();
done();
});
it(' ".reduce()" must iterate thru your custom elements, not ElementFinders', (done) => {
arrayFrag
.reduce((value, customel) => {
expect(customel instanceof TestFragment).toBeTruthy('You should get custom elements, not ElementFinder while iterating');
})
.then(done);
});
it(' ".get()" must return custom element, not ElementFinder', () => {
expect(arrayFrag.get(0) instanceof TestFragment).toBeTruthy("You should get custom elements, not ElementFinder while calling 'get' ");
expect(arrayFrag.first() instanceof TestFragment).toBeTruthy(
"You should get custom elements, not ElementFinder while calling 'first' "
);
expect(arrayFrag.last() instanceof TestFragment).toBeTruthy("You should get custom elements, not ElementFinder while calling 'last' ");
});
it(' ".every()" must iterate thru your custom elements, not ElementFinders', (done) => {
arrayFrag
.every((customel) => {
expect(customel instanceof TestFragment).toBeTruthy('You should get custom elements, not ElementFinder while iterating');
})
.then(done);
});
it(' ".some()" must iterate thru your custom elements, not ElementFinders', (done) => {
arrayFrag
.some((customel) => {
expect(customel instanceof TestFragment).toBeTruthy('You should get custom elements, not ElementFinder while iterating');
})
.then(done);
});
it(' ".find()" must iterate thru your custom elements, not ElementFinders', (done) => {
arrayFrag
.find((customel) => {
expect(customel instanceof TestFragment).toBeTruthy('You should get custom elements, not ElementFinder while iterating');
})
.then(done);
});
});
describe('Empty BaseArrayFragment', () => {
let arrayFrag;
beforeEach(function() {
arrayFrag = new TestArrayFragment(
new ElementArrayFinder(
{} as any,
() => {
return Promise.resolve([{}, {}, {}]) as any;
},
'html',
{} as any
)
);
});
it(' ".every()" must return true for an empty BaseArrayFragment', (done) => {
expect(
arrayFrag
.every((customel) => {
return false;
})
.then(done)
).toBeTruthy();
});
it(' ".some()" must return false for an empty BaseArrayFragment', (done) => {
expect(
arrayFrag
.some((customel) => {
return true;
})
.then(done)
).toBeTruthy();
});
it(' ".find()" must return undefined for an empty BaseArrayFragment', async (done) => {
const findResult = await arrayFrag
.find((customel) => {
return true;
})
.then(done);
expect(findResult == undefined).toBeTruthy();
});
});
jasmine.execute(['test.js']);