Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit b5adc47

Browse files
committed
Setup initial test using ngHtml2JsPreprocessor
1 parent e13a5cb commit b5adc47

File tree

4 files changed

+79
-10
lines changed

4 files changed

+79
-10
lines changed

bower.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
"tests"
1717
],
1818
"dependencies": {
19-
"angular": "~1.0.8",
20-
"angular-mocks": "~1.0.8",
19+
"angular": "~1.2.0",
20+
"angular-mocks": "~1.2.0",
2121
"jquery": "~2.0.3"
2222
}
2323
}

karma.conf.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ module.exports = function(config) {
1414

1515
// list of files / patterns to load in the browser
1616
files: [
17-
'bower_components/jquery/jquery.js',
1817
'bower_components/angular/angular.js',
1918
'bower_components/angular-mocks/angular-mocks.js',
20-
'select.js',
21-
'test/**/*.spec.js'
19+
'bower_components/jquery/jquery.js',
20+
21+
'src/select.js',
22+
'test/**/*.spec.js',
23+
'**/*.tpl.html'
2224
],
2325

2426

@@ -27,6 +29,14 @@ module.exports = function(config) {
2729

2830
],
2931

32+
preprocessors: {
33+
'**/*.tpl.html': ['ng-html2js']
34+
},
35+
36+
ngHtml2JsPreprocessor: {
37+
// stripPrefix: 'public/',
38+
prependPrefix: '../'
39+
},
3040

3141
// test results reporter to use
3242
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"karma": "~0.10.4",
1717
"grunt": "~0.4.1",
1818
"grunt-karma": "~0.6.2",
19-
"bower": "~1.2.7"
19+
"bower": "~1.2.7",
20+
"karma-ng-html2js-preprocessor": "~0.1.0"
2021
},
2122
"scripts": {
2223
"test": "grunt test"

test/select.spec.js

+62-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,63 @@
1-
describe('select', function() {
2-
it('', function() {
3-
});
4-
});
1+
describe('ui-select tests', function() {
52

3+
var scope, $rootScope, $compile;
4+
5+
beforeEach(module('ui.select'));
6+
beforeEach(module('../src/select2/choices.tpl.html'));
7+
beforeEach(module('../src/select2/match.tpl.html'));
8+
beforeEach(module('../src/select2/select.tpl.html'));
9+
beforeEach(inject(function(_$rootScope_, _$compile_) {
10+
$rootScope = _$rootScope_;
11+
scope = $rootScope.$new();
12+
$compile = _$compile_;
13+
scope.matches = [
14+
{"id": 1, "name": "Wladimir Coka", "email": "[email protected]" },
15+
{"id": 2, "name": "Samantha Smith", "email": "[email protected]" },
16+
{"id": 3, "name": "Estefanía Smith", "email": "[email protected]" },
17+
{"id": 4, "name": "Natasha Jones", "email": "[email protected]" },
18+
{"id": 5, "name": "Nicole Smith", "email": "[email protected]" }
19+
];
20+
}));
21+
22+
//Utility functions
23+
var prepareUiSelectEl = function(inputTpl) {
24+
var el = $compile(angular.element(inputTpl))(scope);
25+
scope.$digest();
26+
return el;
27+
};
28+
29+
var uiSelectElInstance1 = function(inputTpl) {
30+
var element = prepareUiSelectEl(
31+
'<ui-select ng-model="selection" style="width:300px"> \
32+
<match placeholder="Pick one...">{{$select.selected.name}}</match> \
33+
<choices data="matches | filter : $select.search"> \
34+
<div ng-bind-html="trustAsHtml((item.name | highlight:$select.search))"/></div> \
35+
<div> {{item.email}} </div> \
36+
</choices> \
37+
</ui-select> \
38+
');
39+
return element;
40+
};
41+
42+
it('should compile basic ui-select-* elements ', function() {
43+
44+
var el = uiSelectElInstance1();
45+
46+
var searchEl = $(el).find('.ui-select-search');
47+
expect(searchEl.length).toEqual(1);
48+
49+
var matchEl = $(el).find('.ui-select-match');
50+
expect(matchEl.length).toEqual(1);
51+
52+
var choicesContentEl = $(el).find('.ui-select-choices-content');
53+
expect(choicesContentEl.length).toEqual(1);
54+
55+
var choicesContainerEl = $(el).find('.ui-select-choices');
56+
expect(choicesContainerEl.length).toEqual(1);
57+
58+
var choicesElems = $(el).find('.ui-select-choices-row');
59+
expect(choicesElems.length).toEqual(5);
60+
61+
});
62+
63+
});

0 commit comments

Comments
 (0)