Skip to content

Commit e20b949

Browse files
committed
add unit tests
1 parent 1b4ac9f commit e20b949

4 files changed

Lines changed: 166 additions & 58 deletions

File tree

Conjugar.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
038E03152270A9FB005CFC96 /* TestGameCenterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 038E03142270A9FB005CFC96 /* TestGameCenterTests.swift */; };
1313
038E03182270AC01005CFC96 /* DeviceUtilityTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 038E03172270AC01005CFC96 /* DeviceUtilityTests.swift */; };
1414
038E031A22711B76005CFC96 /* UIViewControllerExtensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 038E031922711B76005CFC96 /* UIViewControllerExtensionTests.swift */; };
15+
038E031C2271E239005CFC96 /* AnalyticsServiceableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 038E031B2271E239005CFC96 /* AnalyticsServiceableTests.swift */; };
1516
E10178021F3F753400F0BC97 /* UIViewExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E10178011F3F753400F0BC97 /* UIViewExtensions.swift */; };
1617
E107B08B1EB66CE6004C5E91 /* verbs.xml in Resources */ = {isa = PBXBuildFile; fileRef = E107B08A1EB66CE6004C5E91 /* verbs.xml */; };
1718
E107B0921EB66F28004C5E91 /* VerbParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = E107B0911EB66F28004C5E91 /* VerbParser.swift */; };
@@ -151,6 +152,7 @@
151152
038E03142270A9FB005CFC96 /* TestGameCenterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestGameCenterTests.swift; sourceTree = "<group>"; };
152153
038E03172270AC01005CFC96 /* DeviceUtilityTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceUtilityTests.swift; sourceTree = "<group>"; };
153154
038E031922711B76005CFC96 /* UIViewControllerExtensionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIViewControllerExtensionTests.swift; sourceTree = "<group>"; };
155+
038E031B2271E239005CFC96 /* AnalyticsServiceableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalyticsServiceableTests.swift; sourceTree = "<group>"; };
154156
E10178011F3F753400F0BC97 /* UIViewExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIViewExtensions.swift; sourceTree = "<group>"; };
155157
E107B08A1EB66CE6004C5E91 /* verbs.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = verbs.xml; sourceTree = "<group>"; };
156158
E107B0911EB66F28004C5E91 /* VerbParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VerbParser.swift; sourceTree = "<group>"; };
@@ -287,6 +289,7 @@
287289
isa = PBXGroup;
288290
children = (
289291
038E03172270AC01005CFC96 /* DeviceUtilityTests.swift */,
292+
038E031B2271E239005CFC96 /* AnalyticsServiceableTests.swift */,
290293
);
291294
path = Analytics;
292295
sourceTree = "<group>";
@@ -836,6 +839,7 @@
836839
E1EC70F22198A10B00872787 /* UIViewControllerExtension.swift in Sources */,
837840
E14589F41F5B7BB000EEF141 /* BrowseInfoVCTests.swift in Sources */,
838841
E14589F61F5B7E9D00EEF141 /* VerbVCTests.swift in Sources */,
842+
038E031C2271E239005CFC96 /* AnalyticsServiceableTests.swift in Sources */,
839843
E15D3BF61F533997003771BB /* MockNavigationC.swift in Sources */,
840844
E198F9021F5D79F100BAF553 /* VerbViewTests.swift in Sources */,
841845
038E03152270A9FB005CFC96 /* TestGameCenterTests.swift in Sources */,

Conjugar/AnalyticsServiceable.swift

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ protocol AnalyticsServiceable {
1515
func recordQuizStart()
1616
func recordQuizCompletion(score: Int)
1717
func recordGameCenterAuth()
18+
19+
var visited: String { get }
20+
var viewContröller: String { get }
21+
var quizStart: String { get }
22+
var quizCompletion: String { get }
23+
var scöre: String { get }
24+
var gameCenterAuth: String { get }
1825
}
1926

2027
extension AnalyticsServiceable {
@@ -23,22 +30,42 @@ extension AnalyticsServiceable {
2330
}
2431

2532
func recordVisitation(viewController: String) {
26-
let visited = "visited"
27-
recordEvent(visited, parameters: ["viewController": "\(viewController)"], metrics: nil)
33+
recordEvent(visited, parameters: [viewContröller: "\(viewController)"], metrics: nil)
2834
}
2935

3036
func recordQuizStart() {
31-
let quizStart = "quizStart"
3237
recordEvent(quizStart)
3338
}
3439

3540
func recordQuizCompletion(score: Int) {
36-
let quizCompletion = "quizCompletion"
37-
recordEvent(quizCompletion, parameters: ["score": "\(score)"], metrics: nil)
41+
recordEvent(quizCompletion, parameters: [scöre: "\(score)"], metrics: nil)
3842
}
3943

4044
func recordGameCenterAuth() {
41-
let gameCenterAuth = "gameCenterAuth"
4245
recordEvent(gameCenterAuth)
4346
}
47+
48+
var visited: String {
49+
return "visited"
50+
}
51+
52+
var viewContröller: String {
53+
return "viewController"
54+
}
55+
56+
var quizStart: String {
57+
return "quizStart"
58+
}
59+
60+
var quizCompletion: String {
61+
return "quizCompletion"
62+
}
63+
64+
var scöre: String {
65+
return "score"
66+
}
67+
68+
var gameCenterAuth: String {
69+
return "gameCenterAuth"
70+
}
4471
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
//
2+
// AnalyticsServiceableTests.swift
3+
// ConjugarTests
4+
//
5+
// Created by Joshua Adams on 4/25/19.
6+
// Copyright © 2019 Josh Adams. All rights reserved.
7+
//
8+
9+
import XCTest
10+
@testable import Conjugar
11+
12+
class AnalyticsServiceableTests: XCTestCase {
13+
var analytics: [String] = []
14+
var service: TestAnalyticsService?
15+
private let nilServiceMessage = "TestAnalyticsService was nil."
16+
17+
override func setUp() {
18+
super.setUp()
19+
analytics = []
20+
service = TestAnalyticsService(fire: { event in
21+
self.analytics.append(event)
22+
})
23+
}
24+
25+
func testRecordEvent() {
26+
guard let service = service else {
27+
XCTFail(nilServiceMessage)
28+
return
29+
}
30+
let 🥥 = "🥥"
31+
XCTAssertFalse(analytics.contains(🥥))
32+
service.recordEvent(🥥)
33+
XCTAssert(analytics.contains(🥥))
34+
}
35+
36+
func testRecordVisitation() {
37+
guard let service = service else {
38+
XCTFail(nilServiceMessage)
39+
return
40+
}
41+
let pizzaViewController = "PizzaViewController"
42+
XCTAssertFalse(analytics.contains("\(service.visited) \(pizzaViewController)"))
43+
service.recordVisitation(viewController: pizzaViewController)
44+
XCTAssert(analytics.contains("\(service.visited) \(service.viewContröller): \(pizzaViewController) "))
45+
}
46+
47+
func testRecordQuizStart() {
48+
guard let service = service else {
49+
XCTFail(nilServiceMessage)
50+
return
51+
}
52+
XCTAssertFalse(analytics.contains(service.quizStart))
53+
service.recordQuizStart()
54+
XCTAssert(analytics.contains(service.quizStart))
55+
}
56+
57+
func testRecordQuizCompletion() {
58+
guard let service = service else {
59+
XCTFail(nilServiceMessage)
60+
return
61+
}
62+
let score = 42
63+
XCTAssertFalse(analytics.contains("\(service.quizCompletion) \(service.scöre): \(score) "))
64+
service.recordQuizCompletion(score: score)
65+
XCTAssert(analytics.contains("\(service.quizCompletion) \(service.scöre): \(score) "))
66+
}
67+
68+
func testRecordGameCenterAuth() {
69+
guard let service = service else {
70+
XCTFail(nilServiceMessage)
71+
return
72+
}
73+
XCTAssertFalse(analytics.contains("\(service.gameCenterAuth)"))
74+
service.recordGameCenterAuth()
75+
XCTAssert(analytics.contains("\(service.gameCenterAuth)"))
76+
}
77+
}

ConjugarUITests/QuizVCUITests.swift

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -6,55 +6,55 @@
66
// Copyright © 2018 Josh Adams. All rights reserved.
77
//
88

9-
//import XCTest
10-
//
11-
//class QuizVCUITests: XCTestCase {
12-
// let enableUiTesting = "enable-ui-testing"
13-
//
14-
// override func setUp() {
15-
// continueAfterFailure = false
16-
// }
17-
//
18-
// override func tearDown() {}
19-
//
20-
// func testDifficultSpainQuiz() {
21-
// testQuiz(answers: ["sintiendo", "midiendo", "caminando", "existiendo", "bebiendo", "andas", "ocurre", "leemos", "vais", "duermen", "hago", "fuiste", "dio", "pusimos", "trabajastéis", "recibieron", "aprendí", "ibas", "veía", "caminábamos", "andabais", "sabrán", "cabré", "trabajarás", "estudiará", "escucharíamos", "visitaríais", "podrían", "vaya", "hayas", "sepa", "estudiemos", "permitáis", "comprendan", "pudiera", "viajases", "estuviere", "enseñáremos", "ve", "llevad", "no llegen", "he cubierto", "hubiste bailado", "había dicho", "habremos nadado", "habríais escrito", "hayan cocinado", "hubiera hecho", "hubieses charlado", "hubiere muerto"], region: "Spain", difficulty: "Difficult")
22-
// }
23-
//
24-
// func testDifficultLatinAmericaQuiz() {
25-
// testQuiz(answers: ["sintiendo", "midiendo", "caminando", "existiendo", "bebiendo", "andas", "ocurre", "leemos", "van", "duermo", "haces", "fue", "dimos", "pusieron", "trabajé", "recibiste", "aprendió", "ibamos", "veían", "caminaba", "andabas", "sabrá", "cabremos", "trabajarán", "estudiaré", "escucharías", "visitaría", "podríamos", "vayan", "haya", "sepas", "estudie", "permitamos", "comprendan", "pudiera", "viajases", "estuviere", "enseñáremos", "ve", "lleven", "no llege", "hemos cubierto", "hubieron bailado", "había dicho", "habrás nadado", "habría escrito", "hayamos cocinado", "hubieran hecho", "hubiese charlado", "hubieres muerto"], region: "Latin America", difficulty: "Difficult")
26-
// }
27-
//
28-
// func testModerateSpainQuiz() {
29-
// testQuiz(answers: ["caminas", "anda", "existimos", "bebéis", "van", "duermo", "haces", "muere", "sabremos", "cabréis", "podrán", "caminaré", "andarás", "querría", "pondríamos", "tendríais", "trabajarían", "estudiaría", "has cubierto", "ha dicho", "hemos escrito", "habéis escuchado", "han visitado", "iba", "veías", "era", "viajábamos", "enseñabais", "llevaban", "fui", "diste", "puso", "trabajamos", "ocurristeis", "leieron", "vaya", "hayas", "sepa", "llegemos", "bailéis", "sintiendo", "midiendo", "nadando", "cocinando", "ve", "he", "charlen", "platice", "no lloremos", "no esperéis"], region: "Spain", difficulty: "Moderate")
30-
// }
31-
//
32-
// func testModerateLatinAmericaQuiz() {
33-
// testQuiz(answers: ["caminas", "anda", "existimos", "beben", "voy", "duermes", "hace", "morimos", "sabrán", "cabré", "podrás", "caminará", "andaremos", "querrían", "pondría", "tendrías", "trabajaría", "estudiaríamos", "han cubierto", "he dicho", "has escrito", "ha escuchado", "hemos visitado", "iban", "veía", "eras", "viajaba", "enseñábamos", "llevaban", "fui", "diste", "puso", "trabajamos", "ocurrieron", "leí", "vayas", "haya", "sepamos", "llegen", "baile", "sintiendo", "midiendo", "nadando", "cocinando", "ve", "he", "charle", "platicemos", "no lloren", "no espere"], region: "Latin America", difficulty: "Moderate")
34-
// }
35-
//
36-
// func testEasySpainQuiz() {
37-
// testQuiz(answers: ["caminas", "anda", "trabajamos", "existís", "ocurren", "recibo", "bebes", "lee", "aprendemos", "vais", "duermen", "hago", "mueres", "muerde", "oímos", "podéis", "han", "siento", "sabrás", "cabrá", "podremos", "querréis", "pondrán", "tendré", "vendrás", "saldrá", "estudiaremos", "escucharéis", "visitarán", "permitiré", "partirás", "comprenderá", "correremos", "fuisteis", "dieron", "puse", "pudiste", "estuvo", "tuvimos", "anduvisteis", "supieron", "caminé", "anduviste", "trabajó", "estudiamos", "escuchastéis", "visitaron", "viajé", "enseñaste", "llevó"], region: "Spain", difficulty: "Easy")
38-
// }
39-
//
40-
// func testEasyLatinAmericaQuiz() {
41-
// testQuiz(answers: ["caminas", "anda", "trabajamos", "existen", "ocurro", "recibes", "bebe", "leemos", "aprenden", "voy", "duermes", "hace", "morimos", "muerden", "oigo", "puedes", "ha", "sentimos", "sabrán", "cabré", "podrás", "querrá", "pondremos", "tendrán", "vendré", "saldrás", "estudiará", "escucharemos", "visitarán", "permitiré", "partirás", "comprenderá", "correremos", "fueron", "di", "pusiste", "pudo", "estuvimos", "tuvieron", "anduve", "supiste", "caminó", "anduvimos", "trabajaron", "estudié", "escuchaste", "visitó", "viajamos", "enseñaron", "llevé"], region: "Latin America", difficulty: "Easy")
42-
// }
43-
//
44-
// func testQuiz(answers: [String], region: String, difficulty: String) {
45-
// let app = XCUIApplication()
46-
// app.launchArguments = [enableUiTesting, region, difficulty]
47-
// app.launch()
48-
// app.tabBars.buttons["Quiz"].tap()
49-
// let timeout: TimeInterval = 1.0
50-
// XCTAssert(app.buttons["Start"].waitForExistence(timeout: timeout))
51-
// app.buttons["Start"].tap()
52-
// let textField = app.textFields[" conjugation"]
53-
// answers.forEach { conjugation in
54-
// textField.typeText(conjugation + "\n")
55-
// }
56-
// XCTAssert(app.staticTexts["Results"].waitForExistence(timeout: timeout))
57-
// XCTAssert(app.staticTexts[region].exists)
58-
// XCTAssert(app.staticTexts[difficulty].exists)
59-
// }
60-
//}
9+
import XCTest
10+
11+
class QuizVCUITests: XCTestCase {
12+
let enableUiTesting = "enable-ui-testing"
13+
14+
override func setUp() {
15+
continueAfterFailure = false
16+
}
17+
18+
override func tearDown() {}
19+
20+
func testDifficultSpainQuiz() {
21+
testQuiz(answers: ["sintiendo", "midiendo", "caminando", "existiendo", "bebiendo", "andas", "ocurre", "leemos", "vais", "duermen", "hago", "fuiste", "dio", "pusimos", "trabajastéis", "recibieron", "aprendí", "ibas", "veía", "caminábamos", "andabais", "sabrán", "cabré", "trabajarás", "estudiará", "escucharíamos", "visitaríais", "podrían", "vaya", "hayas", "sepa", "estudiemos", "permitáis", "comprendan", "pudiera", "viajases", "estuviere", "enseñáremos", "ve", "llevad", "no llegen", "he cubierto", "hubiste bailado", "había dicho", "habremos nadado", "habríais escrito", "hayan cocinado", "hubiera hecho", "hubieses charlado", "hubiere muerto"], region: "Spain", difficulty: "Difficult")
22+
}
23+
24+
func testDifficultLatinAmericaQuiz() {
25+
testQuiz(answers: ["sintiendo", "midiendo", "caminando", "existiendo", "bebiendo", "andas", "ocurre", "leemos", "van", "duermo", "haces", "fue", "dimos", "pusieron", "trabajé", "recibiste", "aprendió", "ibamos", "veían", "caminaba", "andabas", "sabrá", "cabremos", "trabajarán", "estudiaré", "escucharías", "visitaría", "podríamos", "vayan", "haya", "sepas", "estudie", "permitamos", "comprendan", "pudiera", "viajases", "estuviere", "enseñáremos", "ve", "lleven", "no llege", "hemos cubierto", "hubieron bailado", "había dicho", "habrás nadado", "habría escrito", "hayamos cocinado", "hubieran hecho", "hubiese charlado", "hubieres muerto"], region: "Latin America", difficulty: "Difficult")
26+
}
27+
28+
func testModerateSpainQuiz() {
29+
testQuiz(answers: ["caminas", "anda", "existimos", "bebéis", "van", "duermo", "haces", "muere", "sabremos", "cabréis", "podrán", "caminaré", "andarás", "querría", "pondríamos", "tendríais", "trabajarían", "estudiaría", "has cubierto", "ha dicho", "hemos escrito", "habéis escuchado", "han visitado", "iba", "veías", "era", "viajábamos", "enseñabais", "llevaban", "fui", "diste", "puso", "trabajamos", "ocurristeis", "leieron", "vaya", "hayas", "sepa", "llegemos", "bailéis", "sintiendo", "midiendo", "nadando", "cocinando", "ve", "he", "charlen", "platice", "no lloremos", "no esperéis"], region: "Spain", difficulty: "Moderate")
30+
}
31+
32+
func testModerateLatinAmericaQuiz() {
33+
testQuiz(answers: ["caminas", "anda", "existimos", "beben", "voy", "duermes", "hace", "morimos", "sabrán", "cabré", "podrás", "caminará", "andaremos", "querrían", "pondría", "tendrías", "trabajaría", "estudiaríamos", "han cubierto", "he dicho", "has escrito", "ha escuchado", "hemos visitado", "iban", "veía", "eras", "viajaba", "enseñábamos", "llevaban", "fui", "diste", "puso", "trabajamos", "ocurrieron", "leí", "vayas", "haya", "sepamos", "llegen", "baile", "sintiendo", "midiendo", "nadando", "cocinando", "ve", "he", "charle", "platicemos", "no lloren", "no espere"], region: "Latin America", difficulty: "Moderate")
34+
}
35+
36+
func testEasySpainQuiz() {
37+
testQuiz(answers: ["caminas", "anda", "trabajamos", "existís", "ocurren", "recibo", "bebes", "lee", "aprendemos", "vais", "duermen", "hago", "mueres", "muerde", "oímos", "podéis", "han", "siento", "sabrás", "cabrá", "podremos", "querréis", "pondrán", "tendré", "vendrás", "saldrá", "estudiaremos", "escucharéis", "visitarán", "permitiré", "partirás", "comprenderá", "correremos", "fuisteis", "dieron", "puse", "pudiste", "estuvo", "tuvimos", "anduvisteis", "supieron", "caminé", "anduviste", "trabajó", "estudiamos", "escuchastéis", "visitaron", "viajé", "enseñaste", "llevó"], region: "Spain", difficulty: "Easy")
38+
}
39+
40+
func testEasyLatinAmericaQuiz() {
41+
testQuiz(answers: ["caminas", "anda", "trabajamos", "existen", "ocurro", "recibes", "bebe", "leemos", "aprenden", "voy", "duermes", "hace", "morimos", "muerden", "oigo", "puedes", "ha", "sentimos", "sabrán", "cabré", "podrás", "querrá", "pondremos", "tendrán", "vendré", "saldrás", "estudiará", "escucharemos", "visitarán", "permitiré", "partirás", "comprenderá", "correremos", "fueron", "di", "pusiste", "pudo", "estuvimos", "tuvieron", "anduve", "supiste", "caminó", "anduvimos", "trabajaron", "estudié", "escuchaste", "visitó", "viajamos", "enseñaron", "llevé"], region: "Latin America", difficulty: "Easy")
42+
}
43+
44+
func testQuiz(answers: [String], region: String, difficulty: String) {
45+
let app = XCUIApplication()
46+
app.launchArguments = [enableUiTesting, region, difficulty]
47+
app.launch()
48+
app.tabBars.buttons["Quiz"].tap()
49+
let timeout: TimeInterval = 1.0
50+
XCTAssert(app.buttons["Start"].waitForExistence(timeout: timeout))
51+
app.buttons["Start"].tap()
52+
let textField = app.textFields[" conjugation"]
53+
answers.forEach { conjugation in
54+
textField.typeText(conjugation + "\n")
55+
}
56+
XCTAssert(app.staticTexts["Results"].waitForExistence(timeout: timeout))
57+
XCTAssert(app.staticTexts[region].exists)
58+
XCTAssert(app.staticTexts[difficulty].exists)
59+
}
60+
}

0 commit comments

Comments
 (0)