1
|
|
|
Nitrate.TestCases = {}; |
|
|
|
|
2
|
|
|
Nitrate.TestCases.Clone = {}; |
3
|
|
|
|
4
|
|
|
(function() { |
5
|
|
|
var TestCases = window.Nitrate.TestCases || {}; |
6
|
|
|
|
7
|
|
|
TestCases.CasesSelection = function(options) { |
8
|
|
|
this.selectedCasesIds = options.selectedCasesIds || []; |
9
|
|
|
this.selectAll = options.selectAll; |
10
|
|
|
|
11
|
|
|
if (Object.prototype.toString.call(this.selectedCasesIds) !== '[object Array]') { |
12
|
|
|
throw new TypeError('selectedCasesIds must an object of Array.'); |
13
|
|
|
} |
14
|
|
|
if (typeof this.selectAll !== 'boolean') { |
15
|
|
|
throw new TypeError('selectAll must be a boolean value.'); |
16
|
|
|
} |
17
|
|
|
}; |
18
|
|
|
|
19
|
|
|
TestCases.CasesSelection.prototype.empty = function() { |
20
|
|
|
return this.selectedCasesIds.length === 0 && !this.selectAll; |
21
|
|
|
}; |
22
|
|
|
|
23
|
|
|
window.Nitrate.TestCases = TestCases; |
24
|
|
|
}()); |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
Nitrate.TestCases.Clone.on_load = function() { |
28
|
|
|
$('#id_product').change(update_version_select_from_product); |
|
|
|
|
29
|
|
|
if (!$('#id_version').val().length) { |
30
|
|
|
update_version_select_from_product(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
jQ('#id_form_search_plan').bind('submit', function(e) { |
34
|
|
|
e.stopPropagation(); |
35
|
|
|
e.preventDefault(); |
36
|
|
|
|
37
|
|
|
var url = '/plans/'; |
38
|
|
|
var container = jQ('#id_plan_container'); |
39
|
|
|
container.show(); |
40
|
|
|
|
41
|
|
|
jQ.ajax({ |
|
|
|
|
42
|
|
|
'url': url, |
43
|
|
|
'type': 'GET', |
44
|
|
|
'data': jQ(this).serialize(), |
45
|
|
|
'success': function (data, textStatus, jqXHR) { |
|
|
|
|
46
|
|
|
container.html(data); |
47
|
|
|
} |
48
|
|
|
}); |
49
|
|
|
}); |
50
|
|
|
|
51
|
|
|
jQ('#id_use_filterplan').bind('click', function(e) { |
|
|
|
|
52
|
|
|
jQ('#id_form_search_plan :input').attr('disabled', false); |
53
|
|
|
jQ('#id_plan_id').val(''); |
54
|
|
|
jQ('#id_plan_id').attr('name', ''); |
55
|
|
|
jQ('#id_copy_case').attr('checked', true); |
56
|
|
|
}); |
57
|
|
|
|
58
|
|
|
if (jQ('#id_use_sameplan').length) { |
59
|
|
|
jQ('#id_use_sameplan').bind('click', function(e) { |
|
|
|
|
60
|
|
|
jQ('#id_form_search_plan :input').attr('disabled', true); |
61
|
|
|
jQ('#id_plan_id').val(jQ('#value_plan_id').val()); |
62
|
|
|
jQ('#id_plan_id').attr('name', 'plan'); |
63
|
|
|
jQ('#id_plan_container').html('<div class="ajax_loading"></div>').hide(); |
64
|
|
|
jQ('#id_copy_case').attr('checked', false); |
65
|
|
|
}); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
jQ('.js-cancel-button').bind('click', function() { |
69
|
|
|
window.history.go('-1'); |
70
|
|
|
}); |
71
|
|
|
|
72
|
|
|
}; |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
/* |
76
|
|
|
* Used for expanding test case in test plan page specifically |
77
|
|
|
* |
78
|
|
|
* Arguments: |
79
|
|
|
* options.caseRowContainer: a jQuery object referring to the container of the |
80
|
|
|
* test case that is being expanded to show more |
81
|
|
|
* information. |
82
|
|
|
* options.expandPaneContainer: a jQuery object referring to the container of |
83
|
|
|
* the expanded pane showing test case detail |
84
|
|
|
* information. |
85
|
|
|
*/ |
86
|
|
|
function toggleExpandArrow(options) { |
87
|
|
|
var container = options.caseRowContainer; |
88
|
|
|
var content_container = options.expandPaneContainer; |
89
|
|
|
var blind_icon = container.find('img.blind_icon'); |
90
|
|
|
if (content_container.css('display') === 'none') { |
91
|
|
|
blind_icon.removeClass('collapse').addClass('expand').attr('src', '/static/images/t1.gif'); |
92
|
|
|
} else { |
93
|
|
|
blind_icon.removeClass('expand').addClass('collapse').attr('src', '/static/images/t2.gif'); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
|
98
|
|
|
function toggleTestCaseContents(template_type, container, content_container, object_pk, case_text_version, case_run_id, callback) { |
99
|
|
|
if (typeof container === 'string') { |
100
|
|
|
var container = jQ('#' + container)[0]; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
if(typeof content_container === 'string') { |
104
|
|
|
var content_container = jQ('#' + content_container)[0]; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
jQ(content_container).toggle(); |
108
|
|
|
|
109
|
|
|
if (jQ('#id_loading_' + object_pk).length) { |
110
|
|
|
var url = Nitrate.http.URLConf.reverse({ name: 'case_details', arguments: {id: object_pk} }); |
|
|
|
|
111
|
|
|
var parameters = { |
112
|
|
|
template_type: template_type, |
113
|
|
|
case_text_version: case_text_version, |
114
|
|
|
case_run_id: case_run_id |
115
|
|
|
}; |
116
|
|
|
|
117
|
|
|
jQ.ajax({ |
|
|
|
|
118
|
|
|
'url': url, |
119
|
|
|
'data': parameters, |
120
|
|
|
'success': function (data, textStatus, jqXHR) { |
|
|
|
|
121
|
|
|
jQ(content_container).html(data); |
122
|
|
|
}, |
123
|
|
|
'error': function (jqXHR, textStatus, errorThrown) { |
|
|
|
|
124
|
|
|
html_failure(); |
125
|
|
|
}, |
126
|
|
|
'complete': function (jqXHR, textStatus) { |
|
|
|
|
127
|
|
|
callback(jqXHR); |
128
|
|
|
} |
129
|
|
|
}); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
toggleExpandArrow({ caseRowContainer: jQ(container), expandPaneContainer: jQ(content_container) }); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
function changeTestCaseStatus(plan_id, case_ids, new_value, container) { |
136
|
|
|
case_ids.forEach(function(element) { |
137
|
|
|
jsonRPC('TestCase.update', [element, {case_status: new_value}], function(data) {}); |
|
|
|
|
138
|
|
|
}); |
139
|
|
|
|
140
|
|
|
|
141
|
|
|
var template_type = 'case'; |
142
|
|
|
if (container.attr('id') === 'reviewcases') { |
143
|
|
|
template_type = 'review_case'; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
var parameters = { |
147
|
|
|
'a': 'initial', |
148
|
|
|
'from_plan': plan_id, |
149
|
|
|
'template_type': template_type, |
150
|
|
|
}; |
151
|
|
|
|
152
|
|
|
// todo: #run_case_count, #case_count, #review_case_count |
153
|
|
|
// are no longer updated |
154
|
|
|
constructPlanDetailsCasesZone(container, plan_id, parameters); |
155
|
|
|
|
156
|
|
|
Nitrate.TestPlans.Details.reopenTabHelper(jQ(container)); |
|
|
|
|
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
function toggleAllCheckBoxes(element, container, name) { |
160
|
|
|
if (element.checked) { |
161
|
|
|
jQ('#' + container).parent().find('input[name="' + name + '"]').not(':disabled').attr('checked', true); |
162
|
|
|
} else { |
163
|
|
|
jQ('#' + container).parent().find('input[name="'+ name + '"]').not(':disabled').attr('checked', false); |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
function toggleAllCases(element) { |
168
|
|
|
//If and only if both case length is 0, remove the lock. |
169
|
|
|
if (jQ('div[id^="id_loading_"].normal_cases').length === 0 && jQ('div[id^="id_loading_"].review_cases').length === 0){ |
170
|
|
|
jQ(element).removeClass('locked'); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
if (jQ(element).is('.locked')) { |
174
|
|
|
return false; |
175
|
|
|
} else { |
|
|
|
|
176
|
|
|
jQ(element).addClass('locked'); |
177
|
|
|
if (jQ(element).is('.collapse-all')) { |
178
|
|
|
element.title = "Collapse all cases"; |
179
|
|
|
blinddownAllCases(element); |
|
|
|
|
180
|
|
|
} else { |
181
|
|
|
element.title = "Expand all cases"; |
182
|
|
|
blindupAllCases(element); |
|
|
|
|
183
|
|
|
} |
184
|
|
|
} |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
function blinddownAllCases(element) { |
188
|
|
|
jQ('img.expand').each(function(e) { |
|
|
|
|
189
|
|
|
fireEvent(this, 'click'); |
190
|
|
|
}); |
191
|
|
|
if (element) { |
192
|
|
|
jQ(element) |
193
|
|
|
.removeClass('collapse-all').addClass('expand-all') |
194
|
|
|
.attr('src', '/static/images/t2.gif'); |
195
|
|
|
} |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
function blindupAllCases(element) { |
199
|
|
|
jQ('.collapse').each(function(e) { |
|
|
|
|
200
|
|
|
fireEvent(this, 'click'); |
201
|
|
|
}); |
202
|
|
|
|
203
|
|
|
if (element) { |
204
|
|
|
jQ(element) |
205
|
|
|
.removeClass('expand-all').addClass('collapse-all') |
206
|
|
|
.attr('src', '/static/images/t1.gif'); |
207
|
|
|
} |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/* |
211
|
|
|
* Serialize selected cases' Ids. |
212
|
|
|
* |
213
|
|
|
* This function inherits the ability from original definition named |
214
|
|
|
* serializeCaseFromInputList, except that it also collects whehter all cases |
215
|
|
|
* are also selected even through not all of cases are displayed. |
216
|
|
|
* |
217
|
|
|
* Return value is an object of dictionary holding two properties. `selectAll' |
218
|
|
|
* is a boolean value indicating whether user select all cases. |
219
|
|
|
* `selectedCasesIds' is an array containing all selected cases' Ids the |
220
|
|
|
* current loaded set of cases. |
221
|
|
|
* |
222
|
|
|
* Whatever user selects all cases, above two properties appears always with |
223
|
|
|
* proper value. |
224
|
|
|
*/ |
225
|
|
|
function serializeCaseFromInputList2(table) { |
226
|
|
|
var selectAll = jQ(table).parent().find('.js-cases-select-all input[type="checkbox"]')[0].checked; |
227
|
|
|
var case_ids = []; |
228
|
|
|
var checkedCases = jQ(table).find('input[name="case"]:checked'); |
229
|
|
|
checkedCases.each(function(i, checkedCase) { |
230
|
|
|
if (typeof checkedCase.value === 'string') { |
231
|
|
|
case_ids.push(checkedCase.value); |
232
|
|
|
} |
233
|
|
|
}); |
234
|
|
|
var selectedCasesIds = case_ids; |
235
|
|
|
|
236
|
|
|
return new Nitrate.TestCases.CasesSelection({ |
|
|
|
|
237
|
|
|
selectedCasesIds: selectedCasesIds, |
238
|
|
|
selectAll: selectAll |
239
|
|
|
}); |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
function serializeCaseFromInputList(table) { |
243
|
|
|
var case_ids = []; |
244
|
|
|
jQ(table).parent().find('input[name="case"]:checked').each(function(i) { |
|
|
|
|
245
|
|
|
if (typeof this.value === 'string') { |
246
|
|
|
case_ids.push(this.value); |
247
|
|
|
} |
248
|
|
|
}); |
249
|
|
|
return case_ids; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/* |
253
|
|
|
* Serialize criterias for searching cases. |
254
|
|
|
* |
255
|
|
|
* Arguments: |
256
|
|
|
* - form: the form from which criterias are searched |
257
|
|
|
* - table: the table containing all loaded cases |
258
|
|
|
* - serialized: whether to serialize the form data. true is default, if not |
259
|
|
|
* passed. |
260
|
|
|
* - exclude_cases: whether to exclude all cases while serializing. For |
261
|
|
|
* instance, when filter cases, it's unnecessary to collect all selected |
262
|
|
|
* cases' IDs, due to all filtered cases in the response should be selected |
263
|
|
|
* by default. Default to true if not passed. |
264
|
|
|
*/ |
265
|
|
|
function serialzeCaseForm(form, table, serialized, exclude_cases) { |
|
|
|
|
266
|
|
|
if (typeof serialized != 'boolean') { |
267
|
|
|
var serialized = true; |
268
|
|
|
} |
269
|
|
|
if (exclude_cases === undefined) { |
270
|
|
|
var exclude_cases = false; |
271
|
|
|
} |
272
|
|
|
var data; |
273
|
|
|
if (serialized) { |
274
|
|
|
data = Nitrate.Utils.formSerialize(form); |
|
|
|
|
275
|
|
|
} else { |
276
|
|
|
data = jQ(form).serialize(); |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
if (!exclude_cases) { |
280
|
|
|
data['case'] = serializeCaseFromInputList(table); |
281
|
|
|
} |
282
|
|
|
return data; |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
/* |
286
|
|
|
* New implementation of serialzeCaseForm to allow to choose whether the |
287
|
|
|
* TestCases' Ids are necessary to be serialized. |
288
|
|
|
* |
289
|
|
|
* Be default if no value is passed to exclude_cases, not exclude them. |
290
|
|
|
*/ |
291
|
|
|
function serializeCaseForm2(form, table, serialized, exclude_cases) { |
|
|
|
|
292
|
|
|
if (typeof serialized != 'boolean') { |
293
|
|
|
var serialized = true; |
294
|
|
|
} |
295
|
|
|
var data; |
296
|
|
|
if (serialized) { |
297
|
|
|
data = Nitrate.Utils.formSerialize(form); |
|
|
|
|
298
|
|
|
} else { |
299
|
|
|
data = jQ(form).serialize(); |
300
|
|
|
} |
301
|
|
|
var _exclude = exclude_cases === undefined ? false : exclude_cases; |
302
|
|
|
if (!_exclude) { |
303
|
|
|
data['case'] = serializeCaseFromInputList(table); |
304
|
|
|
} |
305
|
|
|
return data; |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
function toggleDiv(link, divId) { |
309
|
|
|
var link = jQ(link); |
310
|
|
|
var div = jQ('#' + divId); |
311
|
|
|
var show = 'Show All'; |
312
|
|
|
var hide = 'Hide All'; |
313
|
|
|
div.toggle(); |
314
|
|
|
var text = link.html(); |
315
|
|
|
if (text !== show) { |
316
|
|
|
link.html(show); |
317
|
|
|
} else { |
318
|
|
|
link.html(hide); |
319
|
|
|
} |
320
|
|
|
} |
321
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.