Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Blazors <InputFile> component #317

Closed
egil opened this issue Feb 6, 2021 · 2 comments · Fixed by #700
Closed

Add support for Blazors <InputFile> component #317

egil opened this issue Feb 6, 2021 · 2 comments · Fixed by #700
Labels
enhancement New feature or request investigate This issue require further investigation before closing.

Comments

@egil
Copy link
Member

egil commented Feb 6, 2021

Render a component with the <InputFile> component inside requires additional set up, that bUnit should provide out of the box.

The current solution is to provide a mock of a IOptions<RemoteBrowserFileStreamOptions> and configure the JSInterop to handle the <InputFile> components JSInterop invocation. E.g.

var optionsMock = Substitute.For<IOptions<RemoteBrowserFileStreamOptions>>();
Services.AddSingleton<IOptions<RemoteBrowserFileStreamOptions>>(optionsMock);
JSInterop.SetupVoid("Blazor._internal.InputFile.init", x => true);

This will allow the component to render, but additional steps might be needed to test the "input" part of the component.

Related: #314

@egil egil added enhancement New feature or request investigate This issue require further investigation before closing. labels Feb 6, 2021
@egil
Copy link
Member Author

egil commented Jun 2, 2021

This discussion post has a complete example for how to test a component that uses the InputFile component: #415

@linkdotnet
Copy link
Collaborator

To all who are subscribed to that topic: There will be a new nightly build coming out addressing that exact issue. From now on you can use a convenient function to setup InputFile:

// Arrange
var context = new TestContext();
var cut = context.RenderComponent<MyComponent>();
// Arrange the file which gets uploaded
var fileToUpload = InputFileContent.CreateFromText("Hello World", "MyFile.txt");

// Find the InputFile component and upload the file
cut.FindComponent<InputFile>().UploadFiles(fileToUpload);

// Assert

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request investigate This issue require further investigation before closing.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants