{"size": 6643, "ext": "js", "max_stars_repo_path": "example/node_modules/@lugia/lugia-web/dist/radio/_tests_/Radio-group.test.js", "max_stars_repo_name": "xiaochong58/lugid-mega", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "example/node_modules/@lugia/lugia-web/dist/radio/_tests_/Radio-group.test.js", "max_issues_repo_name": "xiaochong58/lugid-mega", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "example/node_modules/@lugia/lugia-web/dist/radio/_tests_/Radio-group.test.js", "max_forks_repo_name": "xiaochong58/lugid-mega", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 6643.0, "max_line_length": 6643, "alphanum_fraction": 0.7160921271}
"use strict";var _react=require("react"),_react2=_interopRequireDefault(_react),_chai=require("chai"),_chai2=_interopRequireDefault(_chai);require("jest-styled-components");var _enzyme=require("enzyme"),_enzyme2=_interopRequireDefault(_enzyme),_enzymeAdapterReact=require("enzyme-adapter-react-16"),_enzymeAdapterReact2=_interopRequireDefault(_enzymeAdapterReact),_radio=require("../radio"),_radio2=_interopRequireDefault(_radio),_radioGroup=require("../radio-group"),_radioGroup2=_interopRequireDefault(_radioGroup),_button=require("../../check-button/button"),_button2=_interopRequireDefault(_button),_demo=require("../demo"),_reactTestRenderer=require("react-test-renderer"),_reactTestRenderer2=_interopRequireDefault(_reactTestRenderer);function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}var exp=_chai2.default.expect;_enzyme2.default.configure({adapter:new _enzymeAdapterReact2.default}),describe("RadioGroup",function(){function n(e){var t=e||{value:"1"};return _react2.default.createElement(_radioGroup2.default,t,_react2.default.createElement(_radio2.default,{value:"1"},"Radio"),_react2.default.createElement(_radio2.default,{value:"2"},"Radio2"),_react2.default.createElement(_radio2.default,{value:"3"},"Radio3"))}function a(e){return _react2.default.createElement(_radioGroup2.default,e,_react2.default.createElement(_button2.default,{value:"1"},"CheckBox1"),_react2.default.createElement(_button2.default,{value:"2"},"CheckBox2"),_react2.default.createElement(_button2.default,{value:"3"},"CheckBox3"))}function l(e){return e.children().at(0).instance().state}function e(e,t){var a=l(e).value;expect(a).toBe(t);for(var u=e.find("label"),n=0;n<3;n++)u.at(n).simulate("click"),expect(a).toBe(t)}it("RadioGroup css",function(){var e=_react2.default.createElement(_demo.RadioGroupDemo,null);expect(_reactTestRenderer2.default.create(e).toJSON()).toMatchSnapshot()}),it("RadioGroup value | defaultValue",function(){var e=(0,_enzyme.mount)(n()),t=(0,_enzyme.mount)(n({defaultValue:"1"})),a=l(e).value,u=l(t).value;expect(a).toBe("1"),expect(u).toBe("1"),t.setProps({defaultValue:"2"}),expect(u).toBe("1")}),it("RadioGroup props:value can not Change ",function(){e((0,_enzyme.mount)(n()),"1")}),it("RadioGroup props:disabled Click",function(){e((0,_enzyme.mount)(n({defaultValue:"1",disabled:!0})),"1")}),it("RadioGroup props:data( disabled in item ) Click",function(){var e=(0,_enzyme.mount)(_react2.default.createElement(_radioGroup2.default,{defaultValue:"apple",data:[{text:"Apple",value:"apple",disabled:!0},{text:"Pear",value:"pear"},{text:"Orange",value:"orange",disabled:!0}]})),t=e.find("label"),a=l(e).value;expect(a).toBe("apple");for(var u=0;u<3;u++)t.at(u).simulate("click"),expect(l(e).value).toBe(0===u?"apple":"pear")}),it("RadioGroup props:onChange",function(){for(var t="0",e=(0,_enzyme.mount)(n({onChange:function(e){t=e.newValue}})).find("label"),a=0;a<3;a++)e.at(a).simulate("click"),expect(t).toBe(""+(a+1))}),it("RadioGroup changeValue === stateValue onChange",function(){var e=(0,_enzyme.mount)(n({onChange:function(e){var t=e.newValue;t}})),t=e.find("label"),a=e.find("RadioGroup").at(0).instance();!function(){for(var e=0;e<3;e++)t.at(e).simulate("click"),expect(a.state.value).toBe(""+(e+1))}()}),it("RadioGroup onChange: oldItem oldValue newItem newValue",function(){var t={},a="0",u={},e=[{text:"Apple",value:"apple"},{text:"Pear",value:"pear"},{text:"Orange",value:"orange"}];var n,l=(0,_enzyme.mount)(_react2.default.createElement(_radioGroup2.default,{defaultValue:"apple",data:e,onChange:function(e){u=Object.assign({},t),a=e.newValue,t=Object.assign({},e)}})).find("label");l.at(0).simulate("click"),expect(a).toBe("0"),l.at(1).simulate("click"),expect(a).toBe("pear");for(var o=0;o<3;o++)n=o,l.at(n).simulate("click"),expect(a).toBe(e[n].value),expect(t.newValue).toBe(e[n].value),expect(t.newItem).toEqual(e[n]),expect(t.oldValue).toBe(u.newValue),expect(t.oldItem).toEqual(u.newItem)});var u=[{text:"a",value:"1"},{text:"b",value:"2"},{text:"c",value:"3"}],o=(0,_enzyme.mount)(_react2.default.createElement(_radioGroup2.default,{data:u}));it("RadioGroup: MapData props:data change-render",function(){var e=o.children().at(0).instance(),t=e.dataItem,a=[].concat(u);expect(e.dataItem).toBe(t),a[0].value="111",o.setProps({data:a}),expect(e.dataItem).not.toBe(t),e.props.data.push({text:"aaa",value:"44"}),e.handleChange({label:"1",value:"1"})("1","44"),expect(e.dataItem).not.toBe(t)}),it("RadioGroup: MapData props:data data push item-not render",function(){var e=o.children().at(0).instance(),t=e.dataItem;e.props.data.push({label:"check1",value:"111",name:"111"}),e.handleChange({label:"check1",value:"111",name:"111"})("666"),expect(e.dataItem).not.toBe(t)}),it("RadioGroup: props: childType: button; value same not onChange",function(){var e=0,t=(0,_enzyme.mount)(a({childType:"button",onChange:function(){e++},defaultValue:"1"})).find("hello");t.at(0).simulate("click"),expect(e).toBe(0),t.at(1).simulate("click"),expect(e).toBe(1),t.at(2).simulate("click"),expect(e).toBe(2)}),it("RadioGroup: props: {childType: button, disabled: true}",function(){var e=0,t=(0,_enzyme.mount)(a({childType:"button",onChange:function(){e++},disabled:!0})).find("hello");t.at(0).simulate("click"),expect(e).toBe(0),t.at(1).simulate("click"),expect(e).toBe(0)});function r(e){return _react2.default.createElement(_radioGroup2.default,Object.assign({childType:"button",data:u,displayValue:"d"},e))}it("RadioGroup: props: {childType: button, data, displayValue, value}",function(){var e=0,t=(0,_enzyme.mount)(r({value:"4",onChange:function(){e++}})),a=t.find("hello"),u=t.children().at(0).instance();a.at(0).simulate("click"),expect(e).toBe(0),a.at(1).simulate("click"),expect(e).toBe(1),expect(u.state.value).toBe("4"),t.setProps({defaultValue:"1"}),expect(u.state.value).toBe("4")});var i=[{text:"a",value:"1"},{text:"b",value:"2"},{text:"c",value:"3"}];it("RadioGroup: props: {childType: button, data, displayValue, defaultValue}",function(){var e=0,t=(0,_enzyme.mount)(r({defaultValue:"4",onChange:function(){e++},data:i})),a=t.find("hello"),u=t.children().at(0).instance();a.at(0).simulate("click"),expect(e).toBe(0),expect(u.state.value).toBe("4"),a.at(1).simulate("click"),expect(e).toBe(1),expect(u.state.value).toBe("1")}),it("RadioGroup: props: {childType: button, data, displayValue, value}",function(){var e=0,t=(0,_enzyme.mount)(r({value:"4",onChange:function(){e++},data:i})),a=t.find("hello"),u=t.children().at(0).instance();a.at(0).simulate("click"),expect(e).toBe(0),expect(u.state.value).toBe("4"),a.at(1).simulate("click"),expect(e).toBe(1),expect(u.state.value).toBe("4")})});