ant-design-blazor/tests/AntDesign.Tests/Upload/UploadTests.razor
jeffersyuan1976 73168930c1
fix(module: upload): add ShowUploadList, showDownloadIcon, showRemoveIcon, showPreviewIcon (#3788)
* Fix ShowUploadList, showDownloadIcon, showRemoveIcon, showPreviewIcon

* Fix ShowUploadList, showDownloadIcon, showRemoveIcon, showPreviewIcon

* fix: split ShowUploadList Parameter type to ShowPreviewIcon, ShowDownloadIcon, ShowRemoveIcon

* fix: Modify test for Upload

* remove useless changes

---------

Co-authored-by: James Yeung <shunjiey@hotmail.com>
2024-05-07 12:46:34 +08:00

85 lines
3.2 KiB
C#

@using System.IO
@using AngleSharp.Html.Dom
@using AngleSharp.Io.Dom
@inherits AntDesignTestBase
@code {
[Fact]
public void Renders_basic_upload()
{
JSInterop.SetupVoid(JSInteropConstants.AddFileClickEventListener, _ => true);
var cut = Context.Render(@<Upload>some content</Upload>);
cut.MarkupMatches(
@<span class="">
<div class=" ant-upload ant-upload-select-text ant-upload-select" style="">
<span tabindex="0" class="ant-upload" style="display: grid;" data-fileid:ignore role="button">
<input type="file" style="display:none;" id:ignore>
some content
</span>
</div>
<div class="ant-upload-list ant-upload-list-text">
</div>
</span>);
}
[Fact]
public void Renders_basic_drag()
{
JSInterop.SetupVoid(JSInteropConstants.AddFileClickEventListener, _ => true);
var cut = Context.Render(@<Upload Drag>some content</Upload>);
cut.MarkupMatches(
@<span class="">
<div class=" ant-upload ant-upload-select-text ant-upload-drag ant-upload-select" style="">
<span tabindex="0" class="ant-upload" style="display: grid;;" data-fileid:ignore role="button" >
<input type="file" style="position: absolute;width: 100%;height: 100%;opacity: 0;top: 0;left: 0;z-index:2;" id:ignore >
<div class="ant-upload-drag-container">
some content
</div>
</span>
</div>
<div class="ant-upload-list ant-upload-list-text">
</div>
</span>);
}
[Fact]
public void Renders_custom_method()
{
JSInterop.SetupVoid(JSInteropConstants.AddFileClickEventListener, _ => true);
var cut = Context.Render(@<Upload Method="put">some content</Upload>);
cut.MarkupMatches(
@<span class="">
<div class=" ant-upload ant-upload-select-text ant-upload-select" style="">
<span tabindex="0" class="ant-upload" style="display: grid;" data-fileid:ignore role="button">
<input type="file" style="display:none;" id:ignore>
some content
</span>
</div>
<div class="ant-upload-list ant-upload-list-text">
</div>
</span>);
}
[Fact]
public async Task Handles_filenames_without_extension()
{
JSInterop.SetupVoid(JSInteropConstants.AddFileClickEventListener, _ => true);
JSInterop.SetupVoid(JSInteropConstants.UploadFile, _ => true).SetCanceled();
JSInterop.SetupVoid(JSInteropConstants.ClearFile, _ => true);
JSInterop.Setup<List<UploadFileItem>>(JSInteropConstants.GetFileInfo, _ => true).SetResult(new List<UploadFileItem> { new UploadFileItem { FileName = "test" } });
var cut = Context.Render(@<Upload>some content</Upload>);
var inputElement = cut.Find("input");
Func<Task> act = () => inputElement.ChangeAsync(new ChangeEventArgs() { Value = "ignored" });
await act.Should().NotThrowAsync();
}
}