-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(DropdownItem): replace react-bootstrap DropdownItem
* only render anchor tag if href prop exists * allow user-provided components with anchors [#114813379] Signed-off-by: Dan Dzoan <ddzoan@pivotal.io>
- Loading branch information
1 parent
824c0f7
commit 442e71a
Showing
3 changed files
with
174 additions
and
38 deletions.
There are no files selected for viewing
115 changes: 115 additions & 0 deletions
115
library/spec/pivotal-ui-react/dropdown/dropdown-item_spec.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 |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import {DropdownItem} from '../../../src/pivotal-ui-react/dropdowns/dropdowns'; | ||
|
||
describe('DropdownItem', () => { | ||
let props = { | ||
className: 'test-item-class', | ||
id: 'test-item-id', | ||
style: { | ||
opacity: '1' | ||
} | ||
}; | ||
|
||
afterEach(() => { | ||
ReactDOM.unmountComponentAtNode(root); | ||
}); | ||
|
||
it('passes through header', () => { | ||
ReactDOM.render( | ||
<DropdownItem header>HeadText</DropdownItem>, | ||
root); | ||
expect('#root li.dropdown-header').toContainText('HeadText'); | ||
}); | ||
|
||
it('passes through divider', () => { | ||
ReactDOM.render( | ||
<DropdownItem divider />, | ||
root); | ||
expect('#root li.divider').toExist(); | ||
}); | ||
|
||
it('passes through className to the li ', () => { | ||
ReactDOM.render( | ||
<DropdownItem {...props}>Item</DropdownItem>, | ||
root); | ||
expect('#root li').toHaveClass(props.className); | ||
}); | ||
|
||
it('passes through style to the li', () => { | ||
ReactDOM.render( | ||
<DropdownItem {...props}>Item</DropdownItem>, | ||
root); | ||
expect('#root li').toHaveCss(props.style); | ||
}); | ||
|
||
describe('href', () => { | ||
it('passes through id to the anchor', () => { | ||
ReactDOM.render( | ||
<DropdownItem href='test' {...props}>Item</DropdownItem>, | ||
root); | ||
expect('#root li a#test-item-id').toExist(); | ||
}); | ||
}); | ||
|
||
describe('onSelect handling', () => { | ||
let handleSelectSpy; | ||
describe('with href', () => { | ||
it('passes through onSelect with eventKey', () => { | ||
handleSelectSpy = jasmine.createSpy('handleSelect'); | ||
const eventKey = '1'; | ||
ReactDOM.render( | ||
<DropdownItem href="/whatever" onSelect={handleSelectSpy} eventKey={eventKey}>Item</DropdownItem>, | ||
root); | ||
|
||
$('#root li a').simulate('click'); | ||
expect(handleSelectSpy).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe('without href', () => { | ||
it('passes through onSelect with eventKey', () => { | ||
handleSelectSpy = jasmine.createSpy('handleSelect'); | ||
const eventKey = '1'; | ||
ReactDOM.render( | ||
<DropdownItem onSelect={handleSelectSpy} eventKey={eventKey}>Item</DropdownItem>, | ||
root); | ||
|
||
$('#root li').simulate('click'); | ||
expect(handleSelectSpy).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe('with disabled prop', () => { | ||
it('does not call onSelect handler', () => { | ||
handleSelectSpy = jasmine.createSpy('handleSelect'); | ||
ReactDOM.render( | ||
<DropdownItem disabled href="/whatever" onSelect={handleSelectSpy}>Item</DropdownItem>, | ||
root); | ||
expect('#root li').toHaveClass('disabled'); | ||
expect('#root li a').toHaveAttr('disabled'); | ||
$('#root li a').simulate('click'); | ||
expect(handleSelectSpy).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when href is not passed in as a prop', () => { | ||
describe('when an a tag is passed in as a child', () => { | ||
beforeEach(() => { | ||
ReactDOM.render( | ||
<DropdownItem><a href="custom">link</a></DropdownItem>, | ||
root); | ||
}); | ||
|
||
it('renders the child link', () => { | ||
expect('#root li a').toHaveAttr('href', 'custom'); | ||
}); | ||
}); | ||
|
||
it('does not render an anchor element', () => { | ||
ReactDOM.render( | ||
<DropdownItem>Item</DropdownItem>, | ||
root); | ||
expect('#root li a').not.toExist(); | ||
}); | ||
}); | ||
}); |
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