Skip to content
Browse files

Added tests for the "hint" option

  • Loading branch information...
1 parent 18c5aba commit 2006cb274ad8023308358f3f7a045b05afaeaeca @rfletcher committed Mar 18, 2009
Showing with 48 additions and 2 deletions.
  1. +48 −2 test/unit/tagbox_test.js
View
50 test/unit/tagbox_test.js
@@ -150,13 +150,61 @@ new Test.Unit.Runner({
tb.addTag( allowed_values[1] );
this.assert( tb.values().length == original_tag_count + 1 );
+ },
+
+ /* option: hint */
+
+ testHintInitiallyHidden: function() {
+ var tb = createTagbox( { hint: 'type something' } );
+ this.assertUndefined( tb.element.down( '.tagbox-hint' ) );
+ },
+
+ testHintVisibleOnInputFocus: function() {
+ var delay = 0;
+ var tb = createTagbox( { hint: 'type something', hint_delay: delay } );
+
+ tb.focus( tb.element.select( '.tagbox-tags li' ).last() );
+
+ this.wait( delay + STD_DELAY, function() {
+ this.assertVisible( tb.element.down( '.tagbox-hint' ) );
+ } );
+ },
+
+ testHintWaitsForDelay: function() {
+ var delay = STD_DELAY;
+ var tb = createTagbox( { hint: 'type something', hint_delay: delay } );
+
+ tb.focus( tb.element.select( '.tagbox-tags li' ).last() );
+
+ this.wait( STD_DELAY / 2, function() {
+ this.assertUndefined( tb.element.down( '.tagbox-hint' ) );
+ } );
+
+ this.wait( delay + STD_DELAY, function() {
+ this.assertVisible( tb.element.down( '.tagbox-hint' ) );
+ } );
+ },
+
+ testHintAppearsOnInputFocus: function() {
+ var delay = 0;
+ var tb = createTagbox( { hint: 'type something', hint_delay: delay } );
+
+ this.assertUndefined( tb.element.down( '.tagbox-hint' ) );
+
+ tb.focus( tb.element.select( '.tagbox-tags li' ).last() );
+
+ this.wait( delay + STD_DELAY, function() {
+ this.assertVisible( tb.element.down( '.tagbox-hint' ) );
+ }.bind( this ) );
}
});
/**
* test helper methods
**/
var helpers = {
+ STD_DELAY: 200,
+
addTags: function( tagbox, values ) {
var original_tag_count = tagbox.values().length;
values.each( tagbox.addTag.bind( tagbox ) );
@@ -183,8 +231,6 @@ var helpers = {
tb.addTag( 'tag-' + getUniqueString() );
} );
- tb.focus( tb.element.select( '.tagbox-tags li' ).last() );
-
return tb;
},

0 comments on commit 2006cb2

Please sign in to comment.
Something went wrong with that request. Please try again.