-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathengine.e2e-spec.ts
209 lines (164 loc) · 9.61 KB
/
engine.e2e-spec.ts
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
import {browser, element, by, protractor} from 'protractor';
/**
* Engine screen tests.
*
* End 2 End Protractor tests (using Jasmine) for testing Engine screen.
* See: http://www.protractortest.org/#/tutorial
*
* TODO - Use by.repeater()/model() instead of by.css() once Angular implement it for lists:
* https://angular.io/docs/ts/latest/guide/upgrade.html
* https://github.com/angular/protractor/issues/3205
*
* @author gazbert
*/
describe('Engine Tests', function () {
const WAIT_TIMEOUT = 300000;
beforeEach(function () {
browser.get('');
});
it('should update Engine fields after Save', function () {
const dashboardItems = element.all(by.css('app-bxbot-ui-dashboard-item'));
// https://stackoverflow.com/questions/28464604/more-than-one-element-found-for-locator-warning
const EC = protractor.ExpectedConditions;
const dashboard = element(by.id('dashboard-grid'));
browser.wait(EC.visibilityOf(dashboard), WAIT_TIMEOUT);
dashboardItems.get(0).click();
expect(element(by.css('h2')).getText()).toEqual('Bitstamp Bot Details');
const tabLinks = element.all(by.css('li'));
tabLinks.get(0).click();
expect(element(by.id('botId')).getAttribute('value')).toBe('bitstamp-1');
expect(element(by.id('botName')).getAttribute('value')).toBe('Bitstamp Bot');
expect(element(by.id('tradeCycleInterval')).getAttribute('value')).toBe('30');
expect(element(by.id('emergencyStopCurrency')).getAttribute('value')).toBe('BTC');
expect(element(by.id('emergencyStopBalance')).getAttribute('value')).toBe('0.5');
// Update fields
const botName = element(by.id('botName'));
const newBotName = 'Bitstamp V2';
botName.clear();
botName.sendKeys(newBotName);
expect(botName.getAttribute('value')).toBe(newBotName);
const tradeCycleInterval = element(by.id('tradeCycleInterval'));
const newTradingCycleInterval = '10';
tradeCycleInterval.clear();
tradeCycleInterval.sendKeys(newTradingCycleInterval);
expect(tradeCycleInterval.getAttribute('value')).toBe(newTradingCycleInterval);
const emergencyStopCurrency = element(by.id('emergencyStopCurrency'));
const newEmergencyStopCurrency = 'USD';
emergencyStopCurrency.clear();
emergencyStopCurrency.sendKeys(newEmergencyStopCurrency);
expect(emergencyStopCurrency.getAttribute('value')).toBe(newEmergencyStopCurrency);
const emergencyStopBalance = element(by.id('emergencyStopBalance'));
const newEmergencyStopBalance = '0.7';
emergencyStopBalance.clear();
emergencyStopBalance.sendKeys(newEmergencyStopBalance);
expect(emergencyStopBalance.getAttribute('value')).toBe(newEmergencyStopBalance);
// Save and check the update worked
const saveButton = element(by.id('engineSaveButton'));
saveButton.click();
dashboardItems.get(0).click();
expect(element(by.id('botName')).getAttribute('value')).toBe(newBotName);
expect(element(by.id('tradeCycleInterval')).getAttribute('value')).toBe(newTradingCycleInterval);
expect(element(by.id('emergencyStopCurrency')).getAttribute('value')).toBe(newEmergencyStopCurrency);
expect(element(by.id('emergencyStopBalance')).getAttribute('value')).toBe(newEmergencyStopBalance);
});
it('should NOT update Engine fields after Cancel', function () {
const dashboardItems = element.all(by.css('app-bxbot-ui-dashboard-item'));
const EC = protractor.ExpectedConditions;
const dashboard = element(by.id('dashboard-grid'));
browser.wait(EC.visibilityOf(dashboard), WAIT_TIMEOUT);
dashboardItems.get(0).click();
const title = element(by.css('h2'));
browser.wait(EC.visibilityOf(title), WAIT_TIMEOUT);
expect(title.getText()).toEqual('Bitstamp Bot Details');
const tabLinks = element.all(by.css('li'));
tabLinks.get(0).click();
expect(element(by.id('botId')).getAttribute('value')).toBe('bitstamp-1');
expect(element(by.id('botName')).getAttribute('value')).toBe('Bitstamp Bot');
expect(element(by.id('tradeCycleInterval')).getAttribute('value')).toBe('30');
expect(element(by.id('emergencyStopCurrency')).getAttribute('value')).toBe('BTC');
expect(element(by.id('emergencyStopBalance')).getAttribute('value')).toBe('0.5');
// Update fields
const botName = element(by.id('botName'));
const newBotName = 'Bitstamp V2';
botName.clear();
botName.sendKeys(newBotName);
expect(botName.getAttribute('value')).toBe(newBotName);
const tradeCycleInterval = element(by.id('tradeCycleInterval'));
const newTradingCycleInterval = '10';
tradeCycleInterval.clear();
tradeCycleInterval.sendKeys(newTradingCycleInterval);
expect(tradeCycleInterval.getAttribute('value')).toBe(newTradingCycleInterval);
const emergencyStopCurrency = element(by.id('emergencyStopCurrency'));
const newEmergencyStopCurrency = 'USD';
emergencyStopCurrency.clear();
emergencyStopCurrency.sendKeys(newEmergencyStopCurrency);
expect(emergencyStopCurrency.getAttribute('value')).toBe(newEmergencyStopCurrency);
const emergencyStopBalance = element(by.id('emergencyStopBalance'));
const newEmergencyStopBalance = '0.7';
emergencyStopBalance.clear();
emergencyStopBalance.sendKeys(newEmergencyStopBalance);
expect(emergencyStopBalance.getAttribute('value')).toBe(newEmergencyStopBalance);
// Cancel and check the update was not persisted
const cancelButton = element(by.id('engineCancelButton'));
cancelButton.click();
dashboardItems.get(0).click();
expect(element(by.id('botId')).getAttribute('value')).toBe('bitstamp-1');
expect(element(by.id('botName')).getAttribute('value')).toBe('Bitstamp Bot');
expect(element(by.id('tradeCycleInterval')).getAttribute('value')).toBe('30');
expect(element(by.id('emergencyStopCurrency')).getAttribute('value')).toBe('BTC');
expect(element(by.id('emergencyStopBalance')).getAttribute('value')).toBe('0.5');
});
it('should NOT save Engine fields if there are validation errors', function () {
const dashboardItems = element.all(by.css('app-bxbot-ui-dashboard-item'));
const EC = protractor.ExpectedConditions;
const dashboard = element(by.id('dashboard-grid'));
browser.wait(EC.visibilityOf(dashboard), WAIT_TIMEOUT);
dashboardItems.get(0).click();
expect(element(by.css('h2')).getText()).toEqual('Bitstamp Bot Details');
const tabLinks = element.all(by.css('li'));
tabLinks.get(0).click();
expect(element(by.id('botId')).getAttribute('value')).toBe('bitstamp-1');
expect(element(by.id('botName')).getAttribute('value')).toBe('Bitstamp Bot');
expect(element(by.id('tradeCycleInterval')).getAttribute('value')).toBe('30');
expect(element(by.id('emergencyStopCurrency')).getAttribute('value')).toBe('BTC');
expect(element(by.id('emergencyStopBalance')).getAttribute('value')).toBe('0.5');
// Update fields with some 'bad' values
const botName = element(by.id('botName'));
const newBotName = 'Bitstamp V3!';
botName.clear();
botName.sendKeys(newBotName);
expect(botName.getAttribute('value')).toBe(newBotName);
const tradeCycleInterval = element(by.id('tradeCycleInterval'));
const newTradingCycleInterval = 'a10';
tradeCycleInterval.clear();
tradeCycleInterval.sendKeys(newTradingCycleInterval);
expect(tradeCycleInterval.getAttribute('value')).toBe(newTradingCycleInterval);
const emergencyStopCurrency = element(by.id('emergencyStopCurrency'));
const newEmergencyStopCurrency = 'US_';
emergencyStopCurrency.clear();
emergencyStopCurrency.sendKeys(newEmergencyStopCurrency);
expect(emergencyStopCurrency.getAttribute('value')).toBe(newEmergencyStopCurrency);
const emergencyStopBalance = element(by.id('emergencyStopBalance'));
const newEmergencyStopBalance = '0.k7';
emergencyStopBalance.clear();
emergencyStopBalance.sendKeys(newEmergencyStopBalance);
expect(emergencyStopBalance.getAttribute('value')).toBe(newEmergencyStopBalance);
// Save and check the update did not persist
const saveButton = element(by.id('engineSaveButton'));
saveButton.click();
// Check for validation errors
expect(element(by.id('botId')).getAttribute('value')).toBe('bitstamp-1');
expect(element(by.id('botName')).getAttribute('value')).toBe(newBotName);
expect(element(by.id('invalidBotName')).getText()).toBe(
'Name must be alphanumeric and can only include the following special characters: _ -');
expect(element(by.id('tradeCycleInterval')).getAttribute('value')).toBe(newTradingCycleInterval);
expect(element(by.id('invalidTradeCycleInterval')).getText()).toBe(
'Trade Cycle Interval must be a whole number.');
expect(element(by.id('emergencyStopCurrency')).getAttribute('value')).toBe(newEmergencyStopCurrency);
expect(element(by.id('invalidEmergencyStopCurrency')).getText()).toBe(
'Emergency Stop Currency must be valid 3 character currency id, e.g. BTC');
expect(element(by.id('emergencyStopBalance')).getAttribute('value')).toBe(newEmergencyStopBalance);
expect(element(by.id('invalidEmergencyStopBalance')).getText()).toBe(
'Emergency Stop Balance must be a decimal number.');
});
});