Skip to content

Commit 16941ab

Browse files
committed
splitted tests scaffolding procedure
1 parent 0fb976b commit 16941ab

File tree

3 files changed

+62
-56
lines changed

3 files changed

+62
-56
lines changed

test/config/karma.conf.files.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var files = [
66
'https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular-mocks.js',
77
'../misc/test.css',
88
'../misc/datasources.js',
9-
'../misc/scaffolding.js',
9+
'../misc/scaffolding*.js',
1010
'../*Spec.js',
1111
{
1212
pattern: scrollerPath + '*.js.map',

test/misc/scaffolding.js

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,6 @@ function createHtml(settings) {
2121
'</div>';
2222
}
2323

24-
function createGridHtml (settings) {
25-
var viewportStyle = ' style="height:' + (settings.viewportHeight || 200) + 'px"';
26-
var columns = ['col0', 'col1', 'col2', 'col3'];
27-
28-
var html =
29-
'<table ui-scroll-viewport ' + viewportStyle + ' >' +
30-
'<thead style="display:block">' +
31-
'<tr>';
32-
columns.forEach(col => { html +=
33-
'<th ui-scroll-th class="' + col + '">' + col + '</th>';
34-
}); html +=
35-
'</tr>' +
36-
'</thead>' +
37-
'<tbody class="grid">' +
38-
'<tr ui-scroll="item in ' + settings.datasource + '" adapter="adapter">';
39-
if(settings.rowTemplate) {
40-
html += settings.rowTemplate;
41-
} else {
42-
columns.forEach(col => { html +=
43-
'<td ui-scroll-td class="' + col + '">{{item.' + col + '}}</td>';
44-
});
45-
} html +=
46-
'</tr>' +
47-
'</tbody>' +
48-
'</table>';
49-
return html;
50-
}
51-
5224
function finalize(scroller, options = {}, scope, $timeout) {
5325
scroller.remove();
5426

@@ -91,31 +63,4 @@ function runTest(scrollSettings, run, options = {}) {
9163
}
9264
}
9365
});
94-
}
95-
96-
function runGridTest(scrollSettings, run, options = {}) {
97-
inject(function($rootScope, $compile, $window, $timeout) {
98-
var scroller = angular.element(createGridHtml(scrollSettings));
99-
var scope = $rootScope.$new();
100-
101-
angular.element(document).find('body').append(scroller);
102-
var head = angular.element(scroller.children()[0]);
103-
var body = angular.element(scroller.children()[1]);
104-
105-
if (options.scope) {
106-
angular.extend(scope, options.scope);
107-
}
108-
109-
$compile(scroller)(scope);
110-
111-
scope.$apply();
112-
$timeout.flush();
113-
114-
try {
115-
run(head, body, scope, $timeout);
116-
} finally {
117-
finalize(scroller, options, scope, $timeout);
118-
}
119-
120-
});
12166
}

test/misc/scaffoldingGrid.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
function createGridHtml (settings) {
2+
var viewportStyle = ' style="height:' + (settings.viewportHeight || 200) + 'px"';
3+
var columns = ['col0', 'col1', 'col2', 'col3'];
4+
5+
var html =
6+
'<table ui-scroll-viewport ' + viewportStyle + ' >' +
7+
'<thead style="display:block">' +
8+
'<tr>';
9+
columns.forEach(col => { html +=
10+
'<th ui-scroll-th class="' + col + '">' + col + '</th>';
11+
}); html +=
12+
'</tr>' +
13+
'</thead>' +
14+
'<tbody class="grid">' +
15+
'<tr ui-scroll="item in ' + settings.datasource + '" adapter="adapter">';
16+
if(settings.rowTemplate) {
17+
html += settings.rowTemplate;
18+
} else {
19+
columns.forEach(col => { html +=
20+
'<td ui-scroll-td class="' + col + '">{{item.' + col + '}}</td>';
21+
});
22+
} html +=
23+
'</tr>' +
24+
'</tbody>' +
25+
'</table>';
26+
return html;
27+
}
28+
29+
function finalize(scroller, options = {}, scope, $timeout) {
30+
scroller.remove();
31+
32+
if (typeof options.cleanupTest === 'function') {
33+
options.cleanupTest(scroller, scope, $timeout);
34+
}
35+
}
36+
37+
function runGridTest(scrollSettings, run, options = {}) {
38+
inject(function($rootScope, $compile, $window, $timeout) {
39+
var scroller = angular.element(createGridHtml(scrollSettings));
40+
var scope = $rootScope.$new();
41+
42+
angular.element(document).find('body').append(scroller);
43+
var head = angular.element(scroller.children()[0]);
44+
var body = angular.element(scroller.children()[1]);
45+
46+
if (options.scope) {
47+
angular.extend(scope, options.scope);
48+
}
49+
50+
$compile(scroller)(scope);
51+
52+
scope.$apply();
53+
$timeout.flush();
54+
55+
try {
56+
run(head, body, scope, $timeout);
57+
} finally {
58+
finalize(scroller, options, scope, $timeout);
59+
}
60+
});
61+
}

0 commit comments

Comments
 (0)