Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

#16: if dismissOnScroll at false, the click on the close button do not close the banner (closes #16) #17

Merged
merged 1 commit into from
May 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/CookieBanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@ export default React.createClass({
const { cookie, onAccept } = this.props;
cookieLite(cookie, true, 60*60*24*365);
onAccept({ cookie });
this.removeOnScrollListener();

if (this.state.listeningScroll) {
this.removeOnScrollListener();
} else {
this.forceUpdate();
}
},

getStyle(style) {
Expand Down Expand Up @@ -163,4 +168,4 @@ export default React.createClass({
this.removeOnScrollListener();
}

});
});
26 changes: 19 additions & 7 deletions test/tests/CookieBanner-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,47 @@ const resetCookies = function () {
}
};

const renderBanner = () => {
const renderBanner = (props) => {
const component =
<div>
<CookieBanner message='cookie message' />
<CookieBanner message='cookie message' {...props} />
</div>;
const cookieWrapper = TestUtils.renderIntoDocument(component);

return TestUtils.scryRenderedDOMComponentsWithClass(cookieWrapper, 'react-cookie-banner');
return {
wrapper: cookieWrapper,
banner: TestUtils.scryRenderedDOMComponentsWithClass(cookieWrapper, 'react-cookie-banner')
};
};

beforeEach(resetCookies);

describe('CookieBanner', function() {

it('should be displayed if no cookies are set', function() {
const banner = renderBanner();
const banner = renderBanner().banner;
expect(banner.length).toBe(1, 'cookie banner is not displayed');
});

it('should hide on click', function() {
const banner = renderBanner()[0];
const banner = renderBanner().banner[0];
const closeButton = TestUtils.findRenderedDOMComponentWithClass(banner, 'button-close');
TestUtils.Simulate.click(closeButton);

const banner2 = renderBanner()[0];
const banner2 = renderBanner().banner[0];
const cookieBanner2 = TestUtils.scryRenderedDOMComponentsWithClass(banner2, 'react-cookie-banner');
expect(cookieBanner2.length).toBe(0, 'cookie banner is displayed');
});

it('should hide on click when dismissOnScroll is false', function() {
const { banner, wrapper } = renderBanner({ dismissOnScroll: false });
const closeButton = TestUtils.findRenderedDOMComponentWithClass(banner[0], 'button-close');
TestUtils.Simulate.click(closeButton);

const cookieBanners = TestUtils.scryRenderedDOMComponentsWithClass(wrapper, 'react-cookie-banner');
expect(cookieBanners.length).toBe(0, 'cookie banner is displayed');
});

it('should be displayed with correct message', function() {
const cookieWrapper = TestUtils.renderIntoDocument(
<div>
Expand Down Expand Up @@ -79,4 +91,4 @@ describe('CookieBanner', function() {
expect(_myComponent.length).toBe(1, 'cookie banner is not displaing custom child component');
});

});
});