import 'reflect-metadata'; import { CarouselSelectorWithAddComponent, } from './carousel-selector-with-add.component'; const initCarouselSelectorWithAddComponent = () => { return new CarouselSelectorWithAddComponent(); }; describe('itemSelected', () => { test('Emits an id to onItemSelected', () => { const carouselSelectorWithAddComponent = initCarouselSelectorWithAddComponent(); carouselSelectorWithAddComponent.onItemSelected.emit = jest.fn(); carouselSelectorWithAddComponent.itemSelected('10'); expect(carouselSelectorWithAddComponent.onItemSelected.emit) .toHaveBeenCalledWith('10'); }); }); describe('addClicked', () => { test('Emits an id to onAddClicked', () => { const carouselSelectorWithAddComponent = initCarouselSelectorWithAddComponent(); carouselSelectorWithAddComponent.onAddClicked.emit = jest.fn(); carouselSelectorWithAddComponent.addClicked(); expect(carouselSelectorWithAddComponent.onAddClicked.emit) .toHaveBeenCalled(); }); }); describe('hasLessThanTwoItems', () => { test('Returns true if ids has a length of 1', () => { const carouselSelectorWithAddComponent = initCarouselSelectorWithAddComponent(); carouselSelectorWithAddComponent.ids = ['1']; const result = carouselSelectorWithAddComponent.hasLessThanTwoItems(); expect(result).toBe(true); }); test('Returns false if ids has a length of 2', () => { const carouselSelectorWithAddComponent = initCarouselSelectorWithAddComponent(); carouselSelectorWithAddComponent.ids = ['1', '2']; const result = carouselSelectorWithAddComponent.hasLessThanTwoItems(); expect(result).toBe(false); }); }); describe('getText', () => { test('Returns lessThanTwoItemsText if there is a single item', () => { const carouselSelectorWithAddComponent = initCarouselSelectorWithAddComponent(); carouselSelectorWithAddComponent.ids = ['1']; carouselSelectorWithAddComponent.lessThanTwoItemsText = 'lessThanTwo'; const text = carouselSelectorWithAddComponent.getText(); expect(text).toBe('lessThanTwo'); }); test('Returns noItemsText if there is a single item', () => { const carouselSelectorWithAddComponent = initCarouselSelectorWithAddComponent(); carouselSelectorWithAddComponent.ids = []; carouselSelectorWithAddComponent.noItemsText = 'noItems'; const text = carouselSelectorWithAddComponent.getText(); expect(text).toBe('noItems'); }); });