-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
97 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { expect } from 'chai'; | ||
import * as Actions from '../../src/actions'; | ||
|
||
describe('actions', () => { | ||
it('sets the correct notification level', () => { | ||
expect(Actions.success().level).to.equal('success'); | ||
expect(Actions.warning().level).to.equal('warning'); | ||
expect(Actions.info().level).to.equal('info'); | ||
expect(Actions.error().level).to.equal('error'); | ||
}); | ||
|
||
it('accepts custom opts', () => { | ||
expect(Actions.success({ custom: true }).custom).to.be.ok; | ||
}); | ||
|
||
it('generates random uid when not provided', () => { | ||
expect(Actions.success().uid).to.be.defined; | ||
}); | ||
|
||
if('sets the custom uid when provided', () => { | ||
expect(Actions.success({ uid: 1 }).uid).to.equal(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { expect } from 'chai'; | ||
import * as Constants from '../../src/const'; | ||
|
||
describe('constants', () => { | ||
it('should be defined', () => { | ||
expect(Constants.RNS_SHOW_NOTIFICATION).to.be.defined; | ||
expect(Constants.RNS_HIDE_NOTIFICATION).to.be.defined; | ||
}); | ||
}); |
14 changes: 9 additions & 5 deletions
14
src/__tests__/notifications.js → test/__tests__/notifications.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,24 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import Component from '../notifications'; | ||
import { expect } from 'chai'; | ||
import sinon from 'sinon'; | ||
import Component from '../../src/notifications'; | ||
import NotifySystem from 'react-notification-system'; | ||
|
||
describe('NotificationsComponent', () => { | ||
it('should render one <NotifySystem /> component', () => { | ||
const wrapper = shallow(<Component />); | ||
expect(wrapper.children()).toBeDefined(); | ||
expect(wrapper.children()).to.exist; | ||
}); | ||
|
||
it('should warn if prop:notifications is not array', () => { | ||
spyOn(console, 'error'); | ||
const c = sinon.stub(console, 'error'); | ||
|
||
const wrapper = shallow(<Component notifications={1} />); | ||
const warning = console.error.calls.argsFor(0)[0]; | ||
const warning = c.args[0][0]; | ||
|
||
expect(warning).toMatch(/Invalid prop `notifications` of type `number` supplied to `Notifications`, expected `array`./); | ||
expect(warning).to.match(/Invalid prop `notifications` of type `number` supplied to `Notifications`, expected `array`./); | ||
|
||
c.restore(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,27 @@ | ||
import Reducer from '../reducer'; | ||
import * as Actions from '../actions'; | ||
import { expect } from 'chai'; | ||
|
||
import Reducer from '../../src/reducer'; | ||
import * as Actions from '../../src/actions'; | ||
|
||
describe('reducer', () => { | ||
it('initializes state with an array', () => { | ||
expect(Reducer()).toEqual([]); | ||
expect(Reducer()).to.deep.equal([]); | ||
}); | ||
|
||
it('stores the notification to state', () => { | ||
const action = Actions.success(); | ||
const state = Reducer([], action); | ||
|
||
expect(state.length).toEqual(1); | ||
expect(state.length).to.equal(1); | ||
}); | ||
|
||
it('stores and removes notification', () => { | ||
const uid = 1; | ||
|
||
const state = Reducer([], Actions.success({ uid })); | ||
expect(state.length).toEqual(1); | ||
expect(state.length).to.equal(1); | ||
|
||
const newState = Reducer(state, Actions.hide(uid)); | ||
expect(newState.length).toEqual(0); | ||
expect(newState.length).to.equal(0); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--compilers js:babel-register | ||
--require test/utils/dom.js | ||
--reporter spec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const jsdom = require('jsdom'); | ||
|
||
// setup the simplest document possible | ||
const doc = jsdom.jsdom('<!doctype html><html><body></body></html>'); | ||
|
||
// get the window object out of the document | ||
const win = doc.defaultView; | ||
|
||
// set globals for mocha that make access to document and window feel | ||
// natural in the test environment | ||
global.document = doc; | ||
global.window = win; | ||
|
||
//JSDOM doesn't support localStrage by default, so lets just fake it.. | ||
if (!global.window.localStorage) { | ||
global.window.localStorage = { | ||
getItem() { return '{}'; }, | ||
setItem() {} | ||
}; | ||
} | ||
|
||
// take all properties of the window object and also attach it to the | ||
// mocha global object | ||
propagateToGlobal(win); | ||
|
||
// from mocha-jsdom https://github.com/rstacruz/mocha-jsdom/blob/master/index.js#L80 | ||
function propagateToGlobal (window) { | ||
for (let key in window) { | ||
if (!window.hasOwnProperty(key)) continue; | ||
if (key in global) continue; | ||
|
||
global[key] = window[key]; | ||
} | ||
} |