Skip to content

Commit

Permalink
Merge pull request #34 from wizeline/feature/wrapping-new-version
Browse files Browse the repository at this point in the history
Add tests for collection views
  • Loading branch information
Jorge R Ovalle Z authored Jul 2, 2019
2 parents 84c9098 + 7191f15 commit 16158fb
Show file tree
Hide file tree
Showing 22 changed files with 142 additions and 52 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
osx_image: xcode10
osx_image: xcode10.2
language: swift
env:
global:
- LC_CTYPE=en_US.UTF-8
- LANG=en_US.UTF-8
- WORKSPACE=Example/WLEmptyState.xcworkspace
- SCHEME=WLEmptyState-Example
- SDK=iphonesimulator12.0
- DESTINATION="OS=12.0,name=iPhone XS"
- SDK=iphonesimulator12.2
- DESTINATION="OS=12.2,name=iPhone XS"
script:
- set -o pipefail
- xcodebuild -version
Expand Down
13 changes: 9 additions & 4 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 36 additions & 10 deletions Example/Tests/DataSourceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ class DataSourceTests: XCTestCase {
WLEmptyState.configure()
}

func testDefaultDataSetProperties() {
// MARK: - Default protocol implementation

func testDefaultTableDataSetProperties() {
let defaultTableViewController = DefaultTableViewController()

let titleDataSource = defaultTableViewController.tableView.emptyStateDataSource?.titleForEmptyDataSet()
Expand All @@ -24,20 +26,29 @@ class DataSourceTests: XCTestCase {
let descriptionDataSource = defaultTableViewController.tableView.emptyStateDataSource?.descriptionForEmptyDataSet()
XCTAssertEqual(DefaultDataSource.description, descriptionDataSource)

guard let url = (Bundle(for: WLEmptyState.self)).url(forResource: "WLEmptyState", withExtension: "bundle"),
let bundle = Bundle(url: url) else {
XCTFail("EmptyState image wasn't found.")
return
}
let image = UIImage(named: "Empty", in: bundle, compatibleWith: nil)

let imageDataSource = defaultTableViewController.tableView.emptyStateDataSource?.imageForEmptyDataSet()
XCTAssertEqual(DefaultDataSource.image, imageDataSource)
XCTAssertNotNil(imageDataSource)
}

func testDefaultCollectionDataSetProperties() {
let defaultCollectionViewController = DefaultCollectionViewController(collectionViewLayout: UICollectionViewFlowLayout())

XCTAssertEqual(image, imageDataSource)
let titleDataSource = defaultCollectionViewController.collectionView.emptyStateDataSource?.titleForEmptyDataSet()
XCTAssertEqual(DefaultDataSource.title, titleDataSource)

let descriptionDataSource = defaultCollectionViewController.collectionView.emptyStateDataSource?.descriptionForEmptyDataSet()
XCTAssertEqual(DefaultDataSource.description, descriptionDataSource)

let imageDataSource = defaultCollectionViewController.collectionView.emptyStateDataSource?.imageForEmptyDataSet()

XCTAssertEqual(DefaultDataSource.image, imageDataSource)
XCTAssertNotNil(imageDataSource)
}

func testCustomDataSetProperties() {
// MARK: - Custom protocol implementation

func testTableCustomDataSetProperties() {
let customTableViewController = CustomTableViewController()

let title = NSAttributedString(string: "Test title")
Expand All @@ -51,5 +62,20 @@ class DataSourceTests: XCTestCase {
let imageDataSource = customTableViewController.tableView.emptyStateDataSource?.imageForEmptyDataSet()
XCTAssertNil(imageDataSource)
}

func testCollectionCustomDataSetProperties() {
let customCollectionViewController = CustomCollectionViewController(collectionViewLayout: UICollectionViewFlowLayout())

let title = NSAttributedString(string: "Test title")
let titleDataSource = customCollectionViewController.collectionView.emptyStateDataSource?.titleForEmptyDataSet()
XCTAssertEqual(title, titleDataSource)

let description = NSAttributedString(string: "Test description")
let descriptionDataSource = customCollectionViewController.collectionView.emptyStateDataSource?.descriptionForEmptyDataSet()
XCTAssertEqual(description, descriptionDataSource)

let imageDataSource = customCollectionViewController.collectionView.emptyStateDataSource?.imageForEmptyDataSet()
XCTAssertNil(imageDataSource)
}

}
Binary file added ...tyState_Tests.SnapshotTests/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ...State_Tests.SnapshotTests/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ...te_Tests.SnapshotTests/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ...tyState_Tests.SnapshotTests/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ...WLEmptyState_Tests.SnapshotTests/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ...WLEmptyState_Tests.SnapshotTests/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ...s_64/WLEmptyState_Tests.SnapshotTests/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ...s_64/WLEmptyState_Tests.SnapshotTests/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions Example/Tests/UICollectionViewMocks.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// UICollectionViewMocks.swift
// WLEmptyState_Example
//
// Created by Jorge Ovalle on 6/27/19.
//

import Foundation
import WLEmptyState

final class DefaultCollectionViewController: UICollectionViewController, WLEmptyStateDataSource {

override func viewDidLoad() {
super.viewDidLoad()

collectionView.emptyStateDataSource = self
}

}

final class CustomCollectionViewController: UICollectionViewController, WLEmptyStateDataSource {

override func viewDidLoad() {
super.viewDidLoad()

collectionView.emptyStateDataSource = self
}

func titleForEmptyDataSet() -> NSAttributedString {
return NSAttributedString(string: "Test title")
}

func descriptionForEmptyDataSet() -> NSAttributedString {
return NSAttributedString(string: "Test description")
}

func imageForEmptyDataSet() -> UIImage? {
return nil
}
}
15 changes: 11 additions & 4 deletions Example/Tests/Mocks.swift → Example/Tests/UITableViewMocks.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
//
// Mocks.swift
// UITableViewMocks.swift
// WLEmptyState_Example
//
// Created by Jorge Ovalle on 2/13/19.
// Copyright © 2019 CocoaPods. All rights reserved.
//

import Foundation
import WLEmptyState

class DefaultTableViewController: UITableViewController, WLEmptyStateDataSource {
final class DefaultTableViewController: UITableViewController, WLEmptyStateDataSource {

override func viewDidLoad() {
super.viewDidLoad()
Expand All @@ -19,7 +18,7 @@ class DefaultTableViewController: UITableViewController, WLEmptyStateDataSource

}

class CustomTableViewController: UITableViewController, WLEmptyStateDataSource {
final class CustomTableViewController: UITableViewController, WLEmptyStateDataSource {

override func viewDidLoad() {
super.viewDidLoad()
Expand All @@ -46,4 +45,12 @@ enum DefaultDataSource {

static let description = NSAttributedString(string: "Oops There's no data.",
attributes: [NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .caption1)])

static let image: UIImage? = {
guard let url = (Bundle(for: WLEmptyState.self)).url(forResource: "WLEmptyState", withExtension: "bundle"),
let bundle = Bundle(url: url) else {
return nil
}
return UIImage(named: "Empty", in: bundle, compatibleWith: nil)
}()
}
32 changes: 22 additions & 10 deletions Example/WLEmptyState.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDC1AFB9204008FA782 /* Images.xcassets */; };
607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */; };
617E960222724CCC006F6025 /* SampleCollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 617E960122724CCC006F6025 /* SampleCollectionViewController.swift */; };
7A05C45B22C6B65D001AAD97 /* UICollectionViewMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A3CAFE322C592F100F6FD40 /* UICollectionViewMocks.swift */; };
7A53B06A227F76C1007718E3 /* UIViewController+Storyboard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A53B069227F76C1007718E3 /* UIViewController+Storyboard.swift */; };
7A60354D2214DB2B000265EC /* DataSourceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A60354C2214DB2B000265EC /* DataSourceTests.swift */; };
7A6035502214DC7E000265EC /* Mocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A60354E2214DBBF000265EC /* Mocks.swift */; };
7A6035502214DC7E000265EC /* UITableViewMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A60354E2214DBBF000265EC /* UITableViewMocks.swift */; };
A2D832CF21F965BE00C39001 /* SnapshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A2D832CE21F965BE00C39001 /* SnapshotTests.swift */; };
D1B6CC7AF3E1EC8EF12A6340 /* Pods_WLEmptyState_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0424AD21D7FF86F64DF8F8C3 /* Pods_WLEmptyState_Example.framework */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -44,9 +45,10 @@
607FACE51AFB9204008FA782 /* WLEmptyState_Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = WLEmptyState_Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
607FACEA1AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
617E960122724CCC006F6025 /* SampleCollectionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SampleCollectionViewController.swift; sourceTree = "<group>"; };
7A3CAFE322C592F100F6FD40 /* UICollectionViewMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UICollectionViewMocks.swift; sourceTree = "<group>"; };
7A53B069227F76C1007718E3 /* UIViewController+Storyboard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+Storyboard.swift"; sourceTree = "<group>"; };
7A60354C2214DB2B000265EC /* DataSourceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataSourceTests.swift; sourceTree = "<group>"; };
7A60354E2214DBBF000265EC /* Mocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Mocks.swift; sourceTree = "<group>"; };
7A60354E2214DBBF000265EC /* UITableViewMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UITableViewMocks.swift; sourceTree = "<group>"; };
84DAF8E07A8ECD21288C5213 /* WLEmptyState.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = WLEmptyState.podspec; path = ../WLEmptyState.podspec; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.ruby; };
8A840B888B6222D270FDB5AC /* Pods-WLEmptyState_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WLEmptyState_Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-WLEmptyState_Example/Pods-WLEmptyState_Example.release.xcconfig"; sourceTree = "<group>"; };
8D01069E49EF92D29E2AF9A1 /* Pods-WLEmptyState_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WLEmptyState_Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-WLEmptyState_Example/Pods-WLEmptyState_Example.debug.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -144,10 +146,10 @@
607FACE81AFB9204008FA782 /* Tests */ = {
isa = PBXGroup;
children = (
7A3CAFE222C592D200F6FD40 /* Mocks */,
7A60354C2214DB2B000265EC /* DataSourceTests.swift */,
A2D832CE21F965BE00C39001 /* SnapshotTests.swift */,
607FACE91AFB9204008FA782 /* Supporting Files */,
7A60354E2214DBBF000265EC /* Mocks.swift */,
7A53B069227F76C1007718E3 /* UIViewController+Storyboard.swift */,
);
path = Tests;
Expand All @@ -171,6 +173,15 @@
name = "Podspec Metadata";
sourceTree = "<group>";
};
7A3CAFE222C592D200F6FD40 /* Mocks */ = {
isa = PBXGroup;
children = (
7A60354E2214DBBF000265EC /* UITableViewMocks.swift */,
7A3CAFE322C592F100F6FD40 /* UICollectionViewMocks.swift */,
);
name = Mocks;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -225,11 +236,11 @@
TargetAttributes = {
607FACCF1AFB9204008FA782 = {
CreatedOnToolsVersion = 6.3.1;
LastSwiftMigration = 1000;
LastSwiftMigration = 1020;
};
607FACE41AFB9204008FA782 = {
CreatedOnToolsVersion = 6.3.1;
LastSwiftMigration = 1000;
LastSwiftMigration = 1020;
TestTargetID = 607FACCF1AFB9204008FA782;
};
};
Expand Down Expand Up @@ -382,7 +393,8 @@
files = (
A2D832CF21F965BE00C39001 /* SnapshotTests.swift in Sources */,
7A60354D2214DB2B000265EC /* DataSourceTests.swift in Sources */,
7A6035502214DC7E000265EC /* Mocks.swift in Sources */,
7A05C45B22C6B65D001AAD97 /* UICollectionViewMocks.swift in Sources */,
7A6035502214DC7E000265EC /* UITableViewMocks.swift in Sources */,
7A53B06A227F76C1007718E3 /* UIViewController+Storyboard.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -530,7 +542,7 @@
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -544,7 +556,7 @@
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand All @@ -565,7 +577,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/WLEmptyState_Example.app/WLEmptyState_Example";
};
name = Debug;
Expand All @@ -583,7 +595,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/WLEmptyState_Example.app/WLEmptyState_Example";
};
name = Release;
Expand Down
2 changes: 0 additions & 2 deletions Example/WLEmptyState/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// WLEmptyState
//
// Created by lojals on 12/10/2018.
// Copyright (c) 2018 lojals. All rights reserved.
//

import UIKit
Expand All @@ -14,7 +13,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

WLEmptyState.configure()
Expand Down
5 changes: 5 additions & 0 deletions Example/WLEmptyState/SampleCollectionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ final class SampleCollectionViewController: UICollectionViewController, WLEmptyS
super.viewDidLoad()
collectionView.emptyStateDataSource = self
}

func imageForEmptyDataSet() -> UIImage? {
return UIImage(named: "grid_icon")
}

}
5 changes: 4 additions & 1 deletion Example/WLEmptyState/SampleTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// WLEmptyState
//
// Created by lojals on 12/10/2018.
// Copyright (c) 2018 lojals. All rights reserved.
//

import UIKit
Expand All @@ -16,5 +15,9 @@ final class SampleTableViewController: UITableViewController, WLEmptyStateDataSo
tableView.emptyStateDataSource = self
}

func imageForEmptyDataSet() -> UIImage? {
return UIImage(named: "list_icon")
}

}

4 changes: 2 additions & 2 deletions WLEmptyState.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Pod::Spec.new do |s|
s.source = { :git => 'https://github.com/wizeline/WLEmptyState.git', :tag => s.version.to_s }

s.ios.deployment_target = '9.0'
s.pod_target_xcconfig = { 'SWIFT_VERSION' => '4.0' }
s.swift_version = '4.0'
s.pod_target_xcconfig = { 'SWIFT_VERSION' => '5.0' }
s.swift_version = '5.0'
s.source_files = 'WLEmptyState/Classes/**/*'

s.resource_bundles = {
Expand Down
Loading

0 comments on commit 16158fb

Please sign in to comment.