Skip to content

Commit 8673f47

Browse files
committed
Updated tests
1 parent 1a8bb0c commit 8673f47

File tree

7 files changed

+190
-109
lines changed

7 files changed

+190
-109
lines changed

samples/js/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ import React from "react";
22
import ReactDOM from "react-dom";
33
import App from "./components/App";
44
import "../styles/stylesheet.scss";
5-
import "babel-polyfill";
5+
import "@babel/polyfill";
66

77
ReactDOM.render(<App />, document.getElementById("root"));

src/helpers.js

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,35 @@ export function slidingExitTransition(notification) {
176176
);
177177
}
178178

179+
export function touchSwipeTransition(notification) {
180+
const { swipe } = notification.touchSlidingExit;
181+
182+
return getCubicBezierTransition(
183+
swipe.duration,
184+
swipe.cubicBezier,
185+
swipe.delay,
186+
"left"
187+
);
188+
}
189+
190+
export function touchFadeTransition(notification) {
191+
const { fade } = notification.touchSlidingExit;
192+
193+
return getCubicBezierTransition(
194+
fade.duration,
195+
fade.cubicBezier,
196+
fade.delay,
197+
"opacity"
198+
);
199+
}
200+
179201
export function getInitialSlidingState({ notification, isFirstNotification }) {
180202
// no sliding needed for first notification in container
181203
const hasSliding = shouldNotificationHaveSliding(notification) && !isFirstNotification;
182204
const state = {};
183205

184206
// set default classes for animated element
185-
state.animatedElementClasses = exports.getHtmlClassesForType(notification);
207+
state.animatedElementClasses = getHtmlClassesForType(notification);
186208
state.rootElementStyle = {
187209
height: "0",
188210
marginBottom: 0,
@@ -204,8 +226,8 @@ export function getInitialSlidingState({ notification, isFirstNotification }) {
204226

205227
export function getChildStyleForTouchTransitionExit(notification, startX, currentX) {
206228
const width = window.innerWidth * 2;
207-
const touchSwipe = exports.touchSwipeTransition(notification);
208-
const touchFade = exports.touchFadeTransition(notification);
229+
const touchSwipe = touchSwipeTransition(notification);
230+
const touchFade = touchFadeTransition(notification);
209231

210232
return {
211233
opacity: 0,
@@ -221,11 +243,11 @@ export function getChildStyleForTouchTransitionExit(notification, startX, curren
221243

222244
export function handleTouchSlidingAnimationExit(notification, currentX, startX) {
223245
// set current html classes
224-
const animatedElementClasses = exports.getHtmlClassesForType(notification);
246+
const animatedElementClasses = getHtmlClassesForType(notification);
225247
// set opacity and left to pull-out notification
226248
const childElementStyle = getChildStyleForTouchTransitionExit(notification, startX, currentX);
227249
// sliding out transition
228-
const slidingTransition = exports.slidingExitTransition(notification);
250+
const slidingTransition = slidingExitTransition(notification);
229251

230252
return {
231253
childElementStyle,
@@ -242,7 +264,7 @@ export function handleTouchSlidingAnimationExit(notification, currentX, startX)
242264

243265
export function handleSlidingAnimationExit(notification) {
244266
const { animationOut } = notification;
245-
const animatedElementClasses = exports.getHtmlClassesForType(notification);
267+
const animatedElementClasses = getHtmlClassesForType(notification);
246268

247269
if (animationOut) {
248270
// add CSS classes if any defined
@@ -283,7 +305,7 @@ export function handleStageTransition(notification, state) {
283305
if (notification.resized) {
284306
// window got resized, do not apply animations
285307
rootElementStyle = stateRootStyle;
286-
animatedElementClasses = exports.getHtmlClassesForType(notification);
308+
animatedElementClasses = getHtmlClassesForType(notification);
287309
} else {
288310
// use values from state
289311
rootElementStyle = stateRootStyle;
@@ -315,28 +337,6 @@ export function getRootHeightStyle(notification, scrollHeight) {
315337
};
316338
}
317339

318-
export function touchSwipeTransition(notification) {
319-
const { swipe } = notification.touchSlidingExit;
320-
321-
return getCubicBezierTransition(
322-
swipe.duration,
323-
swipe.cubicBezier,
324-
swipe.delay,
325-
"left"
326-
);
327-
}
328-
329-
export function touchFadeTransition(notification) {
330-
const { fade } = notification.touchSlidingExit;
331-
332-
return getCubicBezierTransition(
333-
fade.duration,
334-
fade.cubicBezier,
335-
fade.delay,
336-
"opacity"
337-
);
338-
}
339-
340340
export function getIconHtmlContent(notification, onClickHandler) {
341341
// use icon defined by user
342342
if (notification.dismissIcon) {
@@ -383,7 +383,7 @@ export function getNotificationOptions(options, userDefinedTypes) {
383383
} = notification;
384384

385385
// for now we'll use Math.random for id
386-
notification.id = exports.getRandomId();
386+
notification.id = getRandomId();
387387

388388
// validate notification's title
389389
validateTitle(notification);

src/react-notification.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ export default class ReactNotification extends React.Component {
4848

4949
componentWillUnmount() {
5050
if (this.timeoutId) {
51-
// timeout cleanup
52-
clearTimeout(this.timeoutId);
51+
this.timeoutId = clearTimeout(this.timeoutId);
5352
}
5453
}
5554

tests/__snapshots__/react-notification.test.js.snap

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,37 @@ Object {
289289
}
290290
`;
291291

292-
exports[`Notification component onTransitionEnd updates state with needed CSS classes 1`] = `[Function]`;
292+
exports[`Notification component onTransitionEnd updates state with needed CSS classes 1`] = `
293+
Object {
294+
"animatedElementClasses": Array [
295+
"notification-item",
296+
"notification-success",
297+
"notification-visible",
298+
"html5",
299+
"css3",
300+
],
301+
"hasSliding": true,
302+
"rootElementStyle": Object {
303+
"height": "auto",
304+
"width": undefined,
305+
},
306+
}
307+
`;
293308

294-
exports[`Notification component onTransitionEnd updates state with needed CSS classes 2`] = `[Function]`;
309+
exports[`Notification component onTransitionEnd updates state with needed CSS classes 2`] = `
310+
Object {
311+
"animatedElementClasses": Array [
312+
"notification-item",
313+
"notification-success",
314+
"notification-visible",
315+
],
316+
"hasSliding": true,
317+
"rootElementStyle": Object {
318+
"height": "auto",
319+
"width": undefined,
320+
},
321+
}
322+
`;
295323

296324
exports[`Notification component timeout handler skips setting state if stage is REMOVAL/EXIT 1`] = `
297325
Object {
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`test suite for stage-helpers adds CSS animation classes on removal if animationOut is defined 1`] = `
4+
Object {
5+
"animatedElementClasses": Array [
6+
"notification-item",
7+
"notification-success",
8+
"jest-test",
9+
],
10+
"rootElementStyle": Object {
11+
"height": 0,
12+
"marginBottom": 0,
13+
"transition": "600ms all cubic-bezier(0.215, 0.61, 0.355, 1) 0ms",
14+
"width": undefined,
15+
},
16+
}
17+
`;
18+
19+
exports[`test suite for stage-helpers does not add CSS animation classes on removal if animationOut is undefined 1`] = `
20+
Object {
21+
"animatedElementClasses": Array [
22+
"notification-item",
23+
"notification-success",
24+
],
25+
"rootElementStyle": Object {
26+
"height": 0,
27+
"marginBottom": 0,
28+
"transition": "600ms all cubic-bezier(0.215, 0.61, 0.355, 1) 0ms",
29+
"width": undefined,
30+
},
31+
}
32+
`;
33+
34+
exports[`test suite for stage-helpers notification slides to the left edge of the window 1`] = `
35+
Object {
36+
"left": "-2048px",
37+
"opacity": 0,
38+
"position": "relative",
39+
"transition": "600ms left ease-in 0ms, 300ms opacity ease-in 0ms",
40+
}
41+
`;
42+
43+
exports[`test suite for stage-helpers notification slides to the right edge of the window 1`] = `
44+
Object {
45+
"left": "2048px",
46+
"opacity": 0,
47+
"position": "relative",
48+
"transition": "600ms left ease-in 0ms, 300ms opacity ease-in 0ms",
49+
}
50+
`;

0 commit comments

Comments
 (0)