diff --git a/sources/HUBCollectionViewFactory.h b/sources/HUBCollectionViewFactory.h index 1798c604..dac0f3a2 100644 --- a/sources/HUBCollectionViewFactory.h +++ b/sources/HUBCollectionViewFactory.h @@ -19,7 +19,11 @@ * under the License. */ -#import +#import +#import "HUBHeaderMacros.h" + +@protocol HUBComponentLayoutManager; +@protocol HUBComponentRegistry; @class HUBCollectionView; @@ -28,6 +32,15 @@ NS_ASSUME_NONNULL_BEGIN /// Factory used to create collection views for use in a `HUBViewController` @interface HUBCollectionViewFactory : NSObject +/** + Designated initializer. + + @param componentRegistry The registry to use to lookup component information + @param componentLayoutManager The object that manages layout for components in the view controller + */ +- (instancetype)initWithComponentRegistry:(id)componentRegistry + componentLayoutManager:(id)componentLayoutManager HUB_DESIGNATED_INITIALIZER; + /// Create a collection view. It will be setup with a default layout. - (HUBCollectionView *)createCollectionView; diff --git a/sources/HUBCollectionViewFactory.m b/sources/HUBCollectionViewFactory.m index b4489eb0..4017a223 100644 --- a/sources/HUBCollectionViewFactory.m +++ b/sources/HUBCollectionViewFactory.m @@ -20,16 +20,42 @@ */ #import "HUBCollectionViewFactory.h" + #import "HUBCollectionView.h" +#import "HUBCollectionViewLayout.h" NS_ASSUME_NONNULL_BEGIN +@interface HUBCollectionViewFactory () + +@property (nonatomic, strong, readonly) id componentRegistry; +@property (nonatomic, strong, readonly) id componentLayoutManager; + +@end + @implementation HUBCollectionViewFactory +- (instancetype)initWithComponentRegistry:(id)componentRegistry + componentLayoutManager:(id)componentLayoutManager +{ + NSParameterAssert(componentRegistry != nil); + NSParameterAssert(componentLayoutManager != nil); + + self = [super init]; + if (self) { + _componentRegistry = componentRegistry; + _componentLayoutManager = componentLayoutManager; + } + return self; +} + - (HUBCollectionView *)createCollectionView { + HUBCollectionViewLayout *collectionViewLayout = [[HUBCollectionViewLayout alloc] initWithComponentRegistry:self.componentRegistry + componentLayoutManager:self.componentLayoutManager]; + HUBCollectionView *collectionView = [[HUBCollectionView alloc] initWithFrame:CGRectZero - collectionViewLayout:[UICollectionViewLayout new]]; + collectionViewLayout:collectionViewLayout]; collectionView.accessibilityIdentifier = @"collectionView"; return collectionView; diff --git a/sources/HUBConfigViewControllerFactory.m b/sources/HUBConfigViewControllerFactory.m index eb4d908b..26413856 100644 --- a/sources/HUBConfigViewControllerFactory.m +++ b/sources/HUBConfigViewControllerFactory.m @@ -58,7 +58,8 @@ - (HUBViewController *)createViewControllerWithConfig:(HUBConfig *)config HUBViewModelRenderer * const viewModelRenderer = [HUBViewModelRenderer new]; - HUBCollectionViewFactory * const collectionViewFactory = [HUBCollectionViewFactory new]; + HUBCollectionViewFactory * const collectionViewFactory = [[HUBCollectionViewFactory alloc] initWithComponentRegistry:config.componentRegistry + componentLayoutManager:config.componentLayoutManager]; HUBComponentReusePool * const componentReusePool = [[HUBComponentReusePool alloc] initWithComponentRegistry:config.componentRegistry]; id const actionHandlerWrapper = [[HUBActionHandlerWrapper alloc] initWithActionHandler:actionHandler @@ -74,9 +75,7 @@ - (HUBViewController *)createViewControllerWithConfig:(HUBConfig *)config viewModelLoader:viewModelLoader viewModelRenderer:viewModelRenderer collectionViewFactory:collectionViewFactory - componentRegistry:config.componentRegistry componentReusePool:componentReusePool - componentLayoutManager:config.componentLayoutManager actionHandler:actionHandlerWrapper scrollHandler:scrollHandlerToUse imageLoader:imageLoader]; diff --git a/sources/HUBViewControllerExperimentalImplementation.h b/sources/HUBViewControllerExperimentalImplementation.h index 1ee96b6d..15119866 100644 --- a/sources/HUBViewControllerExperimentalImplementation.h +++ b/sources/HUBViewControllerExperimentalImplementation.h @@ -22,8 +22,6 @@ #import "HUBViewController.h" @protocol HUBFeatureInfo; -@protocol HUBComponentRegistry; -@protocol HUBComponentLayoutManager; @protocol HUBActionHandler; @protocol HUBViewControllerScrollHandler; @protocol HUBImageLoader; @@ -43,9 +41,7 @@ NS_ASSUME_NONNULL_BEGIN * @param featureInfo Information about the feature that the view controller is for * @param viewModelLoader The object to use to load view models for the view controller * @param collectionViewFactory The factory to use to create collection views - * @param componentRegistry The registry to use to lookup component information * @param componentReusePool The reuse pool to use to manage component wrappers - * @param componentLayoutManager The object that manages layout for components in the view controller * @param actionHandler The object that will handle actions for this view controller * @param scrollHandler The object that will handle scrolling for the view controller * @param imageLoader The loader to use to load images for components @@ -54,9 +50,7 @@ NS_ASSUME_NONNULL_BEGIN featureInfo:(id)featureInfo viewModelLoader:(id)viewModelLoader collectionViewFactory:(HUBCollectionViewFactory *)collectionViewFactory - componentRegistry:(id)componentRegistry componentReusePool:(HUBComponentReusePool *)componentReusePool - componentLayoutManager:(id)componentLayoutManager actionHandler:(id)actionHandler scrollHandler:(id)scrollHandler imageLoader:(id)imageLoader NS_DESIGNATED_INITIALIZER; diff --git a/sources/HUBViewControllerExperimentalImplementation.m b/sources/HUBViewControllerExperimentalImplementation.m index 53bc149e..627231ea 100644 --- a/sources/HUBViewControllerExperimentalImplementation.m +++ b/sources/HUBViewControllerExperimentalImplementation.m @@ -33,7 +33,6 @@ #import "HUBComponentViewObserver.h" #import "HUBComponentWrapper.h" #import "HUBComponentWrapperImageLoader.h" -#import "HUBComponentRegistry.h" #import "HUBComponentCollectionViewCell.h" #import "HUBUtilities.h" #import "HUBCollectionViewFactory.h" @@ -62,9 +61,7 @@ @interface HUBViewControllerExperimentalImplementation () < @property (nonatomic, strong, readonly) id featureInfo; @property (nonatomic, strong, readonly) id viewModelLoader; @property (nonatomic, strong, readonly) HUBCollectionViewFactory *collectionViewFactory; -@property (nonatomic, strong, readonly) id componentRegistry; @property (nonatomic, strong, readonly) HUBComponentReusePool *componentReusePool; -@property (nonatomic, strong, readonly) id componentLayoutManager; @property (nonatomic, strong, readonly) id actionHandler; @property (nonatomic, strong, readonly) id scrollHandler; @property (nonatomic, strong, nullable, readonly) id contentReloadPolicy; @@ -101,9 +98,7 @@ - (instancetype)initWithViewURI:(NSURL *)viewURI featureInfo:(id)featureInfo viewModelLoader:(id)viewModelLoader collectionViewFactory:(HUBCollectionViewFactory *)collectionViewFactory - componentRegistry:(id)componentRegistry componentReusePool:(HUBComponentReusePool *)componentReusePool - componentLayoutManager:(id)componentLayoutManager actionHandler:(id)actionHandler scrollHandler:(id)scrollHandler imageLoader:(id)imageLoader @@ -112,9 +107,7 @@ - (instancetype)initWithViewURI:(NSURL *)viewURI NSParameterAssert(featureInfo != nil); NSParameterAssert(viewModelLoader != nil); NSParameterAssert(collectionViewFactory != nil); - NSParameterAssert(componentRegistry != nil); NSParameterAssert(componentReusePool != nil); - NSParameterAssert(componentLayoutManager != nil); NSParameterAssert(actionHandler != nil); NSParameterAssert(scrollHandler != nil); NSParameterAssert(imageLoader != nil); @@ -127,9 +120,7 @@ - (instancetype)initWithViewURI:(NSURL *)viewURI _featureInfo = featureInfo; _viewModelLoader = viewModelLoader; _collectionViewFactory = collectionViewFactory; - _componentRegistry = componentRegistry; _componentReusePool = componentReusePool; - _componentLayoutManager = componentLayoutManager; _actionHandler = actionHandler; _scrollHandler = scrollHandler; _componentWrapperImageLoader = [[HUBComponentWrapperImageLoader alloc] initWithImageLoader:imageLoader]; @@ -893,11 +884,6 @@ - (HUBOperation *)createReloadCollectionViewOperation return; } - if (![self.collectionView.collectionViewLayout isKindOfClass:[HUBCollectionViewLayout class]]) { - self.collectionView.collectionViewLayout = [[HUBCollectionViewLayout alloc] initWithComponentRegistry:self.componentRegistry - componentLayoutManager:self.componentLayoutManager]; - } - [self saveStatesForVisibleComponents]; [self configureHeaderComponent]; [self configureOverlayComponents]; diff --git a/sources/HUBViewControllerFactoryImplementation.m b/sources/HUBViewControllerFactoryImplementation.m index 37da9555..951d82cb 100644 --- a/sources/HUBViewControllerFactoryImplementation.m +++ b/sources/HUBViewControllerFactoryImplementation.m @@ -166,7 +166,8 @@ - (HUBViewController *)createStandardViewControllerForViewURI:(NSURL *)viewURI HUBViewModelRenderer * const viewModelRenderer = [HUBViewModelRenderer new]; id const imageLoader = [self.imageLoaderFactory createImageLoader]; - HUBCollectionViewFactory * const collectionViewFactory = [HUBCollectionViewFactory new]; + HUBCollectionViewFactory * const collectionViewFactory = [[HUBCollectionViewFactory alloc] initWithComponentRegistry:self.componentRegistry + componentLayoutManager:self.componentLayoutManager]; HUBComponentReusePool * const componentReusePool = [[HUBComponentReusePool alloc] initWithComponentRegistry:self.componentRegistry]; id const actionHandler = featureRegistration.actionHandler ?: self.defaultActionHandler; @@ -182,9 +183,7 @@ - (HUBViewController *)createStandardViewControllerForViewURI:(NSURL *)viewURI viewModelLoader:viewModelLoader viewModelRenderer:viewModelRenderer collectionViewFactory:collectionViewFactory - componentRegistry:self.componentRegistry componentReusePool:componentReusePool - componentLayoutManager:self.componentLayoutManager actionHandler:actionHandlerWrapper scrollHandler:scrollHandlerToUse imageLoader:imageLoader]; @@ -200,7 +199,8 @@ - (HUBViewController *)createExperimentalViewControllerForViewURI:(NSURL *)viewU featureRegistration:featureRegistration]; id const imageLoader = [self.imageLoaderFactory createImageLoader]; - HUBCollectionViewFactory * const collectionViewFactory = [HUBCollectionViewFactory new]; + HUBCollectionViewFactory * const collectionViewFactory = [[HUBCollectionViewFactory alloc] initWithComponentRegistry:self.componentRegistry + componentLayoutManager:self.componentLayoutManager]; HUBComponentReusePool * const componentReusePool = [[HUBComponentReusePool alloc] initWithComponentRegistry:self.componentRegistry]; id const actionHandler = featureRegistration.actionHandler ?: self.defaultActionHandler; @@ -215,9 +215,7 @@ - (HUBViewController *)createExperimentalViewControllerForViewURI:(NSURL *)viewU featureInfo:featureInfo viewModelLoader:viewModelLoader collectionViewFactory:collectionViewFactory - componentRegistry:self.componentRegistry componentReusePool:componentReusePool - componentLayoutManager:self.componentLayoutManager actionHandler:actionHandlerWrapper scrollHandler:scrollHandlerToUse imageLoader:imageLoader]; diff --git a/sources/HUBViewControllerImplementation.h b/sources/HUBViewControllerImplementation.h index effa15f3..ae5ed70a 100644 --- a/sources/HUBViewControllerImplementation.h +++ b/sources/HUBViewControllerImplementation.h @@ -22,8 +22,6 @@ #import "HUBViewController.h" @protocol HUBFeatureInfo; -@protocol HUBComponentRegistry; -@protocol HUBComponentLayoutManager; @protocol HUBActionHandler; @protocol HUBViewControllerScrollHandler; @protocol HUBImageLoader; @@ -45,9 +43,7 @@ NS_ASSUME_NONNULL_BEGIN * @param viewModelLoader The object to use to load view models for the view controller * @param viewModelRenderer The object used to render the view model * @param collectionViewFactory The factory to use to create collection views - * @param componentRegistry The registry to use to lookup component information * @param componentReusePool The reuse pool to use to manage component wrappers - * @param componentLayoutManager The object that manages layout for components in the view controller * @param actionHandler The object that will handle actions for this view controller * @param scrollHandler The object that will handle scrolling for the view controller * @param imageLoader The loader to use to load images for components @@ -57,9 +53,7 @@ NS_ASSUME_NONNULL_BEGIN viewModelLoader:(id)viewModelLoader viewModelRenderer:(HUBViewModelRenderer *)viewModelRenderer collectionViewFactory:(HUBCollectionViewFactory *)collectionViewFactory - componentRegistry:(id)componentRegistry componentReusePool:(HUBComponentReusePool *)componentReusePool - componentLayoutManager:(id)componentLayoutManager actionHandler:(id)actionHandler scrollHandler:(id)scrollHandler imageLoader:(id)imageLoader NS_DESIGNATED_INITIALIZER; diff --git a/sources/HUBViewControllerImplementation.m b/sources/HUBViewControllerImplementation.m index 2db13f19..d320bbf1 100644 --- a/sources/HUBViewControllerImplementation.m +++ b/sources/HUBViewControllerImplementation.m @@ -33,7 +33,6 @@ #import "HUBComponentViewObserver.h" #import "HUBComponentWrapper.h" #import "HUBComponentWrapperImageLoader.h" -#import "HUBComponentRegistry.h" #import "HUBComponentCollectionViewCell.h" #import "HUBUtilities.h" #import "HUBCollectionViewFactory.h" @@ -62,9 +61,7 @@ @interface HUBViewControllerImplementation () < @property (nonatomic, strong, readonly) id featureInfo; @property (nonatomic, strong, readonly) id viewModelLoader; @property (nonatomic, strong, readonly) HUBCollectionViewFactory *collectionViewFactory; -@property (nonatomic, strong, readonly) id componentRegistry; @property (nonatomic, strong, readonly) HUBComponentReusePool *componentReusePool; -@property (nonatomic, strong, readonly) id componentLayoutManager; @property (nonatomic, strong, readonly) id actionHandler; @property (nonatomic, strong, readonly) id scrollHandler; @property (nonatomic, strong, nullable, readonly) id contentReloadPolicy; @@ -103,9 +100,7 @@ - (instancetype)initWithViewURI:(NSURL *)viewURI viewModelLoader:(id)viewModelLoader viewModelRenderer:(HUBViewModelRenderer *)viewModelRenderer collectionViewFactory:(HUBCollectionViewFactory *)collectionViewFactory - componentRegistry:(id)componentRegistry componentReusePool:(HUBComponentReusePool *)componentReusePool - componentLayoutManager:(id)componentLayoutManager actionHandler:(id)actionHandler scrollHandler:(id)scrollHandler imageLoader:(id)imageLoader @@ -115,9 +110,7 @@ - (instancetype)initWithViewURI:(NSURL *)viewURI NSParameterAssert(viewModelLoader != nil); NSParameterAssert(viewModelRenderer != nil); NSParameterAssert(collectionViewFactory != nil); - NSParameterAssert(componentRegistry != nil); NSParameterAssert(componentReusePool != nil); - NSParameterAssert(componentLayoutManager != nil); NSParameterAssert(actionHandler != nil); NSParameterAssert(scrollHandler != nil); NSParameterAssert(imageLoader != nil); @@ -131,9 +124,7 @@ - (instancetype)initWithViewURI:(NSURL *)viewURI _viewModelLoader = viewModelLoader; _viewModelRenderer = viewModelRenderer; _collectionViewFactory = collectionViewFactory; - _componentRegistry = componentRegistry; _componentReusePool = componentReusePool; - _componentLayoutManager = componentLayoutManager; _actionHandler = actionHandler; _scrollHandler = scrollHandler; _componentWrapperImageLoader = [[HUBComponentWrapperImageLoader alloc] initWithImageLoader:imageLoader]; @@ -855,11 +846,6 @@ - (HUBOperation *)createReloadCollectionViewOperation return; } - if (![self.collectionView.collectionViewLayout isKindOfClass:[HUBCollectionViewLayout class]]) { - self.collectionView.collectionViewLayout = [[HUBCollectionViewLayout alloc] initWithComponentRegistry:self.componentRegistry - componentLayoutManager:self.componentLayoutManager]; - } - [self saveStatesForVisibleComponents]; [self configureHeaderComponent]; [self configureOverlayComponents]; diff --git a/tests/HUBCollectionViewFactoryTests.m b/tests/HUBCollectionViewFactoryTests.m index b7d40d36..93fe63bb 100644 --- a/tests/HUBCollectionViewFactoryTests.m +++ b/tests/HUBCollectionViewFactoryTests.m @@ -23,34 +23,51 @@ #import "HUBCollectionViewFactory.h" #import "HUBCollectionView.h" +#import "HUBComponentLayoutManagerMock.h" +#import "HUBComponentRegistryMock.h" @interface HUBCollectionViewFactoryTests : XCTestCase +@property (nonatomic, strong) HUBCollectionViewFactory *factory; + @end @implementation HUBCollectionViewFactoryTests +- (void)setUp +{ + [super setUp]; + + self.factory = [[HUBCollectionViewFactory alloc] initWithComponentRegistry:[HUBComponentRegistryMock new] + componentLayoutManager:[HUBComponentLayoutManagerMock new]]; + +} + +- (void)tearDown +{ + self.factory = nil; + + [super tearDown]; +} + - (void)testThatTheFactoryCreatesNonNilInstances { - HUBCollectionViewFactory *factory = [HUBCollectionViewFactory new]; - HUBCollectionView *collectionView = [factory createCollectionView]; + HUBCollectionView *collectionView = [self.factory createCollectionView]; XCTAssertNotNil(collectionView); } - (void)testThatTheCollectionViewHasAccessibilityId { - HUBCollectionViewFactory *factory = [HUBCollectionViewFactory new]; - HUBCollectionView *collectionView = [factory createCollectionView]; + HUBCollectionView *collectionView = [self.factory createCollectionView]; XCTAssertNotNil(collectionView.accessibilityIdentifier); } - (void)testThatTheFactoryCreatesNewCollectionViewInstances { - HUBCollectionViewFactory *factory = [HUBCollectionViewFactory new]; - HUBCollectionView *collectionView1 = [factory createCollectionView]; - HUBCollectionView *collectionView2 = [factory createCollectionView]; + HUBCollectionView *collectionView1 = [self.factory createCollectionView]; + HUBCollectionView *collectionView2 = [self.factory createCollectionView]; XCTAssertNotEqual(collectionView1, collectionView2); } diff --git a/tests/HUBViewControllerImplementationTests.m b/tests/HUBViewControllerImplementationTests.m index ec8fecbb..aa751cf1 100644 --- a/tests/HUBViewControllerImplementationTests.m +++ b/tests/HUBViewControllerImplementationTests.m @@ -43,7 +43,7 @@ #import "HUBComponentWrapper.h" #import "HUBCollectionViewFactoryMock.h" #import "HUBCollectionViewMock.h" -#import "HUBComponentLayoutManagerMock.h" +#import "HUBCollectionViewLayoutMock.h" #import "HUBActionHandlerMock.h" #import "HUBInitialViewModelRegistry.h" #import "HUBActionRegistryImplementation.h" @@ -135,9 +135,11 @@ - (void)setUp self.component = [HUBComponentMock new]; self.componentFactory = [[HUBComponentFactoryMock alloc] initWithComponents:@{componentDefaults.componentName: self.component}]; [self.componentRegistry registerComponentFactory:self.componentFactory forNamespace:componentDefaults.componentNamespace]; - - self.collectionView = [HUBCollectionViewMock new]; - self.collectionViewFactory = [[HUBCollectionViewFactoryMock alloc] initWithCollectionView:self.collectionView]; + + HUBCollectionViewLayoutMock *layout = [[HUBCollectionViewLayoutMock alloc] initWithComponentRegistry:self.componentRegistry]; + self.collectionView = [[HUBCollectionViewMock alloc] initWithCollectionViewLayout:layout]; + self.collectionViewFactory = [[HUBCollectionViewFactoryMock alloc] initWithCollectionView:self.collectionView + componentRegistry:self.componentRegistry]; self.viewURI = [NSURL URLWithString:@"spotify:hub:framework"]; self.featureInfo = [[HUBFeatureInfoImplementation alloc] initWithIdentifier:@"id" title:@"title"]; @@ -218,7 +220,6 @@ - (void)tearDown - (void)createViewControllerWithViewModelRenderer:(HUBViewModelRenderer *)viewModelRenderer { - id const componentLayoutManager = [HUBComponentLayoutManagerMock new]; id const actionHandler = [[HUBActionHandlerWrapper alloc] initWithActionHandler:self.actionHandler actionRegistry:self.actionRegistry initialViewModelRegistry:self.initialViewModelRegistry @@ -229,9 +230,7 @@ - (void)createViewControllerWithViewModelRenderer:(HUBViewModelRenderer *)viewMo viewModelLoader:self.viewModelLoader viewModelRenderer:viewModelRenderer collectionViewFactory:self.collectionViewFactory - componentRegistry:self.componentRegistry componentReusePool:self.componentReusePool - componentLayoutManager:componentLayoutManager actionHandler:actionHandler scrollHandler:self.scrollHandler imageLoader:self.imageLoader]; diff --git a/tests/HUBViewModelRendererTests.m b/tests/HUBViewModelRendererTests.m index 6c738292..40124d5c 100644 --- a/tests/HUBViewModelRendererTests.m +++ b/tests/HUBViewModelRendererTests.m @@ -24,6 +24,7 @@ #import "HUBCollectionViewLayoutMock.h" #import "HUBCollectionViewMock.h" #import "HUBComponentLayoutManagerMock.h" +#import "HUBComponentRegistryMock.h" #import "HUBViewModelDiff.h" #import "HUBViewModelRenderer.h" #import "HUBViewModelUtilities.h" @@ -69,8 +70,8 @@ - (void)setUp { [super setUp]; - self.collectionView = [HUBCollectionViewMockWithoutBatchUpdates new]; - self.collectionViewLayout = [[HUBCollectionViewLayoutMock alloc] init]; + self.collectionViewLayout = [[HUBCollectionViewLayoutMock alloc] initWithComponentRegistry:[HUBComponentRegistryMock new]]; + self.collectionView = [[HUBCollectionViewMockWithoutBatchUpdates alloc] initWithCollectionViewLayout:self.collectionViewLayout]; self.collectionView.collectionViewLayout = self.collectionViewLayout; self.viewModelRenderer = [HUBViewModelRenderer new]; } diff --git a/tests/mocks/HUBCollectionViewFactoryMock.h b/tests/mocks/HUBCollectionViewFactoryMock.h index 577f08ca..0547812f 100644 --- a/tests/mocks/HUBCollectionViewFactoryMock.h +++ b/tests/mocks/HUBCollectionViewFactoryMock.h @@ -32,7 +32,11 @@ NS_ASSUME_NONNULL_BEGIN * * @param collectionView A collection view that this factory will always create */ -- (instancetype)initWithCollectionView:(HUBCollectionView *)collectionView HUB_DESIGNATED_INITIALIZER; +- (instancetype)initWithCollectionView:(HUBCollectionView *)collectionView + componentRegistry:(id)componentRegistry HUB_DESIGNATED_INITIALIZER; + +- (instancetype)initWithComponentRegistry:(id)componentRegistry + componentLayoutManager:(id)componentLayoutManager NS_UNAVAILABLE; @end diff --git a/tests/mocks/HUBCollectionViewFactoryMock.m b/tests/mocks/HUBCollectionViewFactoryMock.m index c4180f23..6a907dfb 100644 --- a/tests/mocks/HUBCollectionViewFactoryMock.m +++ b/tests/mocks/HUBCollectionViewFactoryMock.m @@ -21,6 +21,9 @@ #import "HUBCollectionViewFactoryMock.h" +#import "HUBComponentLayoutManagerMock.h" +#import "HUBComponentRegistryMock.h" + NS_ASSUME_NONNULL_BEGIN @interface HUBCollectionViewFactoryMock () @@ -32,8 +35,10 @@ @interface HUBCollectionViewFactoryMock () @implementation HUBCollectionViewFactoryMock - (instancetype)initWithCollectionView:(HUBCollectionView *)collectionView + componentRegistry:(id)componentRegistry { - self = [super init]; + self = [super initWithComponentRegistry:componentRegistry + componentLayoutManager:[HUBComponentLayoutManagerMock new]]; if (self) { _collectionView = collectionView; diff --git a/tests/mocks/HUBCollectionViewLayoutMock.h b/tests/mocks/HUBCollectionViewLayoutMock.h index 36205848..d92002f2 100644 --- a/tests/mocks/HUBCollectionViewLayoutMock.h +++ b/tests/mocks/HUBCollectionViewLayoutMock.h @@ -30,8 +30,7 @@ NS_ASSUME_NONNULL_BEGIN */ @interface HUBCollectionViewLayoutMock : HUBCollectionViewLayout -/// Default constructor takes no arguments. -- (instancetype)init; +- (instancetype)initWithComponentRegistry:(id)componentRegistry; /** * Returns the number of times that computeForCollectionViewSize:viewModel:diff:addHeaderMargin: was called. diff --git a/tests/mocks/HUBCollectionViewLayoutMock.m b/tests/mocks/HUBCollectionViewLayoutMock.m index dcc4808a..78315f44 100644 --- a/tests/mocks/HUBCollectionViewLayoutMock.m +++ b/tests/mocks/HUBCollectionViewLayoutMock.m @@ -22,7 +22,6 @@ #import "HUBCollectionViewLayoutMock.h" #import "HUBComponentLayoutManagerMock.h" -#import "HUBComponentRegistryMock.h" NS_ASSUME_NONNULL_BEGIN @@ -35,9 +34,9 @@ @interface HUBCollectionViewLayoutMock () @implementation HUBCollectionViewLayoutMock -- (instancetype)init +- (instancetype)initWithComponentRegistry:(id)componentRegistry { - self = [super initWithComponentRegistry:[HUBComponentRegistryMock new] componentLayoutManager:[HUBComponentLayoutManagerMock new]]; + self = [super initWithComponentRegistry:componentRegistry componentLayoutManager:[HUBComponentLayoutManagerMock new]]; if (self) { _capturedViewModels = [NSMutableArray array]; _capturedViewModelDiffs = [NSMutableArray array]; @@ -50,6 +49,7 @@ - (void)computeForCollectionViewSize:(CGSize)collectionViewSize diff:(nullable HUBViewModelDiff *)diff addHeaderMargin:(BOOL)addHeaderMargin { + [super computeForCollectionViewSize:collectionViewSize viewModel:viewModel diff:diff addHeaderMargin:addHeaderMargin]; [self.capturedViewModels addObject:viewModel]; HUBViewModelDiff *nonNullDiff = (diff == nil) ? (HUBViewModelDiff *)[NSNull null] : diff; [self.capturedViewModelDiffs addObject:nonNullDiff]; diff --git a/tests/mocks/HUBCollectionViewMock.h b/tests/mocks/HUBCollectionViewMock.h index 7480c6e2..3788083e 100644 --- a/tests/mocks/HUBCollectionViewMock.h +++ b/tests/mocks/HUBCollectionViewMock.h @@ -50,6 +50,8 @@ NS_ASSUME_NONNULL_BEGIN /// Whether the collection view should act like the user is dragging its content @property (nonatomic) BOOL mockedIsDragging; +- (instancetype)initWithCollectionViewLayout:(UICollectionViewLayout *)layout; + @end NS_ASSUME_NONNULL_END diff --git a/tests/mocks/HUBCollectionViewMock.m b/tests/mocks/HUBCollectionViewMock.m index 4e07cf56..1623389f 100644 --- a/tests/mocks/HUBCollectionViewMock.m +++ b/tests/mocks/HUBCollectionViewMock.m @@ -32,10 +32,8 @@ @interface HUBCollectionViewMock () @implementation HUBCollectionViewMock -- (instancetype)init +- (instancetype)initWithCollectionViewLayout:(UICollectionViewLayout *)layout { - UICollectionViewLayout * const layout = [UICollectionViewFlowLayout new]; - if (!(self = [super initWithFrame:CGRectZero collectionViewLayout:layout])) { return nil; }