import 'reflect-metadata'; import { ProductSizesContentComponent, } from './product-sizes-content.component'; const initProductSizesContentComponent = () => new ProductSizesContentComponent(); describe('get showContent', () => { const initShowContentData = () => { const mockProductDisplaySkus = new Map([ ['Foo (shipped from UK)', true], ['Bar (shipped from US)', false], ]); const mockUnitsOfMeasure = ['inch', 'cm']; const mockApparelSizeChartSku = new Map( [ ['Bar (shipped from US)', []], ['Foo (shipped from UK)', []], ], ); const productSizeContentComponent = initProductSizesContentComponent(); return { mockApparelSizeChartSku, mockProductDisplaySkus, mockUnitsOfMeasure, productSizeContentComponent, }; }; // tslint:disable-next-line test('Returns true if there are product skus and size chart content supplied', () => { const { mockProductDisplaySkus, mockApparelSizeChartSku, productSizeContentComponent, } = initShowContentData(); productSizeContentComponent.productDisplaySkus = mockProductDisplaySkus; productSizeContentComponent.apparelSizeChart = mockApparelSizeChartSku; const result = productSizeContentComponent.showContent; expect(result).toBe(true); }); test('Returns false if there are no product skus supplied', () => { const { mockApparelSizeChartSku, productSizeContentComponent, } = initShowContentData(); productSizeContentComponent.productDisplaySkus = undefined; productSizeContentComponent.apparelSizeChart = mockApparelSizeChartSku; const result = productSizeContentComponent.showContent; expect(result).toBe(false); }); test('Returns false if no sizechart content is supplied', () => { const { mockProductDisplaySkus, productSizeContentComponent, } = initShowContentData(); productSizeContentComponent.productDisplaySkus = mockProductDisplaySkus; productSizeContentComponent.apparelSizeChart = undefined; const result = productSizeContentComponent.showContent; expect(result).toBe(false); }); }); describe('get getApparelSizeChartAsArray', () => { const initGetApparelSizeChartAsArrayData = () => { const mockApparelSizeChartSku = new Map( [ ['Bar (shipped from US)', []], ['Foo (shipped from UK)', []], ], ); const productSizeContentComponent = initProductSizesContentComponent(); return { mockApparelSizeChartSku, productSizeContentComponent, }; }; // tslint:disable-next-line test('Returns an array from the apparelSizeChart map', () => { const { mockApparelSizeChartSku, productSizeContentComponent, } = initGetApparelSizeChartAsArrayData(); productSizeContentComponent.apparelSizeChart = mockApparelSizeChartSku; const result = productSizeContentComponent.getApparelSizeChartAsArray; expect(result).toEqual(Array.from(mockApparelSizeChartSku)); }); }); describe('get productDisplaySkuAsOptions', () => { // tslint:disable-next-line test('Returns the components shippingCountries input as dropdown options', () => { const mockDisplaySkus = new Map( [ ['T Shirt 1', false], ['T Shirt 2', true], ], ); const productSizesComponent = initProductSizesContentComponent(); productSizesComponent.productDisplaySkus = mockDisplaySkus; const result = productSizesComponent.productDisplaySkuAsOptions; expect(result).toEqual([{ label: 'T Shirt 1', value: 'T Shirt 1', }, { label: 'T Shirt 2', value: 'T Shirt 2', }]); }); }); describe('shippingCountriesOptionsSelectedValue', () => { // tslint:disable-next-line test('Gets the first value from the productDisplaySkus which is true', () => { const mockDisplaySkus = new Map( [ ['T Shirt 1', false], ['T Shirt 2', true], ['T Shirt 3', true], ], ); const productSizesComponent = initProductSizesContentComponent(); productSizesComponent.productDisplaySkus = mockDisplaySkus; const result = productSizesComponent .productDisplaySkuOptionsSelectedValue; expect(result).toBe('T Shirt 2'); }); }); describe('get getUnitsOfMeasureAsArray', () => { const initGetUnitsOfMeasureAsArrayData = () => { const mockUnitsOfMeasure = new Map([ ['inch', true], ['cm', false], ]); const productSizeContentComponent = initProductSizesContentComponent(); return { mockUnitsOfMeasure, productSizeContentComponent, }; }; // tslint:disable-next-line test('Returns an array from the unitsOfMeasure map', () => { const { mockUnitsOfMeasure, productSizeContentComponent, } = initGetUnitsOfMeasureAsArrayData(); productSizeContentComponent.unitsOfMeasure = mockUnitsOfMeasure; const result = productSizeContentComponent.getUnitsOfMeasureAsArray; expect(result).toEqual(Array.from(mockUnitsOfMeasure)); }); }); describe('changeSelectedUnitsOfMeasure', () => { const initChangeSelectedUnitsOfMeasureData = () => { const productSizeContentComponent = initProductSizesContentComponent(); productSizeContentComponent.onChangeSelectedUnitsOfMeasure.emit = jest.fn(); return { productSizeContentComponent, }; }; // tslint:disable-next-line test('Calls onChangeSelectedUnitsOfMeasure.emit with the supplied units of measure', () => { const { productSizeContentComponent, } = initChangeSelectedUnitsOfMeasureData(); productSizeContentComponent.changeSelectedUnitsOfMeasure('cm'); expect(productSizeContentComponent.onChangeSelectedUnitsOfMeasure.emit) .toHaveBeenCalledWith('cm'); }); }); describe('changeSelectedDisplaySku', () => { const initChangeSelectedUnitsOfMeasureData = () => { const productSizeContentComponent = initProductSizesContentComponent(); productSizeContentComponent.onChangeSelectedDisplaySku.emit = jest.fn(); return { productSizeContentComponent, }; }; // tslint:disable-next-line test('Calls onChangeSelectedDisplaySku.emit with the supplied display sku', () => { const { productSizeContentComponent, } = initChangeSelectedUnitsOfMeasureData(); productSizeContentComponent.changeSelectedDisplaySku('Foo'); expect(productSizeContentComponent.onChangeSelectedDisplaySku.emit) .toHaveBeenCalledWith('Foo'); }); }); describe('isChangeSkuSelectVisible', () => { test('Returns true if there are 2 productDisplaySkus', () => { const productSizeContentComponent = initProductSizesContentComponent(); productSizeContentComponent.productDisplaySkus = new Map([['a', true], ['b', false]]); const result = productSizeContentComponent.isChangeSkuSelectVisible(); expect(result).toBe(true); }); test('Returns false if there is a single productDisplaySkus', () => { const productSizeContentComponent = initProductSizesContentComponent(); productSizeContentComponent.productDisplaySkus = new Map([['a', true]]); const result = productSizeContentComponent.isChangeSkuSelectVisible(); expect(result).toBe(false); }); });