@ -16,8 +16,12 @@
@@ -16,8 +16,12 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System.Linq ;
using Avalonia.Controls ;
using Avalonia.Headless ;
using Avalonia.Headless.NUnit ;
using Avalonia.Input ;
using Avalonia.Threading ;
using AwesomeAssertions ;
@ -74,6 +78,63 @@ public class SharpTreeViewTests
@@ -74,6 +78,63 @@ public class SharpTreeViewTests
tree . ItemCount . Should ( ) . Be ( 3 , "collapsing B hides B1 again" ) ;
}
[AvaloniaTest]
public void Shift_Down_Extends_And_Shift_Up_Shrinks_From_The_Anchor ( )
{
// The whole reason for the rewrite: native ListBox anchor selection both extends AND
// shrinks a shift-range -- the thing ProDataGrid's additive SetRowsSelection could not do.
var nodes = Enumerable . Range ( 0 , 5 ) . Select ( i = > new TestNode ( ( ( char ) ( 'A' + i ) ) . ToString ( ) ) ) . ToArray ( ) ;
var root = new TestNode ( "root" , nodes ) ;
var tree = new SharpTreeView { ShowRoot = false , Root = root } ;
var window = new Window { Content = tree , Width = 3 0 0 , Height = 4 0 0 } ;
window . Show ( ) ;
Dispatcher . UIThread . RunJobs ( ) ;
tree . SelectedItem = nodes [ 0 ] ;
Dispatcher . UIThread . RunJobs ( ) ;
( tree . ContainerFromItem ( nodes [ 0 ] ) ) ? . Focus ( ) ;
Dispatcher . UIThread . RunJobs ( ) ;
window . KeyPress ( Key . Down , RawInputModifiers . Shift , PhysicalKey . ArrowDown , null ) ;
Dispatcher . UIThread . RunJobs ( ) ;
window . KeyPress ( Key . Down , RawInputModifiers . Shift , PhysicalKey . ArrowDown , null ) ;
Dispatcher . UIThread . RunJobs ( ) ;
tree . SelectedItems ! . Cast < SharpTreeNode > ( ) . Should ( )
. BeEquivalentTo ( new [ ] { nodes [ 0 ] , nodes [ 1 ] , nodes [ 2 ] } , "Shift+Down twice extends A..C" ) ;
window . KeyPress ( Key . Up , RawInputModifiers . Shift , PhysicalKey . ArrowUp , null ) ;
Dispatcher . UIThread . RunJobs ( ) ;
tree . SelectedItems ! . Cast < SharpTreeNode > ( ) . Should ( )
. BeEquivalentTo ( new [ ] { nodes [ 0 ] , nodes [ 1 ] } , "Shift+Up shrinks the range back toward the anchor (A,B)" ) ;
}
[AvaloniaTest]
public void Type_Ahead_Jumps_To_The_Visible_Node_Matching_The_Typed_Prefix ( )
{
var apple = new TestNode ( "Apple" ) ;
var banana = new TestNode ( "Banana" ) ;
var cherry = new TestNode ( "Cherry" ) ;
var cranberry = new TestNode ( "Cranberry" ) ;
var root = new TestNode ( "root" , apple , banana , cherry , cranberry ) ;
var tree = new SharpTreeView { ShowRoot = false , Root = root } ;
var window = new Window { Content = tree , Width = 3 0 0 , Height = 4 0 0 } ;
window . Show ( ) ;
Dispatcher . UIThread . RunJobs ( ) ;
// "cra": 'c' lands on Cherry, 'r' has to search forward to Cranberry, 'a' stays.
foreach ( char ch in "cra" )
{
tree . RaiseEvent ( new TextInputEventArgs {
RoutedEvent = InputElement . TextInputEvent ,
Text = ch . ToString ( ) ,
Source = tree ,
} ) ;
Dispatcher . UIThread . RunJobs ( ) ;
}
tree . SelectedItem . Should ( ) . BeSameAs ( cranberry , "type-ahead refines forward to the Cr* match" ) ;
}
[AvaloniaTest]
public void Selecting_A_Row_Sets_The_Node_IsSelected ( )
{