import 'reflect-metadata'; import { ProductProductsAndPricesContentComponent, } from './product-products-and-prices-content.component'; import { ProductsAndPricesContentInterface, } from './../../models/index'; const initProductProductsAndPricesContentComponent = () => new ProductProductsAndPricesContentComponent(); describe('defaults', () => { test('Sets currency to GBP by default', () => { expect(initProductProductsAndPricesContentComponent().currency) .toBe('GBP'); }); }); describe('get showContent', () => { const initShowContentData = () => { const mockProductContent = [ { formattedPrice: '£10.99', formattedPrintArea: '10cm x 20cm', formattedPrintQuality: '150dpi', product: 'Foo', template: { filename: 'foo.psd', url: '/foo.psd', }, }, { formattedPrice: '£10.99', formattedPrintArea: '10cm x 20cm', formattedPrintQuality: '150dpi', product: 'Bar', template: { filename: 'bar.psd', url: '/bar.psd', }, }, { formattedPrice: '£10.99', formattedPrintArea: '10cm x 20cm', formattedPrintQuality: '150dpi', product: 'Widgets', template: { filename: 'widgets.psd', url: '/widgets.psd', }, }, { formattedPrice: '£10.99', formattedPrintArea: '10cm x 20cm', formattedPrintQuality: '150dpi', product: 'Doodads', template: { filename: 'doodads.psd', url: '/doodads.psd', }, }, ] as ProductsAndPricesContentInterface[]; const productsAndPricesContentComponent = initProductProductsAndPricesContentComponent(); return { mockProductContent, productsAndPricesContentComponent, }; }; test('Returns true if there are product contents', () => { const { mockProductContent, productsAndPricesContentComponent, } = initShowContentData(); productsAndPricesContentComponent.productContent = mockProductContent; const result = productsAndPricesContentComponent.showContent; expect(result).toBe(true); }); test('Returns false if product contents is an empty array', () => { const { productsAndPricesContentComponent, } = initShowContentData(); productsAndPricesContentComponent.productContent = []; const result = productsAndPricesContentComponent.showContent; expect(result).toBe(false); }); test('Returns false if product contents is undefined', () => { const { productsAndPricesContentComponent, } = initShowContentData(); productsAndPricesContentComponent.productContent = undefined; const result = productsAndPricesContentComponent.showContent; expect(result).toBe(false); }); }); describe('get getUnitsOfMeasureAsArray', () => { const initGetUnitsOfMeasureAsArrayData = () => { const mockUnitsOfMeasureMap = new Map( [ ['CM', true], ['INCH', false], ], ); const productAndPricesContentComponent = initProductProductsAndPricesContentComponent(); productAndPricesContentComponent.unitsOfMeasure = mockUnitsOfMeasureMap; return { mockUnitsOfMeasureMap, productAndPricesContentComponent, }; }; test('Returns expected array from the unitsOfMeasure map', () => { const { mockUnitsOfMeasureMap, productAndPricesContentComponent, } = initGetUnitsOfMeasureAsArrayData(); const result = productAndPricesContentComponent.getUnitsOfMeasureAsArray; expect(result).toEqual(Array.from(mockUnitsOfMeasureMap)); }); }); describe('changeSelectedUnitOfMeasure', () => { const initChangeSelectedUnitOfMeasureData = () => { const productsAndPricesContentComponent = initProductProductsAndPricesContentComponent(); productsAndPricesContentComponent.onChangeUnitsOfMeasure.emit = jest.fn(); return { productsAndPricesContentComponent, }; }; // tslint:disable-next-line test('Calls onChangeUnitOfMeasure.emit with the supplied unit string', () => { const { productsAndPricesContentComponent, } = initChangeSelectedUnitOfMeasureData(); productsAndPricesContentComponent.changeSelectedUnitsOfMeasure('inch'); expect(productsAndPricesContentComponent.onChangeUnitsOfMeasure.emit) .toHaveBeenCalledWith('inch'); }); });