Skip to content

Commit 2d8c06e

Browse files
committed
Adding tests
1 parent b3fabd3 commit 2d8c06e

16 files changed

+681
-47
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ node_modules
22
.npm-debug.log
33
tmp
44
.sass-cache
5-
.publish
5+
.publish
6+
coverage
7+
*.sublime-*

.travis.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
language: node_js
2+
node_js:
3+
- '4.2'
4+
- 'stable'
5+
script: npm run test:single
6+
before_script:
7+
- npm install

README.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jQuery Selectric is a jQuery plugin designed to help at stylizing and manipulati
88
* Pretty lightweight
99
* Options box always stay visible
1010
* Doesn't rely on external libraries (besides jQuery)
11-
* Word search works with western latin characters set (e.g.: á, ñ, ç...)
11+
* Word search works with western latin characters set (for example: á, ñ, ç...)
1212

1313
###[Demo](http://lcdsantos.github.io/jQuery-Selectric/)
1414

@@ -161,15 +161,10 @@ $('select').selectric({
161161
/*
162162
* Type: Object
163163
* Description: Customize classes.
164-
* Every class in 'postfixes' should be separate with a
165-
* space and follow this exact order:
166-
* 'Input Items Open Disabled TempShow HideSelect Wrapper
167-
* Hover Responsive Above Scroll Group GroupLabel'
168164
*/
169165
customClass: {
170166
prefix: 'selectric',
171-
camelCase: false,
172-
overwrite: true
167+
camelCase: false
173168
},
174169

175170
/*
@@ -219,7 +214,7 @@ $('select').selectric({
219214
* first (or last) once reach the end (or start) item of list upon
220215
* keyboard arrow navigation.
221216
*/
222-
allowWrap: false
217+
allowWrap: true
223218
}
224219
```
225220

karma.conf.js

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// Karma configuration
2+
3+
module.exports = function(config) {
4+
'use strict';
5+
6+
config.set({
7+
8+
// base path that will be used to resolve all patterns (eg. files, exclude)
9+
basePath: '',
10+
11+
12+
// frameworks to use
13+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
14+
frameworks: ['jasmine-jquery', 'jasmine'],
15+
16+
17+
// list of files / patterns to load in the browser
18+
files: [
19+
'public/selectric.css',
20+
'public/lib/jquery.min.js',
21+
'src/jquery.selectric.js',
22+
'test/**/*.spec.js',
23+
'test/fixtures/**/*.html',
24+
'test/lib/**/*.js'
25+
],
26+
27+
28+
// list of files to exclude
29+
exclude: [
30+
],
31+
32+
33+
// preprocess matching files before serving them to the browser
34+
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
35+
preprocessors: {
36+
'src/**/*.js': ['coverage']
37+
},
38+
39+
40+
// test results reporter to use
41+
// possible values: 'dots', 'progress'
42+
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
43+
reporters: ['mocha', 'coverage'],
44+
45+
46+
// web server port
47+
port: 9876,
48+
49+
50+
// enable / disable colors in the output (reporters and logs)
51+
colors: true,
52+
53+
54+
// level of logging
55+
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
56+
logLevel: config.LOG_INFO,
57+
58+
59+
// enable / disable watching file and executing tests whenever any file changes
60+
autoWatch: true,
61+
62+
63+
// start these browsers
64+
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
65+
browsers: [
66+
'PhantomJS',
67+
// 'Chrome',
68+
// 'Firefox'
69+
],
70+
71+
72+
// Continuous Integration mode
73+
// if true, Karma captures browsers, runs the tests and exits
74+
singleRun: false,
75+
76+
// Concurrency level
77+
// how many browser should be started simultaneous
78+
concurrency: Infinity,
79+
80+
81+
// optionally, configure the reporter
82+
coverageReporter: {
83+
type : 'html',
84+
dir : 'coverage/'
85+
}
86+
})
87+
}

package.json

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"gulp": "^3.9.1",
3636
"gulp-autoprefixer": "^3.1.0",
3737
"gulp-bump": "^1.0.0",
38-
"gulp-connect": "^3.0.0",
38+
"gulp-connect": "^3.1.0",
3939
"gulp-csscomb": "^3.0.6",
4040
"gulp-gh-pages": "^0.5.4",
4141
"gulp-header": "^1.7.1",
@@ -44,6 +44,21 @@
4444
"gulp-sass": "^2.2.0",
4545
"gulp-uglify": "^1.5.3",
4646
"gulp-util": "^3.0.7",
47-
"gulp-zip": "^3.2.0"
47+
"gulp-zip": "^3.2.0",
48+
"istanbul": "^0.4.2",
49+
"jasmine-core": "^2.4.1",
50+
"karma": "^0.13.22",
51+
"karma-chrome-launcher": "^0.2.2",
52+
"karma-coverage": "^0.5.5",
53+
"karma-firefox-launcher": "^0.1.7",
54+
"karma-jasmine": "^0.3.7",
55+
"karma-jasmine-jquery": "^0.1.1",
56+
"karma-mocha-reporter": "^2.0.0",
57+
"karma-phantomjs-launcher": "^1.0.0",
58+
"phantomjs-prebuilt": "^2.1.5"
59+
},
60+
"scripts": {
61+
"test": "karma start",
62+
"test:single": "./node_modules/.bin/karma start --single-run --browsers PhantomJS"
4863
}
4964
}

public/index.html

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,15 +230,10 @@ <h2>Options</h2>
230230
/*
231231
* Type: Object
232232
* Description: Customize classes.
233-
* Every class in 'postfixes' should be separate with a
234-
* space and follow this exact order:
235-
* 'Input Items Open Disabled TempShow HideSelect Wrapper
236-
* Hover Responsive Above Scroll Group GroupLabel'
237233
*/
238234
customClass: {
239235
prefix: 'selectric',
240-
camelCase: false,
241-
overwrite: true
236+
camelCase: false
242237
},
243238

244239
/*
@@ -288,7 +283,7 @@ <h2>Options</h2>
288283
* first (or last) once reach the end (or start) item of list upon
289284
* keyboard arrow navigation.
290285
*/
291-
allowWrap: false
286+
allowWrap: true
292287
}</code></pre>
293288

294289
<h2>Events</h2>

public/jquery.selectric.js

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
* /,'
1010
* /'
1111
*
12-
* Selectric ϟ v1.9.5 (Feb 26 2016) - http://lcdsantos.github.io/jQuery-Selectric/
12+
* Selectric ϟ v1.9.5 (Mar 13 2016) - http://lcdsantos.github.io/jQuery-Selectric/
1313
*
1414
* Copyright (c) 2016 Leonardo Santos; MIT License
1515
*
1616
*/
1717

1818
(function(factory) {
19+
/* istanbul ignore next */
1920
if (typeof define === 'function' && define.amd) {
2021
define(['jquery'], factory);
2122
} else if (typeof module === 'object' && module.exports) {
@@ -58,8 +59,7 @@
5859
allowWrap: true,
5960
customClass: {
6061
prefix: pluginName,
61-
camelCase: false,
62-
overwrite: true
62+
camelCase: false
6363
},
6464
optionsItemBuilder: '{text}', // function(itemData, element, index)
6565
labelBuilder: '{text}' // function(currItem)
@@ -164,7 +164,7 @@
164164
originalWidth = $original.width();
165165

166166
$.each(postfixes, function(i, currClass) {
167-
var c = customClass.prefix + '-' + currClass;
167+
var c = customClass.prefix + currClass;
168168
_this.classes[currClass.toLowerCase()] = customClass.camelCase ? c : _utils.toDash(c);
169169
});
170170

@@ -267,9 +267,7 @@
267267

268268
$outerWrapper.prop('class', [
269269
_this.classes.wrapper,
270-
_this.options.customClass.overwrite ?
271-
$original.prop('class').replace(/\S+/g, _this.options.customClass.prefix + '-$&') :
272-
$original.prop('class'),
270+
$original.prop('class').replace(/\S+/g, _this.options.customClass.prefix + '-$&'),
273271
_this.options.responsive ? _this.classes.responsive : ''
274272
].join(' '));
275273

@@ -325,12 +323,6 @@
325323
}
326324
})
327325
.on('focusin' + bindSufix, function(e) {
328-
// Stupid, but necessary... Prevent the flicker when
329-
// focusing out and back again in the browser window
330-
$input.one('blur', function() {
331-
$input.blur();
332-
});
333-
334326
isOpen || _open(e);
335327
})
336328
.on('oninput' in $input[0] ? 'input' : 'keyup', function() {
@@ -445,7 +437,8 @@
445437
$outerWrapper.addClass(_this.classes.open);
446438

447439
// Give dummy input focus
448-
$input.val('').is(':focus') || $input.focus();
440+
$input.val('');
441+
e && e.type !== 'focusin' && $input.focus();
449442

450443
$doc.on('click' + bindSufix, _close).on('scroll' + bindSufix, _isInViewport);
451444
_isInViewport();

0 commit comments

Comments
 (0)