import 'reflect-metadata'; import { CoordsInterface, DimensionsInterface, LayoutBoxInterface, PictureInterface, ProductViewImageInterface, ProductViewItemInterface, } from './../../../models/index'; import { RoundingFunctions, } from './../index'; import ImageTransformsFunctions from './image-transforms.functions'; describe('aspectFillImage', () => { const testItSetsZoomToValue = ( expectedZoomValue: number, pictureInterface: PictureInterface, parentDimensions?: DimensionsInterface, baseWidthPercent?: number, horizontalRotation = true, ) => { const productViewImage = { baseWidthPercent: baseWidthPercent ? baseWidthPercent : 1, picture: pictureInterface, rotation: horizontalRotation ? 0 : 90, zoom: 1, } as ProductViewImageInterface; const transformedProductView = ImageTransformsFunctions.aspectFillImage( parentDimensions, productViewImage, ); expect(transformedProductView.zoom).toBe(expectedZoomValue); }; // tslint:disable-next-line test('It sets zoom to 1 if the sent PictureInterface has an aspect ratio of 1:2 and the PictureInterface has an aspect ratio of 1:1', () => { testItSetsZoomToValue( 1, { dimensions: { height: 2, width: 1, }, } as PictureInterface, { height: 1, width: 1, }, ); }); // tslint:disable-next-line test('It sets zoom to 1 if the sent PictureInterface has an aspect ratio of 1:2 and the PictureInterface has an aspect ratio of 1:2', () => { testItSetsZoomToValue( 1, { dimensions: { height: 200, width: 100, }, } as PictureInterface, { height: 600, width: 300, }, ); }); // tslint:disable-next-line test('It sets zoom to 2 if the sent PictureInterface has an aspect ratio of 1:2 and the PictureInterface has an aspect ratio of 1:4', () => { testItSetsZoomToValue( 2, { dimensions: { height: 2, width: 1, }, } as PictureInterface, { height: 4, width: 1, }, ); }); // tslint:disable-next-line test('It sets zoom to 4 if the sent PictureInterface has an aspect ratio of 2:1 and the layoutBoxImageElement has an aspect ratio of 1:2', () => { testItSetsZoomToValue( 4, { dimensions: { height: 1, width: 2, }, } as PictureInterface, { height: 2, width: 1, }, ); }); // tslint:disable-next-line test('It can cope with different base widths', () => { testItSetsZoomToValue( 2, { dimensions: { height: 1, width: 1, }, } as PictureInterface, { height: 1, width: 1, }, 0.5, ); }); // tslint:disable-next-line test('It sets zoom value to the width divided by height if rotated 90 degrees', () => { testItSetsZoomToValue( 2, { dimensions: { height: 3, width: 6, }, } as PictureInterface, { height: 100, width: 100, }, 1, false, ); }); // tslint:disable-next-line test('If rotated by 90 degrees it takes into account the baseWidthPercent', () => { testItSetsZoomToValue( 0.4, { dimensions: { height: 10, width: 20, }, } as PictureInterface, { height: 100, width: 100, }, 5, false, ); }); // tslint:disable-next-line test('It correctly scales up portrait images', () => { testItSetsZoomToValue( 1.2, { dimensions: { height: 150, width: 100, }, } as PictureInterface, { height: 120, width: 100, }, 1, false, ); }); // tslint:disable-next-line test('It correctly scales down potrait images in landscape layout boxes', () => { testItSetsZoomToValue( 200 / 240, { dimensions: { height: 120, width: 100, }, } as PictureInterface, { height: 100, width: 200, }, 1, false, ); }); // tslint:disable-next-line test('It returns a clone of the productViewImage', () => { const productViewImage = { picture: { dimensions: { height: 2, width: 2, }, } as PictureInterface, relativeStartPoint: { x: 0, y: 0, }, } as ProductViewImageInterface; const response = ImageTransformsFunctions.aspectFillImage( { height: 1, width: 1, }, productViewImage, ); expect(response).not.toBe( productViewImage, ); }); }); describe('rotateImage', () => { // tslint:disable-next-line test('It calls _cloneObjectService.clone with the productViewImage', () => { const productViewImage = {} as ProductViewImageInterface; const response = ImageTransformsFunctions.rotateImage( productViewImage, 0, ); expect(response).not.toBe( productViewImage, ); }); // tslint:disable-next-line test('Sets image rotation to the rotation increments if rotation is not set', () => { const productViewImage = { rotation: undefined, } as ProductViewImageInterface; const rotationIncrements = 1; const responseImage = ImageTransformsFunctions.rotateImage( productViewImage, rotationIncrements, ); expect( responseImage.rotation, ). toBe(rotationIncrements); }); // tslint:disable-next-line test('Adds the increment to the images rotation if rotation is less than 360', () => { const productViewImage = { rotation: 2, } as ProductViewImageInterface; const rotationIncrements = 1; const responseImage = ImageTransformsFunctions.rotateImage( productViewImage, rotationIncrements, ); expect( responseImage.rotation, ). toBe(3); }); // tslint:disable-next-line test('Sets rotation to 0 if the current value plus the increment is 360', () => { const productViewImage = { rotation: 359, } as ProductViewImageInterface; const rotationIncrements = 1; const responseImage = ImageTransformsFunctions.rotateImage( productViewImage, rotationIncrements, ); expect( responseImage.rotation, ). toBe(0); }); // tslint:disable-next-line test('Set rotation to 0 if the current value plus the increment is over 360', () => { const productViewImage = { rotation: 359, } as ProductViewImageInterface; const rotationIncrements = 2; const responseImage = ImageTransformsFunctions.rotateImage( productViewImage, rotationIncrements, ); expect( responseImage.rotation, ). toBe(0); }); }); describe('updateImageQuality', () => { // tslint:disable-next-line test('If the productViewImage.zoom multiplied by layoutBoxDimensions.width is greater than 100% of the picture width, return an object where isTooLowQualityToPrint is true', () => { const response = ImageTransformsFunctions.updateImageQuality( { baseWidthPercent: 1, picture: { dimensions: { width: 1, }, }, zoom: 0.5, } as ProductViewImageInterface, { width: 2.21, } as DimensionsInterface, ); expect(response.isTooLowQualityToPrint) .toBe(true); }); // tslint:disable-next-line test('Returns an object which is a copy of the passed object', () => { const productViewImage = { baseWidthPercent: 1, picture: { dimensions: { width: 1, }, }, zoom: 1, } as ProductViewImageInterface; const response = ImageTransformsFunctions.updateImageQuality( productViewImage, { width: 1.11, } as DimensionsInterface, ); expect(response) .not.toBe(productViewImage); }); // tslint:disable-next-line test('If the baseWidthPercent is too low it considers the image low quality', () => { const productViewImage = { baseWidthPercent: 150, picture: { dimensions: { width: 1, }, }, zoom: 1, } as ProductViewImageInterface; const response = ImageTransformsFunctions.updateImageQuality( productViewImage, { width: 1.1, } as DimensionsInterface, ); expect(response.isTooLowQualityToPrint) .toBe(true); }); }); describe('zoomInImage', () => { // tslint:disable-next-line test('It returns a copy of productViewImage', () => { const productViewImage = {} as ProductViewImageInterface; ImageTransformsFunctions.updateImageQuality = jest.fn() .mockImplementation((arg) => arg); const response = ImageTransformsFunctions.zoomInImage( productViewImage, 0, {} as DimensionsInterface, ); expect(response).not.toBe( productViewImage, ); }); // tslint:disable-next-line test('Increases the product image zoom by the increment provided', () => { const productViewImage = { zoom: 1, } as ProductViewImageInterface; const zoomIncrement = 2; ImageTransformsFunctions.updateImageQuality = jest.fn() .mockImplementation((arg) => arg); const responseImage = ImageTransformsFunctions.zoomInImage( productViewImage, zoomIncrement, {} as DimensionsInterface, ); expect(responseImage.zoom) .toBe(3); }); // tslint:disable-next-line test('Increases the product image zoomCount by 1', () => { const productViewImage = { zoomCount: 1, } as ProductViewImageInterface; ImageTransformsFunctions.updateImageQuality = jest.fn() .mockImplementation((arg) => arg); const responseImage = ImageTransformsFunctions.zoomInImage( productViewImage, 5, {} as DimensionsInterface, ); expect(responseImage.zoomCount) .toBe(2); }); // tslint:disable-next-line test('It returns the result of updateImageQuality', () => { const productViewImage = { zoomCount: 1, } as ProductViewImageInterface; const updateImageQualityResponse = {} as ProductViewImageInterface; ImageTransformsFunctions.updateImageQuality = jest.fn() .mockReturnValue(updateImageQualityResponse); const responseImage = ImageTransformsFunctions.zoomInImage( productViewImage, undefined, undefined, ); expect(responseImage) .toBe(updateImageQualityResponse); }); }); describe('zoomOutImage', () => { // tslint:disable-next-line test('It returns a copy of productViewImage', () => { const productViewImage = {} as ProductViewImageInterface; ImageTransformsFunctions.updateImageQuality = jest.fn() .mockImplementation((arg) => arg); const response = ImageTransformsFunctions.zoomOutImage( productViewImage, 0, {} as DimensionsInterface, ); expect(response).not.toBe( productViewImage, ); }); // tslint:disable-next-line test('Decreases the product image zoom by the decrement provided', () => { const productViewImage = { zoom: 1, } as ProductViewImageInterface; const zoomDecrement = 2; ImageTransformsFunctions.updateImageQuality = jest.fn() .mockImplementation((arg) => arg); const responseImage = ImageTransformsFunctions.zoomOutImage( productViewImage, zoomDecrement, {} as DimensionsInterface, ); expect(responseImage.zoom) .toBe(-1); }); // tslint:disable-next-line test('Decreases the product image zoomCount by 1', () => { const productViewImage = { zoomCount: 1, } as ProductViewImageInterface; ImageTransformsFunctions.updateImageQuality = jest.fn() .mockImplementation((arg) => arg); const responseImage = ImageTransformsFunctions.zoomOutImage( productViewImage, 5, {} as DimensionsInterface, ); expect(responseImage.zoomCount) .toBe(0); }); // tslint:disable-next-line test('It returns the result of updateImageQuality', () => { const productViewImage = { zoomCount: 1, } as ProductViewImageInterface; const updateImageQualityResponse = {} as ProductViewImageInterface; ImageTransformsFunctions.updateImageQuality = jest.fn() .mockReturnValue(updateImageQualityResponse); const responseImage = ImageTransformsFunctions.zoomOutImage( productViewImage, undefined, undefined, ); expect(responseImage) .toBe(updateImageQualityResponse); }); }); describe('centerHorizontally', () => { // tslint:disable-next-line test('It sets the relativeStartPoint.x of the productViewImage to 0', () => { const productViewImage = { relativeStartPoint: { x: null, }, } as ProductViewImageInterface; const horizontallyCentered = ImageTransformsFunctions.centerHorizontally( productViewImage, ); expect(horizontallyCentered.relativeStartPoint.x) .toBe(0); }); // tslint:disable-next-line test('It returns a copy of productViewImage', () => { const productViewImage = { relativeStartPoint: {}, } as ProductViewImageInterface; const response = ImageTransformsFunctions.centerHorizontally( productViewImage, ); expect(response).not.toBe( productViewImage, ); }); }); describe('centerVertically', () => { const centerVerticallyTest = ( expectedStartPointY: number, imageHeight: number, imageWidth: number, layoutHeight: number, layoutWidth: number, baseWidthPercent?: number, ) => { const productViewImage = { baseWidthPercent: baseWidthPercent ? baseWidthPercent : 1, picture: { dimensions: { height: imageHeight, width: imageWidth, }, }, relativeStartPoint: {}, } as ProductViewImageInterface; const verticallyCenteredProductViewImage = ImageTransformsFunctions.centerVertically( { height: layoutHeight, width: layoutWidth, }, productViewImage, ); expect( verticallyCenteredProductViewImage .relativeStartPoint.y, ).toBe( expectedStartPointY, ); }; // tslint:disable-next-line test('It sets the relativeStartPoint.y of the contained item to 0 if the image is the same height as the layout box', () => { const imageHeight = 200; const widths = 100; centerVerticallyTest( 0, imageHeight, widths, imageHeight, widths, ); }); // tslint:disable-next-line test('It sets the relativeStartPoint.y of the contained item to -0.25 if the image is twice as high as the layout box', () => { const imageHeight = 200; const widths = 100; centerVerticallyTest( -0.25, imageHeight, widths, imageHeight / 2, widths, ); }); // tslint:disable-next-line test('It sets the relativeStartPoint.y of the contained item to 0.5 if the image is half as high as the layout box', () => { const imageHeight = 200; const widths = 200; centerVerticallyTest( 0.5, imageHeight, widths, imageHeight * 2, widths, ); }); // tslint:disable-next-line test('It can cope with different baseWidthPercent', () => { centerVerticallyTest( 0.5, 1, 1, 1, 1, 0.5, ); }); // tslint:disable-next-line test('It returns of a copy of productViewImage', () => { const productViewImage = { picture: { dimensions: { height: 2, width: 2, }, } as PictureInterface, relativeStartPoint: { x: 0, y: 0, }, } as ProductViewImageInterface; const response = ImageTransformsFunctions.centerVertically( { height: 1, width: 1, }, productViewImage, ); expect(response).not.toBe( productViewImage, ); }); }); describe('centerImage', () => { // tslint:disable-next-line test('It calls centerHorizontally with the correct arguments', () => { const productViewImage = {} as ProductViewImageInterface; const parentDimensions = {} as DimensionsInterface; ImageTransformsFunctions.centerHorizontally = jest.fn(); ImageTransformsFunctions.centerVertically = jest.fn(); ImageTransformsFunctions.centerImage( parentDimensions, productViewImage, ); expect(ImageTransformsFunctions.centerHorizontally) .toHaveBeenCalledWith(productViewImage); }); // tslint:disable-next-line test('It calls centerVertically with the correct arguments', () => { const centerHorizontallyResult = {} as ProductViewImageInterface; const parentDimensions = {} as DimensionsInterface; ImageTransformsFunctions.centerHorizontally = jest.fn() .mockReturnValue(centerHorizontallyResult); ImageTransformsFunctions.centerVertically = jest.fn(); ImageTransformsFunctions.centerImage( parentDimensions, {} as ProductViewImageInterface, ); expect(ImageTransformsFunctions.centerVertically) .toHaveBeenCalledWith( parentDimensions, centerHorizontallyResult, ); }); // tslint:disable-next-line test('It returns the result of centerVertically', () => { const centerVerticallyResult = {} as ProductViewImageInterface; const parentDimensions = {} as DimensionsInterface; ImageTransformsFunctions.centerHorizontally = jest.fn(); ImageTransformsFunctions.centerVertically = jest.fn() .mockReturnValue(centerVerticallyResult); expect( ImageTransformsFunctions.centerImage( parentDimensions, {} as ProductViewImageInterface, ), ).toBe( centerVerticallyResult, ); }); }); describe('onImageDraggedToMovePosition', () => { // tslint:disable-next-line test('It correctly adjusts the startPoint by the x provided', () => { const response = ImageTransformsFunctions.onImageDraggedToMovePosition( { x: 5, y: 0, }, { relativeStartPoint: { x: 0, y: 0, }, } as ProductViewImageInterface, ); expect(response.relativeStartPoint.x) .toBe(5); }); // tslint:disable-next-line test('It correctly adjusts the startPoint by the y provided', () => { const response = ImageTransformsFunctions.onImageDraggedToMovePosition( { x: 0, y: 5, }, { relativeStartPoint: { x: 0, y: 0, }, } as ProductViewImageInterface, ); expect(response.relativeStartPoint.y) .toBe(5); }); // tslint:disable-next-line test('It returns a copy of productViewImage', () => { const productViewImage = { picture: { dimensions: { height: 2, width: 2, }, } as PictureInterface, relativeStartPoint: { x: 0, y: 0, }, } as ProductViewImageInterface; const response = ImageTransformsFunctions.onImageDraggedToMovePosition({ x: 5, y: 5, }, productViewImage); expect(response).not.toBe( productViewImage, ); }); }); describe('adjustImageToRemainInLayoutBox', () => { const adjustImageToRemainInLayoutBoxTest = ( productViewImageStartPoint: CoordsInterface, productZoom: number, expectedNewCoords: CoordsInterface, pictureDimensions?: DimensionsInterface, layoutBoxDimensions?: DimensionsInterface, baseWidthPercent?: number, rotation = 0, ) => { const productViewDimensions = layoutBoxDimensions ? layoutBoxDimensions : { height: 100, width: 100, }; const containedItem = { baseWidthPercent: baseWidthPercent ? baseWidthPercent : 1, picture: { dimensions: pictureDimensions ? pictureDimensions : productViewDimensions, }, relativeStartPoint: productViewImageStartPoint, rotation, zoom: productZoom, } as ProductViewImageInterface; const layoutBox = { containedItem: containedItem as ProductViewItemInterface, dimensionsPercentages: { height: 1, width: 1, }, } as LayoutBoxInterface; ImageTransformsFunctions.getLayoutBoxDimensions = jest.fn() .mockReturnValue(productViewDimensions); RoundingFunctions.roundToDps = jest.fn((value) => value); const response = ImageTransformsFunctions.adjustImageToRemainInLayoutBox( productViewDimensions, layoutBox, ); expect( response.relativeStartPoint.x, ).toBe(expectedNewCoords.x); expect( response.relativeStartPoint.y, ).toBe(expectedNewCoords.y); }; // tslint:disable-next-line test('It adjust the image if the image is equal size to the layoutBox but starts slightly left into the layout', () => { const productViewImageStartPoint = { x: 0.001, y: 0, }; const pictureZoom = 1; const expectedNewCoords = { x: 0, y: 0, }; adjustImageToRemainInLayoutBoxTest( productViewImageStartPoint, pictureZoom, expectedNewCoords, ); }); // tslint:disable-next-line test('It adjusts the image if the image is equal size to the layoutBox but is pulled slightly left in the layout', () => { const productViewImageStartPoint = { x: -0.001, y: 0, }; const pictureZoom = 1; const expectedNewCoords = { x: 0, y: 0, }; adjustImageToRemainInLayoutBoxTest( productViewImageStartPoint, pictureZoom, expectedNewCoords, ); }); // tslint:disable-next-line test('It adjusts the image if the image is equal size to the layoutBox but is pulled slightly up in the layout', () => { const productViewImageStartPoint = { x: 0, y: -0.001, }; const pictureZoom = 1; const expectedNewCoords = { x: 0, y: 0, }; adjustImageToRemainInLayoutBoxTest( productViewImageStartPoint, pictureZoom, expectedNewCoords, ); }); // tslint:disable-next-line test('It adjusts the image if the image is equal size to the layoutBox but is pulled slightly down in the layout', () => { const productViewImageStartPoint = { x: 0, y: 0.001, }; const pictureZoom = 1; const expectedNewCoords = { x: 0, y: 0, }; adjustImageToRemainInLayoutBoxTest( productViewImageStartPoint, pictureZoom, expectedNewCoords, ); }); // tslint:disable-next-line test('It does not adjust the image if the image is equal size to the layoutBox and is centered', () => { const productViewImageStartPoint = { x: 0, y: 0, }; const pictureZoom = 1; const expectedNewCoords = productViewImageStartPoint; adjustImageToRemainInLayoutBoxTest( productViewImageStartPoint, pictureZoom, expectedNewCoords, ); }); // tslint:disable-next-line test('It does not adjust the image if the image is bigger than the layoutBox and is centered', () => { const productViewImageStartPoint = { x: 0, y: 0, }; const pictureZoom = 1.01; const expectedNewCoords = productViewImageStartPoint; adjustImageToRemainInLayoutBoxTest( productViewImageStartPoint, pictureZoom, expectedNewCoords, ); }); // tslint:disable-next-line test('If an image has a much lower aspect ratio than the layoutBox it makes allowances for this when it stays within bounds', () => { const productViewImageStartPoint = { x: 0, y: -0.25, }; const pictureZoom = 1; const expectedNewCoords = productViewImageStartPoint; const imageDimensions = { height: 200, width: 100, }; const layoutBoxDimensions = { height: 100, width: 100, }; adjustImageToRemainInLayoutBoxTest( productViewImageStartPoint, pictureZoom, expectedNewCoords, imageDimensions, layoutBoxDimensions, ); }); // tslint:disable-next-line test('If an image has a much lower aspect ratio than the layoutBox it makes allowances for this when it goes to far', () => { const productViewImageStartPoint = { x: 0, y: -1.001, }; const pictureZoom = 1; const expectedNewCoords = { x: 0, y: -0.5, }; const imageDimensions = { height: 200, width: 100, }; const layoutBoxDimensions = { height: 100, width: 100, }; adjustImageToRemainInLayoutBoxTest( productViewImageStartPoint, pictureZoom, expectedNewCoords, imageDimensions, layoutBoxDimensions, ); }); // tslint:disable-next-line test('If an image has a much higer aspect ratio than the layoutBox it makes allowances for this', () => { const productViewImageStartPoint = { x: 0, y: 0.5, }; const pictureZoom = 2; const expectedNewCoords = productViewImageStartPoint; const imageDimensions = { height: 100, width: 200, }; const layoutBoxDimensions = { height: 100, width: 100, }; adjustImageToRemainInLayoutBoxTest( productViewImageStartPoint, pictureZoom, expectedNewCoords, imageDimensions, layoutBoxDimensions, ); }); // tslint:disable-next-line test('It can cope with different baseWidthPercents', () => { const productViewImageStartPoint = { x: 0, y: 0, }; const pictureZoom = 1; const expectedNewCoords = { x: 0.25, y: 1, }; const imageDimensions = { height: 1, width: 1, }; const layoutBoxDimensions = { height: 1, width: 1, }; const baseWidthPercent = 0.5; adjustImageToRemainInLayoutBoxTest( productViewImageStartPoint, pictureZoom, expectedNewCoords, imageDimensions, layoutBoxDimensions, baseWidthPercent, ); }); // tslint:disable-next-line test('It calls RoundingFunctions.roundToDps with the correct arguments', () => { const dimens = { height: 10, width: 10, }; ImageTransformsFunctions.getLayoutBoxDimensions = jest.fn().mockReturnValue(dimens); RoundingFunctions.roundToDps = jest.fn(); ImageTransformsFunctions.adjustImageToRemainInLayoutBox( {} as DimensionsInterface, { containedItem: { baseWidthPercent: 1, picture: { dimensions: { height: 1, width: 1, }, }, relativeStartPoint: { x: 1, y: 1, }, zoom: 1, } as ProductViewItemInterface, } as LayoutBoxInterface, ); expect(RoundingFunctions.roundToDps) .toHaveBeenCalledWith( 1, 10, ); }); test('It handle large zoomed in images', () => { const productViewImageStartPoint = { x: 0.07123287671232863, y: 0.15346202920330634, }; const pictureZoom = 1.80437; const expectedNewCoords = productViewImageStartPoint; const imageDimensions = { height: 2133, width: 3199, }; const layoutBoxDimensions = { height: 377, width: 370, }; adjustImageToRemainInLayoutBoxTest( productViewImageStartPoint, pictureZoom, expectedNewCoords, imageDimensions, layoutBoxDimensions, ); }); // tslint:disable-next-line test('When an image is rotated 90 degrees and the top edge is just below the layoutBox top edge it adjusts the image', () => { const productViewImageStartPoint = { x: 0, y: 0.6399743, }; const pictureZoom = 1.5; const expectedNewCoords = { x: 0, y: 0.6250000000000001, }; const imageDimensions = { height: 750, width: 1125, }; const layoutBoxDimensions = { height: 132.95, width: 166.2, }; const rotation = 90; adjustImageToRemainInLayoutBoxTest( productViewImageStartPoint, pictureZoom, expectedNewCoords, imageDimensions, layoutBoxDimensions, undefined, rotation, ); }); // tslint:disable-next-line test('When an image is rotated 90 degrees and the bottom edge is just above the layoutBox bottom edge it adjusts the image', () => { const productViewImageStartPoint = { x: 0, y: -0.4300257, }; const pictureZoom = 1.5; const expectedNewCoords = { x: 0, y: -0.4250902527075812, }; const imageDimensions = { height: 750, width: 1125, }; const layoutBoxDimensions = { height: 132.95, width: 166.2, }; const rotation = 90; adjustImageToRemainInLayoutBoxTest( productViewImageStartPoint, pictureZoom, expectedNewCoords, imageDimensions, layoutBoxDimensions, undefined, rotation, ); }); // tslint:disable-next-line test('When an image is rotated 90 degrees and the layoutBox just covers the layoutBox it does not adjust the image', () => { const productViewImageStartPoint = { x: 0, y: -0.4000257, }; const pictureZoom = 1.5; const expectedNewCoords = productViewImageStartPoint; const imageDimensions = { height: 750, width: 1125, }; const layoutBoxDimensions = { height: 132.95, width: 166.2, }; const rotation = 90; adjustImageToRemainInLayoutBoxTest( productViewImageStartPoint, pictureZoom, expectedNewCoords, imageDimensions, layoutBoxDimensions, undefined, rotation, ); }); // tslint:disable-next-line test('When an image is rotated 90 degrees and the layoutBox just covers the layoutBox from the bottom it does not adjust the image', () => { const productViewImageStartPoint = { x: 0, y: -0.35, }; const pictureZoom = 1.5; const expectedNewCoords = productViewImageStartPoint; const imageDimensions = { height: 750, width: 1125, }; const layoutBoxDimensions = { height: 132.95, width: 166.2, }; const rotation = 90; adjustImageToRemainInLayoutBoxTest( productViewImageStartPoint, pictureZoom, expectedNewCoords, imageDimensions, layoutBoxDimensions, undefined, rotation, ); }); // tslint:disable-next-line test('When an image is rotated 90 degrees and the left edge is just to the right the layoutBox left edge it does not adjust the image', () => { const productViewImageStartPoint = { x: 0.12, y: 0, }; const pictureZoom = 1.83333; const expectedNewCoords = { x: 0.11110999999999993, y: 0, }; const imageDimensions = { height: 750, width: 1125, }; const layoutBoxDimensions = { height: 132.95, width: 166.2, }; const rotation = 90; adjustImageToRemainInLayoutBoxTest( productViewImageStartPoint, pictureZoom, expectedNewCoords, imageDimensions, layoutBoxDimensions, undefined, rotation, ); }); // tslint:disable-next-line test('When an image is rotated 90 degrees and the right edge is just to the left the layoutBox right edge it adjusts the image', () => { const productViewImageStartPoint = { x: -0.12, y: 0, }; const pictureZoom = 1.83333; const expectedNewCoords = { x: -0.11110999999999993, y: 0, }; const imageDimensions = { height: 750, width: 1125, }; const layoutBoxDimensions = { height: 132.95, width: 166.2, }; const rotation = 90; adjustImageToRemainInLayoutBoxTest( productViewImageStartPoint, pictureZoom, expectedNewCoords, imageDimensions, layoutBoxDimensions, undefined, rotation, ); }); // tslint:disable-next-line test('When an image is rotated 90 degrees and the left edge is just to the left of the layoutBox left edge it does not adjust the image', () => { const productViewImageStartPoint = { x: 0.1, y: 0, }; const pictureZoom = 1.83333; const expectedNewCoords = productViewImageStartPoint; const imageDimensions = { height: 750, width: 1125, }; const layoutBoxDimensions = { height: 132.95, width: 166.2, }; const rotation = 90; adjustImageToRemainInLayoutBoxTest( productViewImageStartPoint, pictureZoom, expectedNewCoords, imageDimensions, layoutBoxDimensions, undefined, rotation, ); }); // tslint:disable-next-line test('When an image is rotated 90 degrees and the right edge is just to the right of the layoutBox right edge it does not adjust the image', () => { const productViewImageStartPoint = { x: -0.1, y: 0, }; const pictureZoom = 1.83333; const expectedNewCoords = productViewImageStartPoint; const imageDimensions = { height: 750, width: 1125, }; const layoutBoxDimensions = { height: 132.95, width: 166.2, }; const rotation = 90; adjustImageToRemainInLayoutBoxTest( productViewImageStartPoint, pictureZoom, expectedNewCoords, imageDimensions, layoutBoxDimensions, undefined, rotation, ); }); }); describe('setInitialImageTransforms', () => { // tslint:disable-next-line test('It returns the productViewImage if it does not have a picture', () => { const productViewImage = {} as ProductViewImageInterface; const response = ImageTransformsFunctions.setInitialImageTransforms( {} as DimensionsInterface, productViewImage, ); expect(response).toBe(productViewImage); }); // tslint:disable-next-line test('It calls aspectFillImage with the correct arguments', () => { const parentContainerDimensions = {} as DimensionsInterface; const productViewImage = { picture: {}, } as ProductViewImageInterface; ImageTransformsFunctions.aspectFillImage = jest.fn(); ImageTransformsFunctions.updateImageQuality = jest.fn(); ImageTransformsFunctions.centerVertically = jest.fn(); ImageTransformsFunctions.centerHorizontally = jest.fn() .mockReturnValue({}); ImageTransformsFunctions.setInitialImageTransforms( parentContainerDimensions, productViewImage, ); expect(ImageTransformsFunctions.aspectFillImage) .toHaveBeenCalledWith( parentContainerDimensions, productViewImage, ); }); // tslint:disable-next-line test('It calls updateImageQuality with the response of aspectFillImage and the parentContainerDimensions', () => { const parentContainerDimensions = {} as DimensionsInterface; const aspectFilledResponse = {} as ProductViewImageInterface; ImageTransformsFunctions.aspectFillImage = jest.fn().mockReturnValue( aspectFilledResponse, ); ImageTransformsFunctions.updateImageQuality = jest.fn(); ImageTransformsFunctions.centerVertically = jest.fn(); ImageTransformsFunctions.centerHorizontally = jest.fn() .mockReturnValue({}); ImageTransformsFunctions.setInitialImageTransforms( parentContainerDimensions, { picture: {}, } as ProductViewImageInterface, ); expect(ImageTransformsFunctions.updateImageQuality) .toHaveBeenCalledWith( parentContainerDimensions, aspectFilledResponse, ); }); // tslint:disable-next-line test('It calls centerVertically with the response of updateImageQuality and the parentContainerDimensions', () => { const parentContainerDimensions = {} as DimensionsInterface; const updateImageQualityResponse = {} as ProductViewImageInterface; ImageTransformsFunctions.aspectFillImage = jest.fn(); ImageTransformsFunctions.updateImageQuality = jest.fn().mockReturnValue( updateImageQualityResponse, ); ImageTransformsFunctions.centerVertically = jest.fn(); ImageTransformsFunctions.centerHorizontally = jest.fn() .mockReturnValue({}); ImageTransformsFunctions.setInitialImageTransforms( parentContainerDimensions, { picture: {}, } as ProductViewImageInterface, ); expect(ImageTransformsFunctions.centerVertically) .toHaveBeenCalledWith( parentContainerDimensions, updateImageQualityResponse, ); }); // tslint:disable-next-line test('It calls centerHorizontally with the response of centerVertically', () => { const parentContainerDimensions = {} as DimensionsInterface; const centerVerticallyResponse = {} as ProductViewImageInterface; ImageTransformsFunctions.aspectFillImage = jest.fn(); ImageTransformsFunctions.updateImageQuality = jest.fn(); ImageTransformsFunctions.centerVertically = jest.fn().mockReturnValue( centerVerticallyResponse, ); ImageTransformsFunctions.centerHorizontally = jest.fn() .mockReturnValue({}); ImageTransformsFunctions.setInitialImageTransforms( parentContainerDimensions, { picture: {}, } as ProductViewImageInterface, ); expect(ImageTransformsFunctions.centerHorizontally) .toHaveBeenCalledWith( centerVerticallyResponse, ); }); // tslint:disable-next-line test('It returns the response of centerHorizontally', () => { const parentContainerDimensions = {} as DimensionsInterface; const centerHorizontallyResponse = {} as ProductViewImageInterface; ImageTransformsFunctions.aspectFillImage = jest.fn(); ImageTransformsFunctions.updateImageQuality = jest.fn(); ImageTransformsFunctions.centerVertically = jest.fn(); ImageTransformsFunctions.centerHorizontally = jest.fn().mockReturnValue( centerHorizontallyResponse, ); expect(ImageTransformsFunctions.setInitialImageTransforms( parentContainerDimensions, { picture: {}, } as ProductViewImageInterface, )).toBe(centerHorizontallyResponse); }); // tslint:disable-next-line test('It sets zoomCount to 0', () => { const parentContainerDimensions = {} as DimensionsInterface; const centerHorizontallyResponse = { zoomCount: 10, } as ProductViewImageInterface; ImageTransformsFunctions.aspectFillImage = jest.fn(); ImageTransformsFunctions.updateImageQuality = jest.fn(); ImageTransformsFunctions.centerVertically = jest.fn(); ImageTransformsFunctions.centerHorizontally = jest.fn().mockReturnValue( centerHorizontallyResponse, ); expect(ImageTransformsFunctions.setInitialImageTransforms( parentContainerDimensions, { picture: {}, } as ProductViewImageInterface, ).zoomCount).toBe(0); }); });