-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* removed nyc * trial to fix Please tell me who you are * set config global * fixed syntax error * fixed flag * post demo url as pr comment * added onClickOutside event * post pr comment without using circle-github-bot * bugfix for pr demo publish * fixed tests for onClickOutside * finished tests for onClickOutside * fail lint task on warning * fixed lint problems BREAKING CHANGE: first release version
- Loading branch information
Showing
10 changed files
with
221 additions
and
68 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
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
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 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,109 @@ | ||
import expect, { createSpy } from 'expect' | ||
import React, { cloneElement } from 'react' | ||
import { render as renderBase, unmountComponentAtNode } from 'react-dom' | ||
|
||
import Stick from 'src/' | ||
|
||
describe('`onClickOutside` event', () => { | ||
let host | ||
|
||
const anchor = <div id="anchor" /> | ||
const node = <div id="node" /> | ||
|
||
// wrap render to invoke callback only after the node has actually been mounted | ||
const render = (stick, host, callback) => { | ||
let called = false | ||
renderBase( | ||
cloneElement(stick, { | ||
node: cloneElement(stick.props.node, { | ||
ref: el => !!el && !called && window.setTimeout(callback, 1), | ||
}), | ||
}), | ||
host | ||
) | ||
} | ||
|
||
beforeEach(() => { | ||
host = document.createElement('div') | ||
document.body.appendChild(host) | ||
}) | ||
|
||
afterEach(() => { | ||
unmountComponentAtNode(host) | ||
document.body.removeChild(host) | ||
}) | ||
|
||
it('should call `onClickOutside` on click on any element outside of the sticked node an anchor element', done => { | ||
const spy = createSpy() | ||
render( | ||
<Stick onClickOutside={spy} node={node}> | ||
{anchor} | ||
</Stick>, | ||
host, | ||
() => { | ||
const outsideNode = document.createElement('div') | ||
document.body.appendChild(outsideNode) | ||
outsideNode.click() | ||
expect(spy).toHaveBeenCalled() | ||
spy.reset() | ||
|
||
document.body.click() | ||
expect(spy).toHaveBeenCalled() | ||
done() | ||
} | ||
) | ||
}) | ||
|
||
it('should not call `onClickOutside` on click on the anchor element or sticked node', done => { | ||
const spy = createSpy() | ||
render( | ||
<Stick onClickOutside={spy} node={node}> | ||
{anchor} | ||
</Stick>, | ||
host, | ||
() => { | ||
document.getElementById('anchor').click() | ||
expect(spy).toNotHaveBeenCalled() | ||
|
||
document.getElementById('node').click() | ||
expect(spy).toNotHaveBeenCalled() | ||
|
||
done() | ||
} | ||
) | ||
}) | ||
|
||
const inlineOptions = [false, true] | ||
inlineOptions.forEach(outerInline => { | ||
inlineOptions.forEach(innerInline => { | ||
describe(`<Stick ${innerInline ? 'inline ' : ''}/> in node of <Stick ${ | ||
outerInline ? 'inline ' : '' | ||
}/>`, () => { | ||
it('should not call `onClickOutside` on click on the nested sticked node', done => { | ||
const spy = createSpy() | ||
render( | ||
<Stick | ||
inline={outerInline} | ||
onClickOutside={spy} | ||
node={ | ||
<div id="node"> | ||
<Stick inline={innerInline} node={<div id="nested-node" />}> | ||
<span>foo</span> | ||
</Stick> | ||
</div> | ||
} | ||
> | ||
<div /> | ||
</Stick>, | ||
host, | ||
() => { | ||
document.getElementById('nested-node').click() | ||
expect(spy).toNotHaveBeenCalled() | ||
done() | ||
} | ||
) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.