2016-02-26 16:25:47 +03:00
|
|
|
/* jshint expr:true */
|
2016-11-14 16:16:51 +03:00
|
|
|
import {expect} from 'chai';
|
2016-11-24 01:50:57 +03:00
|
|
|
import {describe, it} from 'mocha';
|
|
|
|
import {setupComponentTest} from 'ember-mocha';
|
2016-02-26 16:25:47 +03:00
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
2016-06-30 13:21:47 +03:00
|
|
|
import run from 'ember-runloop';
|
2016-02-26 16:25:47 +03:00
|
|
|
import sinon from 'sinon';
|
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
describe('Integration: Component: gh-image-uploader-with-preview', function() {
|
|
|
|
setupComponentTest('gh-image-uploader-with-preview', {
|
2016-02-26 16:25:47 +03:00
|
|
|
integration: true
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
2016-02-26 16:25:47 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
it('renders image if provided', function() {
|
|
|
|
this.set('image', 'http://example.com/test.png');
|
2016-02-26 16:25:47 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
this.render(hbs`{{gh-image-uploader-with-preview image=image}}`);
|
2016-02-26 16:25:47 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
expect(this.$('.gh-image-uploader.-with-image').length).to.equal(1);
|
|
|
|
expect(this.$('img').attr('src')).to.equal('http://example.com/test.png');
|
|
|
|
});
|
2016-02-26 16:25:47 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
it('renders upload form when no image provided', function () {
|
|
|
|
this.render(hbs`{{gh-image-uploader-with-preview image=image}}`);
|
2016-02-26 16:25:47 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
expect(this.$('input[type="file"]').length).to.equal(1);
|
|
|
|
});
|
2016-02-26 16:25:47 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
it('triggers remove action when delete icon is clicked', function () {
|
|
|
|
let remove = sinon.spy();
|
|
|
|
this.set('remove', remove);
|
|
|
|
this.set('image', 'http://example.com/test.png');
|
2016-02-26 16:25:47 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
this.render(hbs`{{gh-image-uploader-with-preview image=image remove=(action remove)}}`);
|
|
|
|
run(() => {
|
|
|
|
this.$('.icon-trash').click();
|
2016-02-26 16:25:47 +03:00
|
|
|
});
|
2016-11-24 01:50:57 +03:00
|
|
|
|
|
|
|
expect(remove.calledOnce).to.be.true;
|
|
|
|
});
|
|
|
|
});
|