2016-05-27 15:27:46 +03:00
|
|
|
/* global Blob */
|
2016-06-30 13:21:47 +03:00
|
|
|
import $ from 'jquery';
|
|
|
|
import Test from 'ember-test';
|
2016-06-11 19:52:36 +03:00
|
|
|
|
2016-05-27 15:27:46 +03:00
|
|
|
export function createFile(content = ['test'], options = {}) {
|
|
|
|
let {
|
|
|
|
name,
|
|
|
|
type
|
|
|
|
} = options;
|
|
|
|
|
|
|
|
let file = new Blob(content, {type: type ? type : 'text/plain'});
|
|
|
|
file.name = name ? name : 'test.txt';
|
|
|
|
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function fileUpload($element, content, options) {
|
|
|
|
let file = createFile(content, options);
|
2016-06-11 19:52:36 +03:00
|
|
|
let event = $.Event('change', {
|
2016-05-27 15:27:46 +03:00
|
|
|
testingFiles: [file]
|
|
|
|
});
|
|
|
|
|
|
|
|
$element.trigger(event);
|
|
|
|
}
|
|
|
|
|
2016-06-11 19:52:36 +03:00
|
|
|
export default Test.registerAsyncHelper('fileUpload', function(app, selector, content, options) {
|
2016-05-27 15:27:46 +03:00
|
|
|
let file = createFile(content, options);
|
|
|
|
|
|
|
|
return triggerEvent(
|
|
|
|
selector,
|
|
|
|
'change',
|
|
|
|
{foor: 'bar', testingFiles: [file]}
|
|
|
|
);
|
|
|
|
});
|