mirror of
https://github.com/fluent/fluentd-ui.git
synced 2026-05-05 19:06:12 +02:00
Add test/integration/dashboard_test.rb
Signed-off-by: Kenji Okimoto <okimoto@clear-code.com>
This commit is contained in:
parent
ca7926635d
commit
00d06c3f95
48
test/integration/dashboard_test.rb
Normal file
48
test/integration/dashboard_test.rb
Normal file
@ -0,0 +1,48 @@
|
||||
require "test_helper"
|
||||
|
||||
class DashboardTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
login_with(FactoryBot.build(:user))
|
||||
end
|
||||
|
||||
test "no configuration" do
|
||||
visit("/")
|
||||
within("h1") do
|
||||
assert_equal("fluentd", text)
|
||||
end
|
||||
assert do
|
||||
find_link(I18n.t('terms.setup', target: 'fluentd'))
|
||||
end
|
||||
assert do
|
||||
find_link(I18n.t('terms.setup', target: 'td-agent'))
|
||||
end
|
||||
end
|
||||
|
||||
test "fluentd is stop" do
|
||||
stub_daemon
|
||||
visit("/")
|
||||
assert do
|
||||
page.has_css?('h1', text: I18n.t('fluentd.show.page_title'))
|
||||
end
|
||||
assert do
|
||||
page.has_css?('h4', text: I18n.t('fluentd.common.stopped'))
|
||||
end
|
||||
assert do
|
||||
page.has_css?('h4', text: I18n.t('fluentd.common.fluentd_info'))
|
||||
end
|
||||
end
|
||||
|
||||
test "fluentd is running" do
|
||||
stub_daemon(running: true)
|
||||
visit("/")
|
||||
assert do
|
||||
page.has_css?('h1', text: I18n.t('fluentd.show.page_title'))
|
||||
end
|
||||
assert do
|
||||
page.has_css?('h4', text: I18n.t('fluentd.common.running'))
|
||||
end
|
||||
assert do
|
||||
page.has_css?('h4', text: I18n.t('fluentd.common.fluentd_info'))
|
||||
end
|
||||
end
|
||||
end
|
||||
12
test/support/login_macro.rb
Normal file
12
test/support/login_macro.rb
Normal file
@ -0,0 +1,12 @@
|
||||
module LoginMacro
|
||||
def login_with(user)
|
||||
visit("/sessions/new")
|
||||
within("form") do
|
||||
fill_in("session_name", :with => user.name)
|
||||
fill_in("session_password", :with => user.password)
|
||||
end
|
||||
click_button(I18n.t("terms.sign_in"))
|
||||
end
|
||||
end
|
||||
|
||||
ActionDispatch::IntegrationTest.include(LoginMacro)
|
||||
13
test/support/stub_daemon.rb
Normal file
13
test/support/stub_daemon.rb
Normal file
@ -0,0 +1,13 @@
|
||||
module StubDaemon
|
||||
def stub_daemon(running: false)
|
||||
daemon = FactoryBot.build(:fluentd, variant: "td-agent")
|
||||
stub(Fluentd).instance { daemon }
|
||||
any_instance_of(Fluentd::Agent::TdAgent) do |object|
|
||||
stub(object).detached_command { true }
|
||||
stub(object).running? { running }
|
||||
end
|
||||
daemon.agent.config_write("")
|
||||
end
|
||||
end
|
||||
|
||||
ActionDispatch::IntegrationTest.include(StubDaemon)
|
||||
@ -2,10 +2,12 @@ ENV['RAILS_ENV'] ||= 'test'
|
||||
require_relative '../config/environment'
|
||||
require 'test/unit/rails/test_help'
|
||||
require 'test/unit/rr'
|
||||
require 'test/unit/capybara'
|
||||
require 'webmock/test_unit'
|
||||
|
||||
WebMock.disable_net_connect!(allow_localhost: true)
|
||||
|
||||
|
||||
module FixturePath
|
||||
def fixture_path(fixture_name)
|
||||
Rails.root.join("test/fixtures", fixture_name).to_s
|
||||
@ -20,3 +22,21 @@ class ActiveSupport::TestCase
|
||||
include FixturePath
|
||||
extend FixturePath
|
||||
end
|
||||
|
||||
Capybara.register_driver :selenium do |app|
|
||||
Capybara::Selenium::Driver.new(app,
|
||||
browser: :chrome,
|
||||
desired_capabilities: Selenium::WebDriver::Remote::Capabilities.chrome(
|
||||
chrome_options: {
|
||||
args: %w(headless disable-gpu window-size=1920,1080),
|
||||
},
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
Capybara.javascript_driver = :selenium
|
||||
require "capybara-screenshot/testunit"
|
||||
|
||||
Dir[Rails.root.join("test/support/**/*.rb")].each do |path|
|
||||
require(path)
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user