Skip to content

Commit d3fd83e

Browse files
authored
Add snapshot test for FeedbackViewController. (#3971)
1 parent e45c83e commit d3fd83e

File tree

29 files changed

+110
-6
lines changed

29 files changed

+110
-6
lines changed

MapboxNavigation.xcodeproj/project.pbxproj

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@
374374
B4A78D32261FD47700FDF212 /* sthlm-double-back.json in Resources */ = {isa = PBXBuildFile; fileRef = B47C1AFE261FD0A30078546C /* sthlm-double-back.json */; };
375375
B4BB0AD52704D1D7006F502D /* short_route.json in Resources */ = {isa = PBXBuildFile; fileRef = B4BB0AD42704D1D7006F502D /* short_route.json */; };
376376
B4BB0AD72704D1E6006F502D /* multileg_route.json in Resources */ = {isa = PBXBuildFile; fileRef = B4BB0AD62704D1E6006F502D /* multileg_route.json */; };
377+
B4C8E39E286B72FA004D3EDD /* FeedbackViewControllerSnapshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4C8E39D286B72FA004D3EDD /* FeedbackViewControllerSnapshotTests.swift */; };
377378
B4E19C47268114840011581F /* NavigationLocationProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4E19C46268114840011581F /* NavigationLocationProvider.swift */; };
378379
B4E6711F27BB09D6004EE9C1 /* SpriteInfoCacheTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4E6711E27BB09D6004EE9C1 /* SpriteInfoCacheTests.swift */; };
379380
B4E6712227BB0A56004EE9C1 /* SpriteInfoCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4E6712027BB09EF004EE9C1 /* SpriteInfoCache.swift */; };
@@ -962,6 +963,7 @@
962963
B4B61B9627A882E200AA127E /* SpriteRepositoryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpriteRepositoryTests.swift; sourceTree = "<group>"; };
963964
B4BB0AD42704D1D7006F502D /* short_route.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = short_route.json; sourceTree = "<group>"; };
964965
B4BB0AD62704D1E6006F502D /* multileg_route.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = multileg_route.json; sourceTree = "<group>"; };
966+
B4C8E39D286B72FA004D3EDD /* FeedbackViewControllerSnapshotTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedbackViewControllerSnapshotTests.swift; sourceTree = "<group>"; };
965967
B4D4291826260D5900EE92A8 /* MBXInfo.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = MBXInfo.plist; sourceTree = "<group>"; };
966968
B4E19C46268114840011581F /* NavigationLocationProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationLocationProvider.swift; sourceTree = "<group>"; };
967969
B4E6711E27BB09D6004EE9C1 /* SpriteInfoCacheTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpriteInfoCacheTests.swift; sourceTree = "<group>"; };
@@ -1349,7 +1351,7 @@
13491351
8AB316C026BC9FAB00C3AC76 /* Instructions */,
13501352
8AB316C126BC9FFC00C3AC76 /* Cache */,
13511353
8AB316BE26BC9F6A00C3AC76 /* Style */,
1352-
8A379B0E27B5E3E000CE0A23 /* End of Route */,
1354+
8A379B0E27B5E3E000CE0A23 /* Feedback */,
13531355
8AB316BF26BC9F8900C3AC76 /* Speech */,
13541356
8AB316BC26BC9E1E00C3AC76 /* CarPlay */,
13551357
16E11B53212B3D4700027CD3 /* Extensions */,
@@ -1513,12 +1515,13 @@
15131515
name = Instructions;
15141516
sourceTree = "<group>";
15151517
};
1516-
8A379B0E27B5E3E000CE0A23 /* End of Route */ = {
1518+
8A379B0E27B5E3E000CE0A23 /* Feedback */ = {
15171519
isa = PBXGroup;
15181520
children = (
15191521
8A379B0C27B5E3C600CE0A23 /* EndOfRouteFeedbackTests.swift */,
1522+
B4C8E39D286B72FA004D3EDD /* FeedbackViewControllerSnapshotTests.swift */,
15201523
);
1521-
name = "End of Route";
1524+
name = Feedback;
15221525
sourceTree = "<group>";
15231526
};
15241527
8AB316BC26BC9E1E00C3AC76 /* CarPlay */ = {
@@ -2800,6 +2803,7 @@
28002803
E2D14983265CFD3C008135A3 /* StatusViewTests.swift in Sources */,
28012804
8AB8F30026DD7C30003FF4EE /* CGPointTests.swift in Sources */,
28022805
8A5B281226D82AB600622FBD /* UserPuckCourseViewSnapshotTests.swift in Sources */,
2806+
B4C8E39E286B72FA004D3EDD /* FeedbackViewControllerSnapshotTests.swift in Sources */,
28032807
8AD12F4C26C193560008AE55 /* LeaksTests.swift in Sources */,
28042808
3502231A205BC94E00E1449A /* Constants.swift in Sources */,
28052809
DA0557252155040700A1F2AA /* RouteTests.swift in Sources */,

Sources/MapboxNavigation/DayStyle.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ open class DayStyle: Style {
178178
FeedbackCollectionView.appearance(for: phoneTraitCollection).cellColor = .black
179179
FeedbackSubtypeCollectionViewCell.appearance(for: phoneTraitCollection).normalCircleColor = .white
180180
FeedbackSubtypeCollectionViewCell.appearance(for: phoneTraitCollection).normalCircleOutlineColor = .darkText
181-
FeedbackSubtypeCollectionViewCell.appearance(for: phoneTraitCollection).selectedCircleColor = .systemBlue
181+
FeedbackSubtypeCollectionViewCell.appearance(for: phoneTraitCollection).selectedCircleColor = #colorLiteral(red: 0, green: 0.47843137, blue: 1, alpha: 1)
182182

183183
let regularAndRegularSizeClassPhoneTraitCollection = UITraitCollection(traitsFrom: [
184184
UITraitCollection(userInterfaceIdiom: .phone),

Sources/MapboxNavigation/Feedback/FeedbackSubtypeCollectionViewCell.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class FeedbackSubtypeCollectionViewCell: UICollectionViewCell {
3333
}
3434
}
3535

36-
@objc dynamic var selectedCircleColor: UIColor = .lightGray {
36+
@objc dynamic var selectedCircleColor: UIColor = .systemBlue {
3737
didSet {
3838
if showSelectedColor {
3939
circleColor = selectedCircleColor
@@ -42,7 +42,7 @@ class FeedbackSubtypeCollectionViewCell: UICollectionViewCell {
4242
}
4343
}
4444

45-
@objc dynamic var normalCircleColor: UIColor = .black {
45+
@objc dynamic var normalCircleColor: UIColor = .white {
4646
didSet {
4747
if !showSelectedColor {
4848
circleColor = normalCircleColor

Sources/TestHelper/NavigationEventsManagerTestDoubles.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ public class NavigationEventsManagerSpy: NavigationEventsManager {
7676
}
7777
return nil
7878
}
79+
80+
override public func createFeedback(screenshotOption: FeedbackScreenshotOption = .automatic) -> FeedbackEvent? {
81+
let sessionState = SessionState(currentRoute: nil, originalRoute: nil, routeIdentifier: nil)
82+
var event = PassiveNavigationEventDetails(dataSource: PassiveLocationManager(), sessionState: sessionState)
83+
event.userIdentifier = UIDevice.current.identifierForVendor?.uuidString
84+
event.event = MMEEventTypeNavigationFeedback
85+
return FeedbackEvent(eventDetails: event)
86+
}
7987
}
8088

8189
typealias FakeTelemetryEvent = (name: String, attributes: [String: Any])
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import XCTest
2+
import Foundation
3+
import SnapshotTesting
4+
@testable import TestHelper
5+
@testable import MapboxNavigation
6+
7+
class FeedbackViewControllerSnapshotTests: TestCase {
8+
9+
var feedbackViewController: FeedbackViewController!
10+
11+
override func setUp() {
12+
super.setUp()
13+
isRecording = false
14+
15+
feedbackViewController = FeedbackViewController(eventsManager: NavigationEventsManagerSpy(), type: .passiveNavigation)
16+
DayStyle().apply()
17+
}
18+
19+
override func tearDown() {
20+
super.tearDown()
21+
feedbackViewController = nil
22+
}
23+
24+
func createDetailedFeedbackViewController() -> FeedbackSubtypeViewController? {
25+
guard feedbackViewController.sections.count > 0, let feedback = feedbackViewController.currentFeedback else {
26+
XCTFail("Failed to create detailed FeedbackViewController.")
27+
return nil
28+
}
29+
let item = feedbackViewController.sections[0]
30+
let detailedFeedbackViewController = FeedbackSubtypeViewController(eventsManager: NavigationEventsManagerSpy(),
31+
feedbackType: item.type,
32+
feedback: feedback)
33+
return detailedFeedbackViewController
34+
}
35+
36+
func testDayFeedbackViewController() {
37+
assertImageSnapshot(matching: feedbackViewController, as: .image(precision: 0.95))
38+
}
39+
40+
func testNightFeedbackViewController() {
41+
NightStyleSpy().apply()
42+
assertImageSnapshot(matching: feedbackViewController, as: .image(precision: 0.95))
43+
}
44+
45+
func testDayDetailedFeedbackViewController() {
46+
guard let detailedFeedbackViewController = createDetailedFeedbackViewController() else {
47+
XCTFail("Failed to create detailed FeedbackViewController.")
48+
return
49+
}
50+
51+
// test the day style of detailed FeedbackSubtypeViewController
52+
assertImageSnapshot(matching: detailedFeedbackViewController, as: .image(precision: 0.95))
53+
54+
// test the day style of detailed FeedbackSubtypeViewController when selection
55+
let indexPath = IndexPath(row: 0, section: 0)
56+
detailedFeedbackViewController.collectionView(detailedFeedbackViewController.collectionView, didSelectItemAt: indexPath)
57+
assertImageSnapshot(matching: detailedFeedbackViewController, as: .image(precision: 0.95))
58+
}
59+
60+
func testNightDetailedFeedbackViewController() {
61+
NightStyleSpy().apply()
62+
guard let detailedFeedbackViewController = createDetailedFeedbackViewController() else {
63+
XCTFail("Failed to create detailed FeedbackViewController.")
64+
return
65+
}
66+
67+
// test the night style of detailed FeedbackSubtypeViewController
68+
assertImageSnapshot(matching: detailedFeedbackViewController, as: .image(precision: 0.95))
69+
70+
// test the night style of detailed FeedbackSubtypeViewController when selection
71+
let indexPath = IndexPath(row: 0, section: 0)
72+
detailedFeedbackViewController.collectionView(detailedFeedbackViewController.collectionView, didSelectItemAt: indexPath)
73+
assertImageSnapshot(matching: detailedFeedbackViewController, as: .image(precision: 0.95))
74+
75+
// test the detailed FeedbackSubtypeViewController keeping the selection after Style changes
76+
DayStyle().apply()
77+
assertImageSnapshot(matching: detailedFeedbackViewController, as: .image(precision: 0.95))
78+
79+
// test the detailed FeedbackSubtypeViewController deselection function after Style changes
80+
detailedFeedbackViewController.collectionView(detailedFeedbackViewController.collectionView, didDeselectItemAt: indexPath)
81+
assertImageSnapshot(matching: detailedFeedbackViewController, as: .image(precision: 0.95))
82+
}
83+
}
84+
85+
class NightStyleSpy: NightStyle {
86+
override func apply() {
87+
super.apply()
88+
let traitCollection = UITraitCollection(userInterfaceIdiom: .phone)
89+
FeedbackSubtypeCollectionViewCell.appearance(for: traitCollection).normalCircleColor = .lightGray
90+
UILabel.appearance(for: traitCollection, whenContainedInInstancesOf: [FeedbackViewController.self]).textColor = .red
91+
}
92+
}
Loading
Loading
114 KB
Loading
Loading
Loading

0 commit comments

Comments
 (0)