From 80e2bd66f54bca88a749d40784828d29bae8995f Mon Sep 17 00:00:00 2001 From: Jacob Scearcy Date: Mon, 6 May 2024 06:42:35 -0700 Subject: =?UTF-8?q?=F0=9F=94=80=20Use=20vitest=20for=20runtime/vdom=20test?= =?UTF-8?q?ing.=20(#124)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🧪 move tests into test directory, bump birdie to ignore non-gleam files * implement feedback * add comments, update doc --- test-apps/vdom-test-templates/gleam.toml | 7 +++ test-apps/vdom-test-templates/manifest.toml | 15 +++++ .../vdom-test-templates/src/client_test.gleam | 64 ++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 test-apps/vdom-test-templates/gleam.toml create mode 100644 test-apps/vdom-test-templates/manifest.toml create mode 100644 test-apps/vdom-test-templates/src/client_test.gleam (limited to 'test-apps') diff --git a/test-apps/vdom-test-templates/gleam.toml b/test-apps/vdom-test-templates/gleam.toml new file mode 100644 index 0000000..24c306c --- /dev/null +++ b/test-apps/vdom-test-templates/gleam.toml @@ -0,0 +1,7 @@ +name = "app" +version = "1.0.0" +target = "javascript" + +[dependencies] +gleam_stdlib = "~> 0.36" +lustre = { path = "../../" } diff --git a/test-apps/vdom-test-templates/manifest.toml b/test-apps/vdom-test-templates/manifest.toml new file mode 100644 index 0000000..342a523 --- /dev/null +++ b/test-apps/vdom-test-templates/manifest.toml @@ -0,0 +1,15 @@ +# This file was generated by Gleam +# You typically do not need to edit this file + +packages = [ + { name = "gleam_erlang", version = "0.25.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "054D571A7092D2A9727B3E5D183B7507DAB0DA41556EC9133606F09C15497373" }, + { name = "gleam_json", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib", "thoas"], otp_app = "gleam_json", source = "hex", outer_checksum = "9063D14D25406326C0255BDA0021541E797D8A7A12573D849462CAFED459F6EB" }, + { name = "gleam_otp", version = "0.10.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "0B04FE915ACECE539B317F9652CAADBBC0F000184D586AAAF2D94C100945D72B" }, + { name = "gleam_stdlib", version = "0.37.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "5398BD6C2ABA17338F676F42F404B9B7BABE1C8DC7380031ACB05BBE1BCF3742" }, + { name = "lustre", version = "4.2.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_json", "gleam_otp", "gleam_stdlib"], source = "local", path = "../.." }, + { name = "thoas", version = "1.2.0", build_tools = ["rebar3"], requirements = [], otp_app = "thoas", source = "hex", outer_checksum = "540C8CB7D9257F2AD0A14145DC23560F91ACDCA995F0CCBA779EB33AF5D859D1" }, +] + +[requirements] +gleam_stdlib = { version = "~> 0.36" } +lustre = { path = "../../" } 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)])]) +} -- cgit v1.2.3