This repository has been archived by the owner on Jan 28, 2020. It is now read-only.
-
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.
Implemented Select2 element to refactor select2 widgets
- Loading branch information
George Schneeloch
committed
Aug 5, 2015
1 parent
869c145
commit d16a770
Showing
3 changed files
with
204 additions
and
44 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 |
---|---|---|
@@ -0,0 +1,102 @@ | ||
define(['QUnit', 'jquery', 'utils', 'reactaddons', | ||
'test_utils'], function( | ||
QUnit, $, Utils, React, TestUtils) { | ||
'use strict'; | ||
|
||
var Select2 = Utils.Select2; | ||
var options = [ | ||
{id: 'one', text: 'One'}, | ||
{id: 'two', text: 'Two'}, | ||
{id: 'three', text: 'Three'} | ||
]; | ||
|
||
QUnit.module('Tests for Select2', { | ||
beforeEach: function () { | ||
TestUtils.setup(); | ||
|
||
}, | ||
afterEach: function() { | ||
TestUtils.cleanup(); | ||
} | ||
}); | ||
|
||
QUnit.test('Test Select2 defaults', function(assert) { | ||
var done = assert.async(); | ||
var afterMount = function(component) { | ||
var node = React.findDOMNode(component); | ||
var $select = $(node).find("select"); | ||
|
||
assert.equal($select.length, 1); | ||
assert.equal($select.val(), null); | ||
|
||
done(); | ||
}; | ||
|
||
React.addons.TestUtils.renderIntoDocument( | ||
<Select2 ref={afterMount} /> | ||
); | ||
}); | ||
|
||
QUnit.test('Assert onChange handler', function(assert) { | ||
var done = assert.async(); | ||
|
||
var onChange = function(e) { | ||
assert.equal(e.target.value, "two"); | ||
done(); | ||
}; | ||
|
||
var afterMount = function(component) { | ||
var select = $(React.findDOMNode(component)).find("select")[0]; | ||
$(select).val('two').trigger('change'); | ||
}; | ||
|
||
React.addons.TestUtils.renderIntoDocument( | ||
<Select2 ref={afterMount} | ||
options={options} | ||
onChange={onChange} /> | ||
); | ||
}); | ||
|
||
QUnit.test('Assert onChange handler for multi select', function(assert) { | ||
var done = assert.async(); | ||
|
||
var onChange = function(e) { | ||
assert.equal($(e.target).val(), "two,three"); | ||
done(); | ||
}; | ||
|
||
var afterMount = function(component) { | ||
var select = $(React.findDOMNode(component)).find("select")[0]; | ||
$(select).val(['two', 'three']).trigger('change'); | ||
}; | ||
|
||
React.addons.TestUtils.renderIntoDocument( | ||
<Select2 ref={afterMount} | ||
options={options} | ||
multiple={true} | ||
onChange={onChange} /> | ||
); | ||
}); | ||
|
||
QUnit.test('Assert onChange handler for deselect', function(assert) { | ||
var done = assert.async(); | ||
var onChange = function(e) { | ||
assert.equal(e.target.value, "two"); | ||
done(); | ||
}; | ||
|
||
var afterMount = function(component) { | ||
var select = $(React.findDOMNode(component)).find("select")[0]; | ||
$(select).val(['two']).trigger('change'); | ||
}; | ||
|
||
React.addons.TestUtils.renderIntoDocument( | ||
<Select2 ref={afterMount} | ||
options={options} | ||
multiple={true} | ||
values={['one', 'two']} | ||
onChange={onChange} /> | ||
); | ||
}); | ||
} | ||
); |
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