-
Notifications
You must be signed in to change notification settings - Fork 2
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
1 parent
5a22226
commit f1252ad
Showing
16 changed files
with
701 additions
and
16 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 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,10 @@ | ||
{ | ||
"language": "node_js", | ||
"node_js": "6.9.1", | ||
"before_script": [ | ||
"export DISPLAY=:99.0", | ||
"sh -e /etc/init.d/xvfb start", | ||
"yarn" | ||
], | ||
"script": "npm run test" | ||
} |
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 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 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 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,7 +1,124 @@ | ||
import helpers from './helpers.js'; | ||
import * as helpers from './helpers.js'; | ||
|
||
describe.skip('helpers.y', () => { | ||
it('', () => { | ||
expect('').toEqual(''); | ||
describe('helpers.getStoreInstanceName', () => { | ||
it('should handle when no instance', () => { | ||
expect(helpers.getStoreInstanceName('foo')).toEqual('foo'); | ||
}); | ||
|
||
it('should handle when instance', () => { | ||
expect(helpers.getStoreInstanceName('foo', 'bar')).toEqual('foo$bar'); | ||
}); | ||
}); | ||
|
||
describe('helpers.toCamelCase', () => { | ||
it('convert kebab to camel case', () => { | ||
expect(helpers.toCamelCase('a-foo-bar-a$b')).toEqual('aFooBarA$b'); | ||
}); | ||
it('convert snake to camel case', () => { | ||
expect(helpers.toCamelCase('a_foo_bar_a$b')).toEqual('aFooBarA$b'); | ||
}); | ||
it('handles numbers', () => { | ||
expect(helpers.toCamelCase('a-fo1o2-ba3r-4a$5b')).toEqual('aFo1o2Ba3r4a$5b'); | ||
}); | ||
it('keeps camel case intact', () => { | ||
expect(helpers.toCamelCase('aFooBarA$b')).toEqual('aFooBarA$b'); | ||
}); | ||
}); | ||
|
||
describe('helpers.getLocalPath', () => { | ||
it('replaces store name to top instance', () => { | ||
const state = { | ||
'vuex+': { | ||
storeName: 'foo', | ||
instance: 'bar', | ||
}, | ||
}; | ||
expect(helpers.getLocalPath('foo/piri', state)).toEqual('foo$bar/piri'); | ||
}); | ||
|
||
it('replaces keeps store name when no instance', () => { | ||
const state = { | ||
'vuex+': { | ||
storeName: 'foo', | ||
}, | ||
}; | ||
expect(helpers.getLocalPath('foo/piri', state)).toEqual('foo/piri'); | ||
}); | ||
}); | ||
|
||
describe('helpers.getTagName', () => { | ||
it('returns unknown if no $parent', () => { | ||
expect(helpers.getTagName({})).toEqual('<unknown-tag>'); | ||
}); | ||
|
||
it('returns tag from $vnode', () => { | ||
const self = { | ||
$parent: { | ||
$vnode: { | ||
componentOptions: { | ||
tag: 'foo', | ||
}, | ||
}, | ||
}, | ||
}; | ||
expect(helpers.getTagName(self)).toEqual('<foo>'); | ||
}); | ||
|
||
it('returns tag from _vnode', () => { | ||
const self = { | ||
$parent: { | ||
_vnode: { | ||
componentOptions: { | ||
tag: 'foo', | ||
}, | ||
}, | ||
}, | ||
}; | ||
expect(helpers.getTagName(self)).toEqual('<foo>'); | ||
}); | ||
}); | ||
|
||
describe('helpers.getInstances', () => { | ||
it('goes though parents and retrieves instances', () => { | ||
const self = { | ||
$parent: { | ||
instance: 'foo', | ||
$parent: { | ||
instance: 'bar', | ||
$parent: { | ||
instance: 'chuu', | ||
}, | ||
}, | ||
}, | ||
}; | ||
expect(helpers.getInstances('a/b', self)).toEqual(['$chuu', '$bar', '$foo']); | ||
}); | ||
|
||
it('goes though parents and retrieves instances, and handles when parents lack instances', () => { | ||
const self = { | ||
$parent: { | ||
$parent: { | ||
$parent: { | ||
instance: 'chuu', | ||
}, | ||
}, | ||
}, | ||
}; | ||
expect(helpers.getInstances('a/b', self)).toEqual(['$chuu']); | ||
}); | ||
|
||
it('adds subinstances', () => { | ||
const self = { | ||
$parent: { | ||
instance: 'foo', | ||
}, | ||
}; | ||
expect(helpers.getInstances('a$a1/b$b1/c$c1/d', self)).toEqual(['$foo', '$a1', '$b1', '$c1']); | ||
}); | ||
}); | ||
|
||
describe('helpers.getSubInstances', () => { | ||
it('returns all instances from substring', () => { | ||
expect(helpers.getSubInstances('a$a1/b/c$c1/d')).toEqual(['$a1', '$c1']); | ||
}); | ||
}); |
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 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,62 @@ | ||
import * as hmr from './hmrHandler.js'; | ||
import * as vuexInstance from '../vuexInstance.js'; | ||
|
||
beforeEach(() => { | ||
hmr.clearHandlers(); | ||
}); | ||
|
||
describe('hmrHandler.registerForHMR', () => { | ||
it('should be able to register hmr for top stores', () => { | ||
expect(hmr.getHandlers().length).toBe(0); | ||
const newStore = () => {}; | ||
hmr.registerForHMR(newStore, 'foo', 'foo$bar'); | ||
expect(hmr.getHandlers().length).toBe(1); | ||
expect(hmr.getHandlers()[0]).toEqual({ | ||
storeName: 'foo-store', | ||
storeInstanceName: 'foo$bar', | ||
newStore, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('hmrHandler.unregisterForHMR', () => { | ||
it('should be able remove handler for top store', () => { | ||
const newStore = () => {}; | ||
hmr.registerForHMR(newStore, 'foo', 'foo$bar'); | ||
hmr.unregisterForHMR(newStore); | ||
expect(hmr.getHandlers().length).toBe(0); | ||
}); | ||
}); | ||
|
||
describe('hmrHandler.hmrHandler', () => { | ||
it('should return a list of updated stores', () => { | ||
vuexInstance.default.store = { | ||
hotUpdate: jest.fn(), | ||
}; | ||
|
||
hmr.registerForHMR(() => {}, 'foo1', 'foo1$bar1'); | ||
const $api = { | ||
get: 'foo2/bar2', | ||
act: 'foo2/bar2', | ||
mutate: 'foo2/bar2', | ||
}; | ||
const newStore = () => ({ | ||
name: 'foo2', | ||
$api, | ||
}); | ||
hmr.registerForHMR(newStore, 'foo2', 'foo2$bar2'); | ||
hmr.registerForHMR(() => {}, 'foo3', 'foo3$bar3'); | ||
|
||
const updatedStore = {}; | ||
hmr.hmrHandler({ 'foo2-store': updatedStore }); | ||
|
||
expect(vuexInstance.default.store.hotUpdate).toBeCalledWith({ | ||
modules: { | ||
foo2$bar2: { | ||
$api, | ||
name: 'foo2', | ||
}, | ||
}, | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.