dry_running_spec.rb 1.1KB

123456789101112131415161718192021222324252627282930313233343536
  1. require 'rails_helper'
  2. describe "Dry running an Agent", js: true do
  3. let(:formatting_agent) { agents(:bob_formatting_agent) }
  4. let(:user) { users(:bob) }
  5. let(:emitter) { agents(:bob_weather_agent) }
  6. before(:each) do
  7. login_as(user)
  8. end
  9. def open_dry_run_modal(agent)
  10. visit edit_agent_path(agent)
  11. click_on("Dry Run")
  12. expect(page).to have_text('Event to send')
  13. end
  14. context 'successful dry runs' do
  15. it 'sends escape characters correctly to the backend' do
  16. emitter.events << Event.new(payload: {data: "Line 1\nLine 2\nLine 3"})
  17. formatting_agent.sources << emitter
  18. formatting_agent.options.merge!('instructions' => {'data' => "{{data | newline_to_br | strip_newlines | split: '<br />' | join: ','}}"})
  19. formatting_agent.save!
  20. open_dry_run_modal(formatting_agent)
  21. find('.dry-run-event-sample').click
  22. within(:css, '.modal .builder') do
  23. expect(page).to have_text('Line 1\nLine 2\nLine 3')
  24. end
  25. click_on("Dry Run")
  26. expect(page).to have_text('Line 1,Line 2,Line 3')
  27. expect(page).to have_selector(:css, 'li[role="presentation"].active a[href="#tabEvents"]')
  28. end
  29. end
  30. end