diff options
author | Jacob Scearcy <jacobscearcy@gmail.com> | 2024-05-06 06:42:35 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-06 14:42:35 +0100 |
commit | 80e2bd66f54bca88a749d40784828d29bae8995f (patch) | |
tree | 587a8b2d24f09e1955f11ab1ae7ca1e16084d4e1 /test-apps/vdom-test-templates/src/client_test.gleam | |
parent | 8adbae91d3e7d526b5950e2299736ab915dc5489 (diff) | |
download | lustre-80e2bd66f54bca88a749d40784828d29bae8995f.tar.gz lustre-80e2bd66f54bca88a749d40784828d29bae8995f.zip |
๐ Use vitest for runtime/vdom testing. (#124)
* ๐งช move tests into test directory, bump birdie to ignore non-gleam files
* implement feedback
* add comments, update doc
Diffstat (limited to 'test-apps/vdom-test-templates/src/client_test.gleam')
-rw-r--r-- | test-apps/vdom-test-templates/src/client_test.gleam | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/test-apps/vdom-test-templates/src/client_test.gleam b/test-apps/vdom-test-templates/src/client_test.gleam new file mode 100644 index 0000000..ccbb65e --- /dev/null +++ b/test-apps/vdom-test-templates/src/client_test.gleam @@ -0,0 +1,64 @@ +import gleam/int +import gleam/list +import lustre/attribute +import lustre/element +import lustre/element/html + +// VIEW HELPERS ----------------------------------------------------------------- +// Functions to get view definitions for testing client ffi, further testing could reuse examples +pub fn smoke_test() { + html.div([], [html.p([], [element.text("smoke test")])]) +} + +pub fn dynamic_content_test(number: Int, some_string: String) { + html.div([], [ + html.h1([], [element.text(some_string)]), + html.p([], [element.text(int.to_string(number))]), + ]) +} + +const mock_people = [ + #("1dfg", "Person One", 18), + #("abc3", "Person Two", 24), + #("ga4d", "Person Three", 30), +] + +pub fn fragment_test() { + let person_els = + element.fragment( + list.map(mock_people, fn(person) { + let #(_, person_name, age) = person + let person_el = [ + html.td([], [element.text(person_name)]), + html.td([], [element.text(int.to_string(age))]), + ] + element.fragment([html.tr([], person_el)]) + }), + ) + + html.table([], [ + html.head([], [ + html.tr([], [ + html.th([], [element.text("Person Name")]), + html.th([], [element.text("Person Age")]), + ]), + ]), + html.body([], [person_els]), + ]) +} + +pub fn keyed_test() { + element.keyed(html.ul([], _), { + use #(id, person_name, age) <- list.map(mock_people) + let child = + html.tr([], [ + html.td([], [element.text(person_name)]), + html.td([], [element.text(int.to_string(age))]), + ]) + #(id, child) + }) +} + +pub fn disabled_attr_test(is_disabled: Bool) { + html.div([], [html.input([attribute.disabled(is_disabled)])]) +} |