Skip to content

Commit a0922d4

Browse files
authored
Introduce performing? check (#81)
1 parent baa9a72 commit a0922d4

17 files changed

+221
-112
lines changed

.github/workflows/prettier-standard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
steps:
1616
- uses: actions/checkout@v3
1717
- name: Setup Node
18-
uses: actions/setup-node@v1
18+
uses: actions/setup-node@v3
1919
with:
2020
version: '16.x'
2121
- run: yarn

.github/workflows/tests.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest
1515
strategy:
1616
matrix:
17-
ruby-version: ['2.7', '3.0', '3.1']
17+
ruby-version: ['2.7', '3.0', '3.1', '3.2']
1818
steps:
1919
- uses: actions/checkout@v3
2020
- name: Set up Ruby ${{ matrix.ruby-version }}
@@ -27,6 +27,12 @@ jobs:
2727
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
2828
restore-keys: |
2929
${{ runner.os }}-gems-
30+
- name: Setup Node
31+
uses: actions/setup-node@v3
32+
with:
33+
version: '16.x'
34+
- run: yarn
35+
working-directory: .
3036
- name: Bundle install
3137
run: |
3238
gem install bundler

lib/turbo_boost/commands/command_callbacks.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ def errored?
9292
!!@errored
9393
end
9494

95+
def performing?
96+
!!@performing_method_name
97+
end
98+
9599
def performed?
96100
!!@performed
97101
end

lib/turbo_boost/commands/controller_pack.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class TurboBoost::Commands::ControllerPack
1212
delegate(
1313
:command_aborted?,
1414
:command_errored?,
15+
:command_performing?,
1516
:command_performed?,
1617
:command_requested?,
1718
:command_succeeded?,

lib/turbo_boost/commands/runner.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ def command_errored?
9393
!!command_instance&.errored?
9494
end
9595

96+
def command_performing?
97+
!!command_instance&.performing?
98+
end
99+
96100
def command_performed?
97101
!!command_instance&.performed?
98102
end
@@ -114,6 +118,7 @@ def run
114118
return unless command_valid?
115119
return if command_aborted?
116120
return if command_errored?
121+
return if command_performing?
117122
return if command_performed?
118123
command_instance.perform_with_callbacks command_method_name
119124
rescue => error

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"esbuild": "^0.17.2",
2727
"eslint": "^8.19.0",
2828
"flowbite": "^1.5.3",
29+
"playwright": "^1.29.2",
2930
"prettier-standard": "^16.4.1",
3031
"rustywind": "^0.15.1"
3132
},
Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,48 @@
11
# frozen_string_literal: true
22

33
require "test_helper"
4-
require "capybara/cuprite"
4+
require "capybara-playwright-driver"
55

6-
# Capybara setup fom Evil Martians
7-
# SEE: https://evilmartians.com/chronicles/system-of-a-test-setting-up-end-to-end-rails-testing
8-
# NOTE: Will need to set this up for multiple sessions
9-
Capybara.default_max_wait_time = 2
10-
Capybara.default_normalize_ws = true
11-
# Capybara.save_path = ENV.fetch("CAPYBARA_ARTIFACTS", "./tmp/capybara")
12-
13-
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
14-
driven_by :cuprite, using: :headless_chrome, screen_size: [1400, 1400]
6+
class CapybaraNullDriver < Capybara::Driver::Base
7+
def needs_server?
8+
true
9+
end
1510
end
1611

12+
Capybara.register_driver(:null) { CapybaraNullDriver.new }
13+
Capybara.default_driver = :null
14+
Capybara.default_max_wait_time = 12
15+
Capybara.default_normalize_ws = true
16+
Capybara.save_path = "tmp/capybara"
1717
Capybara.configure do |config|
1818
config.server = :puma, {Silent: true}
1919
end
20+
21+
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
22+
driven_by :null
23+
24+
def self.playwright
25+
@playwright ||= Playwright.create(playwright_cli_executable_path: Rails.root.join("../../node_modules/.bin/playwright"))
26+
end
27+
28+
alias_method :orig_page, :page
29+
attr_reader :playwright_browser, :playwright_page
30+
alias_method :page, :playwright_page
31+
32+
def js(...)
33+
page.evaluate(...)
34+
end
35+
36+
def before_setup
37+
super
38+
base_url = Capybara.current_session.server.base_url
39+
@playwright_browser = self.class.playwright.playwright.chromium.launch(headless: true)
40+
@playwright_page = @playwright_browser.new_page(baseURL: base_url)
41+
playwright_page.set_default_timeout Capybara.default_max_wait_time * 1_000
42+
end
43+
44+
def after_teardown
45+
super
46+
playwright_browser&.close
47+
end
48+
end

test/dummy/app/views/demos/increment/_rpc.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<%= cache session[:rpc_count].to_i do %>
22
<div id="rpc">
33
<%= render "stats/stats", id: "rpc-stats" do %>
4-
<%= render "stats/stat", label: "Counter", value: session[:rpc_count].to_i, class: "!bg-indigo-600 dark:!bg-indigo-900",
4+
<%= render "stats/stat", label: "Counter", role: "counter", value: session[:rpc_count].to_i, class: "!bg-indigo-600 dark:!bg-indigo-900",
55
value_class: ["!text-indigo-200 dark:!text-indigo-300"], label_class: ["!text-indigo-400 dark:!text-indigo-500"] %>
66
<% end %>
77

test/dummy/app/views/stats/_stats.html.erb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<%= tag.dl id: local_assigns.fetch(:id, "stats-#{SecureRandom.alphanumeric(12)}"),
2+
data: { command_requested: turbo_boost.command_requested?, command_performing: turbo_boost.command_performing?, command_performed: turbo_boost.command_performed? },
23
class: "grid gap-6 text-gray-900 sm:grid-cols-3 lg:grid-cols-5 dark:text-white" do %>
34
<%= yield %>
45
<%= render "stats/stat", label: "HTTP Fingerprint", role: "http-fingerprint", value: turbo_boost.command_requested? ? SecureRandom.alphanumeric(6).upcase : "N/A",
@@ -11,6 +12,6 @@
1112
class: token_list("!opacity-60": !turbo_boost.command_requested?),
1213
value: turbo_boost.command_requested? ? render(heroicon(:check_circle), solid: true, class: "-mt-2 text-emerald-500 h-10 w-auto inline") : render(heroicon(:x_circle), class: "-mt-2 text-red-500 h-10 w-auto inline") %>
1314
<%= render "stats/stat", label: "Command Performed",
14-
class: token_list("!opacity-60": !turbo_boost.command_performed?),
15-
value: turbo_boost.command_performed? ? render(heroicon(:check_circle), solid: true, class: "-mt-2 text-emerald-500 h-10 w-auto inline") : render(heroicon(:x_circle), class: "-mt-2 text-red-500 h-10 w-auto inline") %>
15+
class: token_list("!opacity-60": !turbo_boost.command_performing? && !turbo_boost.command_performed?),
16+
value: turbo_boost.command_performing? || turbo_boost.command_performed? ? render(heroicon(:check_circle), solid: true, class: "-mt-2 text-emerald-500 h-10 w-auto inline") : render(heroicon(:x_circle), class: "-mt-2 text-red-500 h-10 w-auto inline") %>
1617
<% end %>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# frozen_string_literal: true
2+
3+
require "application_system_test_case"
4+
5+
class IncrementButtonInFrameTest < ApplicationSystemTestCase
6+
test "button-in-frame basic" do
7+
name = "button-in-frame"
8+
page.goto demo_url("increment")
9+
10+
# before demo
11+
meta_element = page.wait_for_selector("meta#turbo-boost", state: "attached")
12+
assert_equal "e30", meta_element["data-state"]
13+
assert_nil js("TurboBoost.state.active_demo")
14+
15+
# open demo
16+
demo_element = page.wait_for_selector("##{name}-demo")
17+
demo_element.wait_for_selector("[data-turbo-command='DemosCommand#toggle']").click
18+
sleep 0.1
19+
assert js("document.cookie").include?("turbo_boost.state")
20+
assert_equal 0, demo_element.wait_for_selector("[data-role='counter']").inner_text.to_i
21+
assert_equal "N/A", demo_element.wait_for_selector("[data-role='http-fingerprint']").inner_text
22+
assert_equal "N/A", demo_element.wait_for_selector("[data-role='http-method']").inner_text
23+
24+
# execute demo
25+
demo_element.wait_for_selector("[data-turbo-command='CounterCommand#increment']").click
26+
sleep 0.1
27+
assert_equal 1, demo_element.wait_for_selector("[data-role='counter']").inner_text.to_i
28+
assert_not_equal "N/A", demo_element.wait_for_selector("[data-role='http-fingerprint']").inner_text
29+
assert_equal "GET", demo_element.wait_for_selector("[data-role='http-method']").inner_text
30+
assert demo_element.wait_for_selector("[data-command-requested='true'][data-command-performing='false'][data-command-performed='true']")
31+
32+
# close demo
33+
demo_element.wait_for_selector("[data-turbo-command='DemosCommand#toggle']").click
34+
sleep 0.1
35+
assert js("document.cookie").include?("turbo_boost.state")
36+
assert_equal "e30", meta_element["data-state"]
37+
assert_nil js("TurboBoost.state.active_demo")
38+
end
39+
end

0 commit comments

Comments
 (0)