|
| 1 | +require_relative "../../../support/utils" |
| 2 | +require_relative "../../../support/test_controller" |
| 3 | +include Utils |
| 4 | + |
| 5 | +describe "Action Component", type: :feature, js: true do |
| 6 | + |
| 7 | + before :each do |
| 8 | + |
| 9 | + class ActionTestController < TestController |
| 10 | + |
| 11 | + def test |
| 12 | + receive_timestamp = DateTime.now.strftime('%Q') |
| 13 | + render json: { received_at: receive_timestamp }, status: 200 |
| 14 | + end |
| 15 | + |
| 16 | + end |
| 17 | + |
| 18 | + allow_any_instance_of(ActionTestController).to receive(:expect_params) |
| 19 | + |
| 20 | + end |
| 21 | + |
| 22 | + describe "delay attribute" do |
| 23 | + |
| 24 | + it "if set, delays action submit" do |
| 25 | + |
| 26 | + Rails.application.routes.append do |
| 27 | + post '/action_test', to: 'action_test#test', as: 'action_delay_test' |
| 28 | + end |
| 29 | + Rails.application.reload_routes! |
| 30 | + |
| 31 | + |
| 32 | + class ExamplePage < Matestack::Ui::Page |
| 33 | + |
| 34 | + def response |
| 35 | + components { |
| 36 | + action action_config do |
| 37 | + button text: "Click me!" |
| 38 | + end |
| 39 | + div id: "timestamp" do |
| 40 | + async show_on: "action_submitted_successfully" do |
| 41 | + plain "{{event.data.received_at}}" |
| 42 | + end |
| 43 | + end |
| 44 | + } |
| 45 | + end |
| 46 | + |
| 47 | + def action_config |
| 48 | + return { |
| 49 | + method: :post, |
| 50 | + path: :action_delay_test_path, |
| 51 | + data: { |
| 52 | + foo: DateTime.now.strftime('%Q') |
| 53 | + }, |
| 54 | + delay: 1000, |
| 55 | + success: { |
| 56 | + emit: "action_submitted_successfully" |
| 57 | + } |
| 58 | + } |
| 59 | + end |
| 60 | + |
| 61 | + end |
| 62 | + |
| 63 | + visit "/example" |
| 64 | + |
| 65 | + submit_timestamp = DateTime.now.strftime('%Q').to_i |
| 66 | + click_button "Click me!" |
| 67 | + |
| 68 | + sleep 1.5 |
| 69 | + |
| 70 | + element = page.find("#timestamp") |
| 71 | + receive_timestamp = element.text.to_i |
| 72 | + |
| 73 | + expect(receive_timestamp - submit_timestamp).to be > 1000 |
| 74 | + |
| 75 | + end |
| 76 | + |
| 77 | + end |
| 78 | + |
| 79 | +end |
0 commit comments