TestFiles unstable
A fake HtmlFiles.Files for whole-app tests, so a test decides what the
user chooses in each file picker, and inspects download requests,
without a document, in Node too.
Provide layer next to TestHost.layer(). Every pick stays pending
until choose or dismiss settles it. Run TestHost.settle after it
to see the update. downloads returns the files requested for download.
Example Choosing a file in a whole-app test
import { UiSchema } from "effect/ui"import { Html, HtmlFiles } from "effect/ui/html"import { TestFiles } from "effect/ui/html/testing"import { TestHost } from "effect/ui/testing"import { Effect, Layer, Schema } from "effect"
const Message = UiSchema.TaggedEnum({ ClickedAttach: {}, Picked: { names: Schema.Array(Schema.String) }})
const Attach = Html.component({ name: "Attach", model: Schema.Array(Schema.String), message: Message}).make({ init: () => [], update: { ClickedAttach: ($) => $.run(HtmlFiles.pick(({ files }) => Message.Picked({ names: files.map((file) => file.name) }))), Picked: (_, { names }) => names }, view: (h, names) => h.button.on("click", Message.ClickedAttach()).children(names.join(", ") || "Attach")})
Effect.gen(function*() { const root = yield* TestHost.mount(Attach, {}) root.send(Message.ClickedAttach()) yield* TestHost.settle yield* TestFiles.choose([new File(["hi"], "notes.txt")]) yield* TestHost.settle root.model() // => ["notes.txt"]}).pipe(Effect.provide(Layer.merge(TestHost.layer(), TestFiles.layer)), Effect.scoped, Effect.runPromise)Constructors
Layers
Services
The TestFiles service.
Signature
declare const TestFiles: Service<TestFiles, TestFiles>The TestFiles service: the fake's control.
Signature
interface TestFiles { readonly downloads: () => readonly Array<File>; readonly pending: () => readonly Array<PickOptions>; readonly settle: (picked: Picked) => void;}Testing
Settles the pending picks with files, as the user choosing them.
Signature
declare function choose(files: readonly Array<File>): Effect<void, never, TestFiles>Settles the pending picks with no files, as the user dismissing the picker.
Signature
declare const dismiss: Effect.Effect<void, never, TestFiles>Files requested for download, oldest first. No browser download occurs.
Signature
declare const downloads: Effect.Effect<ReadonlyArray<File>, never, TestFiles>