Skip to content

Commit df86470

Browse files
author
Mark
committed
added test
1 parent c4dd8c6 commit df86470

File tree

6 files changed

+133
-78
lines changed

6 files changed

+133
-78
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License
22

3-
Copyright (c) 2014 Karan Batra-Daitch http://bardo.io
3+
Copyright (c) 2015 Devmark https://github.com/devmark/angular-slick-carousel
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ as either a `<div>` attribute or a `<slick>` element.
3737
</slick>
3838

3939
<slick
40-
settings="slickConfig"
41-
data="number" ng-if="numberLoaded">
40+
settings="slickConfig" ng-if="numberLoaded">
4241
</slick>
4342
```
4443

@@ -61,14 +60,13 @@ $scope.slickConfig = {
6160
}
6261
};
6362
```
64-
`data`: object for ng-repeat data, discussed [below](#data) in detail
6563

6664
### Method ###
6765
1. All the functions in the plugin are exposed through a control
6866
attribute.
6967
2. To utilize this architecture, and have two-way data-binding,
7068
define an empty control handle on scope:
71-
```js
69+
```js
7270
$scope.slickConfig = {
7371
method: {}
7472
}
@@ -87,18 +85,18 @@ as shown in the example.
8785
```
8886

8987
### Slide data ###
90-
For change slide content, you have to set `data` attribute AND `ng-if`
88+
For change slide content, you have to set `ng-if` to destroy and init it
9189

9290
- controller:
9391
```js
9492
$scope.number = [{label: 1}, {label: 2}, {label: 3}, {label: 4}, {label: 5}, {label: 6}, {label: 7}, {label: 8}];
9593
$scope.numberLoaded = true;
9694
$scope.numberUpdate = function(){
97-
$scope.numberLoaded = false; //disable slick
95+
$scope.numberLoaded = false; // disable slick
9896

9997
//number update
10098

101-
$scope.numberLoaded = true; //enable slick
99+
$scope.numberLoaded = true; // enable slick
102100
};
103101
```
104102
- html:
@@ -107,7 +105,7 @@ For change slide content, you have to set `data` attribute AND `ng-if`
107105
<h3>{{ i.label }}</h3>
108106
</script>
109107

110-
<slick data="number" ng-if="numberLoaded">
108+
<slick ng-if="numberLoaded">
111109
<div ng-repeat="i in number">
112110
<div class="" ng-include="'tpl.html'"></div>
113111
</div>

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-slick-carousel",
3-
"version": "3.0.11",
3+
"version": "3.1.0",
44
"homepage": "https://github.com/devmark/angular-slick-carousel",
55
"authors": [
66
"DevMark <[email protected]>"

karma.conf.js

Lines changed: 37 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,48 @@
1-
'use strict';
1+
module.exports = function (config) {
2+
config.set({
23

3-
var path = require('path');
4-
var conf = require('./gulp/conf');
4+
// Base path, that will be used to resolve files and exclude
5+
basePath: '',
56

6-
var _ = require('lodash');
7-
var wiredep = require('wiredep');
7+
// Frameworks to use
8+
frameworks: ['jasmine'],
89

9-
function listFiles() {
10-
var wiredepOptions = _.extend({}, conf.wiredep, {
11-
dependencies: true,
12-
devDependencies: true
13-
});
14-
15-
return wiredep(wiredepOptions).js
16-
.concat([
17-
path.join(conf.paths.src, '/app/**/*.module.js'),
18-
path.join(conf.paths.src, '/app/**/*.js'),
19-
path.join(conf.paths.src, '/**/*.spec.js'),
20-
path.join(conf.paths.src, '/**/*.mock.js'),
21-
path.join(conf.paths.src, '/**/*.html')
22-
]);
23-
}
24-
25-
module.exports = function(config) {
26-
27-
var configuration = {
28-
files: listFiles(),
29-
30-
singleRun: true,
10+
// List of files / patterns to load in the browser
11+
files: [
12+
'bower_components/jquery/dist/jquery.js',
13+
'bower_components/angular/angular.js',
14+
'bower_components/angular-mocks/angular-mocks.js',
3115

32-
autoWatch: false,
33-
34-
frameworks: ['jasmine', 'angular-filesort'],
16+
'bower_components/slick-carousel/slick/slick.js',
17+
'dist/angular-slick.js',
18+
'test/**/*.spec.js'
19+
],
3520

36-
angularFilesort: {
37-
whitelist: [path.join(conf.paths.src, '/**/!(*.html|*.spec|*.mock).js')]
38-
},
21+
// List of files to exclude
22+
exclude: [],
3923

40-
ngHtml2JsPreprocessor: {
41-
stripPrefix: 'src/',
42-
moduleName: 'angularSlickCarousel'
43-
},
24+
// Web server port
25+
port: 9876,
4426

45-
browsers : ['PhantomJS'],
27+
// Level of logging
28+
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
29+
logLevel: config.LOG_INFO,
4630

47-
plugins : [
48-
'karma-phantomjs-launcher',
49-
'karma-angular-filesort',
50-
'karma-jasmine',
51-
'karma-ng-html2js-preprocessor'
52-
],
31+
// Enable / disable watching file and executing tests whenever any file changes
32+
autoWatch: true,
5333

54-
preprocessors: {
55-
'src/**/*.html': ['ng-html2js']
56-
}
57-
};
34+
// Start these browsers, currently available:
35+
// - Chrome
36+
// - ChromeCanary
37+
// - Firefox
38+
// - Opera
39+
// - Safari (only Mac)
40+
// - PhantomJS
41+
// - IE (only Windows)
42+
browsers: [process.env.TRAVIS ? 'Firefox' : 'Chrome'],
5843

59-
// This block is needed to execute Chrome on Travis
60-
// If you ever plan to use Chrome and Travis, you can keep it
61-
// If not, you can safely remove it
62-
// https://github.com/karma-runner/karma/issues/1144#issuecomment-53633076
63-
if(configuration.browsers[0] === 'Chrome' && process.env.TRAVIS) {
64-
configuration.customLaunchers = {
65-
'chrome-travis-ci': {
66-
base: 'Chrome',
67-
flags: ['--no-sandbox']
68-
}
69-
};
70-
configuration.browsers = ['chrome-travis-ci'];
71-
}
72-
73-
config.set(configuration);
44+
// Continuous Integration mode
45+
// if true, it capture browsers, run tests and exit
46+
singleRun: false
47+
});
7448
};

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-slick-carousel",
3-
"version": "3.0.11",
3+
"version": "3.1.0",
44
"main": "dist/angular-slick.js",
55
"repository": {
66
"type": "git",
@@ -15,7 +15,7 @@
1515
"gulp-autoprefixer": "~2.3.1",
1616
"gulp-angular-templatecache": "~1.6.0",
1717
"del": "~1.2.0",
18-
"lodash": "~3.9.3",
18+
"lodash": "~3.10.1",
1919
"gulp-csso": "~1.0.0",
2020
"gulp-filter": "~2.0.2",
2121
"gulp-flatten": "~0.0.4",
@@ -36,14 +36,14 @@
3636
"gulp-sourcemaps": "~1.5.2",
3737
"gulp-less": "~3.0.3",
3838
"gulp-angular-filesort": "~1.1.1",
39-
"main-bower-files": "~2.8.0",
39+
"main-bower-files": "~2.9.0",
4040
"merge-stream": "~0.1.7",
4141
"jshint-stylish": "~2.0.0",
4242
"wiredep": "~2.2.2",
43-
"karma": "~0.12.36",
43+
"karma": "~0.13.10",
4444
"karma-jasmine": "~0.3.5",
45+
"karma-chrome-launcher": "^0.2.0",
4546
"karma-phantomjs-launcher": "~0.2.0",
46-
"karma-angular-filesort": "~0.1.0",
4747
"karma-ng-html2js-preprocessor": "~0.1.2",
4848
"concat-stream": "~1.5.0",
4949
"require-dir": "~0.3.0",

test/main.spec.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,88 @@
11
'use strict';
22

33
describe('angular slick testing', function () {
4+
var scope, $rootScope, $compile, $timeout, $injector;
5+
6+
beforeEach(module('slickCarousel'));
7+
8+
beforeEach(inject(function (_$rootScope_, _$compile_, _$timeout_, _$injector_) {
9+
$rootScope = _$rootScope_;
10+
scope = $rootScope.$new();
11+
$compile = _$compile_;
12+
$timeout = _$timeout_;
13+
$injector = _$injector_;
14+
15+
scope.date = [
16+
{id: 1, name: 'Mark', email: '[email protected]'},
17+
{id: 2, name: 'Ken', email: '[email protected]'},
18+
{id: 3, name: 'Oren', email: '[email protected]'},
19+
{id: 4, name: 'Kenny', email: '[email protected]'}
20+
];
21+
}));
22+
23+
// DSL (domain-specific language)
24+
function compileTemplate(template) {
25+
var el = $compile(angular.element(template))(scope);
26+
scope.$digest();
27+
return el;
28+
}
29+
30+
it('should init', function () {
31+
var element = compileTemplate('\
32+
<slick>\
33+
<div> 1 </div>\
34+
<div> 2 </div>\
35+
</slick>');
36+
scope.$digest();
37+
expect(element.hasClass('slick-initialized')).toBe(true);
38+
});
39+
40+
it('should init if ng-if is true', function () {
41+
scope.slickConfigLoaded = true;
42+
var element = compileTemplate('\
43+
<slick ng-if="1">\
44+
<div> 1 </div>\
45+
<div> 2 </div>\
46+
</slick>');
47+
scope.$digest();
48+
expect(element.next().hasClass('slick-initialized')).toBe(true);
49+
});
50+
51+
it('should re-init if change ng-if', function () {
52+
scope.slickConfigLoaded = true;
53+
var element = compileTemplate('\
54+
<slick ng-if="slickConfigLoaded">\
55+
<div ng-repeat="i in data">\
56+
<div> i </div>\
57+
</slick>');
58+
scope.$digest();
59+
expect(element.next().hasClass('slick-initialized')).toBe(true);
60+
});
61+
62+
it('should re-init if config change', function () {
63+
scope.isDestroy = false;
64+
scope.slickConfig = {
65+
autoplay: true,
66+
event: {
67+
destroy: function (event, slick) {
68+
scope.isDestroy = true;
69+
}
70+
}
71+
};
72+
var element = compileTemplate('\
73+
<slick settings="slickConfig">\
74+
<div ng-repeat="i in data">\
75+
<div> i </div>\
76+
</slick>');
77+
scope.$digest();
78+
79+
expect(element.hasClass('slick-initialized')).toBe(true);
80+
81+
scope.slickConfig.autoplay = false;
82+
scope.$digest();
83+
expect(scope.isDestroy).toBe(true);
84+
expect(element.hasClass('slick-initialized')).toBe(true);
85+
86+
});
487

588
});

0 commit comments

Comments
 (0)