mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-09-25 20:00:42 +00:00
Unit test token field autocomplete window close.
This commit is contained in:
@@ -901,6 +901,8 @@ CPTexturedBackgroundWindowMask
|
||||
|
||||
[_platformWindow orderFront:self];
|
||||
[_platformWindow order:CPWindowAbove window:self relativeTo:nil];
|
||||
#else
|
||||
_isVisible = YES;
|
||||
#endif
|
||||
|
||||
if (!CPApp._keyWindow)
|
||||
@@ -946,6 +948,8 @@ CPTexturedBackgroundWindowMask
|
||||
|
||||
#if PLATFORM(DOM)
|
||||
[_platformWindow order:CPWindowOut window:self relativeTo:nil];
|
||||
#else
|
||||
_isVisible = NO;
|
||||
#endif
|
||||
|
||||
[self _updateMainAndKeyWindows];
|
||||
|
||||
@@ -187,7 +187,7 @@ var _CPAutocompleteMenuMaximumHeight = 307;
|
||||
{
|
||||
var indexOfSelectedItem = [self indexOfSelectedItem];
|
||||
|
||||
[self setContentArray:[textField _completionsForSubstring:[textField _inputElement].value indexOfToken:0 indexOfSelectedItem:indexOfSelectedItem]];
|
||||
[self setContentArray:[textField _completionsForSubstring:[textField _editorValue] indexOfToken:0 indexOfSelectedItem:indexOfSelectedItem]];
|
||||
|
||||
if (![contentArray count])
|
||||
return;
|
||||
|
||||
@@ -28,4 +28,53 @@
|
||||
[[aWindow contentView] addSubview:tokenField];
|
||||
}
|
||||
|
||||
- (void)testCloseParentWindow
|
||||
{
|
||||
var aWindow = [[CPWindow alloc] initWithContentRect:CGRectMake(0.0, 0.0, 1024.0, 768.0) styleMask:CPTitledWindowMask],
|
||||
tokenField = [[CPTokenField alloc] initWithFrame:CGRectMake(10, 10, 100, 28)];
|
||||
|
||||
[[aWindow contentView] addSubview:tokenField];
|
||||
[tokenField setEnabled:YES];
|
||||
[tokenField setEditable:YES];
|
||||
|
||||
[aWindow makeKeyAndOrderFront:nil];
|
||||
|
||||
// Start autocomplete.
|
||||
var tokenDelegate = [TokenFieldDelegate new];
|
||||
[tokenDelegate setCompletions:[@"Tokyo", @"Toronto", @"Gothenburg", @"London"]];
|
||||
[tokenField setDelegate:tokenDelegate];
|
||||
|
||||
[tokenField setStringValue:@"To"];
|
||||
// Start autocomplete programmatically.
|
||||
[aWindow makeFirstResponder:tokenField];
|
||||
[[tokenField _autocompleteMenu] _showCompletions:nil];
|
||||
|
||||
// Verify we're now autocompleting.
|
||||
[self assertTrue:[[tokenField _autocompleteMenu]._menuWindow isVisible] message:@"autocomplete visible"];
|
||||
|
||||
[aWindow close];
|
||||
[self assertFalse:[[tokenField _autocompleteMenu]._menuWindow isVisible] message:@"autocomplete not visible when token field window closes"];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation TokenFieldDelegate : CPObject
|
||||
{
|
||||
CPArray completions @accessors;
|
||||
}
|
||||
|
||||
- (CPArray)tokenField:(CPTokenField)aTokenField completionsForSubstring:(CPString)substring indexOfToken:(int)tokenIndex indexOfSelectedItem:(int)selectedIndex
|
||||
{
|
||||
var r = [];
|
||||
|
||||
if (!substring)
|
||||
return completions;
|
||||
|
||||
for (var i = 0; i < completions.length; i++)
|
||||
if (completions[i].toLowerCase().indexOf(completions.toLowerCase()) == 0)
|
||||
r.push(completions[i]);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user