Skip to content

Commit ad04ad1

Browse files
committed
Add an extra test
1 parent 10d6325 commit ad04ad1

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

tests/Core/Components/InputFile/FluentInputFileDialogServiceTests.razor

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,42 @@
8686
}
8787
}
8888

89+
[Fact]
90+
public async Task FluentInputFile_DialogService_FileError()
91+
{
92+
var errorDetected = false;
93+
var fileToUpload = InputFileContent.CreateFromText("Text content", "Filename.txt");
94+
var filesDownloaded = new List<FluentInputFileEventArgs>();
95+
96+
// Arrange
97+
await DialogService.RegisterInputFileAsync("MyButton", CompletedAsync, options =>
98+
{
99+
options.MaximumFileSize = 3; // Set a small size to trigger an error
100+
options.OnFileErrorAsync = (e) => ErrorAsync(e);
101+
});
102+
103+
// Act
104+
var inputFile = DialogProvider.FindComponent<InputFile>();
105+
inputFile.UploadFiles(fileToUpload);
106+
107+
// Assert
108+
Assert.Single(filesDownloaded);
109+
Assert.Equal("The maximum size allowed is reached", filesDownloaded[0].ErrorMessage);
110+
Assert.True(errorDetected);
111+
112+
async Task CompletedAsync(IEnumerable<FluentInputFileEventArgs> args)
113+
{
114+
filesDownloaded = args.ToList();
115+
await Task.CompletedTask;
116+
}
117+
118+
async Task ErrorAsync(FluentInputFileErrorEventArgs args)
119+
{
120+
errorDetected = true;
121+
await Task.CompletedTask;
122+
}
123+
}
124+
89125
[Fact]
90126
public async Task FluentInputFile_DialogService_Unregister()
91127
{

0 commit comments

Comments
 (0)