forked from wwELi/ccms-components
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test framework * GridCtrl 测试用例 * test package.json update * GridHelper单元测试 * GridHelper单元测试 * 添加GridCtrl $onInit单元测试 * 补充测试覆盖率配置 * ci配置更新 * ci npm test * ci npm test * add coverage to readme * add download badge * readme update
- Loading branch information
Showing
17 changed files
with
394 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,8 @@ | |
"env": { | ||
"browser": true, | ||
"es6": true, | ||
"node": true | ||
"node": true, | ||
"mocha": true | ||
}, | ||
|
||
"plugins": [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
--- | ||
language: node_js | ||
node_js: | ||
- 6.2.0 # lastest | ||
cache: | ||
directories: | ||
- node_modules | ||
script: | ||
- npm test | ||
- cat ./test/coverage/lcov.info | ./node_modules/.bin/codecov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/** | ||
* @author Kuitos | ||
* @homepage https://github.com/kuitos/ | ||
* @since 2016-07-14 | ||
*/ | ||
|
||
import GridCtrl from '../GridCtrl'; | ||
import GRID_TEMPLATES from '../Constant'; | ||
import rowCellTemplate from '../tpls/row-cell.tpl.html'; | ||
|
||
import {assert} from 'chai'; | ||
|
||
describe('GridCtrl', () => { | ||
|
||
let gridCtrl; | ||
|
||
before(() => { | ||
|
||
gridCtrl = new GridCtrl(); | ||
gridCtrl.opts = { | ||
response: null, | ||
queryParams: { | ||
pageNum: 2 | ||
}, | ||
columnsDef: [ | ||
{ | ||
cellTemplate: '<span style="color:blue" ng-bind="entity.name" ng-click="app.click()" tooltip="entity.name" tooltip-append-to-body="true"></span>', | ||
displayName: '姓名', | ||
align: 'center', | ||
width: '100px' | ||
}, | ||
{field: 'age', displayName: '年龄', align: 'center'}, | ||
{field: 'gender', displayName: '性别', align: 'right'} | ||
], | ||
transformer: { | ||
pageNum: 'currentPage' | ||
} | ||
}; | ||
|
||
gridCtrl.$onInit(); | ||
}); | ||
|
||
it('$onInit', done => { | ||
|
||
const type = 'default'.toUpperCase(); | ||
|
||
Promise.all([gridCtrl.headerTemplate, gridCtrl.emptyTipsTemplate]) | ||
.then(tpls => { | ||
assert.equal(tpls[0], GRID_TEMPLATES[type][0]); | ||
assert.equal(tpls[1], GRID_TEMPLATES[type][2]); | ||
|
||
const bodyTpl = rowCellTemplate.replace('{::cell-placeholder}', GRID_TEMPLATES[type][1]); | ||
assert.equal(gridCtrl.bodyTemplate, bodyTpl); | ||
|
||
done(); | ||
}); | ||
}); | ||
|
||
it('switchSelectAll', () => { | ||
gridCtrl.switchSelectAll(true, [{name: 'kuitos'}, {age: 20}]); | ||
assert.deepEqual(gridCtrl.selectedItems, [{name: 'kuitos'}, {age: 20}]); | ||
|
||
gridCtrl.switchSelectAll(false, [{age: 20}]); | ||
assert.deepEqual(gridCtrl.selectedItems, [{name: 'kuitos'}]); | ||
}); | ||
|
||
it('switchSelectItem', () => { | ||
|
||
gridCtrl.switchSelectItem(true, {gender: 'xx'}); | ||
assert.deepEqual(gridCtrl.selectedItems, [{name: 'kuitos'}, {gender: 'xx'}]); | ||
|
||
gridCtrl.switchSelectItem(false, {gender: 'xx'}); | ||
assert.deepEqual(gridCtrl.selectedItems, [{name: 'kuitos'}]); | ||
}); | ||
|
||
it('isEntitySelected', () => { | ||
|
||
assert.isTrue(gridCtrl.isEntitySelected({name: 'kuitos'})); | ||
assert.isFalse(gridCtrl.isEntitySelected({name: 'kuitosx'})); | ||
}); | ||
|
||
it('$allSelected should auto change', () => { | ||
|
||
gridCtrl.opts.data = [{name: 'kuitos'}]; | ||
assert.isTrue(gridCtrl.$allSelected); | ||
|
||
gridCtrl.opts.data = [{name: 'kuitos'}, {age: 10}]; | ||
assert.isFalse(gridCtrl.$allSelected); | ||
}); | ||
|
||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* @author Kuitos | ||
* @homepage https://github.com/kuitos/ | ||
* @since 2016-07-25 | ||
*/ | ||
|
||
import GridHelper from '../GridHelper'; | ||
|
||
import {assert} from 'chai'; | ||
|
||
describe('GridHelper', () => { | ||
|
||
it('fillOpts', () => { | ||
|
||
const opts = { | ||
resource: 'A', | ||
columnsDef: [ | ||
{filed: 'name'} | ||
], | ||
showPagination: false | ||
}; | ||
const filledOpts = GridHelper.fillOpts(opts); | ||
|
||
assert.equal(filledOpts, opts); | ||
assert.equal(filledOpts.resource, 'A'); | ||
assert.deepEqual(filledOpts.columnsDef, [{filed: 'name'}]); | ||
assert.includeMembers(Object.keys(filledOpts), [ | ||
'resource', | ||
'response', | ||
'queryParams', | ||
'columnsDef', | ||
'externalData', | ||
'showPagination', | ||
'headerTpl', | ||
'cellTpl', | ||
'emptyTipTpl', | ||
'pager' | ||
]); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/** | ||
* @author Kuitos | ||
* @homepage https://github.com/kuitos/ | ||
* @since 2016-07-25 | ||
*/ | ||
|
||
var path = require('path'); | ||
var loaders = require('../webpack-common-loaders'); | ||
|
||
module.exports = { | ||
|
||
// base path that will be used to resolve all patterns (eg. files, exclude) | ||
basePath: './', | ||
|
||
// frameworks to use | ||
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter | ||
frameworks: ['mocha'], | ||
|
||
client: { | ||
mocha: { | ||
timeout: 15000 | ||
} | ||
}, | ||
|
||
// list of files / patterns to load in the browser | ||
files: [ | ||
'test.index.js' | ||
], | ||
|
||
// list of files to exclude | ||
exclude: [], | ||
|
||
// preprocess matching files before serving them to the browser | ||
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor | ||
preprocessors: { | ||
'test.index.js': ['webpack'] | ||
}, | ||
|
||
// Webpack | ||
webpack: { | ||
devtool: 'eval', | ||
output: { | ||
pathinfo: true | ||
}, | ||
eslint: { | ||
configFile: '.eslintrc', | ||
emitWarning: true, | ||
emitError: true, | ||
formatter: require('eslint-friendly-formatter') | ||
}, | ||
module: { | ||
preLoaders: [{ | ||
test: /\.js$/, | ||
loader: 'eslint-loader', | ||
exclude: /node_modules/, | ||
include: [path.join(__dirname, '../src')] | ||
}], | ||
loaders: loaders | ||
} | ||
|
||
}, | ||
|
||
// Webpack middleware | ||
webpackMiddleware: { | ||
noInfo: true | ||
}, | ||
|
||
// test results reporter to use | ||
// possible values: 'dots', 'progress' | ||
// available reporters: https://npmjs.org/browse/keyword/karma-reporter | ||
reporters: ['mocha'], | ||
|
||
// web server port | ||
port: 9876, | ||
|
||
// enable / disable colors in the output (reporters and logs) | ||
colors: true, | ||
|
||
// level of logging | ||
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG | ||
// logLevel: config.LOG_INFO, | ||
|
||
// enable / disable watching file and executing tests whenever any file changes | ||
autoWatch: true, | ||
|
||
// start these browsers | ||
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher | ||
browsers: ['Chrome'], | ||
|
||
// Continuous Integration mode | ||
// if true, Karma captures browsers, runs the tests and exits | ||
singleRun: false, | ||
|
||
// Concurrency level | ||
// how many browser should be started simultaneous | ||
concurrency: Infinity | ||
}; |
Oops, something went wrong.