2016-05-27 15:27:46 +03:00
|
|
|
/* global Blob */
|
2016-06-30 13:21:47 +03:00
|
|
|
import $ from 'jquery';
|
2017-08-22 10:53:26 +03:00
|
|
|
import {registerAsyncHelper} 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-11-14 16:16:51 +03:00
|
|
|
// eslint-disable-next-line new-cap
|
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);
|
|
|
|
}
|
|
|
|
|
2018-01-05 18:38:23 +03:00
|
|
|
export default registerAsyncHelper('fileUpload', function (app, selector, content, options) {
|
2016-05-27 15:27:46 +03:00
|
|
|
let file = createFile(content, options);
|
|
|
|
|
|
|
|
return triggerEvent(
|
|
|
|
selector,
|
|
|
|
'change',
|
2017-05-23 11:50:04 +03:00
|
|
|
{testingFiles: [file]}
|
2016-05-27 15:27:46 +03:00
|
|
|
);
|
|
|
|
});
|