Skip to content

Commit

Permalink
Adds some ways to test view controllers, kinda (#292)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZachOrr authored Nov 19, 2018
1 parent 4938841 commit 929cc1c
Show file tree
Hide file tree
Showing 40 changed files with 517 additions and 269 deletions.
6 changes: 3 additions & 3 deletions tba-unit-tests/Core Data/Award/AwardRecipientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class AwardRecipientTestCase: AwardTestCase {
// Our Award Recipient shouldn't be able to be saved without an Award Recipient
XCTAssertThrowsError(try persistentContainer.viewContext.save())

let event = districtEvent()
let event = insertDistrictEvent()

let modelAward = TBAAward(name: "The Fake Award",
awardType: 2,
Expand Down Expand Up @@ -91,7 +91,7 @@ class AwardRecipientTestCase: AwardTestCase {
}

override func test_delete() {
let event = districtEvent()
let event = insertDistrictEvent()

let modelRecipient = TBAAwardRecipient(teamKey: "frc7332")
let recipient = AwardRecipient.insert(modelRecipient, in: persistentContainer.viewContext)
Expand Down Expand Up @@ -126,7 +126,7 @@ class AwardRecipientTestCase: AwardTestCase {
}

func test_delete_deny() {
let event = districtEvent()
let event = insertDistrictEvent()

let modelRecipient = TBAAwardRecipient(awardee: "Zachary Orr")
let recipient = AwardRecipient.insert(modelRecipient, in: persistentContainer.viewContext)
Expand Down
8 changes: 4 additions & 4 deletions tba-unit-tests/Core Data/Award/AwardTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import XCTest
class AwardTestCase: CoreDataTestCase {

func test_insert() {
let event = districtEvent()
let event = insertDistrictEvent()

let modelAwardRecipient = TBAAwardRecipient(teamKey: "frc7332")
let modelAward = TBAAward(name: "The Fake Award",
Expand All @@ -29,7 +29,7 @@ class AwardTestCase: CoreDataTestCase {
}

func test_insert_validate() {
let event = districtEvent()
let event = insertDistrictEvent()

let modelAward = TBAAward(name: "The Fake Award",
awardType: 2,
Expand All @@ -50,7 +50,7 @@ class AwardTestCase: CoreDataTestCase {
}

func test_update() {
let event = districtEvent()
let event = insertDistrictEvent()

let frc1Model = TBAAwardRecipient(teamKey: "frc1")
let frc2Model = TBAAwardRecipient(teamKey: "frc2")
Expand Down Expand Up @@ -112,7 +112,7 @@ class AwardTestCase: CoreDataTestCase {
}

func test_delete() {
let event = districtEvent()
let event = insertDistrictEvent()

let frc1Model = TBAAwardRecipient(teamKey: "frc1")
let frc2Model = TBAAwardRecipient(teamKey: "frc2")
Expand Down
71 changes: 69 additions & 2 deletions tba-unit-tests/Core Data/CoreDataTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class CoreDataTestCase: FBSnapshotTestCase {
super.setUp()

agnosticOptions = .OS
// Uncomment to record all new snapshots
// recordMode = true

persistentContainer = NSPersistentContainer(name: "TBA", managedObjectModel: CoreDataTestCase.managedObjectModel)

Expand All @@ -37,7 +39,45 @@ class CoreDataTestCase: FBSnapshotTestCase {
wait(for: [persistentContainerSetupExpectation], timeout: 10.0)
}

func districtEvent(eventKey: String = "2018miket") -> Event {
func insertEvent(year: Int = 2015) -> Event {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd"

let model = TBAEvent(key: "\(year)qcmo",
name: "FRC Festival de Robotique - Montreal Regional",
eventCode: "qcmo",
eventType: 0,
district: nil,
city: nil,
stateProv: nil,
country: nil,
startDate: dateFormatter.date(from: "\(year)-03-18")!,
endDate: dateFormatter.date(from: "\(year)-03-21")!,
year: year,
shortName: "Festival de Robotique - Montreal",
eventTypeString: "Reginal",
week: 3,
address: nil,
postalCode: nil,
gmapsPlaceID: nil,
gmapsURL: nil,
lat: nil,
lng: nil,
locationName: nil,
timezone: nil,
website: nil,
firstEventID: nil,
firstEventCode: nil,
webcasts: nil,
divisionKeys: [],
parentEventKey: nil,
playoffType: nil,
playoffTypeString: nil)

return Event.insert(model, in: persistentContainer.viewContext)
}

func insertDistrictEvent(eventKey: String = "2018miket") -> Event {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd"

Expand Down Expand Up @@ -76,7 +116,34 @@ class CoreDataTestCase: FBSnapshotTestCase {
return Event.insert(model, in: persistentContainer.viewContext)
}

func verifyView(_ view: UIView, identifier: String) {
func insertTeam() -> Team {
let team = TBATeam(key: "frc7332",
teamNumber: 7332,
nickname: "The Rawrbotz",
name: "General Motors/Premier Tooling Systems/Microsoft/The Chrysler Foundation/Davison Tool & Engineering, L.L.C./The Robot Space/Michigan Department of Education/Kettering University/Taylor Steel/DXC Technology/Complete Scrap/ZF North America & Grand Blanc Community High School",
city: nil,
stateProv: nil,
country: nil,
address: nil,
postalCode: nil,
gmapsPlaceID: nil,
gmapsURL: nil,
lat: nil,
lng: nil,
locationName: nil,
website: nil,
rookieYear: 2010,
motto: nil,
homeChampionship: nil)
return Team.insert(team, in: persistentContainer.viewContext)
}

func insertDistrict() -> District {
let district = TBADistrict(abbreviation: "fim", name: "FIRST In Michigan", key: "2018fim", year: 2018)
return District.insert(district, in: persistentContainer.viewContext)
}

func verifyView(_ view: UIView, identifier: String = "") {
FBSnapshotVerifyView(view,
identifier: identifier,
suffixes: NSOrderedSet(array: [""]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class DistrictEventPointsTestCase: CoreDataTestCase {
}

func test_insert_event() {
let event = districtEvent()
let event = insertDistrictEvent()

let modelPointsOne = TBADistrictEventPoints(teamKey: "frc7332", eventKey: event.key!, alliancePoints: 10, awardPoints: 20, qualPoints: 30, elimPoints: 40, total: 50)
DistrictEventPoints.insert([modelPointsOne], eventKey: event.key!, in: persistentContainer.viewContext)
Expand Down Expand Up @@ -60,7 +60,7 @@ class DistrictEventPointsTestCase: CoreDataTestCase {
}

func test_delete() {
let event = districtEvent()
let event = insertDistrictEvent()
let modelEventPoints = TBADistrictEventPoints(teamKey: "frc7332", eventKey: event.key!, alliancePoints: 10, awardPoints: 20, qualPoints: 30, elimPoints: 40, total: 50)
let modelDistrictRanking = TBADistrictRanking(teamKey: "frc7332", rank: 1, rookieBonus: 10, pointTotal: 30, eventPoints: [modelEventPoints])
event.district!.insert([modelDistrictRanking])
Expand Down
8 changes: 4 additions & 4 deletions tba-unit-tests/Core Data/District/DistrictRankingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import XCTest
class DistrictRankingTestCase: CoreDataTestCase {

func test_insert() {
let event = districtEvent()
let event = insertDistrictEvent()

let eventPoints = TBADistrictEventPoints(teamKey: "frc7332", eventKey: event.key!, alliancePoints: 10, awardPoints: 20, qualPoints: 30, elimPoints: 40, total: 50)
let modelDistrictRanking = TBADistrictRanking(teamKey: "frc7332", rank: 1, rookieBonus: 10, pointTotal: 30, eventPoints: [eventPoints])
Expand All @@ -23,7 +23,7 @@ class DistrictRankingTestCase: CoreDataTestCase {
}

func test_update() {
let event = districtEvent()
let event = insertDistrictEvent()

let eventPoints = TBADistrictEventPoints(teamKey: "frc7332", eventKey: event.key!, alliancePoints: 10, awardPoints: 20, qualPoints: 30, elimPoints: 40, total: 50)
let modelDistrictRanking = TBADistrictRanking(teamKey: "frc7332", rank: 1, rookieBonus: 10, pointTotal: 30, eventPoints: [eventPoints])
Expand All @@ -33,7 +33,7 @@ class DistrictRankingTestCase: CoreDataTestCase {
// Attach to a District so we can save
event.district!.addToRankings(districtRanking)

let eventNew = districtEvent(eventKey: "2018mike2")
let eventNew = insertDistrictEvent(eventKey: "2018mike2")

let eventPointsNew = TBADistrictEventPoints(teamKey: "frc7332", eventKey: eventNew.key!, alliancePoints: 10, awardPoints: 20, qualPoints: 30, elimPoints: 40, total: 50)
let duplicateModelDistrictRanking = TBADistrictRanking(teamKey: "frc7332", rank: 2, rookieBonus: 10, pointTotal: 40, eventPoints: [eventPointsNew])
Expand Down Expand Up @@ -64,7 +64,7 @@ class DistrictRankingTestCase: CoreDataTestCase {
}

func test_delete() {
let event = districtEvent()
let event = insertDistrictEvent()
let district = event.district!

let eventPoints = TBADistrictEventPoints(teamKey: "frc7332", eventKey: event.key!, alliancePoints: 10, awardPoints: 20, qualPoints: 30, elimPoints: 40, total: 50)
Expand Down
2 changes: 1 addition & 1 deletion tba-unit-tests/Core Data/District/DistrictTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class DistrictTestCase: CoreDataTestCase {
}

func test_delete() {
let event = districtEvent()
let event = insertDistrictEvent()
let district = event.district!

let ranking = DistrictRanking(entity: DistrictRanking.entity(), insertInto: persistentContainer.viewContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class EventAllianceBackupTestCase: CoreDataTestCase {
}

func test_delete() {
let event = districtEvent()
let event = insertDistrictEvent()

let modelBackup = TBAAllianceBackup(teamIn: "frc1", teamOut: "frc2")
let modelAlliance = TBAAlliance(name: "Alliance 1", backup: modelBackup, declines: ["frc5"], picks: ["frc1", "frc2", "frc3"], status: nil)
Expand Down
14 changes: 7 additions & 7 deletions tba-unit-tests/Core Data/Event/EventAllianceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import XCTest
class EventAllianceTestCase: CoreDataTestCase {

func test_insert() {
let event = districtEvent()
let event = insertDistrictEvent()

let status = TBAAllianceStatus(currentRecord: nil, level: nil, playoffAverage: nil, record: nil, status: nil)
let model = TBAAlliance(name: "Alliance 1", backup: nil, declines: ["frc5"], picks: ["frc1", "frc2", "frc3"], status: status)
Expand All @@ -29,7 +29,7 @@ class EventAllianceTestCase: CoreDataTestCase {
}

func test_update() {
let event = districtEvent()
let event = insertDistrictEvent()

let modelBackup = TBAAllianceBackup(teamIn: "frc6", teamOut: "frc2")
let modelStatus = TBAAllianceStatus(currentRecord: nil, level: nil, playoffAverage: nil, record: nil, status: nil)
Expand Down Expand Up @@ -65,7 +65,7 @@ class EventAllianceTestCase: CoreDataTestCase {
}

func test_delete() {
let event = districtEvent()
let event = insertDistrictEvent()

let modelBackup = TBAAllianceBackup(teamIn: "frc2", teamOut: "frc3")
let modelStatus = TBAAllianceStatus(currentRecord: nil, level: nil, playoffAverage: nil, record: nil, status: nil)
Expand Down Expand Up @@ -96,7 +96,7 @@ class EventAllianceTestCase: CoreDataTestCase {
}

func test_delete_backup() {
let event = districtEvent()
let event = insertDistrictEvent()

let modelBackup = TBAAllianceBackup(teamIn: "frc2", teamOut: "frc3")

Expand All @@ -107,7 +107,7 @@ class EventAllianceTestCase: CoreDataTestCase {
let backup = allianceOne.backup!

// Attach our Backup to another alliance, so it's not an oprhan after AllianceOne is gone
let eventTwo = districtEvent(eventKey: "2018mike2")
let eventTwo = insertDistrictEvent(eventKey: "2018mike2")
let modelTwo = TBAAlliance(name: "Alliance 1", backup: modelBackup, declines: nil, picks: ["frc1"], status: nil)
let allianceTwo = EventAlliance.insert(modelTwo, eventKey: eventTwo.key!, in: persistentContainer.viewContext)
eventTwo.addToAlliances(allianceTwo)
Expand All @@ -134,7 +134,7 @@ class EventAllianceTestCase: CoreDataTestCase {
}

func test_delete_backup_status() {
let event = districtEvent()
let event = insertDistrictEvent()

let modelBackup = TBAAllianceBackup(teamIn: "frc2", teamOut: "frc3")

Expand Down Expand Up @@ -166,7 +166,7 @@ class EventAllianceTestCase: CoreDataTestCase {

func test_delete_status() {
// Should not delete status when still attached to an Event Status
let event = districtEvent()
let event = insertDistrictEvent()

let modelStatus = TBAAllianceStatus(currentRecord: nil, level: nil, playoffAverage: nil, record: nil, status: nil)

Expand Down
8 changes: 4 additions & 4 deletions tba-unit-tests/Core Data/Event/EventInsightsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import XCTest
class EventInsightsTestCase: CoreDataTestCase {

func test_insert() {
let event = districtEvent()
let event = insertDistrictEvent()

let model = TBAEventInsights(qual: ["abc": 2], playoff: ["def": 3])
let insights = EventInsights.insert(model, eventKey: event.key!, in: persistentContainer.viewContext)
Expand All @@ -20,7 +20,7 @@ class EventInsightsTestCase: CoreDataTestCase {
}

func test_update() {
let event = districtEvent()
let event = insertDistrictEvent()

let modelOne = TBAEventInsights(qual: ["abc": 2], playoff: ["def": 3])
let insightsOne = EventInsights.insert(modelOne, eventKey: event.key!, in: persistentContainer.viewContext)
Expand All @@ -39,7 +39,7 @@ class EventInsightsTestCase: CoreDataTestCase {
}

func test_delete() {
let event = districtEvent()
let event = insertDistrictEvent()

let model = TBAEventInsights(qual: ["abc": 2], playoff: ["def": 3])
let insights = EventInsights.insert(model, eventKey: event.key!, in: persistentContainer.viewContext)
Expand All @@ -56,7 +56,7 @@ class EventInsightsTestCase: CoreDataTestCase {
let insights = EventInsights.init(entity: EventInsights.entity(), insertInto: persistentContainer.viewContext)
XCTAssert(insights.isOrphaned)

insights.event = districtEvent()
insights.event = insertDistrictEvent()
XCTAssertFalse(insights.isOrphaned)
insights.event = nil

Expand Down
2 changes: 1 addition & 1 deletion tba-unit-tests/Core Data/Event/EventKeyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class EventKeyTestCase: CoreDataTestCase {
let eventKey = EventKey.insert(withKey: "2018miket", in: persistentContainer.viewContext)
XCTAssertNil(eventKey.event)

let event = districtEvent()
let event = insertDistrictEvent()
XCTAssertNotNil(eventKey.event)
XCTAssertEqual(eventKey.event, event)
}
Expand Down
10 changes: 5 additions & 5 deletions tba-unit-tests/Core Data/Event/EventRankingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import XCTest
class EventRankingTestCase: CoreDataTestCase {

func test_insert() {
let event = districtEvent()
let event = insertDistrictEvent()

let extraStatsInfo = [TBAEventRankingSortOrder(name: "Total Ranking Points", precision: 0)]
let sortOrderInfo = [
Expand Down Expand Up @@ -34,7 +34,7 @@ class EventRankingTestCase: CoreDataTestCase {
}

func test_insertPredicate() {
let event = districtEvent()
let event = insertDistrictEvent()
let model = TBAEventRanking(teamKey: "frc1", rank: 2)

let ranking = EventRanking.init(entity: EventRanking.entity(), insertInto: persistentContainer.viewContext)
Expand All @@ -58,7 +58,7 @@ class EventRankingTestCase: CoreDataTestCase {
}

func test_update() {
let event = districtEvent()
let event = insertDistrictEvent()

let extraStatsInfo = [TBAEventRankingSortOrder(name: "Total Ranking Points", precision: 0)]
let sortOrderInfo = [
Expand Down Expand Up @@ -92,7 +92,7 @@ class EventRankingTestCase: CoreDataTestCase {
}

func test_delete_orphan() {
let event = districtEvent()
let event = insertDistrictEvent()
let model = TBAEventRanking(teamKey: "frc1", rank: 2)
let qualStatusModel = TBAEventStatusQual(numTeams: nil, status: nil, ranking: nil, sortOrder: nil)

Expand All @@ -117,7 +117,7 @@ class EventRankingTestCase: CoreDataTestCase {
}

func test_delete_qualStatus() {
let event = districtEvent()
let event = insertDistrictEvent()
let model = TBAEventRanking(teamKey: "frc1", rank: 2)
let eventStatusModel = TBAEventStatus(teamKey: "frc1", eventKey: event.key!)
let qualStatusModel = TBAEventStatusQual(numTeams: nil, status: nil, ranking: nil, sortOrder: nil)
Expand Down
Loading

0 comments on commit 929cc1c

Please sign in to comment.