Skip to content
This repository was archived by the owner on Dec 24, 2019. It is now read-only.

Commit 52cb8a7

Browse files
joeyfigaroPatrick Burtchaell
authored andcommitted
Disable timeout
* Add the ability to set notification to not dismiss after timeout * Update documentation for dismissAfter prop * Update tests with new test for dismissAfter with a value of `false`
1 parent 2d9ec5e commit 52cb8a7

File tree

9 files changed

+42
-18
lines changed

9 files changed

+42
-18
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules/
22
bin/tests/.tmp/
33
dist/
4+
.DS_Store
45
*.log*

Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ REPORTER = spec
55
# Task: test
66
# Run mocha tests for components.
77
test:
8-
@NODE_ENV=test $(BIN)/mocha \
9-
--compilers js:babel-core/register \
10-
--reporter $(REPORTER) \
11-
--recursive \
12-
--timeout 5000 \
13-
$(TESTS)
8+
@NODE_ENV=test $(BIN)/mocha \
9+
--compilers js:babel-core/register \
10+
--reporter $(REPORTER) \
11+
--recursive \
12+
--timeout 5000 \
13+
$(TESTS)
1414

1515
.PHONY: test

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ For Notification component:
9595
| actionStyle | object | Custom action styles | | |
9696
| className | string | Custom class to apply to the top-level component | | |
9797
| activeClassName | string | Custom class to apply to the top-level component when active| | `'notification-bar-active'`|
98-
| dismissAfter | number | Timeout for onDismiss event | | `2000` |
98+
| dismissAfter | number or false | Timeout for onDismiss event | | `2000` |
9999

100100
The `style` prop useful if you are not using React inline styles and would like to use CSS instead. See [styles](#styles) for more.
101101

src/defaultPropTypes.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ export default {
1515
actionStyle: PropTypes.object,
1616
barStyle: PropTypes.object,
1717
activeBarStyle: PropTypes.object,
18-
dismissAfter: PropTypes.number,
18+
dismissAfter: PropTypes.oneOfType([
19+
PropTypes.bool,
20+
PropTypes.number
21+
]),
1922
onDismiss: PropTypes.func,
2023
className: PropTypes.string,
2124
activeClassName: PropTypes.string.isRequired,

src/notification.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class Notification extends Component {
1919
}
2020

2121
componentWillReceiveProps(nextProps) {
22+
if (this.props.dismissAfter === false) return;
2223
if (!nextProps.hasOwnProperty('isLast'))
2324
clearTimeout(this.dismissTimeout);
2425
if (nextProps.onDismiss && nextProps.isActive && !this.props.isActive) {
@@ -30,7 +31,7 @@ class Notification extends Component {
3031
}
3132

3233
componentWillUnmount() {
33-
clearTimeout(this.dismissTimeout);
34+
if (this.props.dismissAfter) clearTimeout(this.dismissTimeout);
3435
}
3536

3637
/*

src/stackedNotification.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ class StackedNotification extends Component {
1515
isActive: true
1616
}), 1);
1717

18-
this.dismissTimeout = setTimeout(this.setState.bind(this, {
19-
isActive: false
20-
}), this.props.dismissAfter);
18+
if (this.props.dismissAfter) {
19+
this.dismissTimeout = setTimeout(this.setState.bind(this, {
20+
isActive: false
21+
}), this.props.dismissAfter);
22+
}
2123
}
2224

2325
componentWillUnmount() {

test/notification.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('<Notification />', () => {
3232
expect(component).to.have.className('notification-bar');
3333
});
3434

35-
it('has custom class name', () => {
35+
it('has custom class name', () => {
3636
let classNameComponent = shallow(
3737
<Notification
3838
message={mockNotification.message}
@@ -73,7 +73,6 @@ describe('<Notification />', () => {
7373
expect(classNameComponent).to.have.className(customActiveClassName);
7474
});
7575

76-
7776
it('should render message element', () => {
7877
expect(wrapper).to.have.descendants(messageClassName);
7978
});
@@ -206,18 +205,18 @@ describe('<Notification />', () => {
206205
}, mockNotification.dismissAfter);
207206
});
208207

209-
it('onDismiss fires correctly without prop change', done => {
208+
it('onDismiss fires once when dismissAfter is passed', done => {
210209
const handleDismiss = spy();
211-
212210
const wrapper = mount(
213211
<Notification
214212
message={mockNotification.message}
215213
dismissAfter={mockNotification.dismissAfter}
216214
onDismiss={handleDismiss}
217-
isActive
218215
/>
219216
);
220217

218+
wrapper.setProps({ isActive: true });
219+
221220
setTimeout(() => {
222221
try {
223222
expect(handleDismiss.calledOnce).to.equal(true);
@@ -226,5 +225,19 @@ describe('<Notification />', () => {
226225
done(e);
227226
}
228227
}, mockNotification.dismissAfter);
229-
})
228+
});
229+
230+
it('onDismiss does not get fired when dismissAfter is false', () => {
231+
const handleDismiss = spy();
232+
233+
const wrapper = shallow(
234+
<Notification
235+
message={mockNotification.message}
236+
dismissAfter={false}
237+
onDismiss={handleDismiss}
238+
/>
239+
);
240+
241+
expect(handleDismiss.calledOnce).to.equal(false);
242+
});
230243
});

test/notificationStack.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ describe('<NotificationStack />', () => {
2222
);
2323

2424
wrapper.update();
25+
2526
setTimeout(() => {
2627
try {
2728
expect(handleDismiss.calledOnce).to.equal(true);

test/setup.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import chai from 'chai';
22
import chaiEnzyme from 'chai-enzyme';
33

4+
// Include stack on error
5+
chai.config.includeStack = true;
6+
47
/**
58
* Add commonly used functions in tests to global
69
* so they do not need to be imported each time.

0 commit comments

Comments
 (0)