Files
honeyDueKMP/iosApp/iosApp/Subviews/Task/DynamicTaskCard.swift
Trey T 4df8707b92 UI test infrastructure overhaul — 58% to 96% pass rate (231/241)
Major infrastructure changes:
- BaseUITestCase: per-suite app termination via class setUp() prevents
  stale state when parallel clones share simulators
- relaunchBetweenTests override for suites that modify login/onboarding state
- focusAndType: dedicated SecureTextField path handles iOS strong password
  autofill suggestions (Choose My Own Password / Not Now dialogs)
- LoginScreenObject: tapSignUp/tapForgotPassword use scrollIntoView for
  offscreen buttons instead of simple swipeUp
- Removed all coordinate taps from ForgotPasswordScreen, VerifyResetCodeScreen,
  ResetPasswordScreen (Rule 3 compliance)
- Removed all usleep calls from screen objects (Rule 14 compliance)

App fixes exposed by tests:
- ContractorsListView: added onDismiss to sheet for list refresh after save
- AllTasksView: added Task.RefreshButton accessibility identifier
- AccessibilityIdentifiers: added Task.refreshButton
- DocumentsWarrantiesView: onDismiss handler for document list refresh
- Various form views: textContentType, submitLabel, onSubmit for keyboard flow

Test fixes:
- PasswordResetTests: handle auto-login after reset (app skips success screen)
- AuthenticatedUITestCase: refreshTasks() helper for kanban toolbar button
- All pre-login suites use relaunchBetweenTests for test independence
- Deleted dead code: AuthenticatedTestCase, SeededTestData, SeedTests,
  CleanupTests, old Suite0/2/3, Suite1_RegistrationRebuildTests

10 remaining failures: 5 iOS strong password autofill (simulator env),
3 pull-to-refresh gesture on empty lists, 2 feature coverage edge cases.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 15:05:37 -05:00

255 lines
8.9 KiB
Swift

import SwiftUI
import ComposeApp
/// Task card that dynamically renders buttons based on the column's button types
struct DynamicTaskCard: View {
let task: TaskResponse
let buttonTypes: [String]
let onEdit: () -> Void
let onCancel: () -> Void
let onUncancel: () -> Void
let onMarkInProgress: () -> Void
let onComplete: () -> Void
let onArchive: () -> Void
let onUnarchive: () -> Void
@State private var showCompletionHistory = false
var body: some View {
// let _ = print("📋 DynamicTaskCard - Task: \(task.title), ButtonTypes: \(buttonTypes)")
VStack(alignment: .leading, spacing: 12) {
HStack {
VStack(alignment: .leading, spacing: 4) {
Text(task.title)
.font(.title3)
.foregroundColor(.primary)
if task.inProgress {
StatusBadge(status: "in_progress")
}
}
Spacer()
if let priorityName = task.priorityName, !priorityName.isEmpty {
PriorityBadge(priority: priorityName)
}
}
if !task.description_.isEmpty {
Text(task.description_)
.font(.subheadline)
.foregroundColor(Color.appTextSecondary)
.lineLimit(2)
}
HStack {
if let frequency = task.frequencyDisplayName, !frequency.isEmpty {
Label(frequency, systemImage: "repeat")
.font(.caption)
.foregroundColor(Color.appTextSecondary)
}
Spacer()
if let effectiveDate = task.effectiveDueDate {
Label(effectiveDate.toFormattedDate(), systemImage: "calendar")
.font(.caption)
.foregroundColor(Color.appTextSecondary)
}
}
// Actions row with completion count button and actions menu
if !buttonTypes.isEmpty || task.completionCount > 0 {
Divider()
HStack(spacing: 12) {
// Actions menu
if !buttonTypes.isEmpty {
Menu {
menuContent
} label: {
HStack {
Image(systemName: "ellipsis.circle.fill")
.font(.title3)
Text("Actions")
.fontWeight(.medium)
}
.frame(maxWidth: .infinity)
.padding(.vertical, 12)
.background(Color.appPrimary.opacity(0.1))
.foregroundColor(Color.appPrimary)
.cornerRadius(8)
.overlay(
RoundedRectangle(cornerRadius: 8)
.stroke(Color.appPrimary, lineWidth: 2)
)
}
.zIndex(10)
.menuOrder(.fixed)
}
// Completion count button - shows when count > 0
if task.completionCount > 0 {
Button(action: {
showCompletionHistory = true
}) {
HStack(spacing: 6) {
Image(systemName: "checkmark.circle.fill")
.font(.title3)
Text("\(task.completionCount)")
.fontWeight(.bold)
}
.padding(.horizontal, 16)
.padding(.vertical, 12)
.background(Color.appAccent.opacity(0.1))
.foregroundColor(Color.appAccent)
.cornerRadius(8)
.overlay(
RoundedRectangle(cornerRadius: 8)
.stroke(Color.appAccent, lineWidth: 2)
)
}
}
}
}
}
.padding(16)
.background(Color.appBackgroundSecondary)
.cornerRadius(12)
.shadow(color: Color.black.opacity(0.1), radius: 5, x: 0, y: 2)
.simultaneousGesture(TapGesture(), including: .subviews)
.sheet(isPresented: $showCompletionHistory) {
CompletionHistorySheet(
taskTitle: task.title,
taskId: task.id,
isPresented: $showCompletionHistory
)
.presentationDetents([.medium, .large])
.presentationDragIndicator(.visible)
}
}
// MARK: - Menu Content
@ViewBuilder
private var menuContent: some View {
// Primary actions
ForEach(Array(buttonTypes.enumerated()), id: \.offset) { index, buttonType in
if isPrimaryAction(buttonType) {
menuButton(for: buttonType)
}
}
// Secondary actions (if any exist)
if buttonTypes.contains(where: { isSecondaryAction($0) }) {
Divider()
ForEach(Array(buttonTypes.enumerated()), id: \.offset) { index, buttonType in
if isSecondaryAction(buttonType) {
menuButton(for: buttonType)
}
}
}
// Destructive actions (if any exist)
if buttonTypes.contains(where: { isDestructiveAction($0) }) {
Divider()
ForEach(Array(buttonTypes.enumerated()), id: \.offset) { index, buttonType in
if isDestructiveAction(buttonType) {
menuButton(for: buttonType)
}
}
}
}
private func isPrimaryAction(_ buttonType: String) -> Bool {
["mark_in_progress", "complete", "edit", "uncancel", "unarchive"].contains(buttonType)
}
private func isSecondaryAction(_ buttonType: String) -> Bool {
["archive"].contains(buttonType)
}
private func isDestructiveAction(_ buttonType: String) -> Bool {
["cancel"].contains(buttonType)
}
@ViewBuilder
private func menuButton(for buttonType: String) -> some View {
switch buttonType {
case "mark_in_progress":
Button {
#if DEBUG
print("Mark In Progress tapped for task: \(task.id)")
#endif
onMarkInProgress()
} label: {
Label("Mark Task In Progress", systemImage: "play.circle")
}
.accessibilityIdentifier(AccessibilityIdentifiers.Task.markInProgressButton)
case "complete":
Button {
#if DEBUG
print("Complete tapped for task: \(task.id)")
#endif
onComplete()
} label: {
Label("Complete Task", systemImage: "checkmark.circle")
}
.accessibilityIdentifier(AccessibilityIdentifiers.Task.completeButton)
case "edit":
Button {
#if DEBUG
print("Edit tapped for task: \(task.id)")
#endif
onEdit()
} label: {
Label("Edit Task", systemImage: "pencil")
}
.accessibilityIdentifier(AccessibilityIdentifiers.Task.editButton)
case "cancel":
Button(role: .destructive) {
#if DEBUG
print("Cancel tapped for task: \(task.id)")
#endif
onCancel()
} label: {
Label("Cancel Task", systemImage: "xmark.circle")
}
.accessibilityIdentifier(AccessibilityIdentifiers.Task.deleteButton)
case "uncancel":
Button {
#if DEBUG
print("Restore tapped for task: \(task.id)")
#endif
onUncancel()
} label: {
Label("Restore Task", systemImage: "arrow.uturn.backward.circle")
}
case "archive":
Button {
#if DEBUG
print("Archive tapped for task: \(task.id)")
#endif
onArchive()
} label: {
Label("Archive Task", systemImage: "archivebox")
}
case "unarchive":
Button {
#if DEBUG
print("Unarchive tapped for task: \(task.id)")
#endif
onUnarchive()
} label: {
Label("Unarchive Task", systemImage: "arrow.up.bin")
}
default:
EmptyView()
}
}
}