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-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('vnCore'));
|
2018-02-13 12:15:03 +00:00
|
|
|
|
2018-12-22 10:59:26 +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);
|
2018-12-22 10:59:26 +00:00
|
|
|
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
|
|
|
});
|
|
|
|
});
|