-
Notifications
You must be signed in to change notification settings - Fork 779
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 all 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
564e6f1
WIP - Create test for reordering
75a7159
Change Dictionary to List and preserve TreeBuilder order
c3aa947
Add test to ensure branch expansion/status remains consistent despite…
387372b
Cleanup code
222ff34
Fix regression when removed child was the selected one
fefcb9a
Merge branch 'v2_develop' into 4009-fix-tree-ordering
tznind 1bc647d
Revert "Add class for detecting information about console in extensib…
05e7736
Merge branch '4009-fix-tree-ordering' of https://github.com/tznind/gu…
bc42fc9
Code cleanup and enable nullable on Branch
a3ab90a
Remove color scheme and driver from Branch draw
b801ff6
Add xunit context extensions
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
14 changes: 14 additions & 0 deletions
14
TerminalGuiFluentTesting.Xunit/TerminalGuiFluentTesting.Xunit.csproj
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,14 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\TerminalGuiFluentTesting\TerminalGuiFluentTesting.csproj" /> | ||
| <PackageReference Include="xunit" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
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,25 @@ | ||
| using Xunit; | ||
|
|
||
| namespace TerminalGuiFluentTesting; | ||
|
|
||
| public static class XunitContextExtensions | ||
| { | ||
| public static GuiTestContext AssertTrue (this GuiTestContext context, bool? condition) | ||
| { | ||
| context.Then ( | ||
| () => | ||
| { | ||
| Assert.True (condition); | ||
| }); | ||
| return context; | ||
| } | ||
| public static GuiTestContext AssertEqual (this GuiTestContext context, object? expected, object? actual) | ||
| { | ||
| context.Then ( | ||
| () => | ||
| { | ||
| Assert.Equal (expected,actual); | ||
| }); | ||
| return context; | ||
| } | ||
| } |
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) | ||
| .AssertEqual (root, tv.GetObjectOnRow (0)) | ||
| .Then (() => Assert.Null (tv.GetObjectOnRow (1))) | ||
| .Right () | ||
| .ScreenShot ("After expanding", _out) | ||
| .AssertEqual (root, tv.GetObjectOnRow (0)) | ||
| .AssertEqual (car, tv.GetObjectOnRow (1)) | ||
| .AssertEqual (lorry, tv.GetObjectOnRow (2)) | ||
| .AssertEqual (bike, tv.GetObjectOnRow (3)) | ||
| .Then ( | ||
| () => | ||
| { | ||
| // Re order | ||
| root.Children = [bike, car, lorry]; | ||
| tv.RefreshObject (root); | ||
| }) | ||
| .WaitIteration () | ||
| .ScreenShot ("After re-order", _out) | ||
| .AssertEqual (root, tv.GetObjectOnRow (0)) | ||
| .AssertEqual (bike, tv.GetObjectOnRow (1)) | ||
| .AssertEqual (car, tv.GetObjectOnRow (2)) | ||
| .AssertEqual (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) | ||
| .AssertEqual (root, tv.GetObjectOnRow (0)) | ||
| .AssertEqual (car, tv.GetObjectOnRow (1)) | ||
| .AssertEqual (mrA, tv.GetObjectOnRow (2)) | ||
| .AssertEqual (mrB, tv.GetObjectOnRow (3)) | ||
| .AssertEqual (lorry, tv.GetObjectOnRow (4)) | ||
| .AssertEqual (mrC, tv.GetObjectOnRow (5)) | ||
| .AssertEqual (bike, tv.GetObjectOnRow (6)) | ||
| .AssertEqual (mrD, tv.GetObjectOnRow (7)) | ||
| .AssertEqual (mrE, tv.GetObjectOnRow (8)) | ||
| .Then ( | ||
| () => | ||
| { | ||
| // Re order | ||
| root.Children = [bike, car, lorry]; | ||
| tv.RefreshObject (root); | ||
| }) | ||
| .WaitIteration () | ||
| .ScreenShot ("After re-order", _out) | ||
| .AssertEqual (root, tv.GetObjectOnRow (0)) | ||
| .AssertEqual (bike, tv.GetObjectOnRow (1)) | ||
| .AssertEqual (mrD, tv.GetObjectOnRow (2)) | ||
| .AssertEqual (mrE, tv.GetObjectOnRow (3)) | ||
| .AssertEqual (car, tv.GetObjectOnRow (4)) | ||
| .AssertEqual (mrA, tv.GetObjectOnRow (5)) | ||
| .AssertEqual (mrB, tv.GetObjectOnRow (6)) | ||
| .AssertEqual (lorry, tv.GetObjectOnRow (7)) | ||
| .AssertEqual (mrC, tv.GetObjectOnRow (8)) | ||
| .WriteOutLogs (_out); | ||
|
|
||
| context.Stop (); | ||
| } | ||
| } |
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
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.