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

70 lines
2.2 KiB
JavaScript
Raw Permalink 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;
beforeEach(ngModule('vnCore'));
2018-02-13 12:15:03 +00:00
2020-07-23 14:46:16 +00:00
beforeEach(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
});
});