2017-10-07 00:25:17 -04:00
|
|
|
import imageDiffHelper from '~/image_diff/helpers/index';
|
2021-02-14 13:09:20 -05:00
|
|
|
import ImageBadge from '~/image_diff/image_badge';
|
2017-10-07 00:25:17 -04:00
|
|
|
import * as mockData from './mock_data';
|
|
|
|
|
|
|
|
describe('ImageBadge', () => {
|
|
|
|
const { noteId, discussionId, imageMeta } = mockData;
|
|
|
|
const options = {
|
|
|
|
noteId,
|
|
|
|
discussionId,
|
|
|
|
};
|
|
|
|
|
|
|
|
it('should save actual property', () => {
|
2020-05-07 17:09:26 -04:00
|
|
|
const imageBadge = new ImageBadge({ ...options, actual: imageMeta });
|
2017-10-07 00:25:17 -04:00
|
|
|
|
|
|
|
const { actual } = imageBadge;
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-10-07 00:25:17 -04:00
|
|
|
expect(actual.x).toEqual(imageMeta.x);
|
|
|
|
expect(actual.y).toEqual(imageMeta.y);
|
|
|
|
expect(actual.width).toEqual(imageMeta.width);
|
|
|
|
expect(actual.height).toEqual(imageMeta.height);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should save browser property', () => {
|
2020-05-07 17:09:26 -04:00
|
|
|
const imageBadge = new ImageBadge({ ...options, browser: imageMeta });
|
2017-10-07 00:25:17 -04:00
|
|
|
|
|
|
|
const { browser } = imageBadge;
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-10-07 00:25:17 -04:00
|
|
|
expect(browser.x).toEqual(imageMeta.x);
|
|
|
|
expect(browser.y).toEqual(imageMeta.y);
|
|
|
|
expect(browser.width).toEqual(imageMeta.width);
|
|
|
|
expect(browser.height).toEqual(imageMeta.height);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should save noteId', () => {
|
|
|
|
const imageBadge = new ImageBadge(options);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-10-07 00:25:17 -04:00
|
|
|
expect(imageBadge.noteId).toEqual(noteId);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should save discussionId', () => {
|
|
|
|
const imageBadge = new ImageBadge(options);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-10-07 00:25:17 -04:00
|
|
|
expect(imageBadge.discussionId).toEqual(discussionId);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('default values', () => {
|
|
|
|
let imageBadge;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
imageBadge = new ImageBadge(options);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return defaultimageMeta if actual property is not provided', () => {
|
|
|
|
const { actual } = imageBadge;
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-10-07 00:25:17 -04:00
|
|
|
expect(actual.x).toEqual(0);
|
|
|
|
expect(actual.y).toEqual(0);
|
|
|
|
expect(actual.width).toEqual(0);
|
|
|
|
expect(actual.height).toEqual(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return defaultimageMeta if browser property is not provided', () => {
|
|
|
|
const { browser } = imageBadge;
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-10-07 00:25:17 -04:00
|
|
|
expect(browser.x).toEqual(0);
|
|
|
|
expect(browser.y).toEqual(0);
|
|
|
|
expect(browser.width).toEqual(0);
|
|
|
|
expect(browser.height).toEqual(0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('imageEl property is provided and not browser property', () => {
|
|
|
|
beforeEach(() => {
|
2020-05-11 05:09:45 -04:00
|
|
|
jest.spyOn(imageDiffHelper, 'resizeCoordinatesToImageElement').mockReturnValue(true);
|
2017-10-07 00:25:17 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should generate browser property', () => {
|
2020-05-07 17:09:26 -04:00
|
|
|
const imageBadge = new ImageBadge({ ...options, imageEl: document.createElement('img') });
|
2017-10-07 00:25:17 -04:00
|
|
|
|
|
|
|
expect(imageDiffHelper.resizeCoordinatesToImageElement).toHaveBeenCalled();
|
|
|
|
expect(imageBadge.browser).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|