-
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.
Adding functionality for delimiters option - finishing unit tests for…
… tags and tag components - refactored tests for tags component - installled class properties plugin so we could use static members inside a React Component class - fixing unit test task runner - changing tag container to an unordered list element
- Loading branch information
jfusco
committed
Jul 25, 2016
1 parent
8a7535d
commit 27b9a95
Showing
15 changed files
with
555 additions
and
246 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,8 @@ | |
"presets": [ | ||
"react", | ||
"es2015" | ||
], | ||
"plugins": [ | ||
"transform-class-properties" | ||
] | ||
} |
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,159 @@ | ||
'use strict'; | ||
|
||
jest.disableAutomock(); | ||
|
||
import React from 'react'; | ||
import { findDOMNode } from 'react-dom'; | ||
import { createRenderer, Simulate, renderIntoDocument } from 'react-addons-test-utils'; | ||
import Tag from '../src/js/Tag'; | ||
|
||
const TAG_NAME = 'foo'; | ||
|
||
describe('Tag', () => { | ||
let renderer, | ||
tag; | ||
|
||
beforeEach(() => { | ||
renderer = createRenderer(); | ||
|
||
renderer.render( | ||
<Tag | ||
name={TAG_NAME} /> | ||
); | ||
|
||
tag = renderer.getRenderOutput(); | ||
}); | ||
|
||
afterEach(() => { | ||
renderer = null; | ||
tag = null; | ||
}); | ||
|
||
it('should render', () => { | ||
expect(tag).not.toBeUndefined(); | ||
expect(tag.type).toBe('li'); | ||
}); | ||
|
||
it('should render with a name', () => { | ||
const props = tag.props.children; | ||
|
||
expect(props[0]).toBe(TAG_NAME); | ||
}); | ||
}); | ||
|
||
|
||
describe('Tag - "readOnly"', () => { | ||
let renderer; | ||
|
||
beforeEach(() => { | ||
renderer = createRenderer(); | ||
}); | ||
|
||
afterEach(() => { | ||
renderer = null; | ||
}); | ||
|
||
describe('when readOnly is false', () => { | ||
it('should render the removeTagIcon', () => { | ||
renderer.render( | ||
<Tag | ||
name={TAG_NAME} | ||
readOnly={false} /> | ||
); | ||
|
||
const tag = renderer.getRenderOutput(); | ||
const removeIcon = tag.props.children[1]; | ||
|
||
expect(removeIcon).not.toBeNull(); | ||
expect(removeIcon.type).toBe('a'); | ||
}); | ||
}); | ||
|
||
describe('when readOnly is true', () => { | ||
it('should not render the removeTagIcon', () => { | ||
renderer.render( | ||
<Tag | ||
name={TAG_NAME} | ||
readOnly={true} /> | ||
); | ||
|
||
const tag = renderer.getRenderOutput(); | ||
|
||
expect(tag.props.children[1]).toBeNull(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Tag - "removeTagIcon"', () => { | ||
let renderer; | ||
|
||
beforeEach(() => { | ||
renderer = createRenderer(); | ||
}); | ||
|
||
afterEach(() => { | ||
renderer = null; | ||
}); | ||
|
||
describe('when a custom element is passed in', () => { | ||
it('should render the element', () => { | ||
const customRemoveIcon = ( | ||
<i className="icon-remove"></i> | ||
); | ||
|
||
renderer.render( | ||
<Tag | ||
name={TAG_NAME} | ||
removeTagIcon={customRemoveIcon} /> | ||
); | ||
|
||
const tag = renderer.getRenderOutput(); | ||
const removeIcon = tag.props.children[1].props.children; | ||
|
||
expect(tag.props.children[1].type).toBe('a'); | ||
expect(removeIcon.type).toBe('i'); | ||
expect(removeIcon.props.className).toBe('icon-remove'); | ||
}); | ||
}); | ||
|
||
describe('when a custom string is passed in', () => { | ||
it('should render the string', () => { | ||
const renderer = createRenderer(); | ||
|
||
const customRemoveString = 'remove'; | ||
|
||
renderer.render( | ||
<Tag | ||
name={TAG_NAME} | ||
removeTagIcon={customRemoveString} /> | ||
); | ||
|
||
const tag = renderer.getRenderOutput(); | ||
const removeIcon = tag.props.children[1].props.children; | ||
|
||
expect(tag.props.children[1].type).toBe('a'); | ||
expect(removeIcon).toBe('remove'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Tag - "removeTag"', () => { | ||
it('should be called when clicking the remove icon', () => { | ||
const onRemoveClick = jest.genMockFunction(); | ||
|
||
const tag = renderIntoDocument( | ||
<div> | ||
<Tag | ||
name={TAG_NAME} | ||
removeTag={onRemoveClick} /> | ||
</div> | ||
); | ||
|
||
const statelessTag = findDOMNode(tag).children[0]; | ||
const removeIcon = statelessTag.getElementsByTagName('a')[0]; | ||
|
||
Simulate.click(removeIcon); | ||
|
||
expect(onRemoveClick).toBeCalled(); | ||
}); | ||
}); |
Oops, something went wrong.