72 lines
2.3 KiB
JavaScript
72 lines
2.3 KiB
JavaScript
describe('Directive zoomImage', () => {
|
|
let compile;
|
|
let scope;
|
|
let srcDefault = 'http://default.img.jpg/';
|
|
let srcZoom = 'http://zoom.img.jpg/';
|
|
let findContainer;
|
|
|
|
beforeEach(angular.mock.module('vnCore', $translateProvider => {
|
|
$translateProvider.translations('en', {});
|
|
}));
|
|
|
|
beforeEach(angular.mock.inject(($compile, $rootScope) => {
|
|
compile = $compile;
|
|
scope = $rootScope.$new();
|
|
}));
|
|
|
|
afterEach(() => {
|
|
if (findContainer) {
|
|
findContainer.parentNode.removeChild(findContainer);
|
|
findContainer = undefined;
|
|
}
|
|
});
|
|
|
|
function getCompiledImage(imgHtml) {
|
|
let element = angular.element(imgHtml);
|
|
let compiledElement = compile(element)(scope);
|
|
scope.$digest();
|
|
return compiledElement;
|
|
}
|
|
|
|
it('should create zoom container when click into image', () => {
|
|
let image = getCompiledImage(`<img src="${srcDefault}" zoom-image>`);
|
|
image[0].click();
|
|
|
|
findContainer = document.querySelector('.vn-zoom-image');
|
|
|
|
expect(findContainer).not.toBeNull();
|
|
});
|
|
|
|
it('should detroy zoom container when click outside zoomed image', () => {
|
|
let image = getCompiledImage(`<img src="${srcDefault}" zoom-image>`);
|
|
image[0].click();
|
|
|
|
findContainer = document.querySelector('.vn-zoom-image');
|
|
findContainer.click();
|
|
|
|
findContainer = document.querySelector('.vn-zoom-image');
|
|
|
|
expect(findContainer).toBeNull();
|
|
});
|
|
|
|
it('should create new image, into zoom container, with src as original image src', () => {
|
|
let image = getCompiledImage(`<img src="${srcDefault}" zoom-image>`);
|
|
image[0].click();
|
|
findContainer = document.querySelector('.vn-zoom-image');
|
|
|
|
let zoomedImg = findContainer.querySelector('img');
|
|
|
|
expect(zoomedImg.src).toEqual(srcDefault);
|
|
});
|
|
|
|
it('should create new image, into zoom container, with src likes zoomImage value', () => {
|
|
let image = getCompiledImage(`<img src="${srcDefault}" zoom-image="${srcZoom}">`);
|
|
image[0].click();
|
|
findContainer = document.querySelector('.vn-zoom-image');
|
|
|
|
let zoomedImg = findContainer.querySelector('img');
|
|
|
|
expect(zoomedImg.src).toEqual(srcZoom);
|
|
});
|
|
});
|