diff --git a/spec/features/fluentd/setting/source_and_output_spec.rb b/spec/features/fluentd/setting/source_and_output_spec.rb
index aba8121..9f45ce1 100644
--- a/spec/features/fluentd/setting/source_and_output_spec.rb
+++ b/spec/features/fluentd/setting/source_and_output_spec.rb
@@ -89,4 +89,60 @@ describe "source_and_output", js: true do
end
end
end
+
+ describe "edit, update, delete" do
+ let(:config_contents) { <<-CONF.strip_heredoc }
+
+ type forward
+ port 24224
+
+ CONF
+ let(:new_config) { <<-CONF.strip_heredoc }
+
+ type http
+ port 8899
+
+ CONF
+
+ before do
+ all(".input .panel .panel-heading").first.click
+ end
+
+ it "click edit button transform textarea, then click cancel button to be reset" do
+ page.should_not have_css('.input textarea')
+ find(".btn", text: I18n.t('terms.edit')).click
+ page.should have_css('.input textarea')
+ find('.input textarea').value.should == config_contents
+ find('.input textarea').set "foo"
+ find(".btn", text: I18n.t('terms.cancel')).click
+ content = wait_until do
+ page.evaluate_script("document.querySelector('.input pre').textContent")
+ end
+ content.should == config_contents
+ daemon.agent.config.strip.should == config_contents.strip
+ end
+
+ it "click edit button transform textarea, then click update button to be stored" do
+ page.should_not have_css('.input textarea')
+ find(".btn", text: I18n.t('terms.edit')).click
+ page.should have_css('.input textarea')
+ find('.input textarea').value.should == config_contents
+ find('.input textarea').set new_config
+ find(".btn", text: I18n.t('terms.update')).click
+ content = wait_until do
+ page.evaluate_script("document.querySelector('.input pre').textContent")
+ end
+ content.should == new_config
+ daemon.agent.config.strip.should == new_config.strip
+ end
+
+ it "click delete button transform textarea" do
+ page.should have_css('.input .panel-body')
+ page.execute_script "__backup = window.confirm; window.confirm = function(){return true;}"
+ find(".btn", text: I18n.t('terms.destroy')).click
+ page.should_not have_css('.input .panel-body')
+ page.execute_script "window.confirm = __backup;"
+ daemon.agent.config.strip.should == ""
+ end
+ end
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 603e70f..21554b3 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -34,6 +34,18 @@ RSpec.configure do |config|
# Syntax sugar to use the FactoryGirl methods directly instead FactoryGirl.create ete.
config.include FactoryGirl::Syntax::Methods
config.include LoginMacro
+ def wait_until(seconds = 5, &block)
+ timeout(seconds) do
+ loop do
+ begin
+ ret = block.call
+ break ret if ret
+ rescue Capybara::Poltergeist::JavascriptError
+ end
+ sleep 0.01
+ end
+ end
+ end
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of