it('toggels state.show_options', () => {

      simple_select = TestUtils.renderIntoDocument(<SimpleSelect />)
      TestUtils.Simulate.click(simple_select.refs.simpleSelectValue)
      expect(simple_select.state.show_options).to.be.true

      simple_select = TestUtils.renderIntoDocument(<SimpleSelect />)
      simple_select.setState({show_options: true})
      TestUtils.Simulate.click(simple_select.refs.simpleSelectValue)
      expect(simple_select.state.show_options).to.be.false
    })
  it('overrides qBankHost with localQbankUrl in the iframe code', () => {
    var result = TestUtils.renderIntoDocument(<AdminPreview {...props} />);
    result.setState({openIframe: true});
    let textArea = TestUtils.findRenderedDOMComponentWithClass(result, "c-preview-embed");
    expect(textArea.textContent).toContain("api_url=qbankhost");

    props.settings.localQbankUrl = "localQbankUrl";
    result = TestUtils.renderIntoDocument(<AdminPreview {...props}/>);
    result.setState({openIframe: true});
    textArea = TestUtils.findRenderedDOMComponentWithClass(result, "c-preview-embed");
    expect(textArea.textContent).toContain("api_url=localQbankUrl");
  });
  it('renders input-group with sm or lg class name when bsSize is small or large', function () {
    let instance = ReactTestUtils.renderIntoDocument(
      <Input addonBefore="$" bsSize="small" />
    );

    assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'input-group'));
    assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'input-group-sm'));

    instance = ReactTestUtils.renderIntoDocument(
      <Input addonBefore="$" bsSize="large" />
    );

    assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'input-group'));
    assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'input-group-lg'));
  });
  it('should have disabled class with disabled is true', function () {
    var instance = TestUtils.renderIntoDocument(
      <Loader disabled={true}></Loader>
    );

    expect(instance.getDOMNode().className).toMatch('disabled');
  });
  it('should have custom class with custom className', function () {
    var instance = TestUtils.renderIntoDocument(
      <Loader className="custom"></Loader>
    );

    expect(instance.getDOMNode().className).toMatch('custom');
  });
  it('returns checked value for checkbox/radio', function () {
    let instance = ReactTestUtils.renderIntoDocument(
      <Input type="checkbox" checked readOnly />
    );

    assert.equal(instance.getChecked(), true);
  });
  it('renders custom-form-group class', function() {
    let instance = ReactTestUtils.renderIntoDocument(
      <Input groupClassName='custom-form-class' />
    );

    assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'custom-form-class'));
  });
  it('renders form-group class', function() {
    let instance = ReactTestUtils.renderIntoDocument(
      <Input />
    );

    assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'form-group'));
  });
Exemple #9
0
    it(`should call ${unmountingMethods.join(',')}`, () => {

      class Container extends React.Component {
        constructor(props, context) {
          super(props, context)
          this.state = {}
        }

        clear() {
          this.setState({
            hidden: true
          })
        }

        render() {
          if (this.state.hidden) {
            return null;
          }
          return <Component />
        }
      }

      const container = ReactTestUtils.renderIntoDocument(<Container/>);

      log.reset();

      container.clear();

      expect(log.callCount).to.eql(unmountingMethods.length);
      expect(log.args.map((value)=>value[0])).to.eql(unmountingMethods);

    });
    describe('With optional props', () => {
      const chart = TestUtils.renderIntoDocument(
        <PieChart
          data={mockData}
          mouseOverHandler={mouseOverSpy}
          mouseOutHandler={mouseOutSpy}
          mouseMoveHandler={mouseMoveSpy}
          clickHandler={clickSpy}
        />
      );
      const domRoot = ReactDOM.findDOMNode(chart);
      const svgNode = domRoot.childNodes[1];
      const pieNode = svgNode.childNodes[0].childNodes[0];

      it('responds to click events', () => {
        TestUtils.Simulate.click(pieNode);
        expect(clickSpy).to.have.been.called();
      });

      it('responds to mouse over events', () => {
        TestUtils.SimulateNative.mouseOver(pieNode);
        expect(mouseOverSpy).to.have.been.called();
      });

      it('responds to mouse out events', () => {
        TestUtils.SimulateNative.mouseOut(pieNode);
        expect(mouseOutSpy).to.have.been.called();
      });

      it('responds to mouse move events', () => {
        TestUtils.SimulateNative.mouseMove(pieNode);
        expect(mouseMoveSpy).to.have.been.called();
      });
    });
 beforeEach(() => {
   component = TestUtils.renderIntoDocument(
     <NumericFilter
     onChange={fakeOnChange}
     column={fakeColumn}
     />);
 });
 it('Should set target attribute on anchor', function () {
   let instance = ReactTestUtils.renderIntoDocument(
         <NavItem href="/some/unique-thing/" target="_blank">Item content</NavItem>
       );
   let linkElement = React.findDOMNode(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a'));
   assert.equal(linkElement.target, '_blank');
 });
 it('Should output a "div" with the class "list-group"', function () {
   let instance = ReactTestUtils.renderIntoDocument(
     <ListGroup/>
   );
   assert.equal(React.findDOMNode(instance).nodeName, 'DIV');
   assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'list-group'));
 });
describe('StepControl', function() {

  var currentPage = 0;
  var main = TestUtils.renderIntoDocument((
    <StepForm currentPage={ currentPage }>
      <div className="page page0"></div>
      <div className="page page1"></div>
      <div className="page page2"></div>
    </StepForm>
  ));

  describe('Rendering:', function() {

    it('renders correctly', function() {
      var formControl = TestUtils.findRenderedDOMComponentWithClass(main, 'StepControl');
      expect(formControl).toExist();
    });

    it('disables correct radio buttons', function() {
      var disabledButtons = TestUtils.scryRenderedDOMComponentsWithClass(main, 'StepControl--button--disabled');
      expect(disabledButtons.length).toEqual(2);
    });

  });

});
Exemple #15
0
 it('Calls onChange when changed', (done) => {
   const doneOp = () => done();
   const instance = renderIntoDocument(
     <Checkbox onChange={doneOp} />
   );
   Simulate.change(getInputNode(instance));
 });
Exemple #16
0
    it(`should call ${updatingMethods.join(',')}`, () => {

      class Container extends React.Component {
        constructor(props, context) {
          super(props, context)
          this.state = {}
        }

        render() {
          return <Component {...this.state}/>
        }
      }

      const container = ReactTestUtils.renderIntoDocument(<Container/>);

      log.reset();

      container.setState({
        someProp: true
      });

      expect(log.callCount).to.eql(updatingMethods.length);
      expect(log.args.map((value)=>value[0])).to.eql(updatingMethods);

    });
 beforeEach(()=>{
   var getCurrentRoutes = () => {
     return [{ name: 'home' }];
   };
   Subject = new StubContext(Page, {}, { getCurrentRoutes });
   result = TestUtils.renderIntoDocument(<Subject />);
 });
  it('renders wrapper', function () {
    let instance = ReactTestUtils.renderIntoDocument(
      <Input wrapperClassName="wrapper" />
    );

    assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'wrapper'));
  });
 it('expects the value to change to the option that was clicked', () => {
   let simple_select = TestUtils.renderIntoDocument(<SimpleSelect options={['foo','bar']} value={'foo'}/>)
   simple_select.setState({show_options: true})
   let options = TestUtils.scryRenderedDOMComponentsWithClass(simple_select, 'simple-select-option');
   TestUtils.Simulate.click(options[1])
   expect(simple_select.state.value).to.equal('bar')
 });
  it('renders help', function () {
    let instance = ReactTestUtils.renderIntoDocument(
      <Input help="Help" />
    );

    assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'help-block'));
  });
 it('sets the value to null when empty option is clicked', () => {
   let simple_select = TestUtils.renderIntoDocument(<SimpleSelect includeBlank={true} options={['foo','bar']} value={'foo'}/>)
   simple_select.setState({show_options: true})
   let options = TestUtils.scryRenderedDOMComponentsWithClass(simple_select, 'simple-select-option');
   TestUtils.Simulate.click(options[0])
   expect(simple_select.state.value).to.be.null
 });
  it('renders no form-group class', function() {
    let instance = ReactTestUtils.renderIntoDocument(
      <Input standalone />
    );

    assert.equal(ReactTestUtils.scryRenderedDOMComponentsWithClass(instance, 'form-group').length, 0);
  });
  it('should have child by default', function () {
    var instance = TestUtils.renderIntoDocument(
      <Loader>123</Loader>
    );

    expect(instance.getDOMNode().textContent).toMatch('123');
  });
  it('renders feedback icon', function () {
    let instance = ReactTestUtils.renderIntoDocument(
      <Input hasFeedback={true} bsStyle="error" />
    );

    assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'form-control-feedback'));
  });
  it('should have active class with active is true', function () {
    var instance = TestUtils.renderIntoDocument(
      <Loader active={true}></Loader>
    );

    expect(instance.getDOMNode().className).toMatch('active');
  });
describe('AlertMessage', function(){
  var alert = TestUtils.renderIntoDocument(<AlertMessage id="test-alert" actionNames={['test']}/>);
  var alertDOM = alert.getDOMNode();
  var hiddenClassName = 'hidden alert alert-dismissible alert-info';

  it('can display a message to the user', function(done){
    Flux.doAction('test', 'info', 'This is a test.').then(function(){
      expect(alertDOM.childNodes[1].textContent).toEqual('This is a test.');
      done();
    });
  });

  it('can display a custom message type', function(done){
    Flux.doAction('test', 'danger', 'This is a test.').then(function(){
      expect(alertDOM.className).toEqual('alert alert-dismissible alert-danger');
      done();
    });
  });

  it('will allow the user to close it', function(){
    TestUtils.Simulate.click(alertDOM.childNodes[0], {});
    expect(alertDOM.className).toEqual(hiddenClassName);
    expect(alertDOM.childNodes[1].textContent).toEqual('');
  });

  it('can autoclose itself after a set duration', function(done){
    Flux.doAction('test', 'info', 'This is a delayed test.', true).then(function(){
      setTimeout(function(){
        expect(alertDOM.className).toEqual(hiddenClassName);
        done();
      }, 1000);
    });
  });
});
  it('should pass all props to all valid children', function() {
    var React = require('react');
    var ReactTestUtils = require('react/lib/ReactTestUtils');
    var ReactFrag = require('../ReactFrag');

    var didMount = jest.genMockFn();
    var Test = React.createClass({displayName: "Test",
      render: function() { return null; },
      componentDidMount: function() {
        didMount(this.props);
      }
    });

    var map = {};
    var testProp = {};
    ReactTestUtils.renderIntoDocument(
      React.createElement(ReactFrag, {map: map, testProp: testProp}, 
        React.createElement(Test, null), 
        null, 
        false, 
        React.createElement(ReactFrag, null, 
          React.createElement(Test, null)
        )
      )
    );

    expect(didMount.mock.calls.length).toBe(2);
    expect(didMount.mock.calls[0][0]).toEqual({map: map});
    expect(didMount.mock.calls[1][0]).toEqual({map: map});
  });
  it('throws a deprecation warning on type=submit', function () {
    ReactTestUtils.renderIntoDocument(
      <Input type="submit" />
    );

    shouldWarn('deprecated');
  });
  it('throws a warning when type=static', function () {
    ReactTestUtils.renderIntoDocument(
      <Input type="static" value="v" />
    );

    shouldWarn('deprecated');
  });
  it('renders a textarea element when type=textarea', function () {
    let instance = ReactTestUtils.renderIntoDocument(
      <Input type="textarea" defaultValue="v" />
    );

    assert.ok(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'textarea'));
    assert.equal(instance.getValue(), 'v');
  });