Show completed task feature (#5)
This PR contains the work done to add support for showing or hiding completed todo tasks to the *Task list* view. Reviewed-on: rock-n-code/todos-app#5 Co-authored-by: Javier Cicchelli <javier@rock-n-code.com> Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
This commit was merged in pull request #5.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import Foundation
|
||||
import SwiftData
|
||||
import SwiftUI
|
||||
import Testing
|
||||
|
||||
@testable import Todos
|
||||
@@ -7,10 +8,73 @@ import Testing
|
||||
@Suite("TaskList view model tests")
|
||||
struct TaskListViewModelTests {
|
||||
|
||||
// MARK: Computed tests
|
||||
// MARK: Initializers tests
|
||||
|
||||
@Test(
|
||||
"navigationTitle returns correct title for each and every group",
|
||||
"properties are set correctly during initialization",
|
||||
arguments: TodoGroup.allCases
|
||||
)
|
||||
func initialization(for group: TodoGroup) {
|
||||
// GIVEN
|
||||
// WHEN
|
||||
let viewModel = TaskListView.ViewModel(group: group)
|
||||
|
||||
// THEN
|
||||
#expect(viewModel.group == group)
|
||||
#expect(viewModel.showCompleted == false)
|
||||
}
|
||||
|
||||
// MARK: Computed property tests
|
||||
|
||||
@Test(
|
||||
"buttonCompleted returns correct values when showCompleted is true",
|
||||
arguments: TodoGroup.allCases, [true, false]
|
||||
)
|
||||
func buttonCompleted(
|
||||
for group: TodoGroup,
|
||||
showCompleted: Bool
|
||||
) {
|
||||
// GIVEN
|
||||
let viewModel = TaskListView.ViewModel(group: group)
|
||||
|
||||
viewModel.showCompleted = showCompleted
|
||||
|
||||
// WHEN
|
||||
let (title, icon) = viewModel.buttonCompleted
|
||||
|
||||
// THEN
|
||||
if showCompleted {
|
||||
#expect(title == "view.task-list.label.hide-completed")
|
||||
#expect(icon == "eye.slash")
|
||||
} else {
|
||||
#expect(title == "view.task-list.label.show-completed")
|
||||
#expect(icon == "eye")
|
||||
}
|
||||
}
|
||||
|
||||
@Test(
|
||||
"canShowCompleted returns correct value for each group",
|
||||
arguments: zip(
|
||||
TodoGroup.allCases,
|
||||
[true, true, true, false]
|
||||
)
|
||||
)
|
||||
func canShowCompleted(
|
||||
for group: TodoGroup,
|
||||
expects expectation: Bool
|
||||
) {
|
||||
// GIVEN
|
||||
let viewModel = TaskListView.ViewModel(group: group)
|
||||
|
||||
// WHEN
|
||||
let canShowCompleted = viewModel.canShowCompleted
|
||||
|
||||
// THEN
|
||||
#expect(canShowCompleted == expectation)
|
||||
}
|
||||
|
||||
@Test(
|
||||
"navigationTitle returns correct view title for each group",
|
||||
arguments: TodoGroup.allCases
|
||||
)
|
||||
func navigationTitle(for group: TodoGroup) {
|
||||
@@ -24,4 +88,25 @@ struct TaskListViewModelTests {
|
||||
#expect(title == group.title)
|
||||
}
|
||||
|
||||
// MARK: Method tests
|
||||
|
||||
@Test("toggleCompletedVisbility toggles the showCompleted property")
|
||||
func toggleCompletedVisibility() {
|
||||
// GIVEN
|
||||
let viewModel = TaskListView.ViewModel(group: .today)
|
||||
let initialValue = viewModel.showCompleted
|
||||
|
||||
// WHEN
|
||||
viewModel.toggleCompletedVisibility()
|
||||
let afterFirstToggle = viewModel.showCompleted
|
||||
|
||||
viewModel.toggleCompletedVisibility()
|
||||
let afterSecondToggle = viewModel.showCompleted
|
||||
|
||||
// THEN
|
||||
#expect(initialValue == false)
|
||||
#expect(afterFirstToggle == true)
|
||||
#expect(afterSecondToggle == false)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user