2026-02-12 04:08:30 +01:00
|
|
|
import SwiftUI
|
2026-02-09 17:53:40 +00:00
|
|
|
import Testing
|
|
|
|
|
|
|
|
|
|
@testable import Todos
|
|
|
|
|
|
2026-02-11 18:22:26 +00:00
|
|
|
@MainActor
|
2026-02-10 02:22:41 +00:00
|
|
|
@Suite("ContentView view model tests")
|
2026-02-09 17:53:40 +00:00
|
|
|
struct ContentViewModelTests {
|
|
|
|
|
|
|
|
|
|
// MARK: Initialization Tests
|
|
|
|
|
|
|
|
|
|
@Test("View model initializes with default values")
|
|
|
|
|
func initialization() {
|
|
|
|
|
// GIVEN
|
|
|
|
|
// WHEN
|
|
|
|
|
let viewModel = ContentView.ViewModel()
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
#expect(viewModel.newTaskShown == false)
|
2026-02-12 04:08:30 +01:00
|
|
|
#expect(viewModel.group == nil)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MARK: - Computed Property Tests
|
|
|
|
|
|
|
|
|
|
@Test(
|
|
|
|
|
"showNewTaskButtonInDetails returns expected value for every group",
|
|
|
|
|
arguments: zip(
|
|
|
|
|
[TodoGroup.today, .upcoming, .overdue, .completed, nil],
|
|
|
|
|
[true, true, true, false, false]
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
func showNewTaskButtonInDetails(
|
|
|
|
|
for group: TodoGroup?,
|
|
|
|
|
expects expectation: Bool
|
|
|
|
|
) {
|
|
|
|
|
// GIVEN
|
|
|
|
|
let viewModel = ContentView.ViewModel()
|
|
|
|
|
|
|
|
|
|
viewModel.group = group
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
let shouldNewTaskButton = viewModel.showNewTaskButtonInDetails
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
#expect(shouldNewTaskButton == expectation)
|
2026-02-09 17:53:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MARK: - Functions Tests
|
|
|
|
|
|
2026-02-12 04:08:30 +01:00
|
|
|
@Test("showNewTask sets newTaskShown to true")
|
2026-02-09 17:53:40 +00:00
|
|
|
func newTaskShown() {
|
|
|
|
|
// GIVEN
|
|
|
|
|
let viewModel = ContentView.ViewModel()
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
viewModel.showNewTask()
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
#expect(viewModel.newTaskShown == true)
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-12 04:08:30 +01:00
|
|
|
@Test(
|
|
|
|
|
"showNewTaskButtonInSidebar returns expected value for every horizontal size class",
|
|
|
|
|
arguments: zip(
|
|
|
|
|
[UserInterfaceSizeClass.compact, .regular, nil],
|
|
|
|
|
[true, false, false]
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
func showNewTaskButtonInSidebar(
|
|
|
|
|
for horizontalSizeClass: UserInterfaceSizeClass?,
|
|
|
|
|
expects expectation: Bool
|
|
|
|
|
) {
|
|
|
|
|
// GIVEN
|
|
|
|
|
let viewModel = ContentView.ViewModel()
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
let shouldNewTaskButton = viewModel.showNewTaskButtonInSidebar(when: horizontalSizeClass)
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
#expect(shouldNewTaskButton == expectation)
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-09 17:53:40 +00:00
|
|
|
}
|