I'd like to create a basic acceptance test in ember that uploads a file.
I can mock the server with Pretender, but I need to know how to fill the input type="file"
field with a file from my filesystem. So the questions are basically:
fillIn
helper?Rails.root
for this purpose.Ember CLI comes with acceptance test support out of the box. For creating your first test, you just need to run ember generate acceptance-test <name> . In our case, ember generate acceptance-test user-can-login-via-form . Ember CLI will create a new test file under tests/acceptance/ .
ember-cli-file-picker - An addon for ember-cli that provides a component to easily add a filepicker to your ember-cli app. emberx-file-input - A tiny Ember component which does one thing and only: select files beautifully. ember-profile-upload - A simple photo upload component.
I solved it differently: I don't upload a file from the file system, but create a Blob manually and use triggerHandler on the input element:
let inputElement = $('input[type=file]');
let blob = new Blob(['foo', 'bar'], {type: 'text/plain'});
blob.name = 'foobar.txt';
inputElement.triggerHandler({
type: 'change',
target: {
files: {
0: blob,
length: 1,
item() { return blob; }
}
}
});
This triggers the upload.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With