-
Notifications
You must be signed in to change notification settings - Fork 725
Fixes #4009 - fix tree ordering #4015
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7e4253c
Add class for detecting information about console in extensible way
tznind 564e6f1
WIP - Create test for reordering
tznind 75a7159
Change Dictionary to List and preserve TreeBuilder order
tznind c3aa947
Add test to ensure branch expansion/status remains consistent despite…
tznind 387372b
Cleanup code
tznind 222ff34
Fix regression when removed child was the selected one
tznind fefcb9a
Merge branch 'v2_develop' into 4009-fix-tree-ordering
tznind 1bc647d
Revert "Add class for detecting information about console in extensib…
tznind 05e7736
Merge branch '4009-fix-tree-ordering' of https://github.com/tznind/gu…
tznind bc42fc9
Code cleanup and enable nullable on Branch
tznind a3ab90a
Remove color scheme and driver from Branch draw
tznind b801ff6
Add xunit context extensions
tznind File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,15 @@ | ||
| using System.Text; | ||
| using Xunit.Abstractions; | ||
|
|
||
| namespace IntegrationTests.FluentTests; | ||
|
|
||
| public class TestOutputWriter : TextWriter | ||
| { | ||
| private readonly ITestOutputHelper _output; | ||
|
|
||
| public TestOutputWriter (ITestOutputHelper output) { _output = output; } | ||
|
|
||
| public override void WriteLine (string? value) { _output.WriteLine (value ?? string.Empty); } | ||
|
|
||
| public override Encoding Encoding => Encoding.UTF8; | ||
| } |
162 changes: 162 additions & 0 deletions
162
Tests/IntegrationTests/FluentTests/TreeViewFluentTests.cs
This file contains hidden or 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,162 @@ | ||
| using Terminal.Gui; | ||
| using TerminalGuiFluentTesting; | ||
| using Xunit.Abstractions; | ||
|
|
||
| namespace IntegrationTests.FluentTests; | ||
|
|
||
| public class TreeViewFluentTests | ||
| { | ||
| private readonly TextWriter _out; | ||
|
|
||
| public TreeViewFluentTests (ITestOutputHelper outputHelper) { _out = new TestOutputWriter (outputHelper); } | ||
|
|
||
| [Theory] | ||
| [ClassData (typeof (V2TestDrivers))] | ||
| public void TreeView_AllowReOrdering (V2TestDriver d) | ||
| { | ||
| var tv = new TreeView | ||
| { | ||
| Width = Dim.Fill (), | ||
| Height = Dim.Fill () | ||
| }; | ||
|
|
||
| TreeNode car; | ||
| TreeNode lorry; | ||
| TreeNode bike; | ||
|
|
||
| var root = new TreeNode ("Root") | ||
| { | ||
| Children = | ||
| [ | ||
| car = new ("Car"), | ||
| lorry = new ("Lorry"), | ||
| bike = new ("Bike") | ||
| ] | ||
| }; | ||
|
|
||
| tv.AddObject (root); | ||
|
|
||
| using GuiTestContext context = | ||
| With.A<Window> (40, 10, d) | ||
| .Add (tv) | ||
| .Focus (tv) | ||
| .WaitIteration () | ||
| .ScreenShot ("Before expanding", _out) | ||
| .Then (() => Assert.Equal (root, tv.GetObjectOnRow (0))) | ||
| .Then (() => Assert.Null (tv.GetObjectOnRow (1))) | ||
| .Right () | ||
| .ScreenShot ("After expanding", _out) | ||
| .Then (() => Assert.Equal (root, tv.GetObjectOnRow (0))) | ||
| .Then (() => Assert.Equal (car, tv.GetObjectOnRow (1))) | ||
| .Then (() => Assert.Equal (lorry, tv.GetObjectOnRow (2))) | ||
| .Then (() => Assert.Equal (bike, tv.GetObjectOnRow (3))) | ||
| .Then ( | ||
| () => | ||
| { | ||
| // Re order | ||
| root.Children = [bike, car, lorry]; | ||
| tv.RefreshObject (root); | ||
| }) | ||
| .WaitIteration () | ||
| .ScreenShot ("After re-order", _out) | ||
| .Then (() => Assert.Equal (root, tv.GetObjectOnRow (0))) | ||
| .Then (() => Assert.Equal (bike, tv.GetObjectOnRow (1))) | ||
| .Then (() => Assert.Equal (car, tv.GetObjectOnRow (2))) | ||
| .Then (() => Assert.Equal (lorry, tv.GetObjectOnRow (3))) | ||
| .WriteOutLogs (_out); | ||
|
|
||
| context.Stop (); | ||
| } | ||
|
|
||
| [Theory] | ||
| [ClassData (typeof (V2TestDrivers))] | ||
| public void TreeViewReOrder_PreservesExpansion (V2TestDriver d) | ||
| { | ||
| var tv = new TreeView | ||
| { | ||
| Width = Dim.Fill (), | ||
| Height = Dim.Fill () | ||
| }; | ||
|
|
||
| TreeNode car; | ||
| TreeNode lorry; | ||
| TreeNode bike; | ||
|
|
||
| TreeNode mrA; | ||
| TreeNode mrB; | ||
|
|
||
| TreeNode mrC; | ||
|
|
||
| TreeNode mrD; | ||
| TreeNode mrE; | ||
|
|
||
| var root = new TreeNode ("Root") | ||
| { | ||
| Children = | ||
| [ | ||
| car = new ("Car") | ||
| { | ||
| Children = | ||
| [ | ||
| mrA = new ("Mr A"), | ||
| mrB = new ("Mr B") | ||
| ] | ||
| }, | ||
| lorry = new ("Lorry") | ||
| { | ||
| Children = | ||
| [ | ||
| mrC = new ("Mr C") | ||
| ] | ||
| }, | ||
| bike = new ("Bike") | ||
| { | ||
| Children = | ||
| [ | ||
| mrD = new ("Mr D"), | ||
| mrE = new ("Mr E") | ||
| ] | ||
| } | ||
| ] | ||
| }; | ||
|
|
||
| tv.AddObject (root); | ||
| tv.ExpandAll (); | ||
|
|
||
| using GuiTestContext context = | ||
| With.A<Window> (40, 13, d) | ||
| .Add (tv) | ||
| .WaitIteration () | ||
| .ScreenShot ("Initial State", _out) | ||
| .Then (() => Assert.Equal (root, tv.GetObjectOnRow (0))) | ||
| .Then (() => Assert.Equal (car, tv.GetObjectOnRow (1))) | ||
| .Then (() => Assert.Equal (mrA, tv.GetObjectOnRow (2))) | ||
| .Then (() => Assert.Equal (mrB, tv.GetObjectOnRow (3))) | ||
| .Then (() => Assert.Equal (lorry, tv.GetObjectOnRow (4))) | ||
| .Then (() => Assert.Equal (mrC, tv.GetObjectOnRow (5))) | ||
| .Then (() => Assert.Equal (bike, tv.GetObjectOnRow (6))) | ||
| .Then (() => Assert.Equal (mrD, tv.GetObjectOnRow (7))) | ||
| .Then (() => Assert.Equal (mrE, tv.GetObjectOnRow (8))) | ||
| .Then ( | ||
| () => | ||
| { | ||
| // Re order | ||
| root.Children = [bike, car, lorry]; | ||
| tv.RefreshObject (root); | ||
| }) | ||
| .WaitIteration () | ||
| .ScreenShot ("After re-order", _out) | ||
| .Then (() => Assert.Equal (root, tv.GetObjectOnRow (0))) | ||
| .Then (() => Assert.Equal (bike, tv.GetObjectOnRow (1))) | ||
| .Then (() => Assert.Equal (mrD, tv.GetObjectOnRow (2))) | ||
| .Then (() => Assert.Equal (mrE, tv.GetObjectOnRow (3))) | ||
| .Then (() => Assert.Equal (car, tv.GetObjectOnRow (4))) | ||
| .Then (() => Assert.Equal (mrA, tv.GetObjectOnRow (5))) | ||
| .Then (() => Assert.Equal (mrB, tv.GetObjectOnRow (6))) | ||
| .Then (() => Assert.Equal (lorry, tv.GetObjectOnRow (7))) | ||
| .Then (() => Assert.Equal (mrC, tv.GetObjectOnRow (8))) | ||
| .WriteOutLogs (_out); | ||
|
|
||
| context.Stop (); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.