|
| 1 | +var assert = require('assert'); |
| 2 | +var expect = require('expect'); |
| 3 | +var React = require('react/addons'); |
| 4 | +var Route = require('../Route'); |
| 5 | +var Redirect = require('../Redirect'); |
| 6 | +var Routes = require('../Routes'); |
| 7 | + |
| 8 | +describe('a Redirect', function () { |
| 9 | + |
| 10 | + it('redirects from old to new', function (done) { |
| 11 | + var descriptor = Redirect({ from: 'old', to: 'new' }); |
| 12 | + |
| 13 | + expect(descriptor.props.path).toEqual('old'); |
| 14 | + |
| 15 | + var fakeTransition = { |
| 16 | + redirect: function(to) { |
| 17 | + expect(to).toEqual('new'); |
| 18 | + done(); |
| 19 | + } |
| 20 | + }; |
| 21 | + |
| 22 | + descriptor.props.handler.willTransitionTo(fakeTransition); |
| 23 | + }); |
| 24 | + |
| 25 | + it('uses params and query from current path', function (done) { |
| 26 | + var descriptor = Redirect({ from: 'old', to: 'new' }); |
| 27 | + var expectedParams = { foo: 'bar' }; |
| 28 | + var expectedQuery = { baz: 'qux' }; |
| 29 | + |
| 30 | + var fakeTransition = { |
| 31 | + redirect: function(to, params, query) { |
| 32 | + expect(params).toEqual(expectedParams); |
| 33 | + expect(query).toEqual(expectedQuery); |
| 34 | + done(); |
| 35 | + } |
| 36 | + }; |
| 37 | + |
| 38 | + descriptor.props.handler.willTransitionTo(fakeTransition, expectedParams, expectedQuery); |
| 39 | + }); |
| 40 | + |
| 41 | + it('uses params and query from the Redirect definition', function (done) { |
| 42 | + var expectedParams = { foo: 'bar' }; |
| 43 | + var expectedQuery = { baz: 'qux' }; |
| 44 | + var fakePathParams = { hooba: 'scooba' }; |
| 45 | + var fakePathQuery = { doobie: 'scoobie' }; |
| 46 | + |
| 47 | + var descriptor = Redirect({ |
| 48 | + from: 'old', |
| 49 | + to: 'new', |
| 50 | + params: expectedParams, |
| 51 | + query: expectedQuery |
| 52 | + }); |
| 53 | + |
| 54 | + var fakeTransition = { |
| 55 | + redirect: function(to, params, query) { |
| 56 | + expect(params).toEqual(expectedParams); |
| 57 | + expect(query).toEqual(expectedQuery); |
| 58 | + done(); |
| 59 | + } |
| 60 | + }; |
| 61 | + |
| 62 | + descriptor.props.handler.willTransitionTo(fakeTransition, fakePathParams, fakePathQuery); |
| 63 | + }); |
| 64 | + |
| 65 | +}); |
| 66 | + |
0 commit comments