-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dist directory, if someone loading the package via GH
- Loading branch information
Showing
27 changed files
with
2,823 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
dist | ||
node_modules | ||
*.log |
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,12 @@ | ||
"use strict"; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.setWindow = setWindow; | ||
function setWindow(search) { | ||
global.window = { | ||
location: { search: search }, | ||
addEventListener: function addEventListener() {} | ||
}; | ||
} |
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,156 @@ | ||
'use strict'; | ||
|
||
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
|
||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
|
||
var _typeof2 = require('babel-runtime/helpers/typeof'); | ||
|
||
var _typeof3 = _interopRequireDefault(_typeof2); | ||
|
||
var _chai = require('chai'); | ||
|
||
var _client_api = require('../client_api'); | ||
|
||
var _client_api2 = _interopRequireDefault(_client_api); | ||
|
||
var _sinon = require('sinon'); | ||
|
||
var _sinon2 = _interopRequireDefault(_sinon); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
var _global = global; | ||
var describe = _global.describe; | ||
var it = _global.it; | ||
|
||
|
||
function getClientApi() { | ||
var syncedStore = { aa: 30 }; | ||
var storyStore = { aa: 10 }; | ||
var api = new _client_api2.default({ syncedStore: syncedStore, storyStore: storyStore }); | ||
|
||
return api; | ||
} | ||
|
||
describe('client.ClientApi', function () { | ||
describe('constructor', function () { | ||
it('should set _syncedStore & _storyStore properly', function () { | ||
var syncedStore = { aa: 30 }; | ||
var storyStore = { aa: 10 }; | ||
var api = new _client_api2.default({ syncedStore: syncedStore, storyStore: storyStore }); | ||
|
||
(0, _chai.expect)(api._syncedStore).to.be.equal(syncedStore); | ||
(0, _chai.expect)(api._storyStore).to.be.equal(storyStore); | ||
}); | ||
}); | ||
|
||
describe('storiesOf', function () { | ||
it('should return an api where we can add stories', function () { | ||
var api = getClientApi(); | ||
var chainApi = api.storiesOf('kind'); | ||
(0, _chai.expect)((0, _typeof3.default)(chainApi.add)).to.be.equal('function'); | ||
}); | ||
|
||
it('should remove story of the given kind, when hot module is disposing', function () { | ||
var doDispose = null; | ||
var hotModule = { | ||
hot: { | ||
dispose: function dispose(fn) { | ||
doDispose = fn; | ||
} | ||
} | ||
}; | ||
|
||
var api = getClientApi(); | ||
api._storyStore.removeStoryKind = _sinon2.default.stub(); | ||
api.storiesOf('kind', hotModule); | ||
|
||
doDispose(); | ||
|
||
(0, _chai.expect)(api._storyStore.removeStoryKind.args[0][0]).to.be.equal('kind'); | ||
}); | ||
}); | ||
|
||
describe('storiesOf.add', function () { | ||
it('should add a given story', function () { | ||
var api = getClientApi(); | ||
var handle = function handle() {}; | ||
|
||
api._storyStore.addStory = _sinon2.default.stub(); | ||
api.storiesOf('kind').add('name', handle); | ||
|
||
var args = api._storyStore.addStory.args[0]; | ||
(0, _chai.expect)(args[0]).to.be.equal('kind'); | ||
(0, _chai.expect)(args[1]).to.be.equal('name'); | ||
(0, _chai.expect)(args[2]).to.be.equal(handle); | ||
}); | ||
|
||
it('should support method chaining', function () { | ||
var api = getClientApi(); | ||
var handle = function handle() {}; | ||
|
||
api._storyStore.addStory = _sinon2.default.stub(); | ||
api.storiesOf('kind').add('name', handle).add('name2', handle); | ||
}); | ||
}); | ||
|
||
describe('action', function () { | ||
it('should send action info to the syncedStore', function () { | ||
var api = getClientApi(); | ||
api._syncedStore.getData = function () { | ||
return { actions: [] }; | ||
}; | ||
api._syncedStore.setData = _sinon2.default.stub(); | ||
|
||
var cb = api.action('hello'); | ||
cb(10, 20); | ||
|
||
var args = api._syncedStore.setData.args[0]; | ||
(0, _chai.expect)(args[0].actions).to.be.deep.equal([{ | ||
name: 'hello', | ||
args: [10, 20] | ||
}]); | ||
}); | ||
|
||
it('should only keep the latest 5 actions in the syncedStore', function () { | ||
var api = getClientApi(); | ||
api._syncedStore.getData = function () { | ||
return { | ||
actions: [50, 40, 30, 20, 10] | ||
}; | ||
}; | ||
api._syncedStore.setData = _sinon2.default.stub(); | ||
|
||
var cb = api.action('hello'); | ||
cb(10, 20); | ||
|
||
var args = api._syncedStore.setData.args[0]; | ||
(0, _chai.expect)(args[0].actions).to.be.deep.equal([{ | ||
name: 'hello', | ||
args: [10, 20] | ||
}, 50, 40, 30, 20]); | ||
}); | ||
|
||
it('should replace any Synthetic Event with it\'s name', function () { | ||
var api = getClientApi(); | ||
api._syncedStore.getData = function () { | ||
return { actions: [] }; | ||
}; | ||
api._syncedStore.setData = _sinon2.default.stub(); | ||
|
||
var SyntheticAction = function SyntheticAction() { | ||
(0, _classCallCheck3.default)(this, SyntheticAction); | ||
}; | ||
|
||
var cb = api.action('hello'); | ||
cb(new SyntheticAction()); | ||
|
||
var args = api._syncedStore.setData.args[0]; | ||
(0, _chai.expect)(args[0].actions).to.be.deep.equal([{ | ||
name: 'hello', | ||
args: ['[SyntheticAction]'] | ||
}]); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.