|
| 1 | +var assert = require('assert'); |
| 2 | +var React = require('react/addons'); |
| 3 | +var ReactTestUtils = React.addons.TestUtils; |
| 4 | +var Route = require('../../components/Route'); |
| 5 | +var ActiveDelegate = require('../ActiveDelegate'); |
| 6 | + |
| 7 | +describe('ActiveDelegate', function () { |
| 8 | + var App = React.createClass({ |
| 9 | + mixins: [ ActiveDelegate ], |
| 10 | + render: function () { |
| 11 | + return React.DOM.div(); |
| 12 | + } |
| 13 | + }); |
| 14 | + |
| 15 | + describe('when a route is active', function () { |
| 16 | + var route; |
| 17 | + beforeEach(function () { |
| 18 | + route = Route({ name: 'products', handler: App }); |
| 19 | + }); |
| 20 | + |
| 21 | + describe('and it has no params', function () { |
| 22 | + var component; |
| 23 | + beforeEach(function () { |
| 24 | + component = ReactTestUtils.renderIntoDocument( |
| 25 | + App({ |
| 26 | + initialState: { |
| 27 | + activeRoutes: [ route ] |
| 28 | + } |
| 29 | + }) |
| 30 | + ); |
| 31 | + }); |
| 32 | + |
| 33 | + afterEach(function () { |
| 34 | + React.unmountComponentAtNode(component.getDOMNode()); |
| 35 | + }); |
| 36 | + |
| 37 | + it('is active', function () { |
| 38 | + assert(component.isActive('products')); |
| 39 | + }); |
| 40 | + }); |
| 41 | + |
| 42 | + describe('and the right params are given', function () { |
| 43 | + var component; |
| 44 | + beforeEach(function () { |
| 45 | + component = ReactTestUtils.renderIntoDocument( |
| 46 | + App({ |
| 47 | + initialState: { |
| 48 | + activeRoutes: [ route ], |
| 49 | + activeParams: { id: '123', show: 'true', variant: 456 }, |
| 50 | + activeQuery: { search: 'abc', limit: 789 } |
| 51 | + } |
| 52 | + }) |
| 53 | + ); |
| 54 | + }); |
| 55 | + |
| 56 | + afterEach(function () { |
| 57 | + React.unmountComponentAtNode(component.getDOMNode()); |
| 58 | + }); |
| 59 | + |
| 60 | + describe('and no query is used', function () { |
| 61 | + it('is active', function () { |
| 62 | + assert(component.isActive('products', { id: 123, variant: '456' })); |
| 63 | + }); |
| 64 | + }); |
| 65 | + |
| 66 | + describe('and a matching query is used', function () { |
| 67 | + it('is active', function () { |
| 68 | + assert(component.isActive('products', { id: 123 }, { search: 'abc', limit: '789' })); |
| 69 | + }); |
| 70 | + }); |
| 71 | + |
| 72 | + describe('but the query does not match', function () { |
| 73 | + it('is not active', function () { |
| 74 | + assert(component.isActive('products', { id: 123 }, { search: 'def', limit: '123' }) === false); |
| 75 | + }); |
| 76 | + }); |
| 77 | + }); |
| 78 | + |
| 79 | + describe('and the wrong params are given', function () { |
| 80 | + var component; |
| 81 | + beforeEach(function () { |
| 82 | + component = ReactTestUtils.renderIntoDocument( |
| 83 | + App({ |
| 84 | + initialState: { |
| 85 | + activeRoutes: [ route ], |
| 86 | + activeParams: { id: 123 } |
| 87 | + } |
| 88 | + }) |
| 89 | + ); |
| 90 | + }); |
| 91 | + |
| 92 | + afterEach(function () { |
| 93 | + React.unmountComponentAtNode(component.getDOMNode()); |
| 94 | + }); |
| 95 | + |
| 96 | + it('is not active', function () { |
| 97 | + assert(component.isActive('products', { id: 345 }) === false); |
| 98 | + }); |
| 99 | + }); |
| 100 | + }); |
| 101 | + |
| 102 | +}); |
0 commit comments