92 lines
2.8 KiB
Swift
92 lines
2.8 KiB
Swift
import SwiftUI
|
|
import Testing
|
|
@testable import Clawdbot
|
|
|
|
@Suite(.serialized)
|
|
@MainActor
|
|
struct CronJobEditorSmokeTests {
|
|
@Test func statusPillBuildsBody() {
|
|
_ = StatusPill(text: "ok", tint: .green).body
|
|
_ = StatusPill(text: "disabled", tint: .secondary).body
|
|
}
|
|
|
|
@Test func cronJobEditorBuildsBodyForNewJob() {
|
|
let view = CronJobEditor(
|
|
job: nil,
|
|
isSaving: .constant(false),
|
|
error: .constant(nil),
|
|
onCancel: {},
|
|
onSave: { _ in })
|
|
_ = view.body
|
|
}
|
|
|
|
@Test func cronJobEditorBuildsBodyForExistingJob() {
|
|
let job = CronJob(
|
|
id: "job-1",
|
|
agentId: "ops",
|
|
name: "Daily summary",
|
|
description: nil,
|
|
enabled: true,
|
|
deleteAfterRun: nil,
|
|
createdAtMs: 1_700_000_000_000,
|
|
updatedAtMs: 1_700_000_000_000,
|
|
schedule: .every(everyMs: 3_600_000, anchorMs: 1_700_000_000_000),
|
|
sessionTarget: .isolated,
|
|
wakeMode: .nextHeartbeat,
|
|
payload: .agentTurn(
|
|
message: "Summarize the last day",
|
|
thinking: "low",
|
|
timeoutSeconds: 120,
|
|
deliver: true,
|
|
provider: "whatsapp",
|
|
to: "+15551234567",
|
|
bestEffortDeliver: true),
|
|
isolation: CronIsolation(postToMainPrefix: "Cron"),
|
|
state: CronJobState(
|
|
nextRunAtMs: 1_700_000_100_000,
|
|
runningAtMs: nil,
|
|
lastRunAtMs: 1_700_000_050_000,
|
|
lastStatus: "ok",
|
|
lastError: nil,
|
|
lastDurationMs: 1000))
|
|
|
|
let view = CronJobEditor(
|
|
job: job,
|
|
isSaving: .constant(false),
|
|
error: .constant(nil),
|
|
onCancel: {},
|
|
onSave: { _ in })
|
|
_ = view.body
|
|
}
|
|
|
|
@Test func cronJobEditorExercisesBuilders() {
|
|
var view = CronJobEditor(
|
|
job: nil,
|
|
isSaving: .constant(false),
|
|
error: .constant(nil),
|
|
onCancel: {},
|
|
onSave: { _ in })
|
|
view.exerciseForTesting()
|
|
}
|
|
|
|
@Test func cronJobEditorIncludesDeleteAfterRunForAtSchedule() throws {
|
|
var view = CronJobEditor(
|
|
job: nil,
|
|
isSaving: .constant(false),
|
|
error: .constant(nil),
|
|
onCancel: {},
|
|
onSave: { _ in })
|
|
view.name = "One-shot"
|
|
view.sessionTarget = .main
|
|
view.payloadKind = .systemEvent
|
|
view.systemEventText = "hello"
|
|
view.scheduleKind = .at
|
|
view.atDate = Date(timeIntervalSince1970: 1_700_000_000)
|
|
view.deleteAfterRun = true
|
|
|
|
let payload = try view.buildPayload()
|
|
let raw = payload["deleteAfterRun"]?.value as? Bool
|
|
#expect(raw == true)
|
|
}
|
|
}
|