Skip to content

sf-field tests, and minor changes to karma.conf #873

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ module.exports = function(config) {

// test results reporter to use
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
reporters: ['dots','progress','coverage','growler'],
reporters: ['mocha','coverage','growler'],

mochaReporter: {
showDiff: true
},

preprocessors: {
'src/**/*.js': ['coverage']
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@
"babel-polyfill": "^6.16.0",
"babel-preset-es2015": "^6.18.0",
"chai": "^3.5.0",
"diff": "^3.2.0",
"html-webpack-externals-plugin": "^2.1.2",
"karma": "^1.3.0",
"karma-babel-preprocessor": "^6.0.1",
"karma-chai-sinon": "^0.1.5",
"karma-coverage": "^1.1.1",
"karma-growler-reporter": "0.0.1",
"karma-mocha": "^1.3.0",
"karma-mocha-reporter": "^2.2.3",
"karma-phantomjs-launcher": "^1.0.2",
"karma-webpack": "^1.8.0",
"mocha": "^3.2.0",
Expand Down
80 changes: 80 additions & 0 deletions src/directives/sf-field.directive.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
chai.should();

var runSync = function (scope, tmpl) {
var directiveScope = tmpl.isolateScope();
var stub = sinon.stub(directiveScope, 'resolveReferences', function(schema, form) {
directiveScope.render(schema, form);
});
scope.$apply();
}

describe('sf-field.directive.js',function() {
beforeEach(module('schemaForm'));
beforeEach(
module(function($sceProvider){
$sceProvider.enabled(false);
})
);

var keyTests = [
{
name: 'array of objects',
targetKey: ['arrayOfObjects', 0, 'stringVal'],
schema: {
type: 'object',
properties: {
arrayOfObjects: {
type: 'array',
items: {
type: 'object',
properties: {
stringVal: {
type: 'string',
'x-schema-form': {
htmlClass: 'targetKey'
}
}
}
}
}
}
},
},

{
name: 'array of strings',
targetKey: ['arrayOfStrings', 0],
schema: {
type: 'object',
properties: {
arrayOfStrings: {
type: 'array',
items: {
type: 'string',
'x-schema-form': {
htmlClass: 'targetKey'
}
}
}
}
}
}
];

keyTests.forEach(function(keyTest) {
it('should generate correct form keys for ' + keyTest.name, function(done) {
inject(function($compile,$rootScope) {
var scope = $rootScope.$new();
scope.model = {};
scope.schema = keyTest.schema;

var tmpl = angular.element('<form sf-schema="schema" sf-model="model"></form>');

$compile(tmpl)(scope);
runSync(scope, tmpl);

tmpl.children().find('.targetKey').scope().form.key.should.deep.equal(keyTest.targetKey);
});
});
});
});
191 changes: 0 additions & 191 deletions src/directives/sf-schema.directive.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2217,197 +2217,6 @@ describe('sf-schema.directive.js', function() {
});
});

it('should not add "has-success" class to radios field if a correct value is entered, but disableSuccessState is set on form', function () {
var field = {
name: 'radios',
property: {
type: 'boolean',
},
form: {
key: ["field"],
type: "radios",
titleMap: [
{
"value": false,
"name": "No way"
},
{
"value": true,
"name": "OK"
}
]
}
};

inject(function($compile, $rootScope) {
var scope = $rootScope.$new();
scope.model = {}
scope.schema = {
type: 'object',
properties: {
field: field.property
}
};
scope.form = [field.form];

var tmpl = angular.element('<form name="theForm" sf-schema="schema" sf-form="form" sf-model="model"></form>');
$compile(tmpl)(scope);
runSync(scope, tmpl);
var ngModelCtrl = tmpl.find('.field').scope().ngModel;
ngModelCtrl.$valid = true;
ngModelCtrl.$pristine = false;
$rootScope.$apply();
tmpl.find('.field').hasClass('has-success').should.be.true;
scope.form[0].disableSuccessState = true;
$rootScope.$apply();
tmpl.find('.field').hasClass('has-success').should.be.false;
});
});

it('should not add "has-error" class to radios field if invalid value is entered, but disableErrorState is set on form', function () {
var field = {
name: 'radios',
property: {
type: 'boolean',
},
form: {
key: ["field"],
type: "radios",
titleMap: [
{
"value": false,
"name": "No way"
},
{
"value": true,
"name": "OK"
}
]
}
};

inject(function($compile, $rootScope) {
var scope = $rootScope.$new();
scope.model = {
field: field.errorValue
}
scope.schema = {
type: 'object',
properties: {
field: field.property
}
};
scope.form = [field.form];

var tmpl = angular.element('<form name="theForm" sf-schema="schema" sf-form="form" sf-model="model"></form>');
$compile(tmpl)(scope);
runSync(scope, tmpl);
var ngModelCtrl = tmpl.find('.field').scope().ngModel;
ngModelCtrl.$invalid = true;
ngModelCtrl.$pristine = false;
$rootScope.$apply();
tmpl.find('.field').hasClass('has-error').should.be.true;
scope.form[0].disableErrorState = true;
$rootScope.$apply();
tmpl.find('.field').hasClass('has-error').should.be.false;
});
});

it('should not add "has-success" class to radios-inline field if a correct value is entered, but disableSuccessState is set on form', function () {
var field = {
name: 'radios',
property: {
type: 'boolean',
},
form: {
key: ["field"],
type: "radios",
titleMap: [
{
"value": false,
"name": "No way"
},
{
"value": true,
"name": "OK"
}
]
}
};

inject(function($compile, $rootScope) {
var scope = $rootScope.$new();
scope.model = {}
scope.schema = {
type: 'object',
properties: {
field: field.property
}
};
scope.form = [field.form];

var tmpl = angular.element('<form name="theForm" sf-schema="schema" sf-form="form" sf-model="model"></form>');
$compile(tmpl)(scope);
runSync(scope, tmpl);
var ngModelCtrl = tmpl.find('.field').scope().ngModel;
ngModelCtrl.$valid = true;
ngModelCtrl.$pristine = false;
$rootScope.$apply();
tmpl.find('.field').hasClass('has-success').should.be.true;
scope.form[0].disableSuccessState = true;
$rootScope.$apply();
tmpl.find('.field').hasClass('has-success').should.be.false;
});
});

it('should not add "has-error" class to radios-inline field if invalid value is entered, but disableErrorState is set on form', function () {
var field = {
name: 'radios',
property: {
type: 'boolean',
},
form: {
key: ["field"],
type: "radios",
titleMap: [
{
"value": false,
"name": "No way"
},
{
"value": true,
"name": "OK"
}
]
}
};

inject(function($compile, $rootScope) {
var scope = $rootScope.$new();
scope.model = {
field: field.errorValue
}
scope.schema = {
type: 'object',
properties: {
field: { type: 'boolean' }
}
};
scope.form = [field.form];

var tmpl = angular.element('<form name="theForm" sf-schema="schema" sf-form="form" sf-model="model"></form>');
$compile(tmpl)(scope);
runSync(scope, tmpl);
var ngModelCtrl = tmpl.find('.field').scope().ngModel;
ngModelCtrl.$invalid = true;
ngModelCtrl.$pristine = false;
$rootScope.$apply();
tmpl.find('.field').hasClass('has-error').should.be.true;
scope.form[0].disableErrorState = true;
$rootScope.$apply();
tmpl.find('.field').hasClass('has-error').should.be.false;
});
});
/*
TODO
it('should handle onChange for array type', function () {
Expand Down