salix/front/core/directives/specs/zoom-image.spec.js

72 lines
2.3 KiB
JavaScript
Raw Normal View History

2018-02-13 12:15:03 +00:00
describe('Directive zoomImage', () => {
let compile;
let scope;
let srcDefault = 'http://default.img.jpg/';
let srcZoom = 'http://zoom.img.jpg/';
let findContainer;
2019-09-13 14:09:14 +00:00
beforeEach(angular.mock.module('vnCore', $translateProvider => {
$translateProvider.translations('en', {});
}));
2018-02-13 12:15:03 +00:00
beforeEach(angular.mock.inject(($compile, $rootScope) => {
2018-02-13 12:15:03 +00:00
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);
2018-02-13 12:15:03 +00:00
scope.$digest();
return compiledElement;
}
it('should create zoom container when click into image', () => {
let image = getCompiledImage(`<img src="${srcDefault}" zoom-image>`);
image[0].click();
2018-03-01 18:35:32 +00:00
findContainer = document.querySelector('.vn-zoom-image');
2018-02-13 12:15:03 +00:00
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();
2018-03-01 18:35:32 +00:00
findContainer = document.querySelector('.vn-zoom-image');
findContainer.click();
2018-02-13 12:15:03 +00:00
2018-03-01 18:35:32 +00:00
findContainer = document.querySelector('.vn-zoom-image');
2018-02-13 12:15:03 +00:00
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();
2018-03-01 18:35:32 +00:00
findContainer = document.querySelector('.vn-zoom-image');
let zoomedImg = findContainer.querySelector('img');
2018-02-13 12:15:03 +00:00
2018-03-01 18:35:32 +00:00
expect(zoomedImg.src).toEqual(srcDefault);
2018-02-13 12:15:03 +00:00
});
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();
2018-03-01 18:35:32 +00:00
findContainer = document.querySelector('.vn-zoom-image');
let zoomedImg = findContainer.querySelector('img');
2018-02-13 12:15:03 +00:00
2018-03-01 18:35:32 +00:00
expect(zoomedImg.src).toEqual(srcZoom);
2018-02-13 12:15:03 +00:00
});
});