# Code coverage report for lib/addons/__tests__/ReactFluxComponent-test.js

## Statements: 88.78% (87 / 98) Branches: 53.33% (16 / 30) Functions: 100% (20 / 20) Lines: 100% (74 / 74) Ignored: none

All files » lib/addons/__tests__/ » ReactFluxComponent-test.js

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156

    2

    8

    2

    3

    12

    1

    1
    1
    1
    1

    1
    1

    1
    1
    1
    4

    4
    4

    1

    1

    4

    1

    1
    1
    4

    4

    4
    4

    4

    1

    1

    4

    1

    1
    1
    4

    4

    4
    4

    1

    1

    1
    1

    1
    1
    1

    1
    1

    1

    1
    1

    1
    1
    1

    1

    1
    1
    1
    1

    1
    1
    1

    1

    1

    1

    1
    1
    1

    1

    1

    1
    1
    1
    1

     "use strict";

    var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };

    var _get = function get(object, property, receiver) { var desc = Object.getOwnPropertyDescriptor(object, property); Iif (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else Eif ("value" in desc && desc.writable) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };

    var _prototypeProperties = function (child, staticProps, instanceProps) { Iif (staticProps) Object.defineProperties(child, staticProps); Eif (instanceProps) Object.defineProperties(child.prototype, instanceProps); };

    var _inherits = function (subClass, superClass) { Iif (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); Eif (superClass) subClass.__proto__ = superClass; };

    var _classCallCheck = function (instance, Constructor) { Iif (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };

    var _Flux = require("../../Flux");

    var Flummox = _Flux.Flummox;
    var Store = _Flux.Store;
    var Actions = _Flux.Actions;
    var React = _interopRequire(require("react/addons"));

    var TestUtils = React.addons.TestUtils;
    var FluxComponent = _interopRequire(require("../ReactFluxComponent"));

    describe("ReactFluxComponent", function () {
      var TestActions = (function (Actions) {
        function TestActions() {
          _classCallCheck(this, TestActions);

          Eif (Actions != null) {
            Actions.apply(this, arguments);
          }
        }

        _inherits(TestActions, Actions);

        _prototypeProperties(TestActions, null, {
          getSomething: {
            value: function getSomething(something) {
              return something;
            },
            writable: true,
            configurable: true
          }
        });

        return TestActions;
      })(Actions);

      var TestStore = (function (Store) {
        function TestStore(flux) {
          _classCallCheck(this, TestStore);

          _get(Object.getPrototypeOf(TestStore.prototype), "constructor", this).call(this);

          var testActions = flux.getActions("test");
          this.register(testActions.getSomething, this.handleGetSomething);

          this.state = {
            something: null
          };
        }

        _inherits(TestStore, Store);

        _prototypeProperties(TestStore, null, {
          handleGetSomething: {
            value: function handleGetSomething(something) {
              this.setState({ something: something });
            },
            writable: true,
            configurable: true
          }
        });

        return TestStore;
      })(Store);

      var Flux = (function (Flummox) {
        function Flux() {
          _classCallCheck(this, Flux);

          _get(Object.getPrototypeOf(Flux.prototype), "constructor", this).call(this);

          this.createActions("test", TestActions);
          this.createStore("test", TestStore, this);
        }

        _inherits(Flux, Flummox);

        return Flux;
      })(Flummox);

      before(function () {
        jsdom();
      });

      it("gets Flux property from either props or context", function () {
        var flux = new Flux();
        var contextComponent = undefined,
            propsComponent = undefined;

        React.withContext({ flux: flux }, function () {
          contextComponent = TestUtils.renderIntoDocument(React.createElement(FluxComponent, null));
        });

        propsComponent = TestUtils.renderIntoDocument(React.createElement(FluxComponent, { flux: flux }));

        expect(contextComponent.flux).to.be.an["instanceof"](Flummox);
        expect(propsComponent.flux).to.be.an["instanceof"](Flummox);
      });

      it("passes connectToStore prop to ReactMixin's connectToStores()", function () {
        var flux = new Flux();
        var actions = flux.getActions("test");

        var component = TestUtils.renderIntoDocument(React.createElement(FluxComponent, { flux: flux, connectToStores: "test" }));

        actions.getSomething("something good");
        expect(component.state.something).to.deep.equal("something good");
        actions.getSomething("something else");
        expect(component.state.something).to.deep.equal("something else");
      });

      it("injects children with flux prop", function () {
        var flux = new Flux();
        var actions = flux.getActions("test");

        var tree = TestUtils.renderIntoDocument(React.createElement(
          FluxComponent,
          { flux: flux },
          React.createElement("div", null)
        ));

        var div = TestUtils.findRenderedDOMComponentWithTag(tree, "div");

        expect(div.props.flux).to.equal(flux);
      });

      it("injects children with props corresponding to component state", function () {
        var flux = new Flux();
        var actions = flux.getActions("test");

        var tree = TestUtils.renderIntoDocument(React.createElement(
          FluxComponent,
          { flux: flux, connectToStores: "test" },
          React.createElement("div", null)
        ));

        var div = TestUtils.findRenderedDOMComponentWithTag(tree, "div");

        actions.getSomething("something good");
        expect(div.props.something).to.equal("something good");
        actions.getSomething("something else");
        expect(div.props.something).to.equal("something else");
      });
    });
    //# sourceMappingURL=data:application/json;base64,