|
| 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 | +} |
0 commit comments