Skip to content

Commit 3333b1f

Browse files
Peter VanhoefPeter Vanhoef
Peter Vanhoef
authored and
Peter Vanhoef
committed
Completes task 9 (closes #9)
1 parent a11cd82 commit 3333b1f

File tree

3 files changed

+67
-14
lines changed

3 files changed

+67
-14
lines changed

Calculator/Calculator/Base.lproj/Main.storyboard

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<splitViewController id="fcY-c8-IEH" sceneMemberID="viewController">
1818
<connections>
1919
<segue destination="TDa-oR-bW1" kind="relationship" relationship="masterViewController" id="duf-bC-jqV"/>
20-
<segue destination="Blb-hR-aDj" kind="relationship" relationship="detailViewController" id="jyr-Pc-8eS"/>
20+
<segue destination="UDb-wa-Ofv" kind="relationship" relationship="detailViewController" id="jyr-Pc-8eS"/>
2121
</connections>
2222
</splitViewController>
2323
<placeholder placeholderIdentifier="IBFirstResponder" id="17o-kj-Tfc" userLabel="First Responder" sceneMemberID="firstResponder"/>
@@ -137,7 +137,7 @@
137137
<color key="titleColor" red="1" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
138138
</state>
139139
<connections>
140-
<segue destination="Blb-hR-aDj" kind="showDetail" identifier="graph" id="Zbq-q6-BA9"/>
140+
<segue destination="UDb-wa-Ofv" kind="showDetail" identifier="graph" id="Zbq-q6-BA9"/>
141141
</connections>
142142
</button>
143143
</subviews>
@@ -476,13 +476,14 @@
476476
<constraint firstItem="JcA-5Q-PcB" firstAttribute="top" secondItem="puX-M5-gZH" secondAttribute="top" id="uwf-4a-bNJ"/>
477477
</constraints>
478478
</view>
479+
<navigationItem key="navigationItem" id="Byl-gt-gP5"/>
479480
<connections>
480481
<outlet property="graphingView" destination="JcA-5Q-PcB" id="Ylg-pt-MSa"/>
481482
</connections>
482483
</viewController>
483484
<placeholder placeholderIdentifier="IBFirstResponder" id="rWH-Xh-Lu5" userLabel="First Responder" sceneMemberID="firstResponder"/>
484485
</objects>
485-
<point key="canvasLocation" x="137" y="887"/>
486+
<point key="canvasLocation" x="1076" y="886.50674662668678"/>
486487
</scene>
487488
<!--Navigation Controller-->
488489
<scene sceneID="0lk-22-Puh">
@@ -502,8 +503,26 @@
502503
</objects>
503504
<point key="canvasLocation" x="136.80000000000001" y="137.18140929535232"/>
504505
</scene>
506+
<!--Navigation Controller-->
507+
<scene sceneID="H1N-rL-x3A">
508+
<objects>
509+
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="UDb-wa-Ofv" sceneMemberID="viewController">
510+
<toolbarItems/>
511+
<navigationBar key="navigationBar" contentMode="scaleToFill" id="ZPK-pT-Z9r">
512+
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
513+
<autoresizingMask key="autoresizingMask"/>
514+
</navigationBar>
515+
<nil name="viewControllers"/>
516+
<connections>
517+
<segue destination="Blb-hR-aDj" kind="relationship" relationship="rootViewController" id="FTt-lI-yuD"/>
518+
</connections>
519+
</navigationController>
520+
<placeholder placeholderIdentifier="IBFirstResponder" id="3YU-4j-vls" userLabel="First Responder" sceneMemberID="firstResponder"/>
521+
</objects>
522+
<point key="canvasLocation" x="136.80000000000001" y="886.50674662668678"/>
523+
</scene>
505524
</scenes>
506525
<inferredMetricsTieBreakers>
507-
<segue reference="Zbq-q6-BA9"/>
526+
<segue reference="jyr-Pc-8eS"/>
508527
</inferredMetricsTieBreakers>
509528
</document>

Calculator/Calculator/CalculatorViewController.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,17 @@ class CalculatorViewController: UIViewController {
115115
// MARK: - Navigation
116116

117117
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
118-
let destinationViewController = segue.destination
118+
var destinationViewController = segue.destination
119+
if let navigationController = destinationViewController as? UINavigationController {
120+
destinationViewController = navigationController.visibleViewController ?? destinationViewController
121+
}
119122
if let graphingViewController = destinationViewController as? GraphingViewController {
120123
if let identifier = segue.identifier {
121124
if identifier == "graph" {
122125
graphingViewController.unaryFunction = { [weak weakSelf = self] operand in
123126
let graphingDictionary: [String: Double] = ["M": operand]
124127
return weakSelf?.brain.evaluate(using: graphingDictionary).result }
128+
graphingViewController.navigationItem.title = self.brain.evaluate().description
125129
}
126130
}
127131
}

Calculator/CalculatorUITests/CalculatorUITests.swift

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -623,14 +623,22 @@ class CalculatorUITests: XCTestCase {
623623
XCTAssertTrue(app.staticTexts["39"].exists)
624624
}
625625

626-
func showCalculator() {
626+
func showCalculator(navBarTitle: String = "Calculator.GraphingView") {
627627
// Don't know if this is the best way to make the calculator visible ...
628-
if XCUIApplication().navigationBars["Calculator.GraphingView"].exists {
629-
XCUIApplication().navigationBars["Calculator.GraphingView"].buttons["Calculator"].tap()
630-
} else {
631-
if !XCUIApplication().navigationBars.element.isHittable {
628+
if XCUIApplication().buttons["Graph"].exists {
629+
if !XCUIApplication().buttons["Graph"].isHittable {
632630
XCUIApplication().children(matching: .window).element(boundBy: 0).children(matching: .other).element.children(matching: .other).element(boundBy: 1).children(matching: .other).element.swipeRight()
633631
}
632+
} else {
633+
if XCUIApplication().navigationBars[navBarTitle].exists {
634+
if XCUIApplication().navigationBars[navBarTitle].buttons["Calculator"].exists {
635+
XCUIApplication().navigationBars[navBarTitle].buttons["Calculator"].tap()
636+
}
637+
} else {
638+
if !XCUIApplication().navigationBars.element.isHittable {
639+
XCUIApplication().children(matching: .window).element(boundBy: 0).children(matching: .other).element.children(matching: .other).element(boundBy: 1).children(matching: .other).element.swipeRight()
640+
}
641+
}
634642
}
635643
}
636644

@@ -640,15 +648,15 @@ class CalculatorUITests: XCTestCase {
640648
app.buttons["M"].tap()
641649
app.buttons["cos"].tap()
642650
app.buttons["Graph"].tap()
643-
showCalculator()
651+
showCalculator(navBarTitle: "cos(M)")
644652
XCTAssert(app.staticTexts["cos(M) ="].exists)
645653
XCTAssert(app.staticTexts["1"].exists)
646654
XCTAssert(app.staticTexts[" "].exists)
647655

648656
app.buttons["M"].tap()
649657
app.buttons[""].tap()
650658
app.buttons["Graph"].tap()
651-
showCalculator()
659+
showCalculator(navBarTitle: "√(M)")
652660
XCTAssert(app.staticTexts["√(M) ="].exists)
653661
XCTAssert(app.staticTexts["0"].exists)
654662
XCTAssert(app.staticTexts[" "].exists)
@@ -660,17 +668,39 @@ class CalculatorUITests: XCTestCase {
660668
XCTAssert(app.staticTexts["3"].exists)
661669
XCTAssert(app.staticTexts["9"].exists)
662670
app.buttons["Graph"].tap()
663-
showCalculator()
671+
showCalculator(navBarTitle: "√(M)")
664672
XCTAssert(app.staticTexts["√(M) ="].exists)
665673
XCTAssert(app.staticTexts["3"].exists)
666674
XCTAssert(app.staticTexts["9"].exists)
667675

668676
app.buttons["M"].tap()
669677
app.buttons["tan"].tap()
670678
app.buttons["Graph"].tap()
671-
showCalculator()
679+
showCalculator(navBarTitle: "tan(M)")
672680
XCTAssert(app.staticTexts["tan(M) ="].exists)
673681
XCTAssert(app.staticTexts["-0.452316"].exists)
674682
XCTAssert(app.staticTexts["9"].exists)
675683
}
684+
685+
func testGraphTitleAssignment3Task8() {
686+
let app = XCUIApplication()
687+
688+
app.buttons["M"].tap()
689+
app.buttons["cos"].tap()
690+
app.buttons["Graph"].tap()
691+
XCTAssert(app.staticTexts["cos(M)"].exists)
692+
showCalculator(navBarTitle: "cos(M)")
693+
XCTAssert(app.staticTexts["cos(M) ="].exists)
694+
XCTAssert(app.staticTexts["1"].exists)
695+
XCTAssert(app.staticTexts[" "].exists)
696+
697+
app.buttons["M"].tap()
698+
app.buttons[""].tap()
699+
app.buttons["Graph"].tap()
700+
XCTAssert(app.staticTexts["√(M)"].exists)
701+
showCalculator(navBarTitle: "√(M)")
702+
XCTAssert(app.staticTexts["√(M) ="].exists)
703+
XCTAssert(app.staticTexts["0"].exists)
704+
XCTAssert(app.staticTexts[" "].exists)
705+
}
676706
}

0 commit comments

Comments
 (0)