|
| 1 | +require('./helper'); |
| 2 | +var RouteStore = require('../modules/stores/RouteStore'); |
| 3 | +var NotFoundRoute = require('../modules/components/NotFoundRoute'); |
| 4 | +var Route = require('../modules/components/Route'); |
| 5 | +var Routes = require('../modules/components/Routes'); |
| 6 | + |
| 7 | +var App = React.createClass({ |
| 8 | + displayName: 'App', |
| 9 | + render: function () { |
| 10 | + return React.DOM.div(); |
| 11 | + } |
| 12 | +}); |
| 13 | + |
| 14 | +describe('when registering a NotFoundRoute', function () { |
| 15 | + describe('nested inside a Route component', function () { |
| 16 | + it('becomes that Route\'s notFoundRoute', function () { |
| 17 | + var notFoundRoute; |
| 18 | + var route = Route({ handler: App }, |
| 19 | + notFoundRoute = NotFoundRoute({ handler: App }) |
| 20 | + ); |
| 21 | + |
| 22 | + RouteStore.registerRoute(route); |
| 23 | + expect(route.props.notFoundRoute).toBe(notFoundRoute); |
| 24 | + RouteStore.unregisterRoute(route); |
| 25 | + }); |
| 26 | + }); |
| 27 | + |
| 28 | + describe('nested inside a Routes component', function () { |
| 29 | + it('becomes that Routes\' notFoundRoute', function () { |
| 30 | + var notFoundRoute; |
| 31 | + var routes = Routes({ handler: App }, |
| 32 | + notFoundRoute = NotFoundRoute({ handler: App }) |
| 33 | + ); |
| 34 | + |
| 35 | + RouteStore.registerRoute(notFoundRoute, routes); |
| 36 | + expect(routes.props.notFoundRoute).toBe(notFoundRoute); |
| 37 | + RouteStore.unregisterRoute(notFoundRoute); |
| 38 | + }); |
| 39 | + }); |
| 40 | +}); |
| 41 | + |
| 42 | +describe('when no child routes match a URL, but the beginning of the parent\'s path matches', function () { |
| 43 | + it('matches the default route', function () { |
| 44 | + var notFoundRoute; |
| 45 | + var routes = ReactTestUtils.renderIntoDocument( |
| 46 | + Routes(null, |
| 47 | + Route({ name: 'user', path: '/users/:id', handler: App }, |
| 48 | + Route({ name: 'home', path: '/users/:id/home', handler: App }), |
| 49 | + // Make it the middle sibling to test order independence. |
| 50 | + notFoundRoute = NotFoundRoute({ handler: App }), |
| 51 | + Route({ name: 'news', path: '/users/:id/news', handler: App }) |
| 52 | + ) |
| 53 | + ) |
| 54 | + ); |
| 55 | + |
| 56 | + var matches = routes.match('/users/5/not-found'); |
| 57 | + assert(matches); |
| 58 | + expect(matches.length).toEqual(2); |
| 59 | + |
| 60 | + expect(matches[1].route).toBe(notFoundRoute); |
| 61 | + |
| 62 | + expect(matches[0].route.props.name).toEqual('user'); |
| 63 | + }); |
| 64 | +}); |
0 commit comments