Contextful guarantee: notification includes past value #
This property checks that if there’s a non-blank name
entered, and it is submitted, then eventually there will be a
notification that includes the name. This example uses an outer
thunk to force a cell value (nameEntered) at every
state, and then closes over that value with the inner thunk
passed to eventually.
import { extract, always, now, next, eventually } from "@antithesishq/bombadil";
export * from "@antithesishq/bombadil/browser/defaults";
const name = extract((state) => {
const element =
state.document.body.querySelector("#name-field");
return (element as HTMLInputElement | null)?.value ?? null;
});
const submitInProgress = extract((state) =>
state.document.body.querySelector("submit.progress")
!== null,
);
const notificationText = extract((state) =>
state.document.body.querySelector(".notification")?.textContent
?? null,
);
export const notificationIncludesMessage = always(() => {
const nameEntered = name.current?.trim() ?? "";
return now(() => nameEntered !== "")
.and(next(() => submitInProgress.current))
.implies(eventually(() =>
notificationText.current?.includes(nameEntered)
?? false,
).within(5, "seconds"));
});