Skip to content

Commit 8917bb2

Browse files
committed
Improved code. Added UI Tests
1 parent 217276a commit 8917bb2

File tree

11 files changed

+94
-45
lines changed

11 files changed

+94
-45
lines changed

Fojusi UI Tests/Fojusi_UI_Tests.swift

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Fojusi_UI_Tests: XCTestCase {
3636
super.tearDown()
3737
}
3838

39-
func testSelectingBreakDisablesOtherButtons() {
39+
func testSelectingBreak_DisablesOtherButtons() {
4040
XCTAssertTrue(procrastinateButton.enabled)
4141
XCTAssertTrue(workButton.enabled)
4242
XCTAssertTrue(breakButton.enabled)
@@ -51,7 +51,7 @@ class Fojusi_UI_Tests: XCTestCase {
5151
app.alerts["Stop?"].collectionViews.buttons["Stop"].tap()
5252
}
5353

54-
func testSelectingWorkDisablesOtherButtons() {
54+
func testSelectingWork_DisablesOtherButtons() {
5555
XCTAssertTrue(procrastinateButton.enabled)
5656
XCTAssertTrue(workButton.enabled)
5757
XCTAssertTrue(breakButton.enabled)
@@ -66,7 +66,7 @@ class Fojusi_UI_Tests: XCTestCase {
6666
app.alerts["Stop?"].collectionViews.buttons["Stop"].tap()
6767
}
6868

69-
func testSelectingProcrastinateDisablesOtherButtons() {
69+
func testSelectingProcrastinate_DisablesOtherButtons() {
7070
XCTAssertTrue(procrastinateButton.enabled)
7171
XCTAssertTrue(workButton.enabled)
7272
XCTAssertTrue(breakButton.enabled)
@@ -81,4 +81,45 @@ class Fojusi_UI_Tests: XCTestCase {
8181
app.alerts["Stop?"].collectionViews.buttons["Stop"].tap()
8282
}
8383

84+
func testTimerValues_CanBeChangedInSettings() {
85+
86+
app.buttons["Settings"].tap()
87+
88+
app.pickerWheels.element.adjustToPickerWheelValue("55 min")
89+
XCTAssertTrue(app.staticTexts["55 min"].exists)
90+
app.pickerWheels.element.adjustToPickerWheelValue("10 min")
91+
XCTAssertTrue(app.staticTexts["10 min"].exists)
92+
app.pickerWheels.element.adjustToPickerWheelValue("25 min")
93+
XCTAssertTrue(app.staticTexts["25 min"].exists)
94+
95+
app.staticTexts["Break duration"].tap()
96+
app.childrenMatchingType(.Window).elementBoundByIndex(0).childrenMatchingType(.Other).element.childrenMatchingType(.Other).element.tap()
97+
app.pickerWheels.element.adjustToPickerWheelValue("1 min")
98+
XCTAssertTrue(app.staticTexts["1 min"].exists)
99+
app.pickerWheels.element.adjustToPickerWheelValue("10 min")
100+
XCTAssertTrue(app.staticTexts["10 min"].exists)
101+
app.pickerWheels.element.adjustToPickerWheelValue("5 min")
102+
XCTAssertTrue(app.staticTexts["5 min"].exists)
103+
104+
app.navigationBars["Settings"].buttons["Done"].tap()
105+
}
106+
107+
func testCanShowTwitter_InAbout() {
108+
109+
app.buttons["About"].tap()
110+
app.buttons["Twitter"].tap()
111+
XCTAssertTrue(app.toolbars.buttons["OpenInSafari"].exists)
112+
XCTAssertTrue(app.toolbars.buttons["Share"].exists)
113+
app.buttons["Done"].tap()
114+
}
115+
116+
func testCanShowGithub_InAbout() {
117+
118+
app.buttons["About"].tap()
119+
app.buttons["Github"].tap()
120+
XCTAssertTrue(app.toolbars.buttons["OpenInSafari"].exists)
121+
XCTAssertTrue(app.toolbars.buttons["Share"].exists)
122+
app.buttons["Done"].tap()
123+
}
124+
84125
}

Tomate.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
F2AB30B819600A4000D8D989 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2AB30B719600A4000D8D989 /* AppDelegate.swift */; };
3030
F2AB30BA19600A4000D8D989 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F2AB30B919600A4000D8D989 /* Images.xcassets */; };
3131
F2AB30D4196016B800D8D989 /* TimerStyleKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2AB30D3196016B800D8D989 /* TimerStyleKit.swift */; };
32+
F2AC01411BDCC68300D50C4E /* DHNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2AC01401BDCC68300D50C4E /* DHNavigationController.swift */; };
3233
F2BB35F319F38FB700CD9CA5 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F2BB35F219F38FB700CD9CA5 /* LaunchScreen.storyboard */; };
3334
F2EB866B1B2A1E4D009EF689 /* TimerType.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2EB866A1B2A1E4D009EF689 /* TimerType.swift */; };
3435
F2FC44021B2CCCCC00851923 /* Fojusi_UI_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2FC44011B2CCCCC00851923 /* Fojusi_UI_Tests.swift */; };
@@ -141,6 +142,7 @@
141142
F2AB30BF19600A4000D8D989 /* TomateTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TomateTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
142143
F2AB30C419600A4000D8D989 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
143144
F2AB30D3196016B800D8D989 /* TimerStyleKit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TimerStyleKit.swift; sourceTree = "<group>"; };
145+
F2AC01401BDCC68300D50C4E /* DHNavigationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DHNavigationController.swift; sourceTree = "<group>"; };
144146
F2BB35F219F38FB700CD9CA5 /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = "<group>"; };
145147
F2EB866A1B2A1E4D009EF689 /* TimerType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TimerType.swift; sourceTree = "<group>"; };
146148
F2FB4E1A198D0BD000B5474E /* NotificationCenter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = NotificationCenter.framework; path = System/Library/Frameworks/NotificationCenter.framework; sourceTree = SDKROOT; };
@@ -281,6 +283,7 @@
281283
F2FF2C841AB0A4D90017BF04 /* Fojusi.entitlements */,
282284
F2AB30B719600A4000D8D989 /* AppDelegate.swift */,
283285
F20425221961F91100A132D6 /* Int+Extensions.swift */,
286+
F2AC01401BDCC68300D50C4E /* DHNavigationController.swift */,
284287
F273B4C71B56233B00CDF081 /* About */,
285288
F23462371960798900AB11A5 /* Focus */,
286289
F21D3F4E198D4BC50036D4BA /* Settings */,
@@ -622,6 +625,7 @@
622625
F234623D1960798900AB11A5 /* TimerView.swift in Sources */,
623626
F2AB30B819600A4000D8D989 /* AppDelegate.swift in Sources */,
624627
F273B4C91B56235600CDF081 /* AboutView.swift in Sources */,
628+
F2AC01411BDCC68300D50C4E /* DHNavigationController.swift in Sources */,
625629
F2AB30D4196016B800D8D989 /* TimerStyleKit.swift in Sources */,
626630
F20425231961F91100A132D6 /* Int+Extensions.swift in Sources */,
627631
F21D3F50198D4BE30036D4BA /* SettingsView.swift in Sources */,

Tomate/About/AboutViewController.swift

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,19 @@
99
import UIKit
1010
import SafariServices
1111

12-
class AboutViewController: UIViewController {
12+
final class AboutViewController: UIViewController {
1313

14-
var aboutView: AboutView {
14+
private var aboutView: AboutView {
1515
return view as! AboutView
1616
}
1717

1818
override func loadView() {
1919
let contentView = AboutView(frame: .zero)
2020

2121
title = NSLocalizedString("About", comment: "About")
22-
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: TimerStyleKit.timerColor]
22+
// UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: TimerStyleKit.timerColor]
2323

2424
contentView.twitterButton.addTarget(self, action: "openTwitter", forControlEvents: .TouchUpInside)
25-
// contentView.adnButton.addTarget(self, action: "openADN", forControlEvents: .TouchUpInside)
2625
contentView.githubButton.addTarget(self, action: "openGithub", forControlEvents: .TouchUpInside)
2726
contentView.rateButton.addTarget(self, action: "openRating", forControlEvents: .TouchUpInside)
2827

@@ -47,22 +46,15 @@ class AboutViewController: UIViewController {
4746
extension AboutViewController {
4847
func openTwitter() {
4948
let safariViewController = SFSafariViewController(URL: NSURL(string: "https://twitter.com/fojusiapp")!)
50-
navigationController?.pushViewController(safariViewController, animated: true)
49+
presentViewController(safariViewController, animated: true, completion: nil)
5150
}
5251

53-
// func openADN() {
54-
// let safariViewController = SFSafariViewController(URL: NSURL(string: "https://alpha.app.net/dasdom")!)
55-
// navigationController?.pushViewController(safariViewController, animated: true)
56-
// }
57-
5852
func openGithub() {
5953
let safariViewController = SFSafariViewController(URL: NSURL(string: "https://github.com/dasdom/Tomate")!)
60-
navigationController?.pushViewController(safariViewController, animated: true)
54+
presentViewController(safariViewController, animated: true, completion: nil)
6155
}
6256

6357
func openRating() {
64-
// let safariViewController = SFSafariViewController(URL: NSURL(string: "")!)
65-
// navigationController?.pushViewController(safariViewController, animated: true)
6658
UIApplication.sharedApplication().openURL(NSURL(string: "http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=923044693")!)
6759
}
6860
}

Tomate/AboutView.swift

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88

99
import UIKit
1010

11-
class AboutView: UIView {
11+
final class AboutView: UIView {
1212

1313
let twitterButton: UIButton
14-
// let adnButton: UIButton
1514
let githubButton: UIButton
1615
let rateButton: UIButton
1716
let stackView: UIStackView
@@ -39,30 +38,26 @@ class AboutView: UIView {
3938
}
4039

4140
twitterButton = buttonWithTitle("Twitter")
42-
// adnButton = buttonWithTitle("App.net")
4341
githubButton = buttonWithTitle("Github")
4442
rateButton = buttonWithTitle("Rate me")
4543

4644
stackView = UIStackView(arrangedSubviews: [avatarImageView, handleLabel, twitterButton, githubButton, rateButton])
4745
stackView.translatesAutoresizingMaskIntoConstraints = false
48-
// stackView.distribution = UIStackViewDistribution.EqualSpacing
4946
stackView.axis = .Vertical
5047
stackView.alignment = .Center
5148
stackView.spacing = 10
5249

5350
super.init(frame: frame)
5451

55-
tintColor = UIColor.yellowColor()
52+
tintColor = .yellowColor()
5653
backgroundColor = TimerStyleKit.backgroundColor
5754

5855
addSubview(stackView)
5956

6057
var layoutConstraints = [NSLayoutConstraint]()
61-
// layoutConstraints.append(stackView.topAnchor.constraintEqualToAnchor(topAnchor, constant: 80))
6258
layoutConstraints.append(stackView.centerXAnchor.constraintEqualToAnchor(centerXAnchor))
6359
layoutConstraints.append(avatarImageView.widthAnchor.constraintEqualToConstant(avatarWidth))
6460
layoutConstraints.append(avatarImageView.heightAnchor.constraintEqualToConstant(avatarWidth))
65-
// layoutConstraints.append(twitterButton.widthAnchor.constraintEqualToConstant(120))
6661
NSLayoutConstraint.activateConstraints(layoutConstraints)
6762
}
6863

Tomate/AppDelegate.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
3939
window!.makeKeyAndVisible()
4040

4141
// Override point for customization after application launch.
42-
var shouldPerformAdditionalDelegateHandling = true
42+
// var shouldPerformAdditionalDelegateHandling = true
4343

4444
// If a shortcut was launched, display its information and take the appropriate action
4545
if let shortcutItem = launchOptions?[UIApplicationLaunchOptionsShortcutItemKey] as? UIApplicationShortcutItem {
4646

4747
handleShortcut(shortcutItem.type)
4848

4949
// This will block "performActionForShortcutItem:completionHandler" from being called.
50-
shouldPerformAdditionalDelegateHandling = false
50+
// shouldPerformAdditionalDelegateHandling = false
5151
}
5252

5353
return true
@@ -102,6 +102,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
102102
func customizeAppearance() {
103103
UINavigationBar.appearance().tintColor = UIColor.yellowColor()
104104
UINavigationBar.appearance().barTintColor = TimerStyleKit.backgroundColor
105+
106+
let titleAttributes = [NSForegroundColorAttributeName: TimerStyleKit.timerColor]
107+
UINavigationBar.appearance().titleTextAttributes = titleAttributes
105108
}
106109
}
107110

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// DHNavigationController.swift
3+
// Tomate
4+
//
5+
// Created by dasdom on 25.10.15.
6+
// Copyright © 2015 Dominik Hauser. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
class DHNavigationController: UINavigationController {
12+
13+
override func preferredStatusBarStyle() -> UIStatusBarStyle {
14+
return UIStatusBarStyle.LightContent
15+
}
16+
}

Tomate/Focus/FocusView.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import UIKit
1010
import QuartzCore
1111

12-
class FocusView: UIView {
12+
final class FocusView: UIView {
1313
let timerView: TimerView
1414
let workButton: UIButton
1515
let breakButton: UIButton
@@ -55,6 +55,7 @@ class FocusView: UIView {
5555
// button.setImage(templateImage, forState: .Normal)
5656
// }
5757
button.setImage(TimerStyleKit.imageOfSettings, forState: .Normal)
58+
button.accessibilityLabel = NSLocalizedString("Settings", comment: "")
5859
return button
5960
}()
6061

@@ -66,6 +67,7 @@ class FocusView: UIView {
6667
// button.setImage(templateImage, forState: .Normal)
6768
// }
6869
button.setImage(TimerStyleKit.imageOfInfo, forState: .Normal)
70+
button.accessibilityLabel = NSLocalizedString("About", comment: "")
6971
return button
7072
}()
7173

@@ -128,8 +130,8 @@ class FocusView: UIView {
128130
// timerView.timeLabel.font = timerView.timeLabel.font.fontWithSize((frame.size.width-2*CGFloat(metrics["sidePadding"]!))*0.9/3.0-10.0)
129131
}
130132

131-
required convenience init(coder aDecoder: NSCoder) {
132-
self.init(frame: CGRectZero)
133+
required init?(coder aDecoder: NSCoder) {
134+
fatalError("init(coder:) has not been implemented")
133135
}
134136

135137
func setDuration(duration: CGFloat, maxValue: CGFloat) {

Tomate/Focus/FocusViewController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import UIKit
1010
import AudioToolbox
1111
import WatchConnectivity
1212

13-
class FocusViewController: UIViewController {
13+
final class FocusViewController: UIViewController {
1414

1515
private var focusView: FocusView! { return self.view as! FocusView }
1616
private var timer: NSTimer?
@@ -82,7 +82,7 @@ class FocusViewController: UIViewController {
8282
}
8383

8484
func showSettings() {
85-
presentViewController(UINavigationController(rootViewController: SettingsViewController()), animated: true, completion: nil)
85+
presentViewController(DHNavigationController(rootViewController: SettingsViewController()), animated: true, completion: nil)
8686
}
8787

8888
func showSettingsFromLongPross(sender: UILongPressGestureRecognizer) {
@@ -92,7 +92,7 @@ class FocusViewController: UIViewController {
9292
}
9393

9494
func showAbout() {
95-
presentViewController(UINavigationController(rootViewController: AboutViewController()), animated: true, completion: nil)
95+
presentViewController(DHNavigationController(rootViewController: AboutViewController()), animated: true, completion: nil)
9696
}
9797

9898
func setUIModeForTimerType(timerType: TimerType) {

Tomate/Focus/TimerView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import UIKit
1010
import QuartzCore
1111

12-
class TimerView: UIView {
12+
final class TimerView: UIView {
1313

1414
var durationInSeconds: CGFloat = 0.0
1515
var maxValue: CGFloat = 60.0

Tomate/Settings/SettingsView.swift

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import UIKit
1010
import QuartzCore
1111

12-
class SettingsView: UIView {
12+
final class SettingsView: UIView {
1313

1414
private let markerView: UIView
1515
let workInputHostView: InputHostView
@@ -88,8 +88,8 @@ class SettingsView: UIView {
8888
NSLayoutConstraint.activateConstraints(constraints)
8989
}
9090

91-
convenience required init(coder aDecoder: NSCoder) {
92-
self.init(frame: CGRectZero)
91+
required init?(coder aDecoder: NSCoder) {
92+
fatalError("init(coder:) has not been implemented")
9393
}
9494

9595
func setDurationString(string: String) -> TimerType {
@@ -125,15 +125,14 @@ class SettingsView: UIView {
125125
}, completion: nil)
126126
}
127127

128-
class InputHostView: UIView {
128+
final class InputHostView: UIView {
129129
let nameLabel: UILabel
130130
let durationLabel: UILabel
131131

132132
override init(frame: CGRect) {
133133
let makeLabel = { () -> UILabel in
134134
let label = UILabel()
135135
label.translatesAutoresizingMaskIntoConstraints = false
136-
// label.backgroundColor = UIColor.whiteColor()
137136
label.textColor = TimerStyleKit.timerColor
138137
label.text = "-"
139138
return label
@@ -161,8 +160,8 @@ class SettingsView: UIView {
161160

162161
}
163162

164-
required convenience init(coder aDecoder: NSCoder) {
165-
self.init(frame: CGRectZero)
163+
required init?(coder aDecoder: NSCoder) {
164+
fatalError("init(coder:) has not been implemented")
166165
}
167166
}
168167
}

0 commit comments

Comments
 (0)