From dd950dd57dd7d2cc0b0adf1a4d5ec2277312b054 Mon Sep 17 00:00:00 2001 From: Lee Date: Tue, 6 Jan 2015 02:22:48 +0800 Subject: [PATCH 1/4] Add Commons test. Signed-off-by: Lee --- test/__tests__/commons/Column-test.js | 33 +++++++ test/__tests__/commons/Content-test.js | 33 +++++++ test/__tests__/commons/Field-test.js | 33 +++++++ test/__tests__/commons/Fields-test.js | 33 +++++++ test/__tests__/commons/Row-test.js | 33 +++++++ test/__tests__/commons/Section-test.js | 49 ++++++++++ test/__tests__/commons/Text-test.js | 33 +++++++ test/__tests__/commons/Title-test.js | 41 +++++++++ test/__tests__/commons/Unit-test.js | 118 +++++++++++++++++++++++++ 9 files changed, 406 insertions(+) create mode 100644 test/__tests__/commons/Column-test.js create mode 100644 test/__tests__/commons/Content-test.js create mode 100644 test/__tests__/commons/Field-test.js create mode 100644 test/__tests__/commons/Fields-test.js create mode 100644 test/__tests__/commons/Row-test.js create mode 100644 test/__tests__/commons/Section-test.js create mode 100644 test/__tests__/commons/Text-test.js create mode 100644 test/__tests__/commons/Title-test.js create mode 100644 test/__tests__/commons/Unit-test.js diff --git a/test/__tests__/commons/Column-test.js b/test/__tests__/commons/Column-test.js new file mode 100644 index 0000000..38b03c8 --- /dev/null +++ b/test/__tests__/commons/Column-test.js @@ -0,0 +1,33 @@ +"use strict"; + +jest.dontMock('../../../src/index.js'); + +var React = require('react'); +var TestUtils = require('react/lib/ReactTestUtils'); +var Column = require('../../../src/index.js').Column; + +describe('Column', function () { + it('should have .column class by default', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('column'); + }); + + it('should have child by default', function () { + var instance = TestUtils.renderIntoDocument( + 123 + ); + + expect(instance.getDOMNode().textContent).toMatch('123'); + }); + + it('should have custom class with custom className', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('custom'); + }); +}); diff --git a/test/__tests__/commons/Content-test.js b/test/__tests__/commons/Content-test.js new file mode 100644 index 0000000..520cd21 --- /dev/null +++ b/test/__tests__/commons/Content-test.js @@ -0,0 +1,33 @@ +"use strict"; + +jest.dontMock('../../../src/index.js'); + +var React = require('react'); +var TestUtils = require('react/lib/ReactTestUtils'); +var Content = require('../../../src/index.js').Content; + +describe('Content', function () { + it('should have .content class by default', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('content'); + }); + + it('should have child by default', function () { + var instance = TestUtils.renderIntoDocument( + 123 + ); + + expect(instance.getDOMNode().textContent).toMatch('123'); + }); + + it('should have custom class with custom className', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('custom'); + }); +}); diff --git a/test/__tests__/commons/Field-test.js b/test/__tests__/commons/Field-test.js new file mode 100644 index 0000000..d2f1dc4 --- /dev/null +++ b/test/__tests__/commons/Field-test.js @@ -0,0 +1,33 @@ +"use strict"; + +jest.dontMock('../../../src/index.js'); + +var React = require('react'); +var TestUtils = require('react/lib/ReactTestUtils'); +var Field = require('../../../src/index.js').Field; + +describe('Field', function () { + it('should have .field class by default', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('field'); + }); + + it('should have child by default', function () { + var instance = TestUtils.renderIntoDocument( + 123 + ); + + expect(instance.getDOMNode().textContent).toMatch('123'); + }); + + it('should have custom class with custom className', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('custom'); + }); +}); diff --git a/test/__tests__/commons/Fields-test.js b/test/__tests__/commons/Fields-test.js new file mode 100644 index 0000000..d55e173 --- /dev/null +++ b/test/__tests__/commons/Fields-test.js @@ -0,0 +1,33 @@ +"use strict"; + +jest.dontMock('../../../src/index.js'); + +var React = require('react'); +var TestUtils = require('react/lib/ReactTestUtils'); +var Fields = require('../../../src/index.js').Fields; + +describe('Fields', function () { + it('should have .fields class by default', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('fields'); + }); + + it('should have child by default', function () { + var instance = TestUtils.renderIntoDocument( + 123 + ); + + expect(instance.getDOMNode().textContent).toMatch('123'); + }); + + it('should have custom class with custom className', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('custom'); + }); +}); diff --git a/test/__tests__/commons/Row-test.js b/test/__tests__/commons/Row-test.js new file mode 100644 index 0000000..cbc16b1 --- /dev/null +++ b/test/__tests__/commons/Row-test.js @@ -0,0 +1,33 @@ +"use strict"; + +jest.dontMock('../../../src/index.js'); + +var React = require('react'); +var TestUtils = require('react/lib/ReactTestUtils'); +var Row = require('../../../src/index.js').Row; + +describe('Row', function () { + it('should have .row class by default', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('row'); + }); + + it('should have child by default', function () { + var instance = TestUtils.renderIntoDocument( + 123 + ); + + expect(instance.getDOMNode().textContent).toMatch('123'); + }); + + it('should have custom class with custom className', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('custom'); + }); +}); diff --git a/test/__tests__/commons/Section-test.js b/test/__tests__/commons/Section-test.js new file mode 100644 index 0000000..2fe72a7 --- /dev/null +++ b/test/__tests__/commons/Section-test.js @@ -0,0 +1,49 @@ +"use strict"; + +jest.dontMock('../../../src/index.js'); + +var React = require('react'); +var TestUtils = require('react/lib/ReactTestUtils'); +var Section = require('../../../src/index.js').Section; + +describe('Section', function () { + it('should have .section class by default', function () { + var instance = TestUtils.renderIntoDocument( +
+ ); + + expect(instance.getDOMNode().className).toMatch('section'); + }); + + it('should have child by default', function () { + var instance = TestUtils.renderIntoDocument( +
123
+ ); + + expect(instance.getDOMNode().textContent).toMatch('123'); + }); + + it('should have custom class with custom className', function () { + var instance = TestUtils.renderIntoDocument( +
+ ); + + expect(instance.getDOMNode().className).toMatch('custom'); + }); + + it('should have blue class with color is blue', function () { + var instance = TestUtils.renderIntoDocument( +
+ ); + + expect(instance.getDOMNode().className).toMatch('blue'); + }); + + it('should be with link type', function () { + var instance = TestUtils.renderIntoDocument( +
+ ); + + expect(TestUtils.findRenderedDOMComponentWithTag(instance, 'a')).toBeDefined(); + }); +}); diff --git a/test/__tests__/commons/Text-test.js b/test/__tests__/commons/Text-test.js new file mode 100644 index 0000000..09e768d --- /dev/null +++ b/test/__tests__/commons/Text-test.js @@ -0,0 +1,33 @@ +"use strict"; + +jest.dontMock('../../../src/index.js'); + +var React = require('react'); +var TestUtils = require('react/lib/ReactTestUtils'); +var Text = require('../../../src/index.js').Text; + +describe('Text', function () { + it('should have .text class by default', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('text'); + }); + + it('should have child by default', function () { + var instance = TestUtils.renderIntoDocument( + 123 + ); + + expect(instance.getDOMNode().textContent).toMatch('123'); + }); + + it('should have custom class with custom className', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('custom'); + }); +}); diff --git a/test/__tests__/commons/Title-test.js b/test/__tests__/commons/Title-test.js new file mode 100644 index 0000000..62efa0c --- /dev/null +++ b/test/__tests__/commons/Title-test.js @@ -0,0 +1,41 @@ +"use strict"; + +jest.dontMock('../../../src/index.js'); + +var React = require('react'); +var TestUtils = require('react/lib/ReactTestUtils'); +var Title = require('../../../src/index.js').Title; + +describe('Title', function () { + it('should have .title class by default', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('title'); + }); + + it('should have child by default', function () { + var instance = TestUtils.renderIntoDocument( + 123 + ); + + expect(instance.getDOMNode().textContent).toMatch('123'); + }); + + it('should have custom class with custom className', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('custom'); + }); + + it('should have active class with active is true', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('active'); + }); +}); diff --git a/test/__tests__/commons/Unit-test.js b/test/__tests__/commons/Unit-test.js new file mode 100644 index 0000000..fbeee6b --- /dev/null +++ b/test/__tests__/commons/Unit-test.js @@ -0,0 +1,118 @@ +"use strict"; + +jest.dontMock('../../../src/commons/unit.jsx'); + +var React = require('react/addons'); +var TestUtils = require('react/lib/ReactTestUtils'); +var Unit = require('../../../src/commons/unit.jsx')(React); + +describe('Unit', function () { + it('should have child by default', function () { + var instance = TestUtils.renderIntoDocument( + + 123 + + ); + + expect(instance.getDOMNode().textContent).toMatch('123'); + }); + + it('should have custom class with custom className', function () { + var instance = TestUtils.renderIntoDocument( + + + ); + + expect(instance.getDOMNode().className).toMatch('custom'); + }); + + it('should have blue class with color is blue', function () { + var instance = TestUtils.renderIntoDocument( + + + ); + + expect(instance.getDOMNode().className).toMatch('blue'); + }); + + it('should have props class with props is true', function () { + var instance = TestUtils.renderIntoDocument( + + + ); + + expect(instance.getDOMNode().className).toMatch('disabled'); + expect(instance.getDOMNode().className).toMatch('active'); + expect(instance.getDOMNode().className).toMatch('loading'); + expect(instance.getDOMNode().className).toMatch('focus'); + expect(instance.getDOMNode().className).toMatch('error'); + expect(instance.getDOMNode().className).toMatch('completed'); + expect(instance.getDOMNode().className).toMatch('read-only'); + }); + + it('should call onClick callback when unit click', function () { + + var clickOp = jest.genMockFunction(); + + var instance = TestUtils.renderIntoDocument( + + 123 + + ); + + TestUtils.Simulate.click(instance.getDOMNode()); + + expect(clickOp).toBeCalled(); + }); +}); From 7e80790d60e7942655442f7243ab27296fb09b8a Mon Sep 17 00:00:00 2001 From: Lee Date: Tue, 6 Jan 2015 02:28:43 +0800 Subject: [PATCH 2/4] Use jest.genMockFunction to test onClick Function. issue #7 --- test/__tests__/elements/Button-test.js | 13 +++++++++++++ test/__tests__/elements/Flag-test.js | 13 +++++++++++++ test/__tests__/elements/Header-test.js | 13 +++++++++++++ test/__tests__/elements/Icon-test.js | 13 +++++++++++++ test/__tests__/elements/Label-test.js | 13 +++++++++++++ test/__tests__/elements/Segment-test.js | 13 +++++++++++++ 6 files changed, 78 insertions(+) diff --git a/test/__tests__/elements/Button-test.js b/test/__tests__/elements/Button-test.js index 26ca7d7..f050dcf 100644 --- a/test/__tests__/elements/Button-test.js +++ b/test/__tests__/elements/Button-test.js @@ -63,4 +63,17 @@ describe('Button', function () { expect(instance.getDOMNode().className).toMatch('loading'); }); + + it('should call onClick callback when unit click', function () { + + var clickOp = jest.genMockFunction(); + + var instance = TestUtils.renderIntoDocument( + + ); + + TestUtils.Simulate.click(instance.getDOMNode()); + + expect(clickOp).toBeCalled(); + }); }); diff --git a/test/__tests__/elements/Flag-test.js b/test/__tests__/elements/Flag-test.js index 35175a4..faba451 100644 --- a/test/__tests__/elements/Flag-test.js +++ b/test/__tests__/elements/Flag-test.js @@ -22,4 +22,17 @@ describe('Flag', function () { expect(instance.getDOMNode().className).toMatch('custom'); }); + + it('should call onClick callback when unit click', function () { + + var clickOp = jest.genMockFunction(); + + var instance = TestUtils.renderIntoDocument( + + ); + + TestUtils.Simulate.click(instance.getDOMNode()); + + expect(clickOp).toBeCalled(); + }); }); diff --git a/test/__tests__/elements/Header-test.js b/test/__tests__/elements/Header-test.js index 871bbe2..18c94fe 100644 --- a/test/__tests__/elements/Header-test.js +++ b/test/__tests__/elements/Header-test.js @@ -55,4 +55,17 @@ describe('Header', function () { expect(TestUtils.findRenderedDOMComponentWithTag(instance, 'a')).toBeDefined(); }); + + it('should call onClick callback when unit click', function () { + + var clickOp = jest.genMockFunction(); + + var instance = TestUtils.renderIntoDocument( +
+ ); + + TestUtils.Simulate.click(instance.getDOMNode()); + + expect(clickOp).toBeCalled(); + }); }); diff --git a/test/__tests__/elements/Icon-test.js b/test/__tests__/elements/Icon-test.js index 316f82e..ff56f7e 100644 --- a/test/__tests__/elements/Icon-test.js +++ b/test/__tests__/elements/Icon-test.js @@ -54,4 +54,17 @@ describe('Icon', function () { expect(TestUtils.findRenderedDOMComponentWithTag(instance, 'i')).toBeDefined(); }); + + it('should call onClick callback when unit click', function () { + + var clickOp = jest.genMockFunction(); + + var instance = TestUtils.renderIntoDocument( + + ); + + TestUtils.Simulate.click(instance.getDOMNode()); + + expect(clickOp).toBeCalled(); + }); }); diff --git a/test/__tests__/elements/Label-test.js b/test/__tests__/elements/Label-test.js index 4c65a64..d8c9c22 100644 --- a/test/__tests__/elements/Label-test.js +++ b/test/__tests__/elements/Label-test.js @@ -47,4 +47,17 @@ describe('Label', function () { expect(TestUtils.findRenderedDOMComponentWithTag(instance, 'div')).toBeDefined(); }); + + it('should call onClick callback when unit click', function () { + + var clickOp = jest.genMockFunction(); + + var instance = TestUtils.renderIntoDocument( + + ); + + TestUtils.Simulate.click(instance.getDOMNode()); + + expect(clickOp).toBeCalled(); + }); }); diff --git a/test/__tests__/elements/Segment-test.js b/test/__tests__/elements/Segment-test.js index f60d0f9..3440bb5 100644 --- a/test/__tests__/elements/Segment-test.js +++ b/test/__tests__/elements/Segment-test.js @@ -55,4 +55,17 @@ describe('Segment', function () { expect(instance.getDOMNode().className).toMatch('loading'); }); + + it('should call onClick callback when unit click', function () { + + var clickOp = jest.genMockFunction(); + + var instance = TestUtils.renderIntoDocument( + + ); + + TestUtils.Simulate.click(instance.getDOMNode()); + + expect(clickOp).toBeCalled(); + }); }); From 1e34aa8660ea0c644223cbfc9aaa09bd11c1f84b Mon Sep 17 00:00:00 2001 From: Lee Date: Wed, 7 Jan 2015 00:21:07 +0800 Subject: [PATCH 3/4] Add Modules test function. issue #2 Signed-off-by: Lee --- src/modules/sticky.jsx | 7 --- test/__tests__/modules/Accordion-test.js | 34 ++++++++++++++ test/__tests__/modules/Checkbox-test.js | 50 ++++++++++++++++++++ test/__tests__/modules/Dimmer-test.js | 50 ++++++++++++++++++++ test/__tests__/modules/Dropdown-test.js | 60 ++++++++++++++++++++++++ test/__tests__/modules/Modal-test.js | 42 +++++++++++++++++ test/__tests__/modules/Popup-test.js | 34 ++++++++++++++ test/__tests__/modules/Progress-test.js | 58 +++++++++++++++++++++++ test/__tests__/modules/Rating-test.js | 50 ++++++++++++++++++++ test/__tests__/modules/Search-test.js | 42 +++++++++++++++++ test/__tests__/modules/Shape-test.js | 34 ++++++++++++++ test/__tests__/modules/Sidebar-test.js | 34 ++++++++++++++ test/__tests__/modules/Sticky-test.js | 34 ++++++++++++++ test/__tests__/modules/Tab-test.js | 58 +++++++++++++++++++++++ 14 files changed, 580 insertions(+), 7 deletions(-) create mode 100644 test/__tests__/modules/Accordion-test.js create mode 100644 test/__tests__/modules/Checkbox-test.js create mode 100644 test/__tests__/modules/Dimmer-test.js create mode 100644 test/__tests__/modules/Dropdown-test.js create mode 100644 test/__tests__/modules/Modal-test.js create mode 100644 test/__tests__/modules/Popup-test.js create mode 100644 test/__tests__/modules/Progress-test.js create mode 100644 test/__tests__/modules/Rating-test.js create mode 100644 test/__tests__/modules/Search-test.js create mode 100644 test/__tests__/modules/Shape-test.js create mode 100644 test/__tests__/modules/Sidebar-test.js create mode 100644 test/__tests__/modules/Sticky-test.js create mode 100644 test/__tests__/modules/Tab-test.js diff --git a/src/modules/sticky.jsx b/src/modules/sticky.jsx index 7606e7f..4ed85f7 100644 --- a/src/modules/sticky.jsx +++ b/src/modules/sticky.jsx @@ -9,13 +9,6 @@ module.exports = function (React) { mixins: [ClassGenerator], - propTypes: { - behavior: React.PropTypes.oneOfType([ - React.PropTypes.string, - React.PropTypes.object - ]) - }, - render: function () { var {className, ...other} = this.props; diff --git a/test/__tests__/modules/Accordion-test.js b/test/__tests__/modules/Accordion-test.js new file mode 100644 index 0000000..b708ca6 --- /dev/null +++ b/test/__tests__/modules/Accordion-test.js @@ -0,0 +1,34 @@ +"use strict"; + +jest.dontMock('../../../src/index.js'); + +var React = require('react'); +var TestUtils = require('react/lib/ReactTestUtils'); +var Accordion = require('../../../src/index.js').Accordion; + +describe('Accordion', function () { + it('should have .ui.accordion class by default', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('ui'); + expect(instance.getDOMNode().className).toMatch('accordion'); + }); + + it('should have child by default', function () { + var instance = TestUtils.renderIntoDocument( + 123 + ); + + expect(instance.getDOMNode().textContent).toMatch('123'); + }); + + it('should have custom class with custom className', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('custom'); + }); +}); diff --git a/test/__tests__/modules/Checkbox-test.js b/test/__tests__/modules/Checkbox-test.js new file mode 100644 index 0000000..c29a71c --- /dev/null +++ b/test/__tests__/modules/Checkbox-test.js @@ -0,0 +1,50 @@ +"use strict"; + +jest.dontMock('../../../src/index.js'); + +var React = require('react'); +var TestUtils = require('react/lib/ReactTestUtils'); +var Checkbox = require('../../../src/index.js').Checkbox; + +describe('Checkbox', function () { + it('should have .ui.checkbox class by default', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('ui'); + expect(instance.getDOMNode().className).toMatch('checkbox'); + }); + + it('should have child by default', function () { + var instance = TestUtils.renderIntoDocument( + 123 + ); + + expect(instance.getDOMNode().textContent).toMatch('123'); + }); + + it('should have custom class with custom className', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('custom'); + }); + + it('should have disabled class with disabled is true', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('disabled'); + }); + + it('should have readOnly class with readOnly is true', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('read-only'); + }); +}); diff --git a/test/__tests__/modules/Dimmer-test.js b/test/__tests__/modules/Dimmer-test.js new file mode 100644 index 0000000..eac978e --- /dev/null +++ b/test/__tests__/modules/Dimmer-test.js @@ -0,0 +1,50 @@ +"use strict"; + +jest.dontMock('../../../src/index.js'); + +var React = require('react'); +var TestUtils = require('react/lib/ReactTestUtils'); +var Dimmer = require('../../../src/index.js').Dimmer; + +describe('Dimmer', function () { + it('should have .ui.dimmer class by default', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('ui'); + expect(instance.getDOMNode().className).toMatch('dimmer'); + }); + + it('should have child by default', function () { + var instance = TestUtils.renderIntoDocument( + 123 + ); + + expect(instance.getDOMNode().textContent).toMatch('123'); + }); + + it('should have custom class with custom className', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('custom'); + }); + + it('should have disabled class with disabled is true', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('disabled'); + }); + + it('should have active class with active is true', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('active'); + }); +}); diff --git a/test/__tests__/modules/Dropdown-test.js b/test/__tests__/modules/Dropdown-test.js new file mode 100644 index 0000000..b3c551e --- /dev/null +++ b/test/__tests__/modules/Dropdown-test.js @@ -0,0 +1,60 @@ +"use strict"; + +jest.dontMock('../../../src/index.js'); + +var React = require('react'); +var TestUtils = require('react/lib/ReactTestUtils'); +var Dropdown = require('../../../src/index.js').Dropdown; + +describe('Dropdown', function () { + it('should have .ui.dropdown class by default', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('ui'); + expect(instance.getDOMNode().className).toMatch('dropdown'); + }); + + it('should have child by default', function () { + var instance = TestUtils.renderIntoDocument( + 123 + ); + + expect(instance.getDOMNode().textContent).toMatch('123'); + }); + + it('should have custom class with custom className', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('custom'); + }); + + it('should have disabled class with disabled is true', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('disabled'); + expect(instance.getDOMNode().className).toMatch('simple'); + }); + + it('should have active class with active is true', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('active'); + expect(instance.getDOMNode().className).toMatch('simple'); + }); + + it('should have error class with error is true', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('error'); + }); +}); diff --git a/test/__tests__/modules/Modal-test.js b/test/__tests__/modules/Modal-test.js new file mode 100644 index 0000000..178d710 --- /dev/null +++ b/test/__tests__/modules/Modal-test.js @@ -0,0 +1,42 @@ +"use strict"; + +jest.dontMock('../../../src/index.js'); + +var React = require('react'); +var TestUtils = require('react/lib/ReactTestUtils'); +var Modal = require('../../../src/index.js').Modal; + +describe('Modal', function () { + it('should have .ui.modal class by default', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('ui'); + expect(instance.getDOMNode().className).toMatch('modal'); + }); + + it('should have child by default', function () { + var instance = TestUtils.renderIntoDocument( + 123 + ); + + expect(instance.getDOMNode().textContent).toMatch('123'); + }); + + it('should have custom class with custom className', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('custom'); + }); + + it('should have active class with active is true', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('active'); + }); +}); diff --git a/test/__tests__/modules/Popup-test.js b/test/__tests__/modules/Popup-test.js new file mode 100644 index 0000000..1aaeb93 --- /dev/null +++ b/test/__tests__/modules/Popup-test.js @@ -0,0 +1,34 @@ +"use strict"; + +jest.dontMock('../../../src/index.js'); + +var React = require('react'); +var TestUtils = require('react/lib/ReactTestUtils'); +var Popup = require('../../../src/index.js').Popup; + +describe('Popup', function () { + it('should have .ui.popup class by default', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('ui'); + expect(instance.getDOMNode().className).toMatch('popup'); + }); + + it('should have child by default', function () { + var instance = TestUtils.renderIntoDocument( + 123 + ); + + expect(instance.getDOMNode().textContent).toMatch('123'); + }); + + it('should have custom class with custom className', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('custom'); + }); +}); diff --git a/test/__tests__/modules/Progress-test.js b/test/__tests__/modules/Progress-test.js new file mode 100644 index 0000000..5c21590 --- /dev/null +++ b/test/__tests__/modules/Progress-test.js @@ -0,0 +1,58 @@ +"use strict"; + +jest.dontMock('../../../src/index.js'); + +var React = require('react'); +var TestUtils = require('react/lib/ReactTestUtils'); +var Progress = require('../../../src/index.js').Progress; + +describe('Progress', function () { + it('should have .ui.progress class by default', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('ui'); + expect(instance.getDOMNode().className).toMatch('progress'); + }); + + it('should have child by default', function () { + var instance = TestUtils.renderIntoDocument( + 123 + ); + + expect(instance.getDOMNode().textContent).toMatch('123'); + }); + + it('should have custom class with custom className', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('custom'); + }); + + it('should have value for item data-value', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().getAttribute('data-value')).toMatch('1'); + }); + + it('should have percent for item data-percent', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().getAttribute('data-percent')).toMatch('1'); + }); + + it('should have total for item data-total', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().getAttribute('data-total')).toMatch('1'); + }); +}); diff --git a/test/__tests__/modules/Rating-test.js b/test/__tests__/modules/Rating-test.js new file mode 100644 index 0000000..a5fe1bd --- /dev/null +++ b/test/__tests__/modules/Rating-test.js @@ -0,0 +1,50 @@ +"use strict"; + +jest.dontMock('../../../src/index.js'); + +var React = require('react'); +var TestUtils = require('react/lib/ReactTestUtils'); +var Rating = require('../../../src/index.js').Rating; + +describe('Rating', function () { + it('should have .ui.rating class by default', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('ui'); + expect(instance.getDOMNode().className).toMatch('rating'); + }); + + it('should have child by default', function () { + var instance = TestUtils.renderIntoDocument( + 123 + ); + + expect(instance.getDOMNode().textContent).toMatch('123'); + }); + + it('should have custom class with custom className', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('custom'); + }); + + it('should have rating for item data-rating', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().getAttribute('data-rating')).toMatch('1'); + }); + + it('should have maxRating for item data-max-rating', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().getAttribute('data-max-rating')).toMatch('1'); + }); +}); diff --git a/test/__tests__/modules/Search-test.js b/test/__tests__/modules/Search-test.js new file mode 100644 index 0000000..89bccc3 --- /dev/null +++ b/test/__tests__/modules/Search-test.js @@ -0,0 +1,42 @@ +"use strict"; + +jest.dontMock('../../../src/index.js'); + +var React = require('react'); +var TestUtils = require('react/lib/ReactTestUtils'); +var Search = require('../../../src/index.js').Search; + +describe('Search', function () { + it('should have .ui.search class by default', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('ui'); + expect(instance.getDOMNode().className).toMatch('search'); + }); + + it('should have child by default', function () { + var instance = TestUtils.renderIntoDocument( + 123 + ); + + expect(instance.getDOMNode().textContent).toMatch('123'); + }); + + it('should have custom class with custom className', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('custom'); + }); + + it('should have loading class with loading is true', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('loading'); + }); +}); diff --git a/test/__tests__/modules/Shape-test.js b/test/__tests__/modules/Shape-test.js new file mode 100644 index 0000000..90c332a --- /dev/null +++ b/test/__tests__/modules/Shape-test.js @@ -0,0 +1,34 @@ +"use strict"; + +jest.dontMock('../../../src/index.js'); + +var React = require('react'); +var TestUtils = require('react/lib/ReactTestUtils'); +var Shape = require('../../../src/index.js').Shape; + +describe('Shape', function () { + it('should have .ui.shape class by default', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('ui'); + expect(instance.getDOMNode().className).toMatch('shape'); + }); + + it('should have child by default', function () { + var instance = TestUtils.renderIntoDocument( + 123 + ); + + expect(instance.getDOMNode().textContent).toMatch('123'); + }); + + it('should have custom class with custom className', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('custom'); + }); +}); diff --git a/test/__tests__/modules/Sidebar-test.js b/test/__tests__/modules/Sidebar-test.js new file mode 100644 index 0000000..ff1f9c3 --- /dev/null +++ b/test/__tests__/modules/Sidebar-test.js @@ -0,0 +1,34 @@ +"use strict"; + +jest.dontMock('../../../src/index.js'); + +var React = require('react'); +var TestUtils = require('react/lib/ReactTestUtils'); +var Sidebar = require('../../../src/index.js').Sidebar; + +describe('Sidebar', function () { + it('should have .ui.sidebar class by default', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('ui'); + expect(instance.getDOMNode().className).toMatch('sidebar'); + }); + + it('should have child by default', function () { + var instance = TestUtils.renderIntoDocument( + 123 + ); + + expect(instance.getDOMNode().textContent).toMatch('123'); + }); + + it('should have custom class with custom className', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('custom'); + }); +}); diff --git a/test/__tests__/modules/Sticky-test.js b/test/__tests__/modules/Sticky-test.js new file mode 100644 index 0000000..3d09f16 --- /dev/null +++ b/test/__tests__/modules/Sticky-test.js @@ -0,0 +1,34 @@ +"use strict"; + +jest.dontMock('../../../src/index.js'); + +var React = require('react'); +var TestUtils = require('react/lib/ReactTestUtils'); +var Sticky = require('../../../src/index.js').Sticky; + +describe('Sticky', function () { + it('should have .ui.sticky class by default', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('ui'); + expect(instance.getDOMNode().className).toMatch('sticky'); + }); + + it('should have child by default', function () { + var instance = TestUtils.renderIntoDocument( + 123 + ); + + expect(instance.getDOMNode().textContent).toMatch('123'); + }); + + it('should have custom class with custom className', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('custom'); + }); +}); diff --git a/test/__tests__/modules/Tab-test.js b/test/__tests__/modules/Tab-test.js new file mode 100644 index 0000000..64640f7 --- /dev/null +++ b/test/__tests__/modules/Tab-test.js @@ -0,0 +1,58 @@ +"use strict"; + +jest.dontMock('../../../src/index.js'); + +var React = require('react'); +var TestUtils = require('react/lib/ReactTestUtils'); +var Tab = require('../../../src/index.js').Tab; + +describe('Tab', function () { + it('should have .ui.tab class by default', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('ui'); + expect(instance.getDOMNode().className).toMatch('tab'); + }); + + it('should have child by default', function () { + var instance = TestUtils.renderIntoDocument( + 123 + ); + + expect(instance.getDOMNode().textContent).toMatch('123'); + }); + + it('should have custom class with custom className', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('custom'); + }); + + it('should have loading class with loading is true', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('loading'); + }); + + it('should have active class with active is true', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().className).toMatch('active'); + }); + + it('should have tab for item data-tab', function () { + var instance = TestUtils.renderIntoDocument( + + ); + + expect(instance.getDOMNode().getAttribute('data-tab')).toMatch('1'); + }); +}); From ccc4742acbb44ed32bbba8e6967f74f9cd694ca8 Mon Sep 17 00:00:00 2001 From: Lee Date: Wed, 7 Jan 2015 01:51:11 +0800 Subject: [PATCH 4/4] v0.2.3 - Add Commons and Modules Test Function - Use covrage status. - Use jest.genMockFunction to test onClick Function. Signed-off-by: Lee --- README.md | 11 ++++++++- RELEASE-NOTES.md | 6 +++++ dst/react-semantify.js | 47 +++++++++++++++--------------------- dst/react-semantify.min.js | 2 +- package.json | 2 +- src/mixins/classGenerator.js | 8 +++--- src/mixins/colorSelector.js | 6 ++--- src/mixins/stateSelector.js | 20 +++++++-------- src/mixins/typeSelector.js | 6 ++--- 9 files changed, 58 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index 69268d0..0173d3c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ React-Semantify ============= -[![Dependency Status][david-dm-image]][david-dm-url] [![Build Status][travis-ci-image]][travis-ci-url] +[![Dependency Status][david-dm-image]][david-dm-url] [![Build Status][travis-ci-image]][travis-ci-url][![Coverage Status][coverage-status-image]][coverage-status-url] Integrate Semantic-ui with react components. It depends on Semantic-UI and helps you use with react component. @@ -175,6 +175,12 @@ Wait Semantic-UI Release. 4. Push to the branch `git push origin your-new-feature-branch` 5. Create new Pull Request with `develop` branch +## Run Test + +- `git clone git@github.com:jessy1092/react-semantify.git` +- `npm i` +- `npm test` + ## License The MIT License (MIT) @@ -209,3 +215,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. [travis-ci-image]: https://img.shields.io/travis/jessy1092/react-semantify.svg?style=flat-square [travis-ci-url]: https://travis-ci.org/jessy1092/react-semantify + +[coverage-status-image]: https://img.shields.io/coveralls/jessy1092/react-semantify.svg?style=flat-square +[coverage-status-url]: https://coveralls.io/r/jessy1092/react-semantify diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index a39a827..f0f972b 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -1,6 +1,12 @@ Release Notes ============= +## Version 0.2.3 - 2015/01/07 + +- Add Commons and Modules Test Function +- Use covrage status. +- Use jest.genMockFunction to test onClick Function. + ## Version 0.2.2 - 2015/01/05 - Fix the onClick function Bug. [issue #7](https://github.com/jessy1092/react-semantify/issues/7) diff --git a/dst/react-semantify.js b/dst/react-semantify.js index 16388c4..617e5d6 100644 --- a/dst/react-semantify.js +++ b/dst/react-semantify.js @@ -1070,11 +1070,11 @@ module.exports = function (React) { getClassName: function (defaultClassName, addClassName) { var classResult = defaultClassName; - if (typeof this.props.className != 'undefined') { + if (typeof this.props.className !== 'undefined') { classResult += ' ' + this.props.className; } - if (typeof addClassName != 'undefined') { + if (typeof addClassName !== 'undefined') { if (typeof addClassName === 'object') { classResult += ' ' + classSet(addClassName); } else { @@ -1084,10 +1084,10 @@ module.exports = function (React) { return classResult; } - } + }; return ClassGenerator; -} +}; },{}],33:[function(require,module,exports){ "use strict"; @@ -1106,7 +1106,7 @@ module.exports = function (React) { getColor: function () { var color = 'null'; - if (typeof this.props.color != 'undefined') { + if (typeof this.props.color !== 'undefined') { if (colorArray.indexOf(this.props.color) != -1) { color = this.props.color; @@ -1115,10 +1115,10 @@ module.exports = function (React) { return color; } - } + }; return ColorSelector; -} +}; },{}],34:[function(require,module,exports){ "use strict"; @@ -1143,7 +1143,7 @@ module.exports = function (React) { getDisabled: function () { var disabled = false; - if (typeof this.props.disabled != 'undefined') { + if (typeof this.props.disabled !== 'undefined') { disabled = this.props.disabled; } @@ -1153,7 +1153,7 @@ module.exports = function (React) { getActive: function () { var active = false; - if (typeof this.props.active != 'undefined') { + if (typeof this.props.active !== 'undefined') { active = this.props.active; } @@ -1163,7 +1163,7 @@ module.exports = function (React) { getLoading: function () { var loading = false; - if (typeof this.props.loading != 'undefined') { + if (typeof this.props.loading !== 'undefined') { loading = this.props.loading; } @@ -1173,7 +1173,7 @@ module.exports = function (React) { getFocus: function () { var focus = false; - if (typeof this.props.focus != 'undefined') { + if (typeof this.props.focus !== 'undefined') { focus = this.props.focus; } @@ -1183,7 +1183,7 @@ module.exports = function (React) { getError: function () { var error = false; - if (typeof this.props.error != 'undefined') { + if (typeof this.props.error !== 'undefined') { error = this.props.error; } @@ -1193,7 +1193,7 @@ module.exports = function (React) { getCompleted: function () { var completed = false; - if (typeof this.props.completed != 'undefined') { + if (typeof this.props.completed !== 'undefined') { completed = this.props.completed; } @@ -1203,7 +1203,7 @@ module.exports = function (React) { getReadOnly: function () { var readOnly = false; - if (typeof this.props.readOnly != 'undefined') { + if (typeof this.props.readOnly !== 'undefined') { readOnly = this.props.readOnly; } @@ -1213,7 +1213,7 @@ module.exports = function (React) { getSuccess: function () { var success = false; - if (typeof this.props.success != 'undefined') { + if (typeof this.props.success !== 'undefined') { success = this.props.success; } @@ -1223,7 +1223,7 @@ module.exports = function (React) { getWarning: function () { var warning = false; - if (typeof this.props.warning != 'undefined') { + if (typeof this.props.warning !== 'undefined') { warning = this.props.warning; } @@ -1232,7 +1232,7 @@ module.exports = function (React) { }; return StateSelector; -} +}; },{}],35:[function(require,module,exports){ "use strict"; @@ -1251,17 +1251,17 @@ module.exports = function (React) { getType: function () { var type = 'div'; - if (typeof this.props.type != 'undefined') { + if (typeof this.props.type !== 'undefined') { if (typeArray.indexOf(this.props.type) != -1) { type = this.props.type; } } return type; } - } + }; return TypeSelector; -} +}; },{}],36:[function(require,module,exports){ "use strict"; @@ -1765,13 +1765,6 @@ module.exports = function (React) { mixins: [ClassGenerator], - propTypes: { - behavior: React.PropTypes.oneOfType([ - React.PropTypes.string, - React.PropTypes.object - ]) - }, - render: function () { var $__0= this.props,className=$__0.className,other=(function(source, exclusion) {var rest = {};var hasOwn = Object.prototype.hasOwnProperty;if (source == null) {throw new TypeError();}for (var key in source) {if (hasOwn.call(source, key) && !hasOwn.call(exclusion, key)) {rest[key] = source[key];}}return rest;})($__0,{className:1}); diff --git a/dst/react-semantify.min.js b/dst/react-semantify.min.js index 1a65919..e564e77 100644 --- a/dst/react-semantify.min.js +++ b/dst/react-semantify.min.js @@ -1,2 +1,2 @@ !function e(s,t,r){function i(a,o){if(!t[a]){if(!s[a]){var c="function"==typeof require&&require;if(!o&&c)return c(a,!0);if(n)return n(a,!0);var l=new Error("Cannot find module '"+a+"'");throw l.code="MODULE_NOT_FOUND",l}var p=t[a]={exports:{}};s[a][0].call(p.exports,function(e){var t=s[a][1][e];return i(t?t:e)},p,p.exports,e,s,t,r)}return t[a].exports}for(var n="function"==typeof require&&require,a=0;a