Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 103 additions & 1 deletion CHDStudio.Tests/MainWindowUiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
var panel = window.FindControl<WrapPanel>("FailedActionPanel");

Assert.NotNull(panel);
Assert.Equal(6, panel.Children.OfType<Button>().Count());
Assert.Equal(7, panel.Children.OfType<Button>().Count());
Assert.Equal(
4,
panel.Children
Expand All @@ -100,6 +100,7 @@
or "SubmitSampleButton"
)
);
Assert.Contains(panel.Children, child => child is Button { Name: "RefreshConversionFilesButton" });
Assert.Contains(panel.Children, child => child is Button { Name: "SelectFailedConversionButton" });
Assert.Contains(panel.Children, child => child is Button { Name: "MoveFailedConversionButton" });
Assert.Contains(panel.Children, child => child is Button { Name: "CopyFailureDetailsButton" });
Expand Down Expand Up @@ -345,6 +346,91 @@
});
}

[Fact]
public void RefreshButtons_AreAvailableOnEveryInputTab()
{
UiTestSession.Run(() =>
{
using var window = new MainWindow(new DonationState());

foreach (var name in new[]
{
"RefreshConversionFilesButton",
"RefreshVerificationFilesButton",
"RefreshExtractionFilesButton",
"RefreshRecompressFilesButton"
})
{
var button = window.FindControl<Button>(name);
Assert.NotNull(button);
Assert.Equal("_Refresh", button.Content as string);
var tip = Assert.IsType<string>(ToolTip.GetTip(button));
Assert.Contains("F5", tip, StringComparison.Ordinal);
}
Comment on lines +356 to +369
Comment on lines +356 to +369
});
}

[Fact]
public void RefreshConversionFiles_ReloadsTheFolderAndKeepsUncheckedRowsUnchecked()
{
UiTestSession.RunAsync(async () =>
{
var root = Path.Join(
Path.GetTempPath(),
$"CHDStudio_UiRefresh_{Guid.NewGuid():N}"
);
Directory.CreateDirectory(root);
try
{
var first = Path.Join(root, "first.iso");
await File.WriteAllBytesAsync(first, []);

using var window = new MainWindow(new DonationState());
var inputBox = window.FindControl<TextBox>("ConversionInputFolderTextBox");
Assert.NotNull(inputBox);
inputBox.Text = root;

var files = GetConversionFiles(window);
var button = window.FindControl<Button>("RefreshConversionFilesButton");
Assert.NotNull(button);

button.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
await WaitForFileCountAsync(files, 1);
Assert.True(files[0].IsSelected);

files[0].IsSelected = false;
await File.WriteAllBytesAsync(Path.Join(root, "second.iso"), []);

window.RaiseEvent(
new KeyEventArgs
{
RoutedEvent = InputElement.KeyDownEvent,
Key = Key.F5
}
);
await WaitForFileCountAsync(files, 2);

var byName = files.ToDictionary(
static file => file.FileName,
StringComparer.Ordinal
);
Assert.False(byName["first.iso"].IsSelected);
Assert.True(byName["second.iso"].IsSelected);
}
finally
{
try
{
if (Directory.Exists(root)) Directory.Delete(root, recursive: true);
}
catch (IOException)
{
// Best-effort cleanup only.
}
}
});
}

[Fact]
public void DonationBanner_IsABorderContainingTheDonateButton()
{
Expand Down Expand Up @@ -628,6 +714,22 @@
return Assert.IsType<ObservableCollection<FileItem>>(field?.GetValue(window));
}

/// <summary>Waits for an asynchronous folder scan to publish the expected row count.</summary>
/// <param name="files">The file collection being scanned into.</param>
/// <param name="expected">The expected number of rows.</param>
private static async Task WaitForFileCountAsync(
ObservableCollection<FileItem> files,
int expected
)
{
for (var attempt = 0; attempt < 100 && files.Count != expected; attempt++)
{
await Task.Delay(50);
}

Assert.Equal(expected, files.Count);
}

/// <summary>Invokes the production control-state update so action buttons reflect the list.</summary>
/// <param name="window">Main window under test.</param>
/// <param name="enabled">True for the idle state.</param>
Expand Down
4 changes: 3 additions & 1 deletion CHDStudio/MainWindow.Recompress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ private async Task LoadFilesForRecompressionAsync()
if (string.IsNullOrEmpty(inputFolder) || !Directory.Exists(inputFolder))
return;

var deselectedPaths = GetDeselectedPaths(_recompressFiles);

CancellationToken token;
lock (_ctsLock)
{
Expand All @@ -48,7 +50,7 @@ await AwaitFileScanAsync(Task.Run(
FileName = Path.GetRelativePath(inputFolder, f),
FullPath = f,
FileSize = new FileInfo(f).Length,
IsSelected = true
IsSelected = !deselectedPaths.Contains(f)
})
.ToList();

Expand Down
36 changes: 32 additions & 4 deletions CHDStudio/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,14 @@
ItemSpacing="10"
LineSpacing="8"
Margin="0,0,0,10"
ToolTip.Tip="Select, move, copy or submit files in the conversion list">
ToolTip.Tip="Refresh, select, move, copy or submit files in the conversion list">
<Button
x:Name="RefreshConversionFilesButton"
AutomationProperties.Name="Refresh source file list"
Classes="primary"
Content="_Refresh"
Click="RefreshFileListButton_Click"
ToolTip.Tip="Rescan the current input folder for new or removed files (F5)" />
<Button
Classes="primary"
Content="_Select All"
Expand Down Expand Up @@ -663,7 +670,14 @@
HorizontalAlignment="Right"
Spacing="10"
Margin="0,0,0,10"
ToolTip.Tip="Select or deselect all files in the verification list">
ToolTip.Tip="Refresh or select files in the verification list">
<Button
x:Name="RefreshVerificationFilesButton"
AutomationProperties.Name="Refresh verification file list"
Classes="primary"
Content="_Refresh"
Click="RefreshFileListButton_Click"
ToolTip.Tip="Rescan the current input folder for new or removed files (F5)" />
<Button Classes="primary" Content="_Select All" Click="SelectAllVerification_Click" ToolTip.Tip="Select all files in the list" />
<Button Classes="primary" Content="_Deselect All" Click="DeselectAllVerification_Click" ToolTip.Tip="Deselect all files in the list" />
</StackPanel>
Expand Down Expand Up @@ -883,7 +897,14 @@
HorizontalAlignment="Right"
Spacing="10"
Margin="0,0,0,10"
ToolTip.Tip="Select or deselect all files in the extraction list">
ToolTip.Tip="Refresh or select files in the extraction list">
<Button
x:Name="RefreshExtractionFilesButton"
AutomationProperties.Name="Refresh extraction file list"
Classes="primary"
Content="_Refresh"
Click="RefreshFileListButton_Click"
ToolTip.Tip="Rescan the current input folder for new or removed files (F5)" />
<Button Classes="primary" Content="_Select All" Click="SelectAllExtraction_Click" ToolTip.Tip="Select all files in the list" />
<Button Classes="primary" Content="_Deselect All" Click="DeselectAllExtraction_Click" ToolTip.Tip="Deselect all files in the list" />
</StackPanel>
Expand Down Expand Up @@ -1070,7 +1091,14 @@
HorizontalAlignment="Right"
Spacing="10"
Margin="0,0,0,10"
ToolTip.Tip="Select or deselect all files in the recompression list">
ToolTip.Tip="Refresh or select files in the recompression list">
<Button
x:Name="RefreshRecompressFilesButton"
AutomationProperties.Name="Refresh recompression file list"
Classes="primary"
Content="_Refresh"
Click="RefreshFileListButton_Click"
ToolTip.Tip="Rescan the current input folder for new or removed files (F5)" />
<Button Classes="primary" Content="_Select All" Click="SelectAllRecompress_Click" ToolTip.Tip="Select all files in the list" />
<Button Classes="primary" Content="_Deselect All" Click="DeselectAllRecompress_Click" ToolTip.Tip="Deselect all files in the list" />
</StackPanel>
Expand Down
Loading
Loading