Skip to content

Commit

Permalink
test(cssClasses): Check if double render still returns the same
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerska committed Nov 2, 2015
1 parent e193f45 commit 1a4fcfe
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ describe('hitsPerPageSelector()', () => {
expect(widget.getConfiguration).toEqual(undefined);
});

it('calls ReactDOM.render(<Selector props />, container)', () => {
it('calls twice ReactDOM.render(<Selector props />, container)', () => {
widget.render({helper, results, state: helper.state});
widget.render({helper, results, state: helper.state});
props = {
cssClasses: {
Expand All @@ -73,9 +74,11 @@ describe('hitsPerPageSelector()', () => {
],
setValue: () => {}
};
expect(ReactDOM.render.calledOnce).toBe(true, 'ReactDOM.render called once');
expect(ReactDOM.render.calledTwice).toBe(true, 'ReactDOM.render called twice');
expect(ReactDOM.render.firstCall.args[0]).toEqualJSX(<Selector {...props} />);
expect(ReactDOM.render.firstCall.args[1]).toEqual(container);
expect(ReactDOM.render.secondCall.args[0]).toEqualJSX(<Selector {...props} />);
expect(ReactDOM.render.secondCall.args[1]).toEqual(container);
});

it('sets the underlying hitsPerPage', () => {
Expand Down
7 changes: 5 additions & 2 deletions widgets/hits/__tests__/hits-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,16 @@ describe('hits()', () => {
expect(widget.getConfiguration()).toEqual({hitsPerPage: 20});
});

it('calls ReactDOM.render(<Hits props />, container)', () => {
it('calls twice ReactDOM.render(<Hits props />, container)', () => {
props = getProps();
widget.render({results});
widget.render({results});

expect(ReactDOM.render.calledOnce).toBe(true, 'ReactDOM.render called once');
expect(ReactDOM.render.calledTwice).toBe(true, 'ReactDOM.render called twice');
expect(ReactDOM.render.firstCall.args[0]).toEqualJSX(<Hits {...props} />);
expect(ReactDOM.render.firstCall.args[1]).toEqual(container);
expect(ReactDOM.render.secondCall.args[0]).toEqualJSX(<Hits {...props} />);
expect(ReactDOM.render.secondCall.args[1]).toEqual(container);
});

afterEach(() => {
Expand Down
7 changes: 5 additions & 2 deletions widgets/index-selector/__tests__/index-selector-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ describe('indexSelector()', () => {
expect(widget.getConfiguration).toEqual(undefined);
});

it('calls ReactDOM.render(<Selector props />, container)', () => {
it('calls twice ReactDOM.render(<Selector props />, container)', () => {
widget.render({helper, results});
widget.render({helper, results});
props = {
cssClasses: {
Expand All @@ -71,9 +72,11 @@ describe('indexSelector()', () => {
],
setValue: () => {}
};
expect(ReactDOM.render.calledOnce).toBe(true, 'ReactDOM.render called once');
expect(ReactDOM.render.calledTwice).toBe(true, 'ReactDOM.render called twice');
expect(ReactDOM.render.firstCall.args[0]).toEqualJSX(<Selector {...props} />);
expect(ReactDOM.render.firstCall.args[1]).toEqual(container);
expect(ReactDOM.render.secondCall.args[0]).toEqualJSX(<Selector {...props} />);
expect(ReactDOM.render.secondCall.args[1]).toEqual(container);
});

it('sets the underlying index', () => {
Expand Down
7 changes: 5 additions & 2 deletions widgets/pagination/__tests__/pagination-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@ describe('pagination()', () => {
expect(helper.search.calledOnce).toBe(true);
});

it('calls ReactDOM.render(<Pagination props />, container)', () => {
it('calls twice ReactDOM.render(<Pagination props />, container)', () => {
widget.render({results, helper});
widget.render({results, helper});

expect(ReactDOM.render.calledOnce).toBe(true, 'ReactDOM.render called once');
expect(ReactDOM.render.calledTwice).toBe(true, 'ReactDOM.render called twice');
expect(ReactDOM.render.firstCall.args[0]).toEqualJSX(<Pagination {...getProps()} />);
expect(ReactDOM.render.firstCall.args[1]).toEqual(container);
expect(ReactDOM.render.secondCall.args[0]).toEqualJSX(<Pagination {...getProps()} />);
expect(ReactDOM.render.secondCall.args[1]).toEqual(container);
});

context('mocking getContainerNode', function() {
Expand Down
7 changes: 5 additions & 2 deletions widgets/price-ranges/__tests__/price-ranges-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,15 @@ describe('priceRanges()', () => {
};
});

it('calls ReactDOM.render(<PriceRanges props />, container)', () => {
it('calls twice ReactDOM.render(<PriceRanges props />, container)', () => {
widget.render({results, helper});
widget.render({results, helper});

expect(ReactDOM.render.calledOnce).toBe(true, 'ReactDOM.render called once');
expect(ReactDOM.render.calledTwice).toBe(true, 'ReactDOM.render called twice');
expect(ReactDOM.render.firstCall.args[0]).toEqualJSX(<PriceRanges {...props} />);
expect(ReactDOM.render.firstCall.args[1]).toEqual(container);
expect(ReactDOM.render.secondCall.args[0]).toEqualJSX(<PriceRanges {...props} />);
expect(ReactDOM.render.secondCall.args[1]).toEqual(container);
});

it('calls the decorators', () => {
Expand Down
35 changes: 20 additions & 15 deletions widgets/range-slider/__tests__/range-slider-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,32 @@ describe('rangeSlider()', () => {
expect(widget.getConfiguration()).toEqual({disjunctiveFacets: ['aFacetName']});
});

it('calls ReactDOM.render(<Slider props />, container)', () => {
it('calls twice ReactDOM.render(<Slider props />, container)', () => {
widget.render({results, helper});
expect(ReactDOM.render.calledOnce).toBe(true, 'ReactDOM.render called once');
expect(autoHideContainer.calledOnce).toBe(true, 'autoHideContainer called once');
expect(headerFooter.calledOnce).toBe(true, 'headerFooter called once');
expect(ReactDOM.render.firstCall.args[0]).toEqualJSX(
<Slider
cssClasses={{body: null, root: null}}
onChange={() => {}}
range={{max: 4999.98, min: 1.99}}
shouldAutoHideContainer={false}
start={[-Infinity, Infinity]}
templateProps={{
widget.render({results, helper});

var props = {
cssClasses: {body: null, root: null},
onChange: () => {},
range: {max: 4999.98, min: 1.99},
shouldAutoHideContainer: false,
start: [-Infinity, Infinity],
templateProps: {
templates: {footer: '', header: ''},
templatesConfig: undefined,
transformData: undefined,
useCustomCompileOptions: {footer: false, header: false}
}}
tooltips
/>);
},
tooltips: true
};

expect(ReactDOM.render.calledTwice).toBe(true, 'ReactDOM.render called twice');
expect(autoHideContainer.calledOnce).toBe(true, 'autoHideContainer called once');
expect(headerFooter.calledOnce).toBe(true, 'headerFooter called once');
expect(ReactDOM.render.firstCall.args[0]).toEqualJSX(<Slider {...props} />);
expect(ReactDOM.render.firstCall.args[1]).toEqual(container);
expect(ReactDOM.render.secondCall.args[0]).toEqualJSX(<Slider {...props} />);
expect(ReactDOM.render.secondCall.args[1]).toEqual(container);
});

it('doesn\'t call the refinement functions if not refined', () => {
Expand Down
37 changes: 20 additions & 17 deletions widgets/stats/__tests__/stats-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,33 @@ describe('stats()', () => {
expect(widget.getConfiguration).toEqual(undefined);
});

it('calls ReactDOM.render(<Stats props />, container)', () => {
it('calls twice ReactDOM.render(<Stats props />, container)', () => {
widget.render({results});
expect(ReactDOM.render.calledOnce).toBe(true, 'ReactDOM.render called once');
expect(autoHideContainer.calledOnce).toBe(true, 'autoHideContainer called once');
expect(headerFooter.calledOnce).toBe(true, 'headerFooter called once');
expect(ReactDOM.render.firstCall.args[0]).toEqualJSX(
<Stats
cssClasses={{
widget.render({results});
var props = {
cssClasses: {
body: 'ais-stats--body',
header: 'ais-stats--header',
footer: 'ais-stats--footer',
root: 'ais-stats',
time: 'ais-stats--time'
}}
hitsPerPage={2}
nbHits={20}
nbPages={10}
page={0}
processingTimeMS={42}
query="a query"
shouldAutoHideContainer={false}
templateProps={ReactDOM.render.firstCall.args[0].props.templateProps}
/>);
},
hitsPerPage: 2,
nbHits: 20,
nbPages: 10,
page: 0,
processingTimeMS: 42,
query: 'a query',
shouldAutoHideContainer: false,
templateProps: ReactDOM.render.firstCall.args[0].props.templateProps
};
expect(ReactDOM.render.calledTwice).toBe(true, 'ReactDOM.render called twice');
expect(autoHideContainer.calledOnce).toBe(true, 'autoHideContainer called once');
expect(headerFooter.calledOnce).toBe(true, 'headerFooter called once');
expect(ReactDOM.render.firstCall.args[0]).toEqualJSX(<Stats {...props} />);
expect(ReactDOM.render.firstCall.args[1]).toEqual(container);
expect(ReactDOM.render.secondCall.args[0]).toEqualJSX(<Stats {...props} />);
expect(ReactDOM.render.secondCall.args[1]).toEqual(container);
});

afterEach(() => {
Expand Down
12 changes: 10 additions & 2 deletions widgets/toggle/__tests__/toggle-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,18 @@ describe('toggle()', () => {
};
});

it('calls ReactDOM.render', () => {
it('calls twice ReactDOM.render', () => {
results = {
hits: [{Hello: ', world!'}],
nbHits: 1,
getFacetValues: sinon.stub().returns([{name: 'true', count: 2}, {name: 'false', count: 1}])
};
widget = toggle({container, facetName, label});
widget.render({results, helper});
expect(ReactDOM.render.calledOnce).toBe(true, 'ReactDOM.render called once');
widget.render({results, helper});
expect(ReactDOM.render.calledTwice).toBe(true, 'ReactDOM.render called twice');
expect(ReactDOM.render.firstCall.args[1]).toEqual(container);
expect(ReactDOM.render.secondCall.args[1]).toEqual(container);
});

it('with facet values', () => {
Expand All @@ -127,6 +129,7 @@ describe('toggle()', () => {
};
widget = toggle({container, facetName, label});
widget.render({results, helper});
widget.render({results, helper});

props = {
facetValues: [{count: 1, isRefined: false, name: label}],
Expand All @@ -135,6 +138,7 @@ describe('toggle()', () => {
};

expect(ReactDOM.render.firstCall.args[0]).toEqualJSX(<RefinementList {...props} />);
expect(ReactDOM.render.secondCall.args[0]).toEqualJSX(<RefinementList {...props} />);
});

it('without facet values', () => {
Expand All @@ -145,6 +149,7 @@ describe('toggle()', () => {
};
widget = toggle({container, facetName, label});
widget.render({results, helper});
widget.render({results, helper});

props = {
facetValues: [{name: label, isRefined: false, count: null}],
Expand All @@ -153,6 +158,7 @@ describe('toggle()', () => {
};

expect(ReactDOM.render.firstCall.args[0]).toEqualJSX(<RefinementList {...props} />);
expect(ReactDOM.render.secondCall.args[0]).toEqualJSX(<RefinementList {...props} />);
});

it('when refined', () => {
Expand All @@ -166,6 +172,7 @@ describe('toggle()', () => {
};
widget = toggle({container, facetName, label});
widget.render({results, helper});
widget.render({results, helper});

props = {
facetValues: [{count: 2, isRefined: true, name: label}],
Expand All @@ -174,6 +181,7 @@ describe('toggle()', () => {
};

expect(ReactDOM.render.firstCall.args[0]).toEqualJSX(<RefinementList {...props} />);
expect(ReactDOM.render.secondCall.args[0]).toEqualJSX(<RefinementList {...props} />);
});

it('using props.toggleRefinement', () => {
Expand Down

0 comments on commit 1a4fcfe

Please sign in to comment.