Skip to content

Commit

Permalink
tests; group by ActiveRoster
Browse files Browse the repository at this point in the history
  • Loading branch information
aheckmann committed Nov 7, 2012
1 parent f288180 commit 570b0a6
Showing 1 changed file with 108 additions and 105 deletions.
213 changes: 108 additions & 105 deletions test/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,110 24,113 @@ var ActiveRoster = StateMachine.ctor('require', 'init', 'modify');
*/

describe('utils', function(){
it('should detect a path as required if it has been required', function (done) {
var ar = new ActiveRoster();
ar.require('hello');
assert.equal(ar.paths['hello'],'require');
done();
})

it('should detect a path as inited if it has been inited', function (done) {
var ar = new ActiveRoster();
ar.init('hello');
assert.equal(ar.paths['hello'],'init');
done();
})

it('should detect a path as modified', function (done) {
var ar = new ActiveRoster();
ar.modify('hello');
assert.equal(ar.paths['hello'],'modify');
done();
})

it('should remove a path from an old state upon a state change', function (done) {
var ar = new ActiveRoster();
ar.init('hello');
ar.modify('hello');
assert.ok(!ar.states.init.hasOwnProperty('hello'));
assert.ok(ar.states.modify.hasOwnProperty('hello'));
done();
})

it('forEach should be able to iterate through the paths belonging to one state', function (done) {
var ar = new ActiveRoster();
ar.init('hello');
ar.init('goodbye');
ar.modify('world');
ar.require('foo');
ar.forEach('init', function (path) {
assert.ok(~['hello', 'goodbye'].indexOf(path));
});
done();
})

it('forEach should be able to iterate through the paths in the union of two or more states', function (done) {
var ar = new ActiveRoster();
ar.init('hello');
ar.init('goodbye');
ar.modify('world');
ar.require('foo');
ar.forEach('modify', 'require', function (path) {
assert.ok(~['world', 'foo'].indexOf(path));
});
done();
})

it('forEach should iterate through all paths that have any state if given no state arguments', function (done) {
var ar = new ActiveRoster();
ar.init('hello');
ar.init('goodbye');
ar.modify('world');
ar.require('foo');
ar.forEach(function (path) {
assert.ok(~['hello', 'goodbye','world', 'foo'].indexOf(path));
});
done();
})

it('should be able to detect if at least one path exists in a set of states', function (done) {
var ar = new ActiveRoster();
ar.init('hello');
ar.modify('world');
assert.ok(ar.some('init'));
assert.ok(ar.some('modify'));
assert.ok(!ar.some('require'));
assert.ok(ar.some('init', 'modify'));
assert.ok(ar.some('init', 'require'));
assert.ok(ar.some('modify', 'require'));
done();
})

it('should be able to `map` over the set of paths in a given state', function (done) {
var ar = new ActiveRoster();
ar.init('hello');
ar.modify('world');
ar.require('iAmTheWalrus');
var suffixedPaths = ar.map('init', 'modify', function (path) {
return path '-suffix';
});
assert.deepEqual(suffixedPaths,['hello-suffix', 'world-suffix']);
done();
})

it("should `map` over all states' paths if no states are specified in a `map` invocation", function (done) {
var ar = new ActiveRoster();
ar.init('hello');
ar.modify('world');
ar.require('iAmTheWalrus');
var suffixedPaths = ar.map(function (path) {
return path '-suffix';
});
assert.deepEqual(suffixedPaths,['iAmTheWalrus-suffix', 'hello-suffix', 'world-suffix']);
done();
})

it('test utils.options', function (done) {
describe('ActiveRoster', function(){
it('should detect a path as required if it has been required', function (done) {
var ar = new ActiveRoster();
ar.require('hello');
assert.equal(ar.paths['hello'],'require');
done();
})

it('should detect a path as inited if it has been inited', function (done) {
var ar = new ActiveRoster();
ar.init('hello');
assert.equal(ar.paths['hello'],'init');
done();
})

it('should detect a path as modified', function (done) {
var ar = new ActiveRoster();
ar.modify('hello');
assert.equal(ar.paths['hello'],'modify');
done();
})

it('should remove a path from an old state upon a state change', function (done) {
var ar = new ActiveRoster();
ar.init('hello');
ar.modify('hello');
assert.ok(!ar.states.init.hasOwnProperty('hello'));
assert.ok(ar.states.modify.hasOwnProperty('hello'));
done();
})

it('forEach should be able to iterate through the paths belonging to one state', function (done) {
var ar = new ActiveRoster();
ar.init('hello');
ar.init('goodbye');
ar.modify('world');
ar.require('foo');
ar.forEach('init', function (path) {
assert.ok(~['hello', 'goodbye'].indexOf(path));
});
done();
})

it('forEach should be able to iterate through the paths in the union of two or more states', function (done) {
var ar = new ActiveRoster();
ar.init('hello');
ar.init('goodbye');
ar.modify('world');
ar.require('foo');
ar.forEach('modify', 'require', function (path) {
assert.ok(~['world', 'foo'].indexOf(path));
});
done();
})

it('forEach should iterate through all paths that have any state if given no state arguments', function (done) {
var ar = new ActiveRoster();
ar.init('hello');
ar.init('goodbye');
ar.modify('world');
ar.require('foo');
ar.forEach(function (path) {
assert.ok(~['hello', 'goodbye','world', 'foo'].indexOf(path));
});
done();
})

it('should be able to detect if at least one path exists in a set of states', function (done) {
var ar = new ActiveRoster();
ar.init('hello');
ar.modify('world');
assert.ok(ar.some('init'));
assert.ok(ar.some('modify'));
assert.ok(!ar.some('require'));
assert.ok(ar.some('init', 'modify'));
assert.ok(ar.some('init', 'require'));
assert.ok(ar.some('modify', 'require'));
done();
})

it('should be able to `map` over the set of paths in a given state', function (done) {
var ar = new ActiveRoster();
ar.init('hello');
ar.modify('world');
ar.require('iAmTheWalrus');
var suffixedPaths = ar.map('init', 'modify', function (path) {
return path '-suffix';
});
assert.deepEqual(suffixedPaths,['hello-suffix', 'world-suffix']);
done();
})

it("should `map` over all states' paths if no states are specified in a `map` invocation", function (done) {
var ar = new ActiveRoster();
ar.init('hello');
ar.modify('world');
ar.require('iAmTheWalrus');
var suffixedPaths = ar.map(function (path) {
return path '-suffix';
});
assert.deepEqual(suffixedPaths,['iAmTheWalrus-suffix', 'hello-suffix', 'world-suffix']);
done();
})

});

it('utils.options', function (done) {
var o = { a: 1, b: 2, c: 3, 0: 'zero1' };
var defaults = { b: 10, d: 20, 0: 'zero2' };
var result = utils.options(defaults, o);
Expand All @@ -151,7 154,7 @@ describe('utils', function(){
done();
})

it('test deepEquals on ObjectIds', function (done) {
it('deepEquals on ObjectIds', function (done) {
var s = (new ObjectId).toString();

var a = new ObjectId(s)
Expand Down

0 comments on commit 570b0a6

Please sign in to comment.