From 5b5da87c3a9e9df49ee0e9d61a3a1225c0edf5c1 Mon Sep 17 00:00:00 2001 From: Dominik Sander Date: Wed, 14 Sep 2016 23:29:10 +0200 Subject: [PATCH] Add integration tests for Scenario imports --- spec/features/scenario_import_spec.rb | 46 +++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 spec/features/scenario_import_spec.rb diff --git a/spec/features/scenario_import_spec.rb b/spec/features/scenario_import_spec.rb new file mode 100644 index 00000000..614cda5b --- /dev/null +++ b/spec/features/scenario_import_spec.rb @@ -0,0 +1,46 @@ +require 'rails_helper' + +describe ScenarioImportsController do + let(:user) { users(:bob) } + + before do + login_as(user) + end + + it 'renders the import form' do + visit new_scenario_imports_path + expect(page).to have_text('Import a Public Scenario') + end + + it 'requires a URL or file uplaod' do + visit new_scenario_imports_path + click_on 'Start Import' + expect(page).to have_text('Please provide either a Scenario JSON File or a Public Scenario URL.') + end + + it 'imports a scenario that does not exist yet' do + visit new_scenario_imports_path + attach_file('Option 2: Upload a Scenario JSON File', File.join(Rails.root, 'data/default_scenario.json')) + click_on 'Start Import' + expect(page).to have_text('This scenario has a few agents to get you started. Feel free to change them or delete them as you see fit!') + expect(page).not_to have_text('This Scenario already exists in your system.') + check('I confirm that I want to import these Agents.') + click_on 'Finish Import' + expect(page).to have_text('Import successful!') + end + + it 'asks to accept conflicts when the scenario was modified' do + DefaultScenarioImporter.seed(user) + agent = user.agents.where(name: 'Rain Notifier').first + agent.options['expected_receive_period_in_days'] = 9001 + agent.save! + visit new_scenario_imports_path + attach_file('Option 2: Upload a Scenario JSON File', File.join(Rails.root, 'data/default_scenario.json')) + click_on 'Start Import' + expect(page).to have_text('This Scenario already exists in your system.') + expect(page).to have_text('9001') + check('I confirm that I want to import these Agents.') + click_on 'Finish Import' + expect(page).to have_text('Import successful!') + end +end