Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125//// The /work page: a document the CLI renders, and user changes that are//// also queued as notes for the agent.
import albedo/harness/commandimport albedo/harness/extensions/work/command as work_commandimport albedo/harness/extensions/work/ledger as workimport gleam/dictimport gleam/erlang/processimport gleam/jsonimport gleam/option.{None, Some}import gleam/stringimport gleeunit/should
fn setup() { let assert Ok(store) = work.start(":memory:") let notes = process.new_subject() let context = command.Context(fn(op) { process.send(notes, op) Ok(json.null()) }) #(store, notes, work_command.command(store), context)}
fn run( page: command.Command, context, caller, action: String, details: String,) { let args = case action { "" -> dict.new() _ -> dict.from_list([#("action", action), #("details", details)]) } let assert Ok(command.Data(value)) = page.run(context, caller, args) json.to_string(value)}
pub fn listing_is_a_page_document_ordered_by_status_test() { let #(store, _, page, context) = setup() let assert Ok(_) = work.create(store, "write docs", "", None) let assert Ok(active) = work.create(store, "fix bug", "", None) let assert Ok(_) = work.update(store, work.Item(..active, status: work.Active)) page.page |> should.be_true let document = run(page, context, command.UserCall, "", "") string.contains(document, "\"title\":\"work\"") |> should.be_true string.contains(document, "\"summary\":\"1 active · 1 open\"") |> should.be_true // Active work sorts first, in both the page and its sidebar glance. let assert Ok(#(_, rows)) = string.split_once(document, "\"rows\":") let assert True = string.split_once(rows, "fix bug") |> fn(split) { case split { Ok(#(before, _)) -> !string.contains(before, "write docs") Error(_) -> False } } string.contains(document, "\"glance\":{") |> should.be_true}
pub fn user_changes_update_the_ledger_and_queue_a_note_test() { let #(store, notes, page, context) = setup() let added = run(page, context, command.UserCall, "add", "buy milk") string.contains(added, "added #1 · buy milk") |> should.be_true let assert Ok(command.Note("work", "added #1 · buy milk", text)) = process.receive(notes, 0) string.contains(text, "The user added work item #1") |> should.be_true
run(page, context, command.UserCall, "status", "1 done") let assert Ok(item) = work.get(store, 1) item.status |> should.equal(work.Done) let assert Ok(command.Note(_, "marked done #1 · buy milk", _)) = process.receive(notes, 0)
run(page, context, command.UserCall, "edit", "#1 buy oat milk") let assert Ok(item) = work.get(store, 1) item.title |> should.equal("buy oat milk") let assert Ok(_) = process.receive(notes, 0)
run(page, context, command.UserCall, "remove", "1") work.get(store, 1) |> should.equal(Error(work.NotFound)) let assert Ok(command.Note(_, "removed #1 · buy oat milk", _)) = process.receive(notes, 0)}
pub fn failed_changes_and_model_calls_queue_nothing_test() { let #(store, notes, page, context) = setup() let assert Ok(parent) = work.create(store, "parent", "", None) let assert Ok(_) = work.create(store, "child", "", Some(parent.id)) page.run( context, command.UserCall, dict.from_list([#("action", "remove"), #("details", "1")]), ) |> should.equal(Error("remove its sub-items first")) page.run( context, command.ModelCall, dict.from_list([#("action", "add"), #("details", "sneaky")]), ) |> should.equal(Error("only a user changes the ledger through /work")) page.run( context, command.UserCall, dict.from_list([#("action", "status"), #("details", "1 finished")]), ) |> should.equal(Error( "unknown work status finished; use open, active, blocked, done, or cancelled", )) process.receive(notes, 0) |> should.equal(Error(Nil))}
pub fn delete_is_revision_checked_test() { let #(store, _, _, _) = setup() let assert Ok(item) = work.create(store, "stale", "", None) let assert Ok(_) = work.update(store, work.Item(..item, title: "fresh")) work.delete(store, item.id, item.revision) |> should.equal(Error(work.Conflict)) let assert Ok(current) = work.get(store, item.id) let assert Ok(_) = work.delete(store, current.id, current.revision)}