Skip to content

Commit 627eb7b

Browse files
committed
Add E2E tests for the FileDownload
1 parent 9275b61 commit 627eb7b

File tree

6 files changed

+345
-180
lines changed

6 files changed

+345
-180
lines changed

src/Components/Web.JS/src/Rendering/BinaryMedia.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,6 @@ export class BinaryMedia {
310310
element.addEventListener('error', onError, { once: true });
311311
}
312312

313-
// Added: trigger a download using BinaryMedia pipeline (formerly BinaryFileDownload)
314313
public static async downloadAsync(
315314
element: HTMLElement,
316315
streamRef: { stream: () => Promise<ReadableStream<Uint8Array>> } | null,

src/Components/Web/src/Media/FileDownload.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,16 @@ private async Task OnClickAsync()
8585
CancelPreviousLoad();
8686
var token = ResetCancellationToken();
8787
_hasError = false;
88+
_currentSource = Source;
89+
Render();
8890

8991
var source = Source;
9092

9193
using var streamRef = new DotNetStreamReference(source.Stream, leaveOpen: true);
9294

9395
try
9496
{
95-
var result = await JSRuntime.InvokeAsync<Boolean>(
97+
var result = await JSRuntime.InvokeAsync<bool>(
9698
"Blazor._internal.BinaryMedia.downloadAsync",
9799
token,
98100
Element,
@@ -101,8 +103,9 @@ private async Task OnClickAsync()
101103
source.Length,
102104
FileName);
103105

104-
if (result && !token.IsCancellationRequested)
106+
if (!token.IsCancellationRequested)
105107
{
108+
_currentSource = null;
106109
if (!result)
107110
{
108111
_hasError = true;
@@ -112,9 +115,12 @@ private async Task OnClickAsync()
112115
}
113116
catch (OperationCanceledException)
114117
{
118+
_currentSource = null;
119+
Render();
115120
}
116121
catch
117122
{
123+
_currentSource = null;
118124
_hasError = true;
119125
Render();
120126
}

0 commit comments

Comments
 (0)