2020-08-24 15:10:11 +00:00
|
|
|
import { GlIcon } from '@gitlab/ui';
|
2021-02-14 18:09:20 +00:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2020-03-20 15:09:17 +00:00
|
|
|
import ImageDiffOverlay from '~/diffs/components/image_diff_overlay.vue';
|
|
|
|
import { createStore } from '~/mr_notes/stores';
|
|
|
|
import { imageDiffDiscussions } from '../mock_data/diff_discussions';
|
|
|
|
|
|
|
|
describe('Diffs image diff overlay component', () => {
|
|
|
|
const dimensions = {
|
|
|
|
width: 100,
|
|
|
|
height: 200,
|
|
|
|
};
|
|
|
|
let wrapper;
|
|
|
|
let dispatch;
|
|
|
|
const getAllImageBadges = () => wrapper.findAll('.js-image-badge');
|
|
|
|
|
|
|
|
function createComponent(props = {}, extendStore = () => {}) {
|
|
|
|
const store = createStore();
|
|
|
|
|
|
|
|
extendStore(store);
|
|
|
|
dispatch = jest.spyOn(store, 'dispatch').mockImplementation();
|
|
|
|
|
|
|
|
wrapper = shallowMount(ImageDiffOverlay, {
|
|
|
|
store,
|
2020-12-24 09:10:15 +00:00
|
|
|
parentComponent: {
|
|
|
|
data() {
|
|
|
|
return dimensions;
|
|
|
|
},
|
|
|
|
},
|
2020-03-20 15:09:17 +00:00
|
|
|
propsData: {
|
|
|
|
discussions: [...imageDiffDiscussions],
|
|
|
|
fileHash: 'ABC',
|
2020-11-26 12:09:48 +00:00
|
|
|
renderedWidth: 200,
|
|
|
|
renderedHeight: 200,
|
2020-03-20 15:09:17 +00:00
|
|
|
...props,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders comment badges', () => {
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
expect(getAllImageBadges()).toHaveLength(2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders index of discussion in badge', () => {
|
|
|
|
createComponent();
|
|
|
|
const imageBadges = getAllImageBadges();
|
|
|
|
|
2020-12-23 12:10:26 +00:00
|
|
|
expect(imageBadges.at(0).text().trim()).toBe('1');
|
|
|
|
expect(imageBadges.at(1).text().trim()).toBe('2');
|
2020-03-20 15:09:17 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders icon when showCommentIcon is true', () => {
|
|
|
|
createComponent({ showCommentIcon: true });
|
|
|
|
|
2020-08-24 15:10:11 +00:00
|
|
|
expect(wrapper.find(GlIcon).exists()).toBe(true);
|
2020-03-20 15:09:17 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('sets badge comment positions', () => {
|
|
|
|
createComponent();
|
|
|
|
const imageBadges = getAllImageBadges();
|
|
|
|
|
2020-11-26 12:09:48 +00:00
|
|
|
expect(imageBadges.at(0).attributes('style')).toBe('left: 10%; top: 5%;');
|
|
|
|
expect(imageBadges.at(1).attributes('style')).toBe('left: 5%; top: 2.5%;');
|
2020-03-20 15:09:17 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders single badge for discussion object', () => {
|
|
|
|
createComponent({
|
|
|
|
discussions: {
|
|
|
|
...imageDiffDiscussions[0],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(getAllImageBadges()).toHaveLength(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('dispatches openDiffFileCommentForm when clicking overlay', () => {
|
|
|
|
createComponent({ canComment: true });
|
|
|
|
wrapper.find('.js-add-image-diff-note-button').trigger('click', { offsetX: 0, offsetY: 0 });
|
|
|
|
|
|
|
|
expect(dispatch).toHaveBeenCalledWith('diffs/openDiffFileCommentForm', {
|
|
|
|
fileHash: 'ABC',
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
width: 100,
|
|
|
|
height: 200,
|
2020-11-26 12:09:48 +00:00
|
|
|
xPercent: 0,
|
|
|
|
yPercent: 0,
|
2020-03-20 15:09:17 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('toggle discussion', () => {
|
|
|
|
const getImageBadge = () => wrapper.find('.js-image-badge');
|
|
|
|
|
|
|
|
it('disables buttons when shouldToggleDiscussion is false', () => {
|
|
|
|
createComponent({ shouldToggleDiscussion: false });
|
|
|
|
|
|
|
|
expect(getImageBadge().attributes('disabled')).toEqual('disabled');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('dispatches toggleDiscussion when clicking image badge', () => {
|
|
|
|
createComponent();
|
|
|
|
getImageBadge().trigger('click');
|
|
|
|
|
|
|
|
expect(dispatch).toHaveBeenCalledWith('toggleDiscussion', {
|
|
|
|
discussionId: '1',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('comment form', () => {
|
|
|
|
const getCommentIndicator = () => wrapper.find('.comment-indicator');
|
|
|
|
beforeEach(() => {
|
2020-12-23 21:10:24 +00:00
|
|
|
createComponent({ canComment: true }, (store) => {
|
2020-03-20 15:09:17 +00:00
|
|
|
store.state.diffs.commentForms.push({
|
|
|
|
fileHash: 'ABC',
|
|
|
|
x: 20,
|
|
|
|
y: 10,
|
2020-11-26 12:09:48 +00:00
|
|
|
xPercent: 10,
|
|
|
|
yPercent: 10,
|
2020-03-20 15:09:17 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders comment form badge', () => {
|
|
|
|
expect(getCommentIndicator().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets comment form badge position', () => {
|
2020-11-26 12:09:48 +00:00
|
|
|
expect(getCommentIndicator().attributes('style')).toBe('left: 10%; top: 10%;');
|
2020-03-20 15:09:17 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|