diff --git a/ghost/admin/app/components/gh-file-uploader.js b/ghost/admin/app/components/gh-file-uploader.js index 058095c7a2..f813e40652 100644 --- a/ghost/admin/app/components/gh-file-uploader.js +++ b/ghost/admin/app/components/gh-file-uploader.js @@ -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 () { diff --git a/ghost/admin/app/components/gh-image-uploader.js b/ghost/admin/app/components/gh-image-uploader.js index ac52ae089e..b1bf5abb1c 100644 --- a/ghost/admin/app/components/gh-image-uploader.js +++ b/ghost/admin/app/components/gh-image-uploader.js @@ -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 () { diff --git a/ghost/admin/tests/integration/components/gh-file-uploader-test.js b/ghost/admin/tests/integration/components/gh-file-uploader-test.js index d9e79a507d..51d78f9eb1 100644 --- a/ghost/admin/tests/integration/components/gh-file-uploader-test.js +++ b/ghost/admin/tests/integration/components/gh-file-uploader-test.js @@ -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); diff --git a/ghost/admin/tests/integration/components/gh-image-uploader-test.js b/ghost/admin/tests/integration/components/gh-image-uploader-test.js index 3c52c0c991..d5f0db8a33 100644 --- a/ghost/admin/tests/integration/components/gh-image-uploader-test.js +++ b/ghost/admin/tests/integration/components/gh-image-uploader-test.js @@ -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);