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
5 changes: 5 additions & 0 deletions AudioCuesheetEditor.End2EndTests/Tests/Desktop/BasicTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ public async Task KeyboardCommands_ShouldControlDialogs_WhenUsingEnterOrEscapeAs
var bar = new AppBar(TestPage);
var detailView = new DetailView(TestPage);
await detailView.GotoAsync();
await detailView.CuesheetArtistInput.FillAsync("Test Artist");
await detailView.CuesheetTitleInput.FillAsync("Test Title");
await detailView.AddAudiofileAsync();
await detailView.SetAudiofileInputFileAsync(0, "Kalimba.mp3");
await detailView.AddTrackAsync(0);
await TestPage.GetByRole(AriaRole.Dialog).WaitForAsync(new() { State = WaitForSelectorState.Detached });
await bar.OpenExportDialogAsync("Cuesheet");
await Expect(TestPage.GetByRole(AriaRole.Dialog)).ToBeVisibleAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public async Task DownloadProject_GeneratesProjectFile_WhenCuesheetIsValidAsync(
await detailView.EditTrackAsync("Track Artist 1", "Track Title 1");
await bar.OpenExportDialogAsync("Projectfile");
var downloadTask = TestPage.WaitForDownloadAsync();
await TestPage.GetByRole(AriaRole.Button, new() { Name = "Download project" }).ClickAsync();
await TestPage.GetByRole(AriaRole.Button, new() { Name = "Download" }).ClickAsync();
var download = await downloadTask;
using var stream = await download.CreateReadStreamAsync();
using var reader = new StreamReader(stream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ public async Task KeyboardCommands_ShouldControlDialogs_WhenUsingEnterOrEscapeAs
var bar = new AppBar(TestPage);
var detailView = new DetailView(TestPage);
await detailView.GotoAsync();
await detailView.CuesheetArtistInput.FillAsync("Test Artist");
await detailView.CuesheetTitleInput.FillAsync("Test Title");
await detailView.AddAudiofileAsync();
await detailView.SetAudiofileInputFileAsync(0, "Kalimba.mp3");
await detailView.AddTrackAsync(0);
await TestPage.GetByRole(AriaRole.Dialog).WaitForAsync(new() { State = WaitForSelectorState.Detached });
await bar.OpenExportDialogAsync("Cuesheet");
await Expect(TestPage.GetByRole(AriaRole.Dialog)).ToBeVisibleAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public async Task DownloadProject_GeneratesProjectFile_WhenCuesheetIsValidAsync(
await detailView.EditTrackAsync("Track Artist 1", "Track Title 1");
await bar.OpenExportDialogAsync("Projectfile");
var downloadTask = TestPage.WaitForDownloadAsync();
await TestPage.GetByRole(AriaRole.Button, new() { Name = "Download project" }).ClickAsync();
await TestPage.GetByRole(AriaRole.Button, new() { Name = "Download" }).ClickAsync();
var download = await downloadTask;
using var stream = await download.CreateReadStreamAsync();
using var reader = new StreamReader(stream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,14 @@
//You should have received a copy of the GNU General Public License
//along with Foobar. If not, see
//<http: //www.gnu.org/licenses />.
using System.Globalization;
using AudioCuesheetEditor.Model.AudioCuesheet;
using AudioCuesheetEditor.Model.Entity;
using AudioCuesheetEditor.Model.IO.Audio;
using AudioCuesheetEditor.Services.IO;
using AudioCuesheetEditor.Services.UI;
using Microsoft.Extensions.Localization;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using System;
using System.Globalization;
using System.Linq;

namespace AudioCuesheetEditor.Tests.Services.IO;

Expand All @@ -41,41 +38,6 @@ public CuesheetExportServiceTests()
_cuesheetExportService = new CuesheetExportService(_sessionStateContainerMock.Object, _localizerMock.Object);
}

[TestMethod]
public void CanGenerateExportfile_InvalidExtension_ReturnsValidationMessage()
{
// Arrange
var invalidFilename = "test.txt";
_ = _sessionStateContainerMock.SetupProperty(x => x.Cuesheet, new Cuesheet());
_ = _localizerMock.Setup(x => x["File extension is not '{0}'", It.IsAny<object[]>()]).Returns(new LocalizedString("File extension is not '{0}'", "File extension is not '{0}'"));

// Act
var result = _cuesheetExportService.CanGenerateExportfile(invalidFilename);

// Assert
Assert.IsFalse(result.IsSuccess);
Assert.IsTrue(result.FailureDetails?.Message.Contains("File extension is not"));
}

[TestMethod]
public void CanGenerateExportfile_InvalidAudiofileName_ReturnsValidationMessage()
{
// Arrange
_ = _sessionStateContainerMock.SetupProperty(x => x.Cuesheet, new Cuesheet()
{
Audiofiles = [new()]
});
_ = _localizerMock.Setup(x => x["{0} has no value!", It.IsAny<object[]>()]).Returns((string format, object[] args) => new LocalizedString(format, string.Format(CultureInfo.CurrentCulture, format, args)));
_ = _localizerMock.Setup(x => x[nameof(Audiofile.Name)]).Returns(new LocalizedString(nameof(Audiofile.Name), nameof(Audiofile.Name)));

// Act
var result = _cuesheetExportService.CanGenerateExportfile("test.cue");

// Assert
Assert.IsFalse(result.IsSuccess);
Assert.IsTrue(result.FailureDetails?.Message.Contains($"{nameof(Audiofile.Name)} has no value!"));
}

[TestMethod]
public void CanGenerateExportfile_InvalidCuesheeetTitle_ReturnsValidationMessage()
{
Expand All @@ -85,7 +47,7 @@ public void CanGenerateExportfile_InvalidCuesheeetTitle_ReturnsValidationMessage
_ = _localizerMock.Setup(x => x[nameof(Cuesheet.Title)]).Returns(new LocalizedString(nameof(Cuesheet.Title), nameof(Cuesheet.Title)));

// Act
var result = _cuesheetExportService.CanGenerateExportfile("test.cue");
var result = _cuesheetExportService.CanGenerateExportfile();

// Assert
Assert.IsFalse(result.IsSuccess);
Expand Down Expand Up @@ -122,7 +84,7 @@ public void CanGenerateExportfile_InvalidTrackEnd_ReturnsValidationMessage()
_ = _localizerMock.Setup(x => x[nameof(Track.Finish)]).Returns(new LocalizedString(nameof(Track.Finish), nameof(Track.Finish)));

// Act
var result = _cuesheetExportService.CanGenerateExportfile("test.cue");
var result = _cuesheetExportService.CanGenerateExportfile();

// Assert
Assert.IsFalse(result.IsSuccess);
Expand Down Expand Up @@ -159,7 +121,7 @@ public void CanGenerateExportfiles_ValidExtension_ReturnsSuccess()
_ = _sessionStateContainerMock.SetupProperty(x => x.Cuesheet, cuesheet);

// Act
var result = _cuesheetExportService.CanGenerateExportfile("test.cue");
var result = _cuesheetExportService.CanGenerateExportfile();

// Assert
Assert.IsTrue(result.IsSuccess);
Expand Down
17 changes: 13 additions & 4 deletions AudioCuesheetEditor/Components/AppBar.de.resx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Expand Down Expand Up @@ -135,15 +135,27 @@
<data name="Cuesheet" xml:space="preserve">
<value>Cuesheet</value>
</data>
<data name="Download" xml:space="preserve">
<value>Herunterladen</value>
</data>
<data name="Download cuesheet" xml:space="preserve">
<value>Cuesheet runterladen</value>
</data>
<data name="Download projectfile" xml:space="preserve">
<value>Projektdatei runterladen</value>
</data>
<data name="Export is currently not possible" xml:space="preserve">
<value>Export ist nicht verfügbar</value>
</data>
<data name="Export profiles" xml:space="preserve">
<value>Exportprofile</value>
</data>
<data name="File" xml:space="preserve">
<value>Datei</value>
</data>
<data name="Filename" xml:space="preserve">
<value>Dateiname</value>
</data>
<data name="Help" xml:space="preserve">
<value>Hilfe</value>
</data>
Expand Down Expand Up @@ -171,9 +183,6 @@
<data name="Reset cuesheet" xml:space="preserve">
<value>Cuesheet zurücksetzen</value>
</data>
<data name="Save project" xml:space="preserve">
<value>Projekt speichern</value>
</data>
<data name="Select file" xml:space="preserve">
<value>Datei auswählen</value>
</data>
Expand Down
88 changes: 82 additions & 6 deletions AudioCuesheetEditor/Components/AppBar.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!--
<!--
This file is part of AudioCuesheetEditor.

AudioCuesheetEditor is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -26,6 +26,11 @@ along with Foobar. If not, see
@inject HotKeys _hotKeys
@inject ImportManager _importManager
@inject IFileInputManager _fileInputManager
@inject IDialogManager _dialogManager
@inject ValidationService _validationService
@inject IBlazorDownloadFileService _blazorDownloadFileService
@inject CuesheetExportService _cuesheetExportService
@inject ISnackbar _snackbar

<MudAppBar Elevation="1" Color="Color.Dark" Fixed>
<MudButton StartIcon="@Icons.Material.Outlined.Home" Color="Color.Inherit" OnClick="() => _navigationManager.NavigateTo(_navigationManager.BaseUri)" aria-label="Home">
Expand Down Expand Up @@ -92,6 +97,7 @@ along with Foobar. If not, see
@code {
HotKeysContext? _hotKeysContext;
MudFileUpload<IBrowserFile>? _mudFileUpload;
DownloadOptions? _downloadOptions;

protected override void OnInitialized()
{
Expand All @@ -105,10 +111,25 @@ along with Foobar. If not, see
.Add(ModKey.Ctrl, Key.r, ResetCuesheetClicked);
}

protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
_hotKeysContext = _hotKeys.CreateContext()
.Add(ModKey.Ctrl, Key.z, TraceChangeManager.Undo)
.Add(ModKey.Ctrl, Key.y, TraceChangeManager.Redo)
.Add(ModKey.Ctrl, Key.s, DownloadProjectfileClicked)
.Add(ModKey.Ctrl, Key.e, DownloadExportClicked)
.Add(ModKey.Ctrl, Key.u, DownloadCuesheetClicked)
.Add(ModKey.Ctrl, Key.r, ResetCuesheetClicked);
_downloadOptions = await base.LocalStorageOptionsProvider.GetOptionsAsync<DownloadOptions>();
base.LocalStorageOptionsProvider.OptionSaved += LocalStorageOptionsProvider_OptionSaved;
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
_hotKeysContext?.DisposeAsync();
base.LocalStorageOptionsProvider.OptionSaved -= LocalStorageOptionsProvider_OptionSaved;
}

[Parameter]
Expand Down Expand Up @@ -146,14 +167,61 @@ along with Foobar. If not, see

async Task DownloadProjectfileClicked()
{
var options = new DialogOptions() { BackdropClick = false, CloseOnEscapeKey = true, CloseButton = true, FullWidth = true };
await _dialogService.ShowAsync<DownloadProjectfileDialog>(_localizer["Save project"], options);
var result = await _dialogManager.ShowInputDialogAsync<string?>(
_localizer["Download projectfile"],
null,
_localizer["Filename"],
_downloadOptions?.ProjectFilename,
_localizer["Download"],
null,
value => _validationService.Validate<DownloadOptions>(x => x.ProjectFilename, value));
if (result.IsSuccess)
{
await base.LocalStorageOptionsProvider.SaveOptionsValueAsync<DownloadOptions>(x => x.ProjectFilename, result.Value);
var projectFile = new Projectfile(_sessionStateContainer.Cuesheet);
var fileData = projectFile.GenerateFile();
await _blazorDownloadFileService.DownloadFile(_downloadOptions?.ProjectFilename, fileData, "text/plain");
}
}

async Task DownloadCuesheetClicked()
{
var options = new DialogOptions() { BackdropClick = false, CloseOnEscapeKey = true, CloseButton = true, FullWidth = true };
await _dialogService.ShowAsync<GenerateCuesheetDialog>(_localizer["Download cuesheet"], options);
var canGenerateExportResult = _cuesheetExportService.CanGenerateExportfile();
if (canGenerateExportResult.IsSuccess == false)
{
_snackbar.Add
(
@<div>
<h3>@_localizer["Export is currently not possible"]</h3>
<p>@((MarkupString)canGenerateExportResult.FailureDetails!.Message.Replace(Environment.NewLine, "<br/>"))</p>
</div>
, Severity.Error, (options) =>
{
options.RequireInteraction = true;
});
}
else
{
var result = await _dialogManager.ShowInputDialogAsync<string?>(
_localizer["Download cuesheet"],
null,
_localizer["Filename"],
_downloadOptions?.CuesheetFilename,
_localizer["Download"],
null,
value => _validationService.Validate<DownloadOptions>(x => x.CuesheetFilename, value));
if (result.IsSuccess)
{
await base.LocalStorageOptionsProvider.SaveOptionsValueAsync<DownloadOptions>(x => x.CuesheetFilename, result.Value);
var generateExportResult = _cuesheetExportService.GenerateExportfile(result.Value!);
if (generateExportResult.IsSuccess == false)
{
throw new InvalidOperationException($"Could not generate export file: {generateExportResult.FailureDetails?.Message}");
}
var exportfile = generateExportResult.Value!;
await _blazorDownloadFileService.DownloadFileFromText(exportfile.Name, exportfile.Content, System.Text.Encoding.Default, "text/plain");
}
}
}

async Task DownloadExportClicked()
Expand Down Expand Up @@ -256,4 +324,12 @@ along with Foobar. If not, see
return "🌐";
}
}
}

void LocalStorageOptionsProvider_OptionSaved(object? sender, IOptions option)
{
if (option is DownloadOptions downloadOptions)
{
_downloadOptions = downloadOptions;
}
}
}
17 changes: 13 additions & 4 deletions AudioCuesheetEditor/Components/AppBar.resx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Expand Down Expand Up @@ -135,15 +135,27 @@
<data name="Cuesheet" xml:space="preserve">
<value>Cuesheet</value>
</data>
<data name="Download" xml:space="preserve">
<value>Download</value>
</data>
<data name="Download cuesheet" xml:space="preserve">
<value>Download cuesheet</value>
</data>
<data name="Download projectfile" xml:space="preserve">
<value>Download projectfile</value>
</data>
<data name="Export is currently not possible" xml:space="preserve">
<value>Export is currently not possible</value>
</data>
<data name="Export profiles" xml:space="preserve">
<value>Export profiles</value>
</data>
<data name="File" xml:space="preserve">
<value>File</value>
</data>
<data name="Filename" xml:space="preserve">
<value>Filename</value>
</data>
<data name="Help" xml:space="preserve">
<value>Help</value>
</data>
Expand Down Expand Up @@ -171,9 +183,6 @@
<data name="Reset cuesheet" xml:space="preserve">
<value>Reset cuesheet</value>
</data>
<data name="Save project" xml:space="preserve">
<value>Save project</value>
</data>
<data name="Select file" xml:space="preserve">
<value>Select file</value>
</data>
Expand Down
Loading
Loading