mayu-live / framework

Mayu is a live updating server-side component-based VDOM rendering framework written in Ruby
https://mayu.live
GNU Affero General Public License v3.0
130 stars 4 forks source link

Testing apps #13

Open aalin opened 1 year ago

aalin commented 1 year ago

Without testing there is no way to know if anything works.

I'm thinking there could be page tests, component tests and store tests... I really like how Testing Library does queries by roles, it encourages accessibility, and their API is pretty nice so it's a good source of inspiration

Page tests could look like this:

# app/pages/my-page/page.test.rb

def test_my_page
  page = Blabla.new(setup_env)
  page.navigate "/my-page"

  page.click(page.get_by_text("Load Greeting"))
  page.find_by_role("heading")

  assert(page.get_by_role("heading").text_content == "hello there")
  assert(page.get_by_role("heading").button.disabled)
end
# app/components/MyComponent.test.rb

def test_my_component
  component = render("%MyComponent")
  # now what? suggestions welcome
end

It would maybe be possible to use Capybara by implemeting a driver. That could save some work.