Permalink
Browse files

Unit tests for _next tag

  • Loading branch information...
1 parent b3e6cdc commit cc42ad88cf82e2009a265ef1ea744ddd4951670a @bemson committed Feb 19, 2014
Showing with 137 additions and 0 deletions.
  1. +136 −0 test/api.tag.next.js
  2. +1 −0 test/index.html
View
@@ -0,0 +1,136 @@
+describe( '_next tag', function () {
+
+ var
+ salt,
+ inSpy,
+ onSpy,
+ outSpy
+ ;
+
+ beforeEach(function () {
+ inSpy = sinon.spy();
+ onSpy = sinon.spy();
+ outSpy = sinon.spy();
+ });
+
+ it( 'should navigate to the resolved state when paired with a query', function () {
+ salt = new Salt({
+ _next: 0,
+ _on: onSpy
+ });
+ salt.go(1);
+ onSpy.should.have.been.calledOnce;
+ salt.state.index.should.equal(0);
+ });
+
+ it( 'should only redirect when the state is targeted', function () {
+ salt = new Salt({
+ _next: 0,
+ _on: inSpy,
+ foo: {
+ _next: 1,
+ _in: onSpy
+ }
+ });
+ salt.go('//foo');
+ salt.state.index.should.equal(0);
+ onSpy.should.have.been.calledBefore(inSpy);
+ });
+
+ it( 'should be observed before an `_on` short-form redirects', function () {
+ salt = new Salt({
+ _on: 'bar',
+ _next: 'foo',
+ foo: inSpy,
+ bar: onSpy
+ });
+ salt.go(1);
+ salt.state.name.should.equal('bar');
+ inSpy.should.have.been.calledOnce;
+ onSpy.should.have.been.calledOnce;
+ inSpy.should.have.been.calledBefore(onSpy);
+ });
+
+ it( 'should be observed after `_wait` expires', function () {
+ salt = new Salt({
+ _next: 0,
+ _wait: true,
+ _out: outSpy
+ });
+ salt.go(1);
+ salt.status('paused').should.be.ok;
+ salt.state.index.should.equal(1);
+ outSpy.should.not.have.been.called;
+
+ salt.go(0);
+ salt.state.index.should.equal(0);
+ outSpy.should.have.been.calledOnce;
+ });
+
+ it( 'should inject new waypoints in a `_sequence`', function () {
+ salt = new Salt({
+ _sequence: true,
+ a: {
+ _next: '/b',
+ _out: outSpy
+ },
+ b: {
+ _sequence: false,
+ _in: inSpy
+ },
+ c: onSpy
+ });
+ salt.go(1);
+
+ salt.state.name.should.equal('c');
+ outSpy.should.have.been.calledBefore(inSpy);
+ inSpy.should.have.been.calledBefore(onSpy);
+ });
+
+ it( 'should schedule navigation before `_on` callback', function () {
+ salt = new Salt({
+ _next: 0,
+ _in: function () {
+ var program = this;
+ program.status('targets')[0].should.equal('//');
+ },
+ _on: function () {
+ var program = this;
+ program.status('targets').should.not.be.empty;
+ expect(program.status('targets')[0]).to.equal('..//');
+ program.wait();
+ }
+ });
+ salt.go(1);
+ salt.state.index.should.equal(1);
+ });
+
+ describe( 'prefixed with a ">"', function () {
+
+ it( 'should set a new destination state', function () {
+ salt = new Salt({
+ _on: 'bar',
+ _next: '>foo',
+ foo: inSpy,
+ bar: onSpy
+ });
+ salt.go(1);
+ salt.state.name.should.equal('foo');
+ inSpy.should.have.been.calledOnce;
+ onSpy.should.not.have.been.called;
+ });
+
+ it( 'should pass-thru arguments', function () {
+ var arg = {};
+ salt = new Salt({
+ _next: '>foo',
+ foo: onSpy,
+ });
+ salt.get(1, arg);
+ salt.state.name.should.equal('foo');
+ onSpy.should.have.been.calledWithExactly(arg);
+ });
+
+ });
+
+});
View
@@ -61,6 +61,7 @@
<script src="api.tag.tail.js"></script>
<script src="api.tag.import.js"></script>
<script src="api.tag.wait.js"></script>
+ <script src="api.tag.next.js"></script>
<script>
mocha.run();
</script>

0 comments on commit cc42ad8

Please sign in to comment.