Skip to content

Commit

Permalink
Fix using GetElementById with UI cards. Fixes #11 (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
jerone authored Nov 10, 2024
1 parent e089494 commit cfb7b17
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
28 changes: 15 additions & 13 deletions Jvw.DevToys.SemverCalculator.Tests/Tests/Programs/GuiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public async Task Gui_OnPackageLoadButtonClick_Success_FetchesPackageAndShowsVer
.WithPackageManagerServiceSetVersions(packageVersions)
.WithPackageManagerServiceTryParseRange(versionRange, true)
.WithPackageManagerServiceGetVersions(false, versionsResult, Times.Exactly(3));
var sut = fixture.CreateSut();
_ = fixture.CreateSut();

fixture.GetElementById<IUISingleLineTextInput>(Ids.PackageNameInput).Text(packageName);
fixture
Expand All @@ -166,7 +166,7 @@ public async Task Gui_OnPackageLoadButtonClick_Success_FetchesPackageAndShowsVer

// Assert.
fixture.VerifyAll();
await Verify(sut._versionsList); // Replace with `fixture.GetElementById<IUIWrap>(Ids.VersionsList)` once https://github.com/DevToys-app/DevToys/issues/1406 is fixed.
await Verify(fixture.GetElementById<IUIWrap>(Ids.VersionsList));
}

[Fact]
Expand All @@ -191,14 +191,16 @@ public async Task Gui_OnVersionButtonClick_Success_TriggersClipboardWithVersion(
.WithPackageManagerServiceGetVersions(false, versionsResult, Times.Exactly(2))
#endif
.WithClipboardSetClipboardTextAsync("1.0.0");
var sut = fixture.CreateSut();
_ = fixture.CreateSut();

fixture.GetElementById<IUISingleLineTextInput>(Ids.PackageNameInput).Text(packageName);
var packageLoadButton = fixture.GetElementById<IUIButton>(Ids.PackageLoadButton);

// Act.
await packageLoadButton.OnClickAction!();
await ((IUIButton)sut._versionsList.Children![0]).OnClickAction!();
await (
(IUIButton)fixture.GetElementById<IUIWrap>(Ids.VersionsList).Children![0]
).OnClickAction!();

// Assert.
fixture.VerifyAll();
Expand Down Expand Up @@ -302,7 +304,7 @@ public void Gui_OnPackageManagerSettingChanged_SetNpm_ShowsNpmCheatSheet()
.WithPackageManagerServiceGetVersions(false, [], Times.Exactly(2))
#endif
;
var sut = fixture.CreateSut();
_ = fixture.CreateSut();

var packageManagerSetting = fixture.GetElementById<IUISetting>(Ids.PackageManagerSetting);
var packageManagerDropDown = Assert.IsAssignableFrom<IUISelectDropDownList>(
Expand All @@ -320,8 +322,8 @@ public void Gui_OnPackageManagerSettingChanged_SetNpm_ShowsNpmCheatSheet()

// Assert.
Assert.Equal(PackageManager.Npm, packageManagerDropDown.SelectedItem!.Value);
Assert.True(sut._cheatSheetNpmDataGrid.IsVisible); // Replace with `fixture.GetElementById<IUIWrap>(Ids.CheatSheetNpmDataGrid)` once https://github.com/DevToys-app/DevToys/issues/1406 is fixed.
Assert.False(sut._cheatSheetNuGetDataGrid.IsVisible); // Replace with `fixture.GetElementById<IUIWrap>(Ids.CheatSheetNuGetDataGrid)` once https://github.com/DevToys-app/DevToys/issues/1406 is fixed.
Assert.True(fixture.GetElementById<IUIDataGrid>(Ids.CheatSheetNpmDataGrid).IsVisible);
Assert.False(fixture.GetElementById<IUIDataGrid>(Ids.CheatSheetNuGetDataGrid).IsVisible);
fixture.VerifyAll();
}

Expand Down Expand Up @@ -350,7 +352,7 @@ public void Gui_OnPackageManagerSettingChanged_SetNuGet_ShowsNpmCheatSheet()
.WithPackageManagerServiceGetVersions(false, [], Times.Exactly(2))
#endif
;
var sut = fixture.CreateSut();
_ = fixture.CreateSut();

var packageManagerSetting = fixture.GetElementById<IUISetting>(Ids.PackageManagerSetting);
var packageManagerDropDown = Assert.IsAssignableFrom<IUISelectDropDownList>(
Expand All @@ -364,8 +366,8 @@ public void Gui_OnPackageManagerSettingChanged_SetNuGet_ShowsNpmCheatSheet()

// Assert.
Assert.Equal(PackageManager.NuGet, packageManagerDropDown.SelectedItem!.Value);
Assert.False(sut._cheatSheetNpmDataGrid.IsVisible); // Replace with `fixture.GetElementById<IUIWrap>(Ids.CheatSheetNpmDataGrid)` once https://github.com/DevToys-app/DevToys/issues/1406 is fixed.
Assert.True(sut._cheatSheetNuGetDataGrid.IsVisible); // Replace with `fixture.GetElementById<IUIWrap>(Ids.CheatSheetNuGetDataGrid)` once https://github.com/DevToys-app/DevToys/issues/1406 is fixed.
Assert.False(fixture.GetElementById<IUIDataGrid>(Ids.CheatSheetNpmDataGrid).IsVisible);
Assert.True(fixture.GetElementById<IUIDataGrid>(Ids.CheatSheetNuGetDataGrid).IsVisible);
fixture.VerifyAll();
}

Expand Down Expand Up @@ -394,7 +396,7 @@ public void Gui_OnPackageManagerSettingChanged_SetUnknownPackageManager_ShowsNoC
.WithPackageManagerServiceGetVersions(false, [], Times.Exactly(2))
#endif
;
var sut = fixture.CreateSut();
_ = fixture.CreateSut();

var packageManagerSetting = fixture.GetElementById<IUISetting>(Ids.PackageManagerSetting);
var packageManagerDropDown = Assert.IsAssignableFrom<IUISelectDropDownList>(
Expand All @@ -414,8 +416,8 @@ public void Gui_OnPackageManagerSettingChanged_SetUnknownPackageManager_ShowsNoC

// Assert.
Assert.Equal((PackageManager)256, packageManagerDropDown.SelectedItem!.Value);
Assert.False(sut._cheatSheetNpmDataGrid.IsVisible); // Replace with `fixture.GetElementById<IUIWrap>(Ids.CheatSheetNpmDataGrid)` once https://github.com/DevToys-app/DevToys/issues/1406 is fixed.
Assert.False(sut._cheatSheetNuGetDataGrid.IsVisible); // Replace with `fixture.GetElementById<IUIWrap>(Ids.CheatSheetNuGetDataGrid)` once https://github.com/DevToys-app/DevToys/issues/1406 is fixed.
Assert.False(fixture.GetElementById<IUIDataGrid>(Ids.CheatSheetNpmDataGrid).IsVisible);
Assert.False(fixture.GetElementById<IUIDataGrid>(Ids.CheatSheetNuGetDataGrid).IsVisible);
fixture.VerifyAll();
dropDownListItemMock.VerifyAll();
}
Expand Down
10 changes: 3 additions & 7 deletions Jvw.DevToys.SemverCalculator/Gui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,9 @@ internal sealed class Gui : IGuiTool
);
private readonly IUIInfoBar _versionRangeWarningBar = InfoBar(Ids.VersionRangeWarningBar);
private readonly IUIProgressRing _progressRing = ProgressRing(Ids.ProgressRing);

// ReSharper disable InconsistentNaming -- Internal until https://github.com/DevToys-app/DevToys/issues/1406 is fixed.
internal readonly IUIWrap _versionsList = Wrap(Ids.VersionsList);
internal readonly IUIDataGrid _cheatSheetNpmDataGrid = CheatSheetComponent.CheatSheetNpm();
internal readonly IUIDataGrid _cheatSheetNuGetDataGrid = CheatSheetComponent.CheatSheetNuGet();

// ReSharper restore InconsistentNaming
private readonly IUIWrap _versionsList = Wrap(Ids.VersionsList);
private readonly IUIDataGrid _cheatSheetNpmDataGrid = CheatSheetComponent.CheatSheetNpm();
private readonly IUIDataGrid _cheatSheetNuGetDataGrid = CheatSheetComponent.CheatSheetNuGet();

private bool _includePreReleases;

Expand Down

0 comments on commit cfb7b17

Please sign in to comment.