Skip to content
70 changes: 66 additions & 4 deletions lua/elixir/projectionist/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ local config = {
},
},
["test/**/views/*_view_test.exs"] = {
alternate = "lib/{dirname}/views/{basename}_view.ex",
type = "test",
alternate = "lib/{dirname}/views/{basename}_view.ex",
template = {
"defmodule {dirname|camelcase|capitalize}.{basename|camelcase|capitalize}ViewTest do",
" use ExUnit.Case, async: true",
Expand All @@ -32,11 +32,73 @@ local config = {
},
},
["test/**/controllers/*_controller_test.exs"] = {
type = "test",
alternate = "lib/{dirname}/controllers/{basename}_controller.ex",
template = {
"defmodule {dirname|camelcase|capitalize}.{basename|camelcase|capitalize}ControllerTest do",
" use {dirname|camelcase|capitalize}.ConnCase, async: true",
"end",
},
},
["lib/**/controllers/*_html.ex"] = {
type = "html",
alternate = "test/{dirname}/controllers/{basename}_html_test.exs",
template = {
"defmodule {dirname|camelcase|capitalize}.{basename|camelcase|capitalize}HTML do",
" use {dirname|camelcase|capitalize}, :html",
"",
" embed_templates {basename|snake_case}_html/*",
"end",
},
},
["test/**/controllers/*_html_test.exs"] = {
type = "test",
alternate = "lib/{dirname}/controllers/{basename}_html.ex",
template = {
"defmodule {dirname|camelcase|capitalize}.{basename|camelcase|capitalize}ControllerTest do",
" use {dirname|camelcase|capitalize}.ConnCase, async: true",
"",
" alias {dirname|camelcase|capitalize}.{basename|camelcase|capitalize}HTML",
"end",
},
},
["lib/**/components/*_component.ex"] = {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this i would for sure just name lib/**/components/*.ex.

I don't think anyone would be naming their components in a way that would be <TableComponent.render {@foo}>...</TableComponent.render>

(well, at least I wouldn't ever name a component like that).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, okay so you'd also change the module definition to

        "defmodule {dirname|camelcase|capitalize}.{basename|camelcase|capitalize} do",
        "  use Phoenix.Component",
        "end",

or would you scope it differently?

Looking through other open source repos

https://github.com/BeaconCMS/beacon/blob/main/lib/beacon_web/live/admin/media_library_live/upload_form_component.ex
Dockyard seems to use _component on BeaconCMS

https://github.com/adoptoposs/adoptoposs/blob/develop/lib/adoptoposs_web/live/project_component.ex
This one seems to too!

https://github.com/qhwa/bonfire/blob/master/lib/bonfire_web/live/reading_state_componnet.ex
Same here

https://github.com/fremantle-industries/slurpee/blob/main/lib/slurpee_web/components/block_number_component.ex
Also here!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use Surface at my job, which actually has module components, and we don't name them with a "component" suffix 🤷.

But, I'll note that excluding the last link (which was last modified two years ago), those are all examples of LiveComponents, not function components.

I can add a PR that allows to easily override these defaults if that is what you'd like to see.

Copy link
Copy Markdown
Contributor Author

@zolrath zolrath May 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is true, I suppose what might make sense would be another set of projections that detect _component.ex in the live directory and make live component tests?

Though at that point the tests are the same format as normal LiveViews I believe so hm, no action needed!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I did realize that there wasn't one for live components.

nor the new _json convention.

a PR for either/both of those would great!

type = "component",
alternate = "test/{dirname}/components/{basename}_component_test.exs",
template = {
"defmodule {dirname|camelcase|capitalize}.{basename|camelcase|capitalize}Component do",
" use Phoenix.Component",
"end",
},
},
["test/**/controllers/*_component_test.exs"] = {
type = "test",
alternate = "lib/{dirname}/components/{basename}_component.ex",
template = {
"defmodule {dirname|camelcase|capitalize}.{basename|camelcase|capitalize}ComponentTest do",
" use {dirname|camelcase|capitalize}.ConnCase, async: true",
"",
" alias {dirname|camelcase|capitalize}.{basename|camelcase|capitalize}Component",
"end",
},
},
["lib/**/live/*_live.ex"] = {
type = "liveview",
alternate = "test/{dirname}/live/{basename}_live_test.exs",
template = {
"defmodule {dirname|camelcase|capitalize}.{basename|camelcase|capitalize}Live do",
" use {dirname|camelcase|capitalize}, :live_view",
"end",
},
},
["test/**/live/*_live_test.exs"] = {
type = "test",
alternate = "lib/{dirname}/live/{basename}_live.ex",
template = {
"defmodule {dirname|camelcase|capitalize}.{basename|camelcase|capitalize}LiveTest do",
" use {dirname|camelcase|capitalize}.ConnCase",
"",
" import Phoenix.LiveViewTest",
"end",
},
},
Expand All @@ -50,8 +112,8 @@ local config = {
},
},
["test/**/channels/*_channel_test.exs"] = {
alternate = "lib/{dirname}/channels/{basename}_channel.ex",
type = "test",
alternate = "lib/{dirname}/channels/{basename}_channel.ex",
template = {
"defmodule {dirname|camelcase|capitalize}.{basename|camelcase|capitalize}ChannelTest do",
" use {dirname|camelcase|capitalize}.ChannelCase, async: true",
Expand All @@ -69,13 +131,13 @@ local config = {
},
},
["lib/*.ex"] = {
alternate = "test/{}_test.exs",
type = "source",
alternate = "test/{}_test.exs",
template = { "defmodule {camelcase|capitalize|dot} do", "end" },
},
["test/*_test.exs"] = {
alternate = "lib/{}.ex",
type = "test",
alternate = "lib/{}.ex",
template = {
"defmodule {camelcase|capitalize|dot}Test do",
" use ExUnit.Case, async: true",
Expand Down