-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added basic e2e test setup
- Loading branch information
Showing
13 changed files
with
487 additions
and
97 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -1,98 +1,99 @@ | ||
|
||
<MudStack Row="false" Class="wh100"> | ||
<MudText>Project</MudText> | ||
|
||
<MudTreeView T="TreeItem" Items="Items" @bind-SelectedValue="Selected" @bind-SelectedValue:after="OnSelectedItemChanged" Class="flex-1"> | ||
<ItemTemplate> | ||
@if (context.Value == null) | ||
{ } | ||
else if (context.Value.Type == TreeItemType.Folder) | ||
{ | ||
<MudTreeViewItem @bind-Expanded="@context.Expanded" Items="@context.Children" Value="@context.Value" Text="@context.Value.Name" EndTextTypo="@Typo.caption" /> | ||
} | ||
else if (context.Value.Type == TreeItemType.Class) | ||
{ | ||
<MudTreeViewItem @bind-Expanded="@context.Expanded" Value="@context.Value" Text="@context.Value.Name" EndTextTypo="@Typo.caption" /> | ||
} | ||
</ItemTemplate> | ||
</MudTreeView> | ||
<MudText>Project</MudText> | ||
|
||
<MudTreeView T="TreeItem" Items="Items" @bind-SelectedValue="Selected" @bind-SelectedValue:after="OnSelectedItemChanged" Class="flex-1" data-test-id="projectExplorer"> | ||
<ItemTemplate> | ||
@if (context.Value == null) | ||
{ } | ||
else if (context.Value.Type == TreeItemType.Folder) | ||
{ | ||
<MudTreeViewItem @bind-Expanded="@context.Expanded" Items="@context.Children" Value="@context.Value" Text="@context.Value.Name" EndTextTypo="@Typo.caption" data-test-id="projectExplorerMethod" /> | ||
} | ||
else if (context.Value.Type == TreeItemType.Class) | ||
{ | ||
<MudTreeViewItem @bind-Expanded="@context.Expanded" Value="@context.Value" Text="@context.Value.Name" EndTextTypo="@Typo.caption" data-test-id="projectExplorerClass" /> | ||
} | ||
</ItemTemplate> | ||
</MudTreeView> | ||
</MudStack> | ||
|
||
@code { | ||
|
||
private enum TreeItemType | ||
{ | ||
Folder, | ||
Class | ||
} | ||
|
||
private record class TreeItem(string Name, TreeItemType Type, NodeDev.Core.Class.NodeClass? Class) | ||
{ | ||
public bool IsExpanded { get; set; } = true; | ||
} | ||
|
||
[Parameter] | ||
public NodeDev.Core.Project Project { get; set; } = null!; | ||
|
||
[Parameter] | ||
public NodeDev.Core.Class.NodeClass? SelectedClass { get; set; } | ||
|
||
[Parameter] | ||
public EventCallback<NodeDev.Core.Class.NodeClass?> SelectedClassChanged { get; set; } | ||
|
||
private TreeItem? Selected = null; | ||
|
||
private List<TreeItemData<TreeItem>> Items { get; } = new(); | ||
|
||
private void OnSelectedItemChanged() | ||
{ | ||
if (Selected?.Type == TreeItemType.Class) | ||
{ | ||
SelectedClass = Selected.Class; | ||
_ = SelectedClassChanged.InvokeAsync(SelectedClass); | ||
} | ||
else | ||
{ | ||
SelectedClass = null; | ||
_ = SelectedClassChanged.InvokeAsync(SelectedClass); | ||
} | ||
} | ||
|
||
protected override void OnInitialized() | ||
{ | ||
base.OnInitialized(); | ||
|
||
foreach (var nodeClass in Project.Classes) | ||
AddClass(nodeClass); | ||
} | ||
|
||
private void AddClass(NodeDev.Core.Class.NodeClass nodeClass) | ||
{ | ||
// find the folder that already exists in the tree | ||
var folders = nodeClass.Namespace.Split('.'); | ||
TreeItemData<TreeItem>? folder = null; | ||
for (int i = 0; i < folders.Length; ++i) | ||
{ | ||
var parent = folder?.Children ?? Items; | ||
folder = parent.FirstOrDefault(x => x.Value?.Name == folders[i] && x.Value?.Type == TreeItemType.Folder); | ||
if (folder == null) | ||
{ | ||
folder = new TreeItemData<TreeItem>() | ||
{ | ||
Value = new(folders[i], TreeItemType.Folder, null), | ||
Children = [] | ||
}; | ||
parent.Add(folder); | ||
} | ||
} | ||
|
||
if (folder?.Children == null) | ||
throw new Exception("Call cannot have no namespace ??"); | ||
|
||
folder.Children.Add(new() | ||
{ | ||
Value = new(nodeClass.Name, TreeItemType.Class, nodeClass) | ||
}); | ||
} | ||
private enum TreeItemType | ||
{ | ||
Folder, | ||
Class | ||
} | ||
|
||
private record class TreeItem(string Name, TreeItemType Type, NodeDev.Core.Class.NodeClass? Class) | ||
{ | ||
public bool IsExpanded { get; set; } = true; | ||
} | ||
|
||
[Parameter] | ||
public NodeDev.Core.Project Project { get; set; } = null!; | ||
|
||
[Parameter] | ||
public NodeDev.Core.Class.NodeClass? SelectedClass { get; set; } | ||
|
||
[Parameter] | ||
public EventCallback<NodeDev.Core.Class.NodeClass?> SelectedClassChanged { get; set; } | ||
|
||
private TreeItem? Selected = null; | ||
|
||
private List<TreeItemData<TreeItem>> Items { get; } = new(); | ||
|
||
private void OnSelectedItemChanged() | ||
{ | ||
if (Selected?.Type == TreeItemType.Class) | ||
{ | ||
SelectedClass = Selected.Class; | ||
_ = SelectedClassChanged.InvokeAsync(SelectedClass); | ||
} | ||
else | ||
{ | ||
SelectedClass = null; | ||
_ = SelectedClassChanged.InvokeAsync(SelectedClass); | ||
} | ||
} | ||
|
||
protected override void OnInitialized() | ||
{ | ||
base.OnInitialized(); | ||
|
||
foreach (var nodeClass in Project.Classes) | ||
AddClass(nodeClass); | ||
} | ||
|
||
private void AddClass(NodeDev.Core.Class.NodeClass nodeClass) | ||
{ | ||
// find the folder that already exists in the tree | ||
var folders = nodeClass.Namespace.Split('.'); | ||
TreeItemData<TreeItem>? folder = null; | ||
for (int i = 0; i < folders.Length; ++i) | ||
{ | ||
var parent = folder?.Children ?? Items; | ||
folder = parent.FirstOrDefault(x => x.Value?.Name == folders[i] && x.Value?.Type == TreeItemType.Folder); | ||
if (folder == null) | ||
{ | ||
folder = new TreeItemData<TreeItem>() | ||
{ | ||
Value = new(folders[i], TreeItemType.Folder, null), | ||
Children = [], | ||
Expanded = true | ||
}; | ||
parent.Add(folder); | ||
} | ||
} | ||
|
||
if (folder?.Children == null) | ||
throw new Exception("Call cannot have no namespace ??"); | ||
|
||
folder.Children.Add(new() | ||
{ | ||
Value = new(nodeClass.Name, TreeItemType.Class, nodeClass) | ||
}); | ||
} | ||
|
||
} |
This file contains 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 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,8 @@ | ||
Feature: Save a project to file system | ||
|
||
Scenario: Save empty project | ||
Given I load the default project | ||
Then The 'Main' method in the 'Program' class should exist | ||
|
||
Given I save the current project | ||
Then Snackbar should contain 'Project saved' |
112 changes: 112 additions & 0 deletions
112
src/NodeDev.EndToEndTests/Features/SaveProject.feature.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.