Skip to content

Commit

Permalink
History for competitions (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanCooper9 authored Jan 7, 2023
1 parent b649fff commit 9dd3703
Show file tree
Hide file tree
Showing 89 changed files with 2,388 additions and 584 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
steps:
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: '14.0'
xcode-version: '14.2'

- name: Checkout
uses: actions/checkout@v3
Expand Down
24 changes: 17 additions & 7 deletions Friendly Competitions Tests/Models/DeepLinkTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,35 @@ import XCTest

final class DeepLinkTests: XCTestCase {
func testThatFriendReferralCanBeInitialized() {
let url = URL(string: "https://friendly-competitions.app/friend/abc123")!
let url = URL(string: "https://friendly-competitions.app/user/abc123")!
let deepLink = DeepLink(from: url)
XCTAssertEqual(deepLink, .friendReferral(id: "abc123"))
XCTAssertEqual(deepLink, .user(id: "abc123"))
}

func testThatCompetitionInviteCanBeInitialized() {
func testThatCompetitionCanBeInitialized() {
let url = URL(string: "https://friendly-competitions.app/competition/abc123")!
let deepLink = DeepLink(from: url)
XCTAssertEqual(deepLink, .competitionInvite(id: "abc123"))
XCTAssertEqual(deepLink, .competition(id: "abc123"))
}

func testThatCompetitionHistoryCanBeInitialized() {
let url = URL(string: "https://friendly-competitions.app/competition/abc123/history")!
let deepLink = DeepLink(from: url)
XCTAssertEqual(deepLink, .competitionHistory(id: "abc123"))
}

func testThatUrlIsCorrect() {
XCTAssertEqual(
DeepLink.friendReferral(id: #function).url,
URL(string: "https://friendly-competitions.app/friend/\(#function)")!
DeepLink.user(id: #function).url,
URL(string: "https://friendly-competitions.app/user/\(#function)")!
)
XCTAssertEqual(
DeepLink.competitionInvite(id: #function).url,
DeepLink.competition(id: #function).url,
URL(string: "https://friendly-competitions.app/competition/\(#function)")!
)
XCTAssertEqual(
DeepLink.competitionHistory(id: #function).url,
URL(string: "https://friendly-competitions.app/competition/\(#function)/history")!
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import XCTest

@testable import Friendly_Competitions

final class DashboardViewModelTests: XCTestCase {
final class HomeViewModelTests: XCTestCase {

private var activitySummaryManager: ActivitySummaryManagingMock!
private var appState: AppStateProvidingMock!
private var competitionsManager: CompetitionsManagingMock!
private var friendsManager: FriendsManagingMock!
private var permissionsManager: PermissionsManagingMock!
Expand All @@ -18,13 +19,15 @@ final class DashboardViewModelTests: XCTestCase {

override func setUp() {
activitySummaryManager = .init()
appState = .init()
competitionsManager = .init()
friendsManager = .init()
permissionsManager = .init()
userManager = .init()
cancellables = .init()

activitySummaryManager.activitySummary = .never()
appState.deepLink = .never()
competitionsManager.competitions = .never()
competitionsManager.invitedCompetitions = .never()
friendsManager.friends = .never()
Expand All @@ -34,6 +37,7 @@ final class DashboardViewModelTests: XCTestCase {
userManager.userPublisher = .just(.evan)

Container.activitySummaryManager.register { self.activitySummaryManager }
Container.appState.register { self.appState }
Container.competitionsManager.register { self.competitionsManager }
Container.friendsManager.register { self.friendsManager }
Container.permissionsManager.register { self.permissionsManager }
Expand All @@ -60,7 +64,7 @@ final class DashboardViewModelTests: XCTestCase {

let ac = ActivitySummary.mock

let viewModel = DashboardViewModel()
let viewModel = HomeViewModel()
viewModel.$activitySummary
.expect(nil, ac, nil, ac, expectation: expectation)
.store(in: &cancellables)
Expand All @@ -80,7 +84,7 @@ final class DashboardViewModelTests: XCTestCase {
let comp1 = Competition.mock
let comp2 = Competition.mockOld

let viewModel = DashboardViewModel()
let viewModel = HomeViewModel()
viewModel.$competitions
.expect([], [comp1], [comp1, comp2], expectation: expectation)
.store(in: &cancellables)
Expand All @@ -99,7 +103,7 @@ final class DashboardViewModelTests: XCTestCase {
let comp1 = Competition.mock
let comp2 = Competition.mockOld

let viewModel = DashboardViewModel()
let viewModel = HomeViewModel()
viewModel.$invitedCompetitions
.expect([], [comp1], [comp1, comp2], expectation: expectation)
.store(in: &cancellables)
Expand All @@ -121,12 +125,12 @@ final class DashboardViewModelTests: XCTestCase {

let activitySummary = ActivitySummary.mock

let evan = DashboardViewModel.FriendRow(user: .evan, activitySummary: nil, isInvitation: false)
let evanWithAC = DashboardViewModel.FriendRow(user: .evan, activitySummary: activitySummary, isInvitation: false)
let andrew = DashboardViewModel.FriendRow(user: .andrew, activitySummary: nil, isInvitation: true)
let evan = HomeViewModel.FriendRow(user: .evan, activitySummary: nil, isInvitation: false)
let evanWithAC = HomeViewModel.FriendRow(user: .evan, activitySummary: activitySummary, isInvitation: false)
let andrew = HomeViewModel.FriendRow(user: .andrew, activitySummary: nil, isInvitation: true)

let viewModel = DashboardViewModel()
viewModel.$friends
let viewModel = HomeViewModel()
viewModel.$friendRows
.expect([], [evan], [evanWithAC], [evanWithAC, andrew], expectation: expectation)
.store(in: &cancellables)

Expand All @@ -143,7 +147,7 @@ final class DashboardViewModelTests: XCTestCase {
let subject = CurrentValueSubject<Bool, Never>(true)
permissionsManager.requiresPermission = subject.eraseToAnyPublisher()

let viewModel = DashboardViewModel()
let viewModel = HomeViewModel()
viewModel.$requiresPermissions
.expect(true, false, true, false, expectation: expectation)
.store(in: &cancellables)
Expand All @@ -160,7 +164,7 @@ final class DashboardViewModelTests: XCTestCase {
let subject = CurrentValueSubject<User, Never>(.evan)
userManager.userPublisher = subject.eraseToAnyPublisher()

let viewModel = DashboardViewModel()
let viewModel = HomeViewModel()
viewModel.$title
.expect(User.evan.name, Bundle.main.name, expectation: expectation)
.store(in: &cancellables)
Expand Down
61 changes: 0 additions & 61 deletions Friendly Competitions Tests/Views/HomeViewModelTests.swift

This file was deleted.

Loading

0 comments on commit 9dd3703

Please sign in to comment.