Skip to content

Commit

Permalink
Merge pull request #10 from cloudinary/ME-4642-fix-opacity-action
Browse files Browse the repository at this point in the history
Fix opacity action (missing actionModel)
  • Loading branch information
magdakwiecien authored Feb 3, 2023
2 parents 306a748 + 5da16c1 commit f7b0581
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
11 changes: 11 additions & 0 deletions __TESTS__/unit/toJson/adjust.toJson.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,15 @@ describe('Adjust toJson()', () => {
}
]});
});

it('adjust.opacity', () => {
const transformation = new Transformation()
.addAction(Adjust.opacity(45));
expect(transformation.toJson()).toStrictEqual({actions:[
{
actionType: 'opacity',
level: 45
}
]});
});
});
15 changes: 15 additions & 0 deletions src/actions/adjust/OpacityAdjustAction.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
import {Action} from "../../internal/Action.js";
import {Qualifier} from "../../internal/qualifier/Qualifier.js";
import {OpacityActionModel} from "../../internal/models/IOpacityActionModel.js";
import {IActionModel} from "../../internal/models/IActionModel.js";

/**
* @description OpacityAction class, used to define the opacity of an asset
* @memberOf Actions.Adjust
* @extends SDK.Action
*/
class OpacityAdjustAction extends Action {
private level: number;
protected _actionModel: OpacityActionModel = {actionType: 'opacity'};

constructor(level: number) {
super();
this.level = level;
this._actionModel.level = level;
this.addQualifier(new Qualifier('o', level));
}

static fromJson(actionModel: IActionModel): OpacityAdjustAction {
const { level } = (actionModel as OpacityActionModel);

// We are using this() to allow inheriting classes to use super.fromJson.apply(this, [actionModel])
// This allows the inheriting classes to determine the class to be created
return new this(level);
}
}

export {OpacityAdjustAction};
7 changes: 7 additions & 0 deletions src/internal/models/IOpacityActionModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {IActionModel} from "./IActionModel.js";

interface OpacityActionModel extends IActionModel {
level?: number;
}

export {OpacityActionModel};

0 comments on commit f7b0581

Please sign in to comment.