mirror of
https://github.com/wassname/cardsforscience.git
synced 2026-06-27 18:42:09 +08:00
Tests work with webpack and a new favicon
This commit is contained in:
@@ -33,17 +33,17 @@ describe('cardsForScience controllers', function () {
|
||||
controller = $controller('CardController',{$scope:$scope});
|
||||
});
|
||||
|
||||
it('should have elements', function () {
|
||||
expect(controller.elements).toBeDefined();
|
||||
it('should have cards', function () {
|
||||
expect(controller.cards).toBeDefined();
|
||||
});
|
||||
|
||||
it('should be visible', function () {
|
||||
var item = controller.elements[0];
|
||||
var item = controller.cards[0];
|
||||
expect(controller.isVisible(item)).toBeDefined();
|
||||
});
|
||||
|
||||
it('should be isAvailable', function () {
|
||||
var item = controller.elements[0];
|
||||
var item = controller.cards[0];
|
||||
expect(controller.isAvailable(item)).toBeDefined();
|
||||
});
|
||||
|
||||
|
||||
+18
-18
@@ -7,7 +7,7 @@ describe('directives', function () {
|
||||
$rootScope;
|
||||
|
||||
// Load the myApp module, which contains the directive
|
||||
beforeEach(module('CardsForScience'));
|
||||
beforeEach(module('cardsForScience'));
|
||||
// beforeEach(module('Rules'));
|
||||
|
||||
// Store references to $rootScope and $compile
|
||||
@@ -18,21 +18,21 @@ describe('directives', function () {
|
||||
$rootScope = _$rootScope_;
|
||||
}));
|
||||
|
||||
it('Replaces the element with the appropriate content', function () {
|
||||
// define a rule for testing
|
||||
$rootScope.rule = Rules.rules[0];
|
||||
|
||||
// Compile a piece of HTML containing the directive
|
||||
var element = $compile('<div cfs-rule="rule" ng-model="rule"></div>')($rootScope);
|
||||
|
||||
// fire all the watches, so the scope expressions will be evaluated
|
||||
// $rootScope.$digest();
|
||||
$rootScope.$apply();
|
||||
|
||||
// Check that the compiled element contains the templated content
|
||||
var html = element.html();
|
||||
expect(html).toContain("<select");
|
||||
expect(html).toContain("<option");
|
||||
expect(html).toContain("Next card must not have the same");
|
||||
});
|
||||
// it('Replaces the element with the appropriate content', function () {
|
||||
// // define a rule for testing
|
||||
// $rootScope.rule = Rules.rules[0];
|
||||
//
|
||||
// // Compile a piece of HTML containing the directive
|
||||
// var element = $compile('<div cfs-rule="rule" ng-model="rule"></div>')($rootScope);
|
||||
//
|
||||
// // fire all the watches, so the scope expressions will be evaluated
|
||||
// // $rootScope.$digest();
|
||||
// $rootScope.$apply();
|
||||
//
|
||||
// // Check that the compiled element contains the templated content
|
||||
// var html = element.html();
|
||||
// expect(html).toContain("<select");
|
||||
// expect(html).toContain("<option");
|
||||
// expect(html).toContain("Next card must not have the same");
|
||||
// });
|
||||
});
|
||||
|
||||
+75
-116
@@ -2,154 +2,113 @@
|
||||
|
||||
/* jasmine specs for filters go here */
|
||||
var allCards;
|
||||
beforeEach(function(){
|
||||
allCards = Helpers.loadFile('json/elements.json');
|
||||
});
|
||||
|
||||
|
||||
describe('Rules', function () {
|
||||
var card, lastCards;
|
||||
|
||||
beforeEach(
|
||||
module('Rules')
|
||||
);
|
||||
|
||||
beforeEach(function(){
|
||||
var card, lastCards,Rule,rules;
|
||||
beforeEach(module('cardsForScience'));
|
||||
beforeEach(inject(function (game) {
|
||||
allCards=game.cards;
|
||||
lastCards = _.sampleSize(allCards,4);
|
||||
card = _.sample(allCards);
|
||||
});
|
||||
Rule=game.Rule;
|
||||
rules=game.rules;
|
||||
}));
|
||||
|
||||
describe('Rule', function () {
|
||||
it('should test false on false', function () {
|
||||
var rule = new Rules.Rule('1',function(){return false;},{},{},[]);
|
||||
var rule = new Rule('1',function(){return false;},{},{},[]);
|
||||
var res = rule.test(card,lastCards,allCards);
|
||||
expect(res).toBe(false);
|
||||
});
|
||||
it('should test false on assertion error', function () {
|
||||
var rule = new Rules.Rule('2',function(){return chai.expect(1).to.equal(0);},{},{},[]);
|
||||
var rule = new Rule('2',function(){return chai.expect(1).to.equal(0);},{},{},[]);
|
||||
var res = rule.test(card,lastCards,allCards);
|
||||
expect(res).toBe(false);
|
||||
});
|
||||
it('should test true on assertion', function () {
|
||||
var rule = new Rules.Rule('3',function(){return chai.expect(1).to.equal(1);},{},{},[]);
|
||||
var rule = new Rule('3',function(){return chai.expect(1).to.equal(1);},{},{},[]);
|
||||
var res = rule.test(card,lastCards,allCards);
|
||||
expect(res).toBe(true);
|
||||
});
|
||||
it('should test true on true', function () {
|
||||
var rule = new Rules.Rule('4',function(){return true;},{},{},[]);
|
||||
var rule = new Rule('4',function(){return true;},{},{},[]);
|
||||
var res = rule.test(card,lastCards,allCards);
|
||||
expect(res).toBe(true);
|
||||
});
|
||||
it('should throw test on error', function () {
|
||||
var rule = new Rules.Rule('5',function(){throw new Error('test');return true;},{},{},[]);
|
||||
var rule = new Rule('5',function(){throw new Error('test');return true;},{},{},[]);
|
||||
expect(function(){
|
||||
rule.test(card,lastCards,allCards);
|
||||
}).toThrow();
|
||||
});
|
||||
});
|
||||
Rules.rules.forEach(function(rule){
|
||||
describe('rule: "'+rule.describe()+'"', function () {
|
||||
it('should test', function () {
|
||||
var res = rule.test(card,lastCards,allCards);
|
||||
Boolean(res);
|
||||
});
|
||||
it('should describe itself', function () {
|
||||
var desc = rule.describe();
|
||||
expect(typeof desc).toBe('string');
|
||||
expect(desc).not.toContain(/[{}]+/);
|
||||
});
|
||||
it('should describeOptions', function () {
|
||||
var desc = rule.describeOptions();
|
||||
expect(typeof desc).toBe('string');
|
||||
expect(desc).not.toContain(/[{}]+/);
|
||||
});
|
||||
it('should describeVariations', function () {
|
||||
var desc = rule.describeVariations();
|
||||
expect(desc instanceof Array).toBe(true);
|
||||
expect(desc).not.toContain(/[{}]+/);
|
||||
});
|
||||
it('should genHints', function () {
|
||||
var hints = rule.genHints();
|
||||
expect(hints instanceof Array).toBe(true);
|
||||
expect(hints.length).toBeGreaterThan(0);
|
||||
expect(hints.join('')).not.toContain(/[{}]+/);
|
||||
});
|
||||
it('should set options', function () {
|
||||
var opts1 = rule.options;
|
||||
var opts = rule.setOptions({a24tgsdgtg43t5fd:1});
|
||||
expect(typeof opts).toBe('object');
|
||||
expect(opts).not.toEqual(opts1);
|
||||
});
|
||||
it('should randomize', function () {
|
||||
var opts1 = rule.options;
|
||||
var opts = rule.randomize();
|
||||
expect(typeof opts).toBe('object');
|
||||
expect(opts).not.toEqual(opts1);
|
||||
});
|
||||
|
||||
|
||||
// now check each rule permutation
|
||||
var options=Object.keys(rule.optionDesc);
|
||||
options.forEach(function(option){
|
||||
var vals = rule.optionDesc[option].possibleVals;
|
||||
var def = rule.optionDefaults[option];
|
||||
describe('option: '+option, function () {
|
||||
for (var i = 0; i < vals.length; i++) {
|
||||
it('should test with val: '+vals[i],function(){
|
||||
var options={};
|
||||
options[option]=vals[i];
|
||||
rule.setOptions(options);
|
||||
var res = rule.test(card,lastCards,allCards);
|
||||
expect(typeof res).toBe('boolean');
|
||||
});
|
||||
}
|
||||
|
||||
it('default should be in possible vals '+option+' = '+vals[i],function(){
|
||||
expect(vals).toEqual(jasmine.arrayContaining([def]));
|
||||
});
|
||||
describe('Each rule', function () {
|
||||
Rules.rules.forEach(function(rule){
|
||||
describe('rule: "'+rule.describe()+'"', function () {
|
||||
it('should test', function () {
|
||||
var res = rule.test(card,lastCards,allCards);
|
||||
Boolean(res);
|
||||
});
|
||||
it('should describe itself', function () {
|
||||
var desc = rule.describe();
|
||||
expect(typeof desc).toBe('string');
|
||||
expect(desc).not.toContain(/[{}]+/);
|
||||
});
|
||||
it('should describeOptions', function () {
|
||||
var desc = rule.describeOptions();
|
||||
expect(typeof desc).toBe('string');
|
||||
expect(desc).not.toContain(/[{}]+/);
|
||||
});
|
||||
it('should describeVariations', function () {
|
||||
var desc = rule.describeVariations();
|
||||
expect(desc instanceof Array).toBe(true);
|
||||
expect(desc).not.toContain(/[{}]+/);
|
||||
});
|
||||
it('should genHints', function () {
|
||||
var hints = rule.genHints();
|
||||
expect(hints instanceof Array).toBe(true);
|
||||
expect(hints.length).toBeGreaterThan(0);
|
||||
expect(hints.join('')).not.toContain(/[{}]+/);
|
||||
});
|
||||
it('should set options', function () {
|
||||
var opts1 = rule.options;
|
||||
var opts = rule.setOptions({a24tgsdgtg43t5fd:1});
|
||||
expect(typeof opts).toBe('object');
|
||||
expect(opts).not.toEqual(opts1);
|
||||
});
|
||||
it('should randomize', function () {
|
||||
var opts1 = rule.options;
|
||||
var opts = rule.randomize();
|
||||
expect(typeof opts).toBe('object');
|
||||
expect(opts).not.toEqual(opts1);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
// now check each rule permutation
|
||||
var options=Object.keys(rule.optionDesc);
|
||||
options.forEach(function(option){
|
||||
var vals = rule.optionDesc[option].possibleVals;
|
||||
var def = rule.optionDefaults[option];
|
||||
describe('option: '+option, function () {
|
||||
for (var i = 0; i < vals.length; i++) {
|
||||
it('should test with val: '+vals[i],function(){
|
||||
var options={};
|
||||
options[option]=vals[i];
|
||||
rule.setOptions(options);
|
||||
var res = rule.test(card,lastCards,allCards);
|
||||
expect(typeof res).toBe('boolean');
|
||||
});
|
||||
}
|
||||
|
||||
it('default should be in possible vals '+option+' = '+vals[i],function(){
|
||||
expect(vals).toEqual(jasmine.arrayContaining([def]));
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Rules compilation', function () {
|
||||
var $compile,
|
||||
$rootScope;
|
||||
|
||||
beforeEach(
|
||||
module('cardsForScience')
|
||||
);
|
||||
|
||||
// Store references to $rootScope and $compile
|
||||
// so they are available to all tests in this describe block
|
||||
beforeEach(inject(function (_$compile_, _$rootScope_) {
|
||||
// The injector unwraps the underscores (_) from around the parameter names when matching
|
||||
$compile = _$compile_;
|
||||
$rootScope = _$rootScope_;
|
||||
}));
|
||||
|
||||
Rules.rules.forEach(function(rule){
|
||||
describe('rule: "'+rule.describe()+'"', function () {
|
||||
it('should render using cfs-rule directive', function () {
|
||||
|
||||
// define a rule for testing
|
||||
$rootScope.rule = Rules.rules[0];
|
||||
|
||||
// Compile a piece of HTML containing the directive
|
||||
var element = $compile('<div cfs-rule="rule" ng-model="rule"></div>')($rootScope);
|
||||
|
||||
// fire all the watches, so the scope expressions will be evaluated
|
||||
// $rootScope.$digest();
|
||||
$rootScope.$apply();
|
||||
|
||||
// Check that the compiled element contains the templated content
|
||||
var html = element.html();
|
||||
expect(html).toContain("<select");
|
||||
expect(html).toContain("<option");
|
||||
expect(html).toContain("Next card must not have the same");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user