mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-24 14:43:08 +03:00
✨ add fileSelected action to upload components
no issue - upload components will now trigger a passed-in `fileSelected` action upon file selection - useful when users of the components want to utilise the file object without supplying a custom validation action
This commit is contained in:
parent
67b2a159a9
commit
3bfc342314
@ -179,6 +179,7 @@ export default Component.extend({
|
||||
let validationResult = this._validate(file);
|
||||
|
||||
this.set('file', file);
|
||||
invokeAction(this, 'fileSelected', file);
|
||||
|
||||
if (validationResult === true) {
|
||||
run.schedule('actions', this, function () {
|
||||
|
@ -231,6 +231,7 @@ export default Component.extend({
|
||||
let validationResult = this._validate(file);
|
||||
|
||||
this.set('file', file);
|
||||
invokeAction(this, 'fileSelected', file);
|
||||
|
||||
if (validationResult === true) {
|
||||
run.schedule('actions', this, function () {
|
||||
|
@ -131,6 +131,22 @@ describeComponent(
|
||||
});
|
||||
});
|
||||
|
||||
it('fires fileSelected action on file selection', function (done) {
|
||||
let fileSelected = sinon.spy();
|
||||
this.set('fileSelected', fileSelected);
|
||||
|
||||
stubSuccessfulUpload(server);
|
||||
|
||||
this.render(hbs`{{gh-file-uploader url=uploadUrl fileSelected=(action fileSelected)}}`);
|
||||
fileUpload(this.$('input[type="file"]'), ['test'], {type: 'text/csv'});
|
||||
|
||||
wait().then(() => {
|
||||
expect(fileSelected.calledOnce).to.be.true;
|
||||
expect(fileSelected.args[0]).to.not.be.blank;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('fires uploadStarted action on upload start', function (done) {
|
||||
let uploadStarted = sinon.spy();
|
||||
this.set('uploadStarted', uploadStarted);
|
||||
|
@ -201,6 +201,22 @@ describeComponent(
|
||||
});
|
||||
});
|
||||
|
||||
it('fires fileSelected action on file selection', function (done) {
|
||||
let fileSelected = sinon.spy();
|
||||
this.set('fileSelected', fileSelected);
|
||||
|
||||
stubSuccessfulUpload(server);
|
||||
|
||||
this.render(hbs`{{gh-image-uploader url=image fileSelected=(action fileSelected) update=(action update)}}`);
|
||||
fileUpload(this.$('input[type="file"]'), ['test'], {type: 'image/png'});
|
||||
|
||||
wait().then(() => {
|
||||
expect(fileSelected.calledOnce).to.be.true;
|
||||
expect(fileSelected.args[0]).to.not.be.blank;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('fires uploadStarted action on upload start', function (done) {
|
||||
let uploadStarted = sinon.spy();
|
||||
this.set('uploadStarted', uploadStarted);
|
||||
|
Loading…
Reference in New Issue
Block a user