Skip to content

Commit

Permalink
Add test for xib element
Browse files Browse the repository at this point in the history
  • Loading branch information
ra1028 committed Jul 28, 2019
1 parent 8bbec6a commit 8c5f726
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 22 deletions.
16 changes: 16 additions & 0 deletions Carbon.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
6B6594BB21E2532100291AAF /* UITableViewComponentHeaderFooterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B6594A121E2532100291AAF /* UITableViewComponentHeaderFooterView.swift */; };
6B6594BD21E2532100291AAF /* Renderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B6594A321E2532100291AAF /* Renderer.swift */; };
6B6594C221E2599600291AAF /* DifferenceKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6B6594C121E2599600291AAF /* DifferenceKit.framework */; };
6B6F25BF22EE201F009C3029 /* MockCustomXibTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6B6F25BE22EE201F009C3029 /* MockCustomXibTableViewCell.xib */; };
6B6F25C122EE234F009C3029 /* MockCustomXibCollectionViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6B6F25C022EE234F009C3029 /* MockCustomXibCollectionViewCell.xib */; };
6B6F25C322EE25A2009C3029 /* MockCustomXibTableViewHeaderFooterView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6B6F25C222EE25A2009C3029 /* MockCustomXibTableViewHeaderFooterView.xib */; };
6B6F25C522EE267E009C3029 /* MockCustomXibCollectionViewReusableView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6B6F25C422EE267E009C3029 /* MockCustomXibCollectionViewReusableView.xib */; };
6B7ADEB121F783E3003803BE /* ComponentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B7ADEB021F783E3003803BE /* ComponentTests.swift */; };
6B7ADEB321F783E3003803BE /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6B65947A21E252E300291AAF /* Carbon.framework */; };
6B7ADEBA21F78957003803BE /* TestTools.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B7ADEB921F78957003803BE /* TestTools.swift */; };
Expand Down Expand Up @@ -88,6 +92,10 @@
6B6594A321E2532100291AAF /* Renderer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Renderer.swift; sourceTree = "<group>"; };
6B6594BF21E2534B00291AAF /* Carbon.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Carbon.xcconfig; sourceTree = "<group>"; };
6B6594C121E2599600291AAF /* DifferenceKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = DifferenceKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6B6F25BE22EE201F009C3029 /* MockCustomXibTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MockCustomXibTableViewCell.xib; sourceTree = "<group>"; };
6B6F25C022EE234F009C3029 /* MockCustomXibCollectionViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MockCustomXibCollectionViewCell.xib; sourceTree = "<group>"; };
6B6F25C222EE25A2009C3029 /* MockCustomXibTableViewHeaderFooterView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MockCustomXibTableViewHeaderFooterView.xib; sourceTree = "<group>"; };
6B6F25C422EE267E009C3029 /* MockCustomXibCollectionViewReusableView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MockCustomXibCollectionViewReusableView.xib; sourceTree = "<group>"; };
6B7ADEAE21F783E3003803BE /* Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
6B7ADEB021F783E3003803BE /* ComponentTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComponentTests.swift; sourceTree = "<group>"; };
6B7ADEB221F783E3003803BE /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -255,6 +263,10 @@
children = (
6B7ADECB21FA067E003803BE /* UITableViewAdapterTests.swift */,
6B7ADECD21FA1B32003803BE /* UICollectionViewFlowLayoutAdapterTests.swift */,
6B6F25BE22EE201F009C3029 /* MockCustomXibTableViewCell.xib */,
6B6F25C222EE25A2009C3029 /* MockCustomXibTableViewHeaderFooterView.xib */,
6B6F25C022EE234F009C3029 /* MockCustomXibCollectionViewCell.xib */,
6B6F25C422EE267E009C3029 /* MockCustomXibCollectionViewReusableView.xib */,
);
path = Adapters;
sourceTree = "<group>";
Expand Down Expand Up @@ -387,6 +399,10 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
6B6F25C122EE234F009C3029 /* MockCustomXibCollectionViewCell.xib in Resources */,
6B6F25C522EE267E009C3029 /* MockCustomXibCollectionViewReusableView.xib in Resources */,
6B6F25C322EE25A2009C3029 /* MockCustomXibTableViewHeaderFooterView.xib in Resources */,
6B6F25BF22EE201F009C3029 /* MockCustomXibTableViewCell.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
26 changes: 26 additions & 0 deletions Tests/Adapters/MockCustomXibCollectionViewCell.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" id="Tq4-X8-Nmm" customClass="MockCustomXibCollectionViewCell" customModule="Tests" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="50" height="50"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO">
<rect key="frame" x="0.0" y="0.0" width="50" height="50"/>
<autoresizingMask key="autoresizingMask"/>
</view>
<viewLayoutGuide key="safeArea" id="Kl6-z3-Gp4"/>
<point key="canvasLocation" x="74" y="126"/>
</collectionViewCell>
</objects>
</document>
22 changes: 22 additions & 0 deletions Tests/Adapters/MockCustomXibCollectionViewReusableView.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<collectionReusableView opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" id="bvb-aU-m6N" customClass="MockCustomXibCollectionViewReusableView" customModule="Tests" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="414" height="50"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<viewLayoutGuide key="safeArea" id="B9q-0J-F55"/>
<point key="canvasLocation" x="-33" y="88"/>
</collectionReusableView>
</objects>
</document>
24 changes: 24 additions & 0 deletions Tests/Adapters/MockCustomXibTableViewCell.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" id="EPO-Lr-u7W" customClass="MockCustomXibTableViewCell" customModule="Tests" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="414" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="EPO-Lr-u7W" id="XfA-4I-b99">
<rect key="frame" x="0.0" y="0.0" width="414" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
</tableViewCellContentView>
<point key="canvasLocation" x="-61" y="91"/>
</tableViewCell>
</objects>
</document>
24 changes: 24 additions & 0 deletions Tests/Adapters/MockCustomXibTableViewHeaderFooterView.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="WFu-hj-TZ2" customClass="MockCustomXibTableViewHeaderFooterView" customModule="Tests" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="414" height="44"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<viewLayoutGuide key="safeArea" id="xkN-9O-Esg"/>
<point key="canvasLocation" x="52" y="-94"/>
</view>
</objects>
</document>
27 changes: 21 additions & 6 deletions Tests/Adapters/UICollectionViewFlowLayoutAdapterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,14 @@ final class UICollectionViewFlowLayoutAdapterTests: XCTestCase {
}
}

adapter.cellClass = MockCustomCollectionViewCell1.self
adapter.cellRegistration = .init(class: MockCustomCollectionViewCell1.self)
check(expectedClass: MockCustomCollectionViewCell1.self)

adapter.cellClass = MockCustomCollectionViewCell2.self
adapter.cellRegistration = .init(class: MockCustomCollectionViewCell2.self)
check(expectedClass: MockCustomCollectionViewCell2.self)

adapter.cellRegistration = .init(class: MockCustomXibCollectionViewCell.self)
check(expectedClass: MockCustomXibCollectionViewCell.self)
}

func testViewForHeaderFooter() {
Expand Down Expand Up @@ -358,16 +361,28 @@ final class UICollectionViewFlowLayoutAdapterTests: XCTestCase {
check(view: view, expectedClass: expectedClass)
}

adapter.supplementaryViewClasses[UICollectionView.elementKindSectionHeader] = MockCustomCollectionViewReusableView1.self
adapter.supplementaryViewRegistrations[UICollectionView.elementKindSectionHeader] = .init(class: MockCustomCollectionViewReusableView1.self)
checkHeader(expectedClass: MockCustomCollectionViewReusableView1.self)

adapter.supplementaryViewClasses[UICollectionView.elementKindSectionHeader] = MockCustomCollectionViewReusableView2.self
adapter.supplementaryViewRegistrations[UICollectionView.elementKindSectionHeader] = .init(class: MockCustomCollectionViewReusableView2.self)
checkHeader(expectedClass: MockCustomCollectionViewReusableView2.self)

adapter.supplementaryViewClasses[UICollectionView.elementKindSectionFooter] = MockCustomCollectionViewReusableView1.self
adapter.supplementaryViewRegistrations[UICollectionView.elementKindSectionHeader] = .init(
class: MockCustomXibCollectionViewReusableView.self,
nib: UINib(for: MockCustomXibCollectionViewReusableView.self)
)
checkHeader(expectedClass: MockCustomXibCollectionViewReusableView.self)

adapter.supplementaryViewRegistrations[UICollectionView.elementKindSectionFooter] = .init(class: MockCustomCollectionViewReusableView1.self)
checkFooter(expectedClass: MockCustomCollectionViewReusableView1.self)

adapter.supplementaryViewClasses[UICollectionView.elementKindSectionFooter] = MockCustomCollectionViewReusableView2.self
adapter.supplementaryViewRegistrations[UICollectionView.elementKindSectionFooter] = .init(class: MockCustomCollectionViewReusableView2.self)
checkFooter(expectedClass: MockCustomCollectionViewReusableView2.self)

adapter.supplementaryViewRegistrations[UICollectionView.elementKindSectionFooter] = .init(
class: MockCustomXibCollectionViewReusableView.self,
nib: UINib(for: MockCustomXibCollectionViewReusableView.self)
)
checkFooter(expectedClass: MockCustomXibCollectionViewReusableView.self)
}
}
21 changes: 15 additions & 6 deletions Tests/Adapters/UITableViewAdapterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,14 @@ final class UITableViewAdapterTests: XCTestCase {
}
}

adapter.cellClass = MockCustomTableViewCell1.self
adapter.cellRegistration = .init(class: MockCustomTableViewCell1.self)
check(expectedClass: MockCustomTableViewCell1.self)

adapter.cellClass = MockCustomTableViewCell2.self
adapter.cellRegistration = .init(class: MockCustomTableViewCell2.self)
check(expectedClass: MockCustomTableViewCell2.self)

adapter.cellRegistration = .init(class: MockCustomXibTableViewCell.self, nib: UINib(for: MockCustomXibTableViewCell.self))
check(expectedClass: MockCustomXibTableViewCell.self)
}

func testViewForHeaderFooter() {
Expand Down Expand Up @@ -379,16 +382,22 @@ final class UITableViewAdapterTests: XCTestCase {
check(view: view, expectedClass: expectedClass)
}

adapter.headerClass = MockCustomTableViewHeaderFooterView1.self
adapter.headerRegistration = .init(class: MockCustomTableViewHeaderFooterView1.self)
checkHeader(expectedClass: MockCustomTableViewHeaderFooterView1.self)

adapter.headerClass = MockCustomTableViewHeaderFooterView2.self
adapter.headerRegistration = .init(class: MockCustomTableViewHeaderFooterView2.self)
checkHeader(expectedClass: MockCustomTableViewHeaderFooterView2.self)

adapter.footerClass = MockCustomTableViewHeaderFooterView1.self
adapter.headerRegistration = .init(class: MockCustomXibTableViewHeaderFooterView.self, nib: UINib(for: MockCustomXibTableViewHeaderFooterView.self))
checkHeader(expectedClass: MockCustomXibTableViewHeaderFooterView.self)

adapter.footerRegistration = .init(class: MockCustomTableViewHeaderFooterView1.self)
checkFooter(expectedClass: MockCustomTableViewHeaderFooterView1.self)

adapter.footerClass = MockCustomTableViewHeaderFooterView2.self
adapter.footerRegistration = .init(class: MockCustomTableViewHeaderFooterView2.self)
checkFooter(expectedClass: MockCustomTableViewHeaderFooterView2.self)

adapter.footerRegistration = .init(class: MockCustomXibTableViewHeaderFooterView.self, nib: UINib(for: MockCustomXibTableViewHeaderFooterView.self))
checkFooter(expectedClass: MockCustomXibTableViewHeaderFooterView.self)
}
}

0 comments on commit 8c5f726

Please sign in to comment.