Skip to content

Commit 27b513f

Browse files
author
Jonathan Aguele and Ondrej Rafaj
committed
adding taps on collection and table views
1 parent 6be3550 commit 27b513f

File tree

11 files changed

+248
-58
lines changed

11 files changed

+248
-58
lines changed

Example/Pods/Pods.xcodeproj/project.pbxproj

Lines changed: 26 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/SpecTools.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */; };
2020
9742DFBD958C41A0D4A320A7 /* Pods_SpecToolsExample.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA48DE5F6072FA17B587A4CF /* Pods_SpecToolsExample.framework */; };
2121
F230246CE764371409137DF7 /* Pods_SpecToolsExampleTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4025987761D8603D7A3EF403 /* Pods_SpecToolsExampleTests.framework */; };
22+
F4A8DD811FAB3C3A00237CF6 /* CollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4A8DD801FAB3C3A00237CF6 /* CollectionViewController.swift */; };
23+
F4A8DD851FAB3FA000237CF6 /* CollectionViewControllerSpecs.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4A8DD841FAB3FA000237CF6 /* CollectionViewControllerSpecs.swift */; };
2224
/* End PBXBuildFile section */
2325

2426
/* Begin PBXContainerItemProxy section */
@@ -62,6 +64,8 @@
6264
DA48DE5F6072FA17B587A4CF /* Pods_SpecToolsExample.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SpecToolsExample.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6365
DB1653D35AA1B0DA36A7E500 /* Pods-SpecTools_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SpecTools_Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-SpecTools_Tests/Pods-SpecTools_Tests.release.xcconfig"; sourceTree = "<group>"; };
6466
E97AABD13102D001DC13B657 /* Pods-SpecToolsExampleTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SpecToolsExampleTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-SpecToolsExampleTests/Pods-SpecToolsExampleTests.debug.xcconfig"; sourceTree = "<group>"; };
67+
F4A8DD801FAB3C3A00237CF6 /* CollectionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionViewController.swift; sourceTree = "<group>"; };
68+
F4A8DD841FAB3FA000237CF6 /* CollectionViewControllerSpecs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionViewControllerSpecs.swift; sourceTree = "<group>"; };
6569
/* End PBXFileReference section */
6670

6771
/* Begin PBXFrameworksBuildPhase section */
@@ -90,6 +94,7 @@
9094
1504FD4C1F50C6520000D7FA /* BasicSpec.swift */,
9195
1504FD4D1F50C6520000D7FA /* ViewControllerSpec.swift */,
9296
15074DEE1F667F0F00E06BD0 /* TableViewControllerSpec.swift */,
97+
F4A8DD841FAB3FA000237CF6 /* CollectionViewControllerSpecs.swift */,
9398
1504FD441F50C5E10000D7FA /* Info.plist */,
9499
);
95100
path = SpecToolsExampleTests;
@@ -119,6 +124,7 @@
119124
children = (
120125
607FACD71AFB9204008FA782 /* ViewController.swift */,
121126
15074DE91F6443D400E06BD0 /* TableViewController.swift */,
127+
F4A8DD801FAB3C3A00237CF6 /* CollectionViewController.swift */,
122128
);
123129
name = "View controllers";
124130
sourceTree = "<group>";
@@ -428,6 +434,7 @@
428434
1504FD4F1F50C6520000D7FA /* ViewControllerSpec.swift in Sources */,
429435
15074DEF1F667F0F00E06BD0 /* TableViewControllerSpec.swift in Sources */,
430436
1504FD4E1F50C6520000D7FA /* BasicSpec.swift in Sources */,
437+
F4A8DD851FAB3FA000237CF6 /* CollectionViewControllerSpecs.swift in Sources */,
431438
);
432439
runOnlyForDeploymentPostprocessing = 0;
433440
};
@@ -439,6 +446,7 @@
439446
15074DF21F6687B400E06BD0 /* TableViewCell.swift in Sources */,
440447
15074DEA1F6443D400E06BD0 /* TableViewController.swift in Sources */,
441448
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */,
449+
F4A8DD811FAB3C3A00237CF6 /* CollectionViewController.swift in Sources */,
442450
);
443451
runOnlyForDeploymentPostprocessing = 0;
444452
};
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//
2+
// CollectionViewController.swift
3+
// SpecToolsExample
4+
//
5+
// Created by Jonathan Aguele on 02/11/2017.
6+
// Copyright © 2017 manGoweb. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import UIKit
11+
import SnapKit
12+
13+
14+
class CollectionViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout {
15+
16+
var didTapOnCell: ((_ indexPath: IndexPath)->())?
17+
18+
19+
// MARK: View lifecycle
20+
21+
override func viewDidLoad() {
22+
super.viewDidLoad()
23+
24+
collectionView?.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "cell")
25+
// collectionView?.delegate = self
26+
// collectionView?.dataSource = self
27+
//
28+
// view.addSubview(collectionView!)
29+
// collectionView?.snp.makeConstraints({ (make) in
30+
// make.edges.equalToSuperview()
31+
// })
32+
}
33+
34+
// MARK: Collection view delegate & data source methods
35+
36+
override func numberOfSections(in collectionView: UICollectionView) -> Int {
37+
return 1
38+
}
39+
40+
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
41+
return 300
42+
}
43+
44+
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
45+
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath)
46+
return cell
47+
}
48+
49+
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
50+
didTapOnCell?(indexPath)
51+
}
52+
}

Example/SpecTools/TableViewController.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import UIKit
1212

1313
class TableViewController: UITableViewController {
1414

15+
var didTapOnCell: ((_ indexPath: IndexPath)->())?
16+
1517

1618
// MARK: View lifecycle
1719

@@ -40,4 +42,8 @@ class TableViewController: UITableViewController {
4042
return cell
4143
}
4244

45+
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
46+
didTapOnCell?(indexPath)
47+
}
48+
4349
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//
2+
// CollectionViewControllerSpecs.swift
3+
// SpecToolsExampleTests
4+
//
5+
// Created by Jonathan Aguele on 02/11/2017.
6+
// Copyright © 2017 manGoweb. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import UIKit
11+
import Quick
12+
import Nimble
13+
import SpecTools
14+
15+
@testable import SpecToolsExample
16+
17+
18+
class CollectionViewControllerSpec: QuickSpec {
19+
20+
override func spec() {
21+
var subject: CollectionViewController!
22+
23+
describe("CollectionViewController") {
24+
var tapped: Bool = false
25+
26+
beforeEach {
27+
// Create the subject
28+
subject = CollectionViewController(collectionViewLayout: UICollectionViewFlowLayout())
29+
30+
// Give subject a navigation controller
31+
_ = subject.spec.prepare.assignMockNavigationController()
32+
33+
// Simulate view controller being presented to the screen
34+
subject.spec.prepare.simulatePresentViewController()
35+
// Reset the view to specific size
36+
subject.spec.prepare.set(viewSize: .iPhone6Plus)
37+
38+
subject.didTapOnCell = { indexPath in
39+
tapped = true
40+
}
41+
subject.collectionView!.spec.action.tap(item: 0)
42+
}
43+
44+
it("should receive tap on a cell") {
45+
expect(tapped).toEventually(equal(true))
46+
}
47+
}
48+
}
49+
}

Example/SpecToolsExampleTests/TableViewControllerSpec.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import SpecTools
1818
class TableViewControllerSpec: QuickSpec {
1919

2020
override func spec() {
21-
2221
var subject: TableViewController!
2322

2423
describe("TableViewController") {
@@ -63,6 +62,21 @@ class TableViewControllerSpec: QuickSpec {
6362
let ok = subject.tableView.spec.check.allCells(fit: doesFitClosure)
6463
expect(ok).to(beTrue())
6564
}
65+
66+
describe("when user taps on a cell") {
67+
var tapped: Bool = false
68+
69+
beforeEach {
70+
subject.didTapOnCell = { indexPath in
71+
tapped = true
72+
}
73+
subject.tableView!.spec.action.tap(row: 0)
74+
}
75+
76+
it("should register a tap") {
77+
expect(tapped).toEventually(equal(true))
78+
}
79+
}
6680
}
6781
}
6882
}

0 commit comments

Comments
 (0)