-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
102 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// URLSessionExtension.swift | ||
// Conjugar | ||
// | ||
// Created by Joshua Adams on 5/1/19. | ||
// Copyright © 2019 Josh Adams. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
extension URLSession { | ||
static func stubSession(ratingsCount: Int) -> URLSession { | ||
URLProtocolStub.testURLs = [RatingsFetcher.iTunesURL: RatingsFetcher.stubData(ratingsCount: ratingsCount)] | ||
let config = URLSessionConfiguration.ephemeral | ||
config.protocolClasses = [URLProtocolStub.self] | ||
return URLSession(configuration: config) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// | ||
// SettingsVCTests.swift | ||
// ConjugarTests | ||
// | ||
// Created by Joshua Adams on 5/1/19. | ||
// Copyright © 2019 Josh Adams. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
import UIKit | ||
@testable import Conjugar | ||
|
||
class SettingsVCTests: XCTestCase { | ||
func testSettings() { | ||
var analytic = "" | ||
let settings = Settings(getterSetter: DictionaryGetterSetter(dictionary: [:])) | ||
let gameCenter = TestGameCenter(isAuthenticated: false) | ||
let ratingsCount = 42 | ||
let svc = SettingsVC(settings: settings, analyticsService: TestAnalyticsService(fire: { fired in analytic = fired }), gameCenter: gameCenter, session: URLSession.stubSession(ratingsCount: ratingsCount)) | ||
let nc = MockNavigationC(rootViewController: svc) | ||
UIApplication.shared.keyWindow?.rootViewController = nc | ||
XCTAssertNotNil(UIApplication.shared.keyWindow?.rootViewController) | ||
XCTAssertNotNil(svc) | ||
svc.viewWillAppear(true) | ||
XCTAssertTrue(nc.pushedViewController is SettingsVC) | ||
XCTAssertEqual(analytic, "visited viewController: \(SettingsVC.self) ") | ||
|
||
XCTAssertEqual(settings.region, .latinAmerica) | ||
let regionControl = svc.settingsView.regionControl | ||
regionControl.selectedSegmentIndex = 0 | ||
svc.regionChanged(regionControl) | ||
XCTAssertEqual(settings.region, .spain) | ||
|
||
XCTAssertEqual(settings.difficulty, .easy) | ||
let difficultyControl = svc.settingsView.difficultyControl | ||
difficultyControl.selectedSegmentIndex = 2 | ||
svc.difficultyChanged(difficultyControl) | ||
XCTAssertEqual(settings.difficulty, .difficult) | ||
difficultyControl.selectedSegmentIndex = 1 | ||
svc.difficultyChanged(difficultyControl) | ||
XCTAssertEqual(settings.difficulty, .moderate) | ||
|
||
XCTAssertEqual(settings.secondSingularBrowse, .tu) | ||
let browseVosControl = svc.settingsView.browseVosControl | ||
browseVosControl.selectedSegmentIndex = 2 | ||
svc.browseVosChanged(browseVosControl) | ||
XCTAssertEqual(settings.secondSingularBrowse, .both) | ||
browseVosControl.selectedSegmentIndex = 1 | ||
svc.browseVosChanged(browseVosControl) | ||
XCTAssertEqual(settings.secondSingularBrowse, .vos) | ||
|
||
XCTAssertEqual(settings.secondSingularQuiz, .tu) | ||
let quizVosControl = svc.settingsView.quizVosControl | ||
quizVosControl.selectedSegmentIndex = 1 | ||
svc.quizVosChanged(quizVosControl) | ||
XCTAssertEqual(settings.secondSingularQuiz, .vos) | ||
|
||
XCTAssertFalse(gameCenter.isAuthenticated) | ||
svc.authenticate() | ||
XCTAssert(gameCenter.isAuthenticated) | ||
|
||
let expectatiön = expectation(description: "testRateReview") | ||
svc.rateReview(completion: { didSucceed in | ||
XCTAssert(didSucceed) | ||
expectatiön.fulfill() | ||
}) | ||
let timeout: TimeInterval = 0.5 | ||
wait(for: [expectatiön], timeout: timeout) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters