Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds crop selection presets (square, 3:2, 4:3, 5:4, 7:5, 16:9) #54

Merged
merged 3 commits into from
Oct 31, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
added test cases for preset cropzone functions
  • Loading branch information
joelabair committed Aug 23, 2018
commit f48c24c329ccc658734eb7b5e91a69f8318a86b3
4 changes: 2 additions & 2 deletions src/js/component/cropper.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,8 @@ class Cropper extends Component {
}

const canvasImage = this.getCanvasImage();
const oWidth = canvasImage.getOriginalSize().width;
const oHeight = canvasImage.getOriginalSize().height;
const oWidth = canvasImage ? canvasImage.getOriginalSize().width : 800;
const oHeight = canvasImage ? canvasImage.getOriginalSize().height : 600;

let width = (10000 * factor);
let height = 10000;
Expand Down
71 changes: 71 additions & 0 deletions test/cropper.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,77 @@ describe('Cropper', () => {
});
});

describe('"presets - setCropzoneRect()"', () => {
it('should return cropzone rect as a square', () => {
cropper.start();
spyOn(cropper._cropzone, 'isValid').and.returnValue(true);
cropper.setCropzoneRect(1 / 1);
expect(cropper.getCropzoneRect()).toBeTruthy();
expect(cropper.getCropzoneRect().width).toEqual(cropper.getCropzoneRect().height);
cropper.end();
});

it('should return cropzone rect as a 3:2 aspect box', () => {
cropper.start();
spyOn(cropper._cropzone, 'isValid').and.returnValue(true);
cropper.setCropzoneRect(3 / 2);
expect(cropper.getCropzoneRect()).toBeTruthy();
expect(cropper.getCropzoneRect().width).toEqual(cropper.getCropzoneRect().height * (3 / 2));
cropper.end();
});

it('should return cropzone rect as a 4:3 aspect box', () => {
cropper.start();
spyOn(cropper._cropzone, 'isValid').and.returnValue(true);
cropper.setCropzoneRect(4 / 3);
expect(cropper.getCropzoneRect()).toBeTruthy();
expect(cropper.getCropzoneRect().width).toEqual(cropper.getCropzoneRect().height * (4 / 3));
cropper.end();
});

it('should return cropzone rect as a 5:4 aspect box', () => {
cropper.start();
spyOn(cropper._cropzone, 'isValid').and.returnValue(true);
cropper.setCropzoneRect(5 / 4);
expect(cropper.getCropzoneRect()).toBeTruthy();
expect(cropper.getCropzoneRect().width).toEqual(cropper.getCropzoneRect().height * (5 / 4));
cropper.end();
});

it('should return cropzone rect as a 7:5 aspect box', () => {
cropper.start();
spyOn(cropper._cropzone, 'isValid').and.returnValue(true);
cropper.setCropzoneRect(7 / 5);
expect(cropper.getCropzoneRect()).toBeTruthy();
expect(cropper.getCropzoneRect().width).toEqual(cropper.getCropzoneRect().height * (7 / 5));
cropper.end();
});

it('should return cropzone rect as a 16:9 aspect box', () => {
cropper.start();
spyOn(cropper._cropzone, 'isValid').and.returnValue(true);
cropper.setCropzoneRect(16 / 9);
expect(cropper.getCropzoneRect()).toBeTruthy();
expect(cropper.getCropzoneRect().width).toEqual(cropper.getCropzoneRect().height * (16 / 9));
cropper.end();
});

it('should remove cropzone of cropper when falsy is passed', () => {
cropper.start();

cropper.setCropzoneRect();
expect(cropper.getCropzoneRect()).toBeFalsy();

cropper.setCropzoneRect(0);
expect(cropper.getCropzoneRect()).toBeFalsy();

cropper.setCropzoneRect(null);
expect(cropper.getCropzoneRect()).toBeFalsy();

cropper.end();
});
});

describe('"end()"', () => {
it('should set cropzone of cropper to null', () => {
cropper.start();
Expand Down