Created
May 23, 2016 10:08
-
-
Save chrism/9d8034b9d76e4a1565d3f791a6b7ba27 to your computer and use it in GitHub Desktop.
Working Ember 2.4.3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
const { | |
run: { | |
bind | |
} | |
} = Ember; | |
export default Ember.Component.extend({ | |
label: 'choose a file', | |
didInsertElement() { | |
this.$().on('change', bind(this,'filesSelected')); | |
}, | |
willDestroyElement() { | |
this.$().off('change', bind(this,'filesSelected')); | |
}, | |
filesSelected(event) { | |
const files = event.target.files; | |
if (files.length === 0) { | |
Ember.Logger.log('you must add a file'); | |
} else if (files.length > 0) { | |
this.sendAction('action', files); | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* global Blob */ | |
import Ember from 'ember'; | |
function createFile(content = ['test'], options = {}) { | |
const { | |
name, | |
type | |
} = options; | |
const file = new Blob(content, {type : type ? type : 'text/plain'}); | |
file.name = name ? name : 'test.txt'; | |
return file; | |
} | |
export default Ember.Test.registerAsyncHelper('uploadFile', function(app, selector, content, options) { | |
const file = createFile(content, options); | |
return triggerEvent( | |
selector, | |
'change', | |
{ target: { files: [file] } } | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment