Skip to content

Commit 06a91e8

Browse files
committed
Updated tests, added prop validation, fixed stylesheets
1 parent c0f2343 commit 06a91e8

File tree

9 files changed

+56
-43
lines changed

9 files changed

+56
-43
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ https://teodosii.github.io/react-notifications-component/
2222
<td>:heavy_check_mark:</td>
2323
</tr>
2424
<tr>
25-
<td>Standard notification types (<code>default</code>, <code>success</code>, <code>info</code>, <code>danger</code>, <code>warning</code>)</td>
25+
<td>Standard notification types <br/> (<code>default</code>, <code>success</code>, <code>info</code>, <code>danger</code>, <code>warning</code>)</td>
2626
<td>:heavy_check_mark:</td>
2727
</tr>
2828
<tr>
2929
<td>Custom notification types</td>
3030
<td>:heavy_check_mark:</td>
3131
</tr>
3232
<tr>
33-
<td>Custom notification content - <code>images</code>, <code>icons</code> etc</td>
33+
<td>Custom notification content <br />(<code>images</code>, <code>icons</code> etc)</td>
3434
<td>:heavy_check_mark:</td>
3535
</tr>
3636
<tr>

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-notifications-component",
3-
"version": "0.2.1",
3+
"version": "1.0.0",
44
"homepage": "http://teodosii.github.io/react-notifications-component",
55
"description": "React component for creating notifications on the fly",
66
"main": "dist/react-notifications-component.js",
@@ -12,10 +12,10 @@
1212
"watch:library": "webpack -w --config webpack.dev.js",
1313
"start": "webpack-dev-server --config ./webpack.samples.dev.js",
1414
"test": "jest",
15-
"predeploy": "npm run build:prod",
15+
"predeploy": "npm run build:samples:prod",
1616
"deploy": "gh-pages -d dist",
1717
"coveralls": "jest --coverage && cat ./coverage/lcov.info | coveralls",
18-
"publish": "npm run prod && npm publish"
18+
"publish": "npm run build:library:prod && npm publish"
1919
},
2020
"repository": {
2121
"type": "git",

samples/styles/_customTypes.scss

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
.notification-custom-icon {
22
flex-basis: 20%;
33
position: relative;
4-
display: inline-block;
54
padding: 8px 8px 8px 12px;
5+
display: flex;
6+
align-items: center;
7+
justify-content: center;
68

79
.fa {
8-
top: 50%;
9-
left: 50%;
1010
color: #fff;
1111
font-size: 28px;
12-
position: relative;
13-
transform: translate(-50%, -50%);
1412
}
1513
}
1614

samples/styles/stylesheet.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ body,
3030
"Segoe UI Symbol" !important;
3131
}
3232

33+
.notification-item-root {
34+
backface-visibility: hidden;
35+
transform: translateZ(0) scale(1.0, 1.0);
36+
}
37+
3338
div.usage-example {
3439
text-align: left;
3540
}

src/constants.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,5 @@ export const ERROR = {
9090
// custom types
9191
TYPE_NOT_FOUND: "custom type not found"
9292
};
93+
94+
export const BREAKPOINT = 768;

src/react-notification-component.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import React from "react";
22
import ReactNotification from "src/react-notification";
3-
import {
4-
isArray,
5-
isNullOrUndefined
6-
} from "src/utils";
3+
import PropTypes from "prop-types";
4+
import { isArray } from "src/utils";
75

86
import {
97
INSERTION,
108
NOTIFICATION_STAGE,
11-
REMOVAL
9+
REMOVAL,
10+
BREAKPOINT
1211
} from "src/constants";
1312

1413
import {
@@ -21,28 +20,30 @@ import {
2120
import "src/scss/notification.scss";
2221

2322
class ReactNotificationComponent extends React.Component {
23+
static propTypes = {
24+
// option for responsiveness (defaults to true)
25+
isMobile: PropTypes.bool,
26+
// responsiveness breakpoint (defaults to 768)
27+
breakpoint: PropTypes.number,
28+
types: PropTypes.array,
29+
onNotificationRemoval: PropTypes.func
30+
}
31+
32+
static defaultProps = {
33+
isMobile: true,
34+
breakpoint: BREAKPOINT
35+
}
36+
2437
constructor(props) {
2538
super(props);
2639

2740
this.state = {
28-
// option for responsiveness (defaults to true)
2941
isMobile: props.isMobile,
30-
// responsiveness breakpoint (defaults to 768)
3142
breakpoint: props.breakpoint,
3243
// notifications array data
3344
notifications: []
3445
};
3546

36-
if (isNullOrUndefined(props.breakpoint)) {
37-
// set default breakpoint
38-
this.state.breakpoint = 768;
39-
}
40-
41-
if (isNullOrUndefined(props.isMobile)) {
42-
// option defaults to true
43-
this.state.isMobile = true;
44-
}
45-
4647
if (isArray(props.types)) {
4748
// check for custom types
4849
this.state.userDefinedTypes = props.types;

tests/react-notifications-component.test.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Enzyme, { mount } from "enzyme";
44
import React16Adapter from "enzyme-adapter-react-16";
55
import sinon from "sinon";
66
import notificationMock from "tests/mocks/notification.mock";
7-
import { NOTIFICATION_STAGE } from "src/constants";
7+
import { NOTIFICATION_STAGE, BREAKPOINT } from "src/constants";
88

99
Enzyme.configure({
1010
// use react-16 adapter
@@ -15,22 +15,20 @@ describe("Wrapper component", () => {
1515
let component;
1616
let clock;
1717

18-
// arrow function helpers
18+
// helpers
1919
const state = () => component.state();
2020
const instance = () => component.instance();
21+
22+
const getTypesMock = () => [{
23+
name: "awesome",
24+
htmlClasses: ["awesome"]
25+
}];
2126

22-
const getTypesMock = function () {
23-
return [{
24-
name: "awesome",
25-
htmlClasses: ["awesome"]
26-
}];
27-
};
28-
29-
const getNotificationMock = function (edits = {}) {
27+
const getNotificationMock = (edits = {}) => {
3028
return Object.assign({}, notificationMock, edits);
3129
};
3230

33-
const addNotification = function (mock) {
31+
const addNotification = (mock) => {
3432
return instance().addNotification(mock);
3533
};
3634

@@ -323,24 +321,30 @@ describe("Wrapper component", () => {
323321
expect(notif.props.toggleTouchEnd).toBeDefined();
324322
});
325323

326-
it("renders mobile if `isMobile` is set", () => {
324+
it("renders mobile for 512px width if `isMobile` is true", () => {
327325
// width for mobile view
328326
global.window.innerWidth = 512;
329327

328+
// just in case we update breakpoint in near future
329+
expect(global.window.innerWidth).toBeLessThan(BREAKPOINT);
330+
330331
// mount
331-
component = mount(<ReactNotificationComponent isMobile={true} />);
332+
component = mount(<ReactNotificationComponent />);
332333

333334
// all mobile containers rendered
334335
expect(component.find(".notification-container-mobile-top").length).toBe(1);
335336
expect(component.find(".notification-container-mobile-bottom").length).toBe(1);
336337
});
337338

338-
it("renders desktop if `isMobile` is not set", () => {
339+
it("renders desktop for 512px width if `isMobile` is false", () => {
339340
// width for mobile view
340341
global.window.innerWidth = 512;
341342

343+
// just in case we update breakpoint in near future
344+
expect(global.window.innerWidth).toBeLessThan(BREAKPOINT);
345+
342346
// mount
343-
component = mount(<ReactNotificationComponent />);
347+
component = mount(<ReactNotificationComponent isMobile={false} />);
344348

345349
// all desktop containers rendered
346350
expect(component.find(".notification-container-top-left").length).toBe(1);

webpack.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = {
1717

1818
plugins: [
1919
new webpack.DefinePlugin({
20-
"process.env.NODE_ENV": JSON.stringify("production")
20+
"process.env.NODE_ENV": JSON.stringify("development")
2121
})
2222
],
2323

webpack.samples.dev.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ module.exports = {
6767
inject: true,
6868
template: "./samples/html/index.html"
6969
}),
70+
new webpack.DefinePlugin({
71+
"process.env.NODE_ENV": JSON.stringify("development")
72+
}),
7073
new webpack.NamedModulesPlugin()
7174
]
7275
};

0 commit comments

Comments
 (0)