create_an_agent_spec.rb 1002B

12345678910111213141516171819202122232425262728293031323334
  1. require 'capybara_helper'
  2. describe "Creating a new agent", js: true do
  3. it "creates an agent" do
  4. login_as(users(:bob))
  5. visit "/"
  6. page.find("a", text: "Agents").trigger(:mouseover)
  7. click_on("New Agent")
  8. select2("Trigger Agent", from: "Type")
  9. fill_in(:agent_name, with: "Test Trigger Agent")
  10. click_on "Save"
  11. expect(page).to have_text("Test Trigger Agent")
  12. end
  13. it "creates an alert if a new agent with invalid json is submitted" do
  14. login_as(users(:bob))
  15. visit "/"
  16. page.find("a", text: "Agents").trigger(:mouseover)
  17. click_on("New Agent")
  18. select2("Trigger Agent", from: "Type")
  19. fill_in(:agent_name, with: "Test Trigger Agent")
  20. click_on("Toggle View")
  21. fill_in(:agent_options, with: '{
  22. "expected_receive_period_in_days": "2"
  23. "keep_event": "false"
  24. }')
  25. expect(get_alert_text_from { click_on "Save" }).to have_text("Sorry, there appears to be an error in your JSON input. Please fix it before continuing.")
  26. end
  27. end