Skip to content

Commit

Permalink
fix: add icon error - apply code review
Browse files Browse the repository at this point in the history
* fix: add custom icon error

* apply code review
  • Loading branch information
jinwoo-kim-nhn committed Oct 4, 2018
1 parent 692a8b0 commit ff3495e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
11 changes: 6 additions & 5 deletions src/js/component/icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class Icon extends Component {
const canvas = this.getCanvas();
const path = this._pathMap[type];
const selectionStyle = consts.fObjectOptions.SELECTION_STYLE;
const isDefaultIconPath = Object.keys(consts.defaultIconPath).indexOf(type) >= 0;
const useDragAddIcon = this.useDragAddIcon && isDefaultIconPath;
const registerdIcon = Object.keys(consts.defaultIconPath).indexOf(type) >= 0;
const useDragAddIcon = this.useDragAddIcon && registerdIcon;
const icon = path ? this._createIcon(path) : null;

if (!icon) {
Expand All @@ -77,18 +77,19 @@ class Icon extends Component {
canvas.add(icon).setActiveObject(icon);

if (useDragAddIcon) {
this._addWithDrag(canvas);
this._addWithDragEvent(canvas);
}

resolve(this.graphics.createObjectProperties(icon));
});
}

/**
* Added icon drag
* Added icon drag event
* @param {fabric.Canvas} canvas - Canvas instance
* @private
*/
_addWithDrag(canvas) {
_addWithDragEvent(canvas) {
canvas.on({
'mouse:move': fEvent => {
canvas.selection = false;
Expand Down
12 changes: 6 additions & 6 deletions test/icon.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,29 +66,29 @@ describe('Icon', () => {
expect(icon._createIcon).toHaveBeenCalledWith(path);
});

it('`_addWithDrag()` should be executed when `useDragAddIcon` is true.', () => {
it('`_addWithDragEvent()` should be executed when `useDragAddIcon` is true.', () => {
const defaultIconKey = 'icon-arrow';
icon._pathMap[defaultIconKey] = true;

spyOn(icon, '_createIcon').and.returnValue(new fabric.Object({}));
spyOn(icon, '_addWithDrag');
spyOn(icon, '_addWithDragEvent');
spyOn(icon, 'useDragAddIcon').and.returnValue(true);

icon.add(defaultIconKey);

expect(icon._addWithDrag).toHaveBeenCalled();
expect(icon._addWithDragEvent).toHaveBeenCalled();
});

it('`_addWithDrag()` should be not executed when target icon is not default icon.', () => {
it('`_addWithDragEvent()` should be not executed when target icon is not default icon.', () => {
const nonDefaultIconKey = 'non-default-icon';

spyOn(icon, '_createIcon').and.returnValue(new fabric.Object({}));
spyOn(icon, '_addWithDrag');
spyOn(icon, '_addWithDragEvent');
spyOn(icon, 'useDragAddIcon').and.returnValue(true);

icon.add(nonDefaultIconKey);

expect(icon._addWithDrag).not.toHaveBeenCalled();
expect(icon._addWithDragEvent).not.toHaveBeenCalled();
});

it('setColor() should change color of next inserted icon.', () => {
Expand Down

0 comments on commit ff3495e

Please sign in to comment.