require "spec_helper"
describe "source_and_output", js: true, stub: :daemon do
let(:exists_user) { build(:user) }
before do
login_with exists_user
end
before do
daemon.agent.config_write config_contents
visit source_and_output_daemon_setting_path
end
context "config is blank" do
let(:config_contents) { "" }
it do
page.should have_content(I18n.t("fluentd.settings.source_and_output.setting_empty"))
page.should have_css(".input .empty")
page.should have_css(".output .empty")
end
end
context "config is given" do
let(:config_contents) { <<-CONF.strip_heredoc }
# http://docs.fluentd.org/articles/out_stdout
type stdout
type s3
aws_key_id fofoaiofa
aws_sec_key aaaaaaaaaaaaaae
s3_bucket test
s3_endpoint s3-us-west-1.amazonaws.com
format out_file
include_time_key false
add_newline false
output_tag true
output_time true
store_as gzip
use_ssl true
buffer_type memory
CONF
it do
page.should_not have_content(I18n.t("fluentd.settings.source_and_output.setting_empty"))
page.should have_css('.input .panel .panel-heading')
page.should have_css('.output .panel .panel-heading')
end
it ".panel-body is hidden by default and click .panel-heading for display" do
page.should_not have_css('.input .panel .panel-body')
page.should_not have_css('.output .panel .panel-body')
all(".input .panel .panel-heading").first.click
page.should have_css('.input .panel .panel-body')
all(".output .panel .panel-heading").first.click
page.should have_css('.output .panel .panel-body')
end
it "display plugin name" do
within ".input" do
page.should have_content("forward")
end
within ".output" do
page.should have_content("stdout")
page.should have_content("s3")
end
end
end
describe "edit, update, delete" do
let(:config_contents) { <<-CONF.strip_heredoc }
CONF
let(:new_config) { <<-CONF.strip_heredoc }
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
skip "Doesn't work on Poltergeist"
page.should_not have_css('.input textarea')
find(".btn", text: I18n.t('terms.edit')).click
page.evaluate_script(<<-JS).should == config_contents
document.querySelector("textarea").codemirror.getValue()
JS
page.evaluate_script <<-JS
var cm = document.querySelector('textarea').codemirror;
cm.setValue(JSON.parse(#{new_config.to_json}));
JS
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
skip "Doesn't work on Poltergeist"
page.should_not have_css('.input textarea')
find(".btn", text: I18n.t('terms.edit')).click
page.evaluate_script(<<-JS).should == config_contents
document.querySelector("textarea").codemirror.getValue()
JS
page.evaluate_script <<-JS
var cm = document.querySelector('textarea').codemirror;
cm.setValue(JSON.parse(#{new_config.to_json}));
JS
find(".btn", text: I18n.t('terms.save')).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')
confirm_dialog(true) do
find(".btn", text: I18n.t('terms.destroy')).click
end
page.should_not have_css('.input .panel-body')
daemon.agent.config.strip.should == ""
end
it "click delete button then cancel it" do
page.should have_css('.input .panel-body')
confirm_dialog(false) do
find(".btn", text: I18n.t('terms.destroy')).click
end
page.should have_css('.input .panel-body')
daemon.agent.config.strip.should == config_contents.strip
end
end
end