-
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.
Editable tags: Update state when props change, fixes #41
see 6775f3b for further details
- Loading branch information
Tobias Schmidt
committed
Apr 30, 2018
1 parent
231a0aa
commit 2f3a68c
Showing
2 changed files
with
54 additions
and
6 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,32 @@ | ||
import { h } from 'preact'; | ||
import TagsEditable from '../index.js'; | ||
import { shallow } from 'preact-render-spy'; | ||
|
||
const testTags1 = ['a', 'b', 'c']; | ||
const testTags2 = ['a', 'd', 'c', 'f']; | ||
|
||
const testSuggestions1 = ['suggestion', 12341, 'other suggestion']; | ||
const testSuggestions2 = ['more ', 'more', 'test']; | ||
|
||
describe('Test that data is copied from props to state', () => { | ||
const context = shallow( | ||
<TagsEditable | ||
classNames={{ selectedTag: 'a' }} | ||
suggestions={testSuggestions1} | ||
tags={testTags1} | ||
/> | ||
); | ||
test('State should match the props', () => { | ||
expect(context.state('tags').map(tag => tag.name)).toEqual(testTags1); | ||
}); | ||
test('State should update when props change', () => { | ||
context.render( | ||
<TagsEditable | ||
classNames={{ selectedTag: 'a' }} | ||
suggestions={testSuggestions2} | ||
tags={testTags2} | ||
/> | ||
); | ||
expect(context.state('tags').map(tag => tag.name)).toEqual(testTags2); | ||
}); | ||
}); |