import 'reflect-metadata'; import { ImageSelectorListComponent, } from './image-selector-list.component'; import { ImageSelectorListOptionInterface, } from '../../models'; const initImageSelectorListComponent = () => new ImageSelectorListComponent(); describe('selectImage', () => { test('Emits event with supplied source if selected is not the same source', () => { const mockSource = { src: 'bar', }; const imageSelectorListComponent = initImageSelectorListComponent(); imageSelectorListComponent.onSelected.emit = jest.fn() .mockReturnValue(mockSource); imageSelectorListComponent.selectedSrc = 'foo'; imageSelectorListComponent.selectImage(mockSource); expect(imageSelectorListComponent.onSelected.emit) .toHaveBeenCalledWith(mockSource.src); }, ); test('Does not emit event when supplied source is the same as selected', () => { const mockSource = 'foo'; const imageSelectorListComponent = initImageSelectorListComponent(); imageSelectorListComponent.onSelected.emit = jest.fn() .mockReturnValue(mockSource); imageSelectorListComponent.selectedSrc = mockSource; imageSelectorListComponent.selectImage({ src: 'foo', }); expect(imageSelectorListComponent.onSelected.emit) .not.toHaveBeenCalled(); }, ); }); describe('isSelected', () => { // tslint:disable-next-line test('Returns true if selectedSrc is the same as the src of the argument', () => { const imageSelectorListComponent = initImageSelectorListComponent(); imageSelectorListComponent.selectedSrc = 'test'; const isSelected = imageSelectorListComponent.isSelected({ src: 'test', }); expect(isSelected).toBe(true); }); // tslint:disable-next-line test('Returns false if selectedSrc is different from the src of the argument', () => { const imageSelectorListComponent = initImageSelectorListComponent(); imageSelectorListComponent.selectedSrc = 'other'; const isSelected = imageSelectorListComponent.isSelected({ src: 'test', }); expect(isSelected).toBe(false); }); }); describe('trackBySrc', () => { test('Gets the src from the argument', () => { const imageSelectorListComponent = initImageSelectorListComponent(); const src = imageSelectorListComponent.trackBySrc({ src: 'test', } as ImageSelectorListOptionInterface); expect(src).toBe('test'); }); });