Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions Canvas.xcworkspace/xcshareddata/swiftpm/Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion Core/Core/Common/CommonUI/Fonts/UIFontExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,14 @@ public extension UIFont {

static func applicationFontName(weight: UIFont.Weight, isItalic: Bool = false) -> String {
let isK5Font = AppEnvironment.shared.k5.isK5Enabled
let font = isK5Font ? "BalsamiqSans" : "Lato"
let font: String
if isK5Font {
font = "BalsamiqSans"
} else if AppEnvironment.shared.app == .horizon {
font = "Figtree"
} else {
font = "Lato"
}
var suffix = ""

if isK5Font {
Expand Down
4 changes: 4 additions & 0 deletions Horizon/Horizon/horizon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ schemes:
build:
targets:
Horizon: all
test:
targets:
- HorizonSnapshotTests
- HorizonUnitTests
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
//
// This file is part of Canvas.
// Copyright (C) 2024-present Instructure, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

import Combine
import Core
import CoreData
@testable import Horizon
import HorizonUI
import SnapshotTesting
import SwiftUI
import TestsFoundation
import XCTest

class AccountViewSnapshotTests: HorizonSnapshotTestCase {
func testAccountViewDefault() {
let viewModel = createMockAccountViewModel(
userName: "John Doe",
isExperienceSwitchAvailable: true,
isLoading: false
)
let view = AccountView(viewModel: viewModel)

assertSnapshot(
of: view,
named: "account-default"
)
}

func testAccountViewLoading() {
let viewModel = createMockAccountViewModel(
userName: "John Doe",
isExperienceSwitchAvailable: true,
isLoading: true
)
let view = AccountView(viewModel: viewModel)

assertSnapshot(
of: view,
named: "account-loading"
)
}

func testAccountViewNoExperienceSwitch() {
let viewModel = createMockAccountViewModel(
userName: "Jane Smith",
isExperienceSwitchAvailable: false,
isLoading: false
)
let view = AccountView(viewModel: viewModel)

assertSnapshot(
of: view,
named: "account-no-experience-switch"
)
}

func testAccountViewAccessibility() {
let viewModel = createMockAccountViewModel(
userName: "Very Long User Name That Should Wrap",
isExperienceSwitchAvailable: true,
isLoading: false
)
let view = AccountView(viewModel: viewModel)

assertAccessibilitySnapshot(
of: view,
named: "account-accessibility"
)
}

// MARK: - Helper Methods

private func createMockAccountViewModel(
userName: String,
isExperienceSwitchAvailable: Bool,
isLoading: Bool
) -> AccountViewModel {
let mockUserInteractor = MockGetUserInteractor(userName: userName, context: databaseClient)
let mockExperienceInteractor = MockExperienceSummaryInteractor(isAvailable: isExperienceSwitchAvailable)

let viewModel = AccountViewModel(
getUserInteractor: mockUserInteractor,
appExperienceInteractor: mockExperienceInteractor
)

// Trigger data loading
viewModel.getUserName()

// Override loading state after initial setup
viewModel.isLoading = isLoading

return viewModel
}
}

// MARK: - Mock Interactors

private class MockGetUserInteractor: GetUserInteractor {
let userName: String
let context: NSManagedObjectContext

init(userName: String, context: NSManagedObjectContext) {
self.userName = userName
self.context = context
}

func getUser() -> AnyPublisher<UserProfile, Error> {
let user = UserProfile(context: context)
user.id = "1"
user.name = userName
user.shortName = userName
user.pronouns = nil
user.avatarURL = URL(string: "https://example.com/avatar.jpg")
user.email = "[email protected]"
user.locale = "en"

return Just(user)
.setFailureType(to: Error.self)
.eraseToAnyPublisher()
}

func canUpdateName() -> AnyPublisher<Bool, Error> {
Just(true)
.setFailureType(to: Error.self)
.eraseToAnyPublisher()
}
}

private class MockExperienceSummaryInteractor: ExperienceSummaryInteractor {
let isAvailable: Bool

init(isAvailable: Bool) {
self.isAvailable = isAvailable
}

func getExperienceSummary() -> AnyPublisher<Experience, Error> {
Just(.careerLearner)
.setFailureType(to: Error.self)
.eraseToAnyPublisher()
}

func isExperienceSwitchAvailable() -> AnyPublisher<Bool, Never> {
Just(isAvailable).eraseToAnyPublisher()
}

func isExperienceSwitchAvailableAsync() async -> Bool {
isAvailable
}

func switchExperience(to _: Experience) -> AnyPublisher<Void, Never> {
Just(()).eraseToAnyPublisher()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
//
// This file is part of Canvas.
// Copyright (C) 2024-present Instructure, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

import Combine
import Core
import CoreData
@testable import Horizon
import HorizonUI
import SnapshotTesting
import SwiftUI
import TestsFoundation
import XCTest

class ProfileAdvancedViewSnapshotTests: HorizonSnapshotTestCase {
func testProfileAdvancedViewDefault() {
let viewModel = createMockProfileAdvancedViewModel(timeZone: "America/Denver")
let view = ProfileAdvancedView(viewModel: viewModel)

assertSnapshot(
of: view,
named: "profile-advanced-default"
)
}

func testProfileAdvancedViewLoading() {
let viewModel = createMockProfileAdvancedViewModel(timeZone: "America/Denver")
viewModel.isLoading = true
let view = ProfileAdvancedView(viewModel: viewModel)

assertSnapshot(
of: view,
named: "profile-advanced-loading"
)
}

private func createMockProfileAdvancedViewModel(timeZone: String) -> ProfileAdvancedViewModel {
let mockGetUserInteractor = MockAdvancedGetUserInteractor(timeZone: timeZone, context: databaseClient)
let mockUpdateInteractor = MockAdvancedUpdateUserProfileInteractor(context: databaseClient)

return ProfileAdvancedViewModel(
getUserInteractor: mockGetUserInteractor,
updateUserProfileInteractor: mockUpdateInteractor
)
}
}

private class MockAdvancedGetUserInteractor: GetUserInteractor {
let timeZone: String
let context: NSManagedObjectContext

init(timeZone: String, context: NSManagedObjectContext) {
self.timeZone = timeZone
self.context = context
}

func getUser() -> AnyPublisher<UserProfile, Error> {
let user = UserProfile(context: context)
user.id = "1"
user.name = "Test User"
user.shortName = "Test"
user.email = "[email protected]"
user.defaultTimeZone = timeZone

return Just(user)
.setFailureType(to: Error.self)
.eraseToAnyPublisher()
}

func canUpdateName() -> AnyPublisher<Bool, Error> {
Just(true)
.setFailureType(to: Error.self)
.eraseToAnyPublisher()
}
}

private class MockAdvancedUpdateUserProfileInteractor: UpdateUserProfileInteractor {
let context: NSManagedObjectContext

init(context: NSManagedObjectContext) {
self.context = context
}

func set(name _: String, shortName _: String) -> AnyPublisher<UserProfile, Error> {
fatalError("Not implemented")
}

func set(timeZone: String) -> AnyPublisher<UserProfile, Error> {
let user = UserProfile(context: context)
user.id = "1"
user.name = "Test User"
user.defaultTimeZone = timeZone

return Just(user)
.setFailureType(to: Error.self)
.eraseToAnyPublisher()
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading