Skip to content

Commit

Permalink
Up AssetImageView test
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed Sep 1, 2023
1 parent e726729 commit 7cde08d
Showing 1 changed file with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import AssetImageView from 'asset_manager/view/AssetImageView';
import Assets from 'asset_manager/model/Assets';

let obj;
import AssetImageView from '../../../../src/asset_manager/view/AssetImageView';
import Assets from '../../../../src/asset_manager/model/Assets';

describe('AssetImageView', () => {
let obj: AssetImageView;

beforeEach(() => {
var coll = new Assets();
var model = coll.add({ type: 'image', src: '/test' });
const coll = new Assets();
const model = coll.add({ type: 'image', src: '/test' });
obj = new AssetImageView({
collection: new Assets(),
config: {},
model,
});
document.body.innerHTML = '<div id="fixtures"></div>';
document.body.querySelector('#fixtures').appendChild(obj.render().el);
document.body.querySelector('#fixtures')!.appendChild(obj.render().el);
});

afterEach(() => {
obj = null;
document.body.innerHTML = '';
});

Expand All @@ -27,40 +26,38 @@ describe('AssetImageView', () => {

describe('Asset should be rendered correctly', () => {
test('Has preview box', () => {
var $asset = obj.$el;
const $asset = obj.$el;
expect($asset.find('.preview').length).toEqual(1);
});

test('Has meta box', () => {
var $asset = obj.$el;
const $asset = obj.$el;
expect($asset.find('.meta').length).toEqual(1);
});

test('Has close button', () => {
var $asset = obj.$el;
const $asset = obj.$el;
expect($asset.find('[data-toggle=asset-remove]').length).toEqual(1);
});
});

test('Could be selected', () => {
var spy = jest.spyOn(obj, 'updateTarget');
const spy = jest.spyOn(obj, 'updateTarget');
obj.$el.trigger('click');
expect(obj.$el.attr('class')).toContain('highlight');
expect(spy).toHaveBeenCalled();
});

test('Could be chosen', () => {
sinon.stub(obj, 'updateTarget');
var spy = jest.spyOn(obj, 'updateTarget');
const spy = jest.spyOn(obj, 'updateTarget');
obj.$el.trigger('dblclick');
expect(spy).toHaveBeenCalled();
//obj.updateTarget.calledOnce.should.equal(true);
});

test('Could be removed', () => {
var spy = sinon.spy();
obj.model.on('remove', spy);
obj.onRemove({ stopImmediatePropagation() {} });
expect(spy.called).toEqual(true);
const fn = jest.fn();
obj.model.on('remove', fn);
obj.onRemove({ stopImmediatePropagation() {} } as any);
expect(fn).toBeCalledTimes(1);
});
});

0 comments on commit 7cde08d

Please sign in to comment.