2018-03-17 18:26:18 +05:30
|
|
|
import * as domHelper from '~/image_diff/helpers/dom_helper';
|
|
|
|
import * as mockData from '../mock_data';
|
|
|
|
|
|
|
|
describe('domHelper', () => {
|
|
|
|
const { imageMeta, badgeNumber } = mockData;
|
|
|
|
|
|
|
|
describe('setPositionDataAttribute', () => {
|
|
|
|
let containerEl;
|
|
|
|
let attributeAfterCall;
|
|
|
|
const position = {
|
|
|
|
myProperty: 'myProperty',
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
containerEl = document.createElement('div');
|
|
|
|
containerEl.dataset.position = JSON.stringify(position);
|
|
|
|
domHelper.setPositionDataAttribute(containerEl, imageMeta);
|
|
|
|
attributeAfterCall = JSON.parse(containerEl.dataset.position);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should set x, y, width, height', () => {
|
|
|
|
expect(attributeAfterCall.x).toEqual(imageMeta.x);
|
|
|
|
expect(attributeAfterCall.y).toEqual(imageMeta.y);
|
|
|
|
expect(attributeAfterCall.width).toEqual(imageMeta.width);
|
|
|
|
expect(attributeAfterCall.height).toEqual(imageMeta.height);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not override other properties', () => {
|
|
|
|
expect(attributeAfterCall.myProperty).toEqual('myProperty');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('updateDiscussionAvatarBadgeNumber', () => {
|
|
|
|
let discussionEl;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
discussionEl = document.createElement('div');
|
|
|
|
discussionEl.innerHTML = `
|
|
|
|
<a href="#" class="image-diff-avatar-link">
|
2022-04-04 11:22:00 +05:30
|
|
|
<div class="design-note-pin"></div>
|
2018-03-17 18:26:18 +05:30
|
|
|
</a>
|
|
|
|
`;
|
|
|
|
domHelper.updateDiscussionAvatarBadgeNumber(discussionEl, badgeNumber);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should update avatar badge number', () => {
|
2022-04-04 11:22:00 +05:30
|
|
|
expect(discussionEl.querySelector('.design-note-pin').textContent).toEqual(
|
|
|
|
badgeNumber.toString(),
|
|
|
|
);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('updateDiscussionBadgeNumber', () => {
|
|
|
|
let discussionEl;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
discussionEl = document.createElement('div');
|
|
|
|
discussionEl.innerHTML = `
|
2022-04-04 11:22:00 +05:30
|
|
|
<div class="design-note-pin"></div>
|
2018-03-17 18:26:18 +05:30
|
|
|
`;
|
|
|
|
domHelper.updateDiscussionBadgeNumber(discussionEl, badgeNumber);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should update discussion badge number', () => {
|
2022-04-04 11:22:00 +05:30
|
|
|
expect(discussionEl.querySelector('.design-note-pin').textContent).toEqual(
|
|
|
|
badgeNumber.toString(),
|
|
|
|
);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('toggleCollapsed', () => {
|
|
|
|
let element;
|
|
|
|
let discussionNotesEl;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
element = document.createElement('div');
|
|
|
|
element.innerHTML = `
|
|
|
|
<div class="discussion-notes">
|
|
|
|
<button></button>
|
|
|
|
<form class="discussion-form"></form>
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
discussionNotesEl = element.querySelector('.discussion-notes');
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('not collapsed', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
domHelper.toggleCollapsed({
|
|
|
|
currentTarget: element.querySelector('button'),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should add collapsed class', () => {
|
|
|
|
expect(discussionNotesEl.classList.contains('collapsed')).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should force formEl to display none', () => {
|
|
|
|
const formEl = element.querySelector('.discussion-form');
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(formEl.style.display).toEqual('none');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('collapsed', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
discussionNotesEl.classList.add('collapsed');
|
|
|
|
|
|
|
|
domHelper.toggleCollapsed({
|
|
|
|
currentTarget: element.querySelector('button'),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should remove collapsed class', () => {
|
|
|
|
expect(discussionNotesEl.classList.contains('collapsed')).toEqual(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should force formEl to display block', () => {
|
|
|
|
const formEl = element.querySelector('.discussion-form');
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(formEl.style.display).toEqual('block');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|