import 'reflect-metadata'; import { CatalogDesignTemplateResponseInterface, } from './../../models/index'; import { ProductCareAndPrintAreaContentComponent, } from './product-care-and-print-area-content.component'; const initProductCareAndPrintAreaContentComponent = () => new ProductCareAndPrintAreaContentComponent(); describe('get showContent', () => { const initGetShowContentData = () => { const mockCareInstructionsByDisplaySku = { 'Bar (shipped from the US)': 'Foo', 'Foo (shipped from the UK)': 'Bar', }; const mockDesignTemplateForDisplaySku = { 'Bar (shipped from the US)': {} as CatalogDesignTemplateResponseInterface, 'Foo (shipped from the UK)': {} as CatalogDesignTemplateResponseInterface, }; const productCareAndPrintAreaContentComponent = initProductCareAndPrintAreaContentComponent(); return { mockCareInstructionsByDisplaySku, mockDesignTemplateForDisplaySku, productCareAndPrintAreaContentComponent, }; }; test('Returns true if care instructions are supplied', () => { const { mockCareInstructionsByDisplaySku, productCareAndPrintAreaContentComponent, } = initGetShowContentData(); productCareAndPrintAreaContentComponent.careInstructionsByDisplaySku = mockCareInstructionsByDisplaySku; const result = productCareAndPrintAreaContentComponent.showContent; expect(result).toBe(true); }); test('Returns true if designTemplateForDisplaySku are supplied', () => { const { mockDesignTemplateForDisplaySku, productCareAndPrintAreaContentComponent, } = initGetShowContentData(); productCareAndPrintAreaContentComponent.designTemplateForDisplaySku = mockDesignTemplateForDisplaySku; const result = productCareAndPrintAreaContentComponent.showContent; expect(result).toBe(true); }); // tslint:disable-next-line test('Returns false if neither designTemplateForDisplaySku nor careInstructionsByDisplaySku are supplied', () => { const { productCareAndPrintAreaContentComponent, } = initGetShowContentData(); productCareAndPrintAreaContentComponent.careInstructionsByDisplaySku = undefined; productCareAndPrintAreaContentComponent.designTemplateForDisplaySku = undefined; const result = productCareAndPrintAreaContentComponent.showContent; expect(result).toBe(false); }); }); describe('get getUnitsOfMeasureAsArray', () => { const initGetUnitsOfMeasureAsArrayData = () => { const mockUnitsOfMeasure = new Map([ ['inch', true], ['cm', false], ]); const productCareAndPrintAreaContentComponent = initProductCareAndPrintAreaContentComponent(); return { mockUnitsOfMeasure, productCareAndPrintAreaContentComponent, }; }; test('Returns an array from the units of measure supplied', () => { const { mockUnitsOfMeasure, productCareAndPrintAreaContentComponent, } = initGetUnitsOfMeasureAsArrayData(); productCareAndPrintAreaContentComponent.unitsOfMeasure = mockUnitsOfMeasure; const result = productCareAndPrintAreaContentComponent.getUnitsOfMeasureAsArray; expect(result).toEqual(Array.from(mockUnitsOfMeasure)); }); }); describe('get getCareInstructionsAsArray', () => { const initGetCareInstructionsAsArrayData = () => { const mockCareInstructionsByDisplaySku = { 'Bar (shipped from the US)': 'Foo', 'Foo (shipped from the UK)': 'Bar', }; const productCareAndPrintAreaContentComponent = initProductCareAndPrintAreaContentComponent(); return { mockCareInstructionsByDisplaySku, productCareAndPrintAreaContentComponent, }; }; test('Returns an array from the units of measure supplied', () => { const { mockCareInstructionsByDisplaySku, productCareAndPrintAreaContentComponent, } = initGetCareInstructionsAsArrayData(); productCareAndPrintAreaContentComponent.careInstructionsByDisplaySku = mockCareInstructionsByDisplaySku; const result = productCareAndPrintAreaContentComponent .getCareInstructionsAsArray; expect(result).toEqual( Object.entries(mockCareInstructionsByDisplaySku), ); }); }); describe('changeSelectedUnitsOfMeasure', () => { const initGetShowContentData = () => { const productCareAndPrintAreaContentComponent = initProductCareAndPrintAreaContentComponent(); productCareAndPrintAreaContentComponent.onChangeUnitsOfMeasure.emit = jest.fn(); return { productCareAndPrintAreaContentComponent, }; }; // tslint:disable-next-line test('Calls onChangeUnitsOfMeasure.emit with the supplied unit value', () => { const { productCareAndPrintAreaContentComponent, } = initGetShowContentData(); productCareAndPrintAreaContentComponent.changeSelectedUnitsOfMeasure( 'cm', ); expect( productCareAndPrintAreaContentComponent.onChangeUnitsOfMeasure.emit, ) .toHaveBeenCalledWith('cm'); }); }); describe('isBrandTitleVisible', () => { test('Returns true if there are 2 display skus', () => { const productCareAndPrintAreaContentComponent = initProductCareAndPrintAreaContentComponent(); productCareAndPrintAreaContentComponent.careInstructionsByDisplaySku = { first: '1', second: '2', }; expect( productCareAndPrintAreaContentComponent.isBrandTitleVisible(), ).toBe(true); }); test('Returns false if there is only 1 display skus', () => { const productCareAndPrintAreaContentComponent = initProductCareAndPrintAreaContentComponent(); productCareAndPrintAreaContentComponent.careInstructionsByDisplaySku = { first: '1', }; expect( productCareAndPrintAreaContentComponent.isBrandTitleVisible(), ).toBe(false); }); });