fluentd-ui 1.0.0.beta.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of fluentd-ui might be problematic. Click here for more details.

Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog.md +24 -0
  3. data/Gemfile +5 -3
  4. data/Gemfile.lock +88 -75
  5. data/README.md +11 -0
  6. data/Rakefile +1 -1
  7. data/app/javascript/packs/aws_credential.js +1 -1
  8. data/app/javascript/packs/in_tail_parse.js +1 -1
  9. data/app/javascript/packs/owned_plugin_form.js +1 -1
  10. data/app/javascript/packs/settings.js +20 -9
  11. data/app/javascript/packs/transport_config.js +1 -1
  12. data/app/javascript/packs/transport_section.js +1 -1
  13. data/app/javascript/packs/treeview.js +2 -2
  14. data/app/models/plugin.rb +2 -2
  15. data/app/views/fluentd/settings/source_and_output.html.haml +12 -10
  16. data/app/views/layouts/application.html.erb +3 -0
  17. data/app/views/plugins/recommended.html.haml +3 -0
  18. data/app/views/plugins/updated.html.haml +5 -6
  19. data/config.ru +3 -1
  20. data/config/application.rb +1 -1
  21. data/config/application.yml +104 -31
  22. data/config/locales/translation_en.yml +1 -0
  23. data/config/locales/translation_ja.yml +1 -0
  24. data/gemfiles/ruby2.2.gemfile +2 -1
  25. data/lib/fluentd-ui/version.rb +1 -1
  26. data/test/application_system_test_case.rb +8 -0
  27. data/test/controllers/application_controller_test.rb +42 -0
  28. data/test/controllers/fluentd/agents_controller_test.rb +39 -0
  29. data/test/controllers/misc_controller_test.rb +70 -0
  30. data/test/controllers/polling_controller_test.rb +29 -0
  31. data/test/decorators/plugin_decorator_test.rb +26 -0
  32. data/{spec → test}/factories/fluentd.rb +0 -0
  33. data/{spec → test}/factories/plugins.rb +0 -0
  34. data/{spec → test}/factories/user.rb +0 -0
  35. data/{spec/support → test}/fixtures/error0.log +0 -0
  36. data/{spec/support → test}/fixtures/error2.log +0 -0
  37. data/{spec/support → test}/fixtures/error3.log +0 -0
  38. data/{spec/support → test}/fixtures/error4.log +0 -0
  39. data/{spec/support → test}/fixtures/multiline_example.log +0 -0
  40. data/test/integration/dashboard_test.rb +57 -0
  41. data/test/integration/fluentd/setting/histories_test.rb +139 -0
  42. data/test/integration/fluentd/setting/notes_test.rb +27 -0
  43. data/test/integration/fluentd/setting/running_backup_test.rb +65 -0
  44. data/test/integration/fluentd_ui_update_checking_test.rb +27 -0
  45. data/test/integration/sesstions_test.rb +56 -0
  46. data/test/integration/setting_test.rb +126 -0
  47. data/test/integration/users_test.rb +43 -0
  48. data/test/lib/filte_reverse_reader_test.rb +63 -0
  49. data/test/lib/fluentd_ui_test.rb +36 -0
  50. data/test/lib/regexp_preview/multi_line_test.rb +86 -0
  51. data/test/lib/regexp_preview/single_line_test.rb +87 -0
  52. data/test/models/fluent_gem_test.rb +76 -0
  53. data/test/models/fluentd/agent_test.rb +331 -0
  54. data/{spec/models/fluentd/setting/in_forward_spec.rb → test/models/fluentd/setting/in_forward_test.rb} +32 -44
  55. data/test/models/fluentd/setting/in_http_test.rb +30 -0
  56. data/test/models/fluentd/setting/in_monitor_agent_test.rb +30 -0
  57. data/test/models/fluentd/setting/in_syslog_test.rb +88 -0
  58. data/test/models/fluentd/setting/in_tail_test.rb +52 -0
  59. data/test/models/fluentd/setting/out_elasticsearch_test.rb +32 -0
  60. data/test/models/fluentd/setting/out_mongo_test.rb +61 -0
  61. data/test/models/fluentd/setting/out_s3_test.rb +112 -0
  62. data/test/models/fluentd/setting/out_stdout_test.rb +32 -0
  63. data/test/models/fluentd/setting/out_tdlog_test.rb +60 -0
  64. data/test/models/fluentd_log_test.rb +140 -0
  65. data/test/models/fluentd_test.rb +185 -0
  66. data/test/models/plugin_test.rb +144 -0
  67. data/test/models/user_test.rb +48 -0
  68. data/test/support/config_histories.rb +72 -0
  69. data/test/support/configurable_daemon_settings.rb +26 -0
  70. data/test/support/login_macro.rb +12 -0
  71. data/test/support/login_required.rb +8 -0
  72. data/test/support/stub_daemon.rb +14 -0
  73. data/test/system/fluentd/setting/in_forward_test.rb +13 -0
  74. data/test/system/fluentd/setting/in_http_test.rb +13 -0
  75. data/test/system/fluentd/setting/in_monitor_agent.rb +13 -0
  76. data/test/system/fluentd/setting/out_elasticsearch_test.rb +32 -0
  77. data/test/system/fluentd/setting/out_forward_test.rb +41 -0
  78. data/test/system/fluentd/setting/out_stdout_test.rb +15 -0
  79. data/test/system/fluentd/setting/out_tdlog_test.rb +15 -0
  80. data/test/system/source_and_output_test.rb +184 -0
  81. data/test/test_helper.rb +34 -0
  82. metadata +147 -161
  83. data/spec/controllers/application_controller_spec.rb +0 -84
  84. data/spec/controllers/fluentd/agents_controller_spec.rb +0 -61
  85. data/spec/controllers/misc_controller_spec.rb +0 -68
  86. data/spec/controllers/polling_controller_spec.rb +0 -39
  87. data/spec/controllers/sessions_controller_spec.rb +0 -5
  88. data/spec/decorators/plugin_decorator_spec.rb +0 -37
  89. data/spec/features/dashboard_spec.rb +0 -42
  90. data/spec/features/fluentd/setting/histories_spec.rb +0 -110
  91. data/spec/features/fluentd/setting/in_forward_spec.rb +0 -6
  92. data/spec/features/fluentd/setting/in_http_spec.rb +0 -6
  93. data/spec/features/fluentd/setting/in_monitor_agent_spec.rb +0 -6
  94. data/spec/features/fluentd/setting/notes_spec.rb +0 -27
  95. data/spec/features/fluentd/setting/out_forward_spec.rb +0 -38
  96. data/spec/features/fluentd/setting/out_stdout_spec.rb +0 -6
  97. data/spec/features/fluentd/setting/running_backup_spec.rb +0 -106
  98. data/spec/features/fluentd_status_spec.rb +0 -36
  99. data/spec/features/fluentd_ui_update_available_spec.rb +0 -33
  100. data/spec/features/out_elasticsearch_spec.rb +0 -28
  101. data/spec/features/out_forward_spec.rb +0 -36
  102. data/spec/features/out_tdlog_spec.rb +0 -26
  103. data/spec/features/sessions_spec.rb +0 -79
  104. data/spec/features/setting_spec.rb +0 -95
  105. data/spec/features/shared_examples/configurable_daemon_settings.rb +0 -17
  106. data/spec/features/shared_examples/login_required.rb +0 -4
  107. data/spec/features/source_and_output_spec.rb +0 -158
  108. data/spec/features/users_spec.rb +0 -53
  109. data/spec/grok_converter_spec.rb +0 -50
  110. data/spec/lib/file_reverse_reader_spec.rb +0 -93
  111. data/spec/lib/fluentd-ui_spec.rb +0 -35
  112. data/spec/lib/regexp_preview/multi_line_spec.rb +0 -111
  113. data/spec/lib/regexp_preview/single_line_spec.rb +0 -185
  114. data/spec/models/fluent_gem_spec.rb +0 -104
  115. data/spec/models/fluentd/agent/common_spec.rb +0 -82
  116. data/spec/models/fluentd/agent_spec.rb +0 -134
  117. data/spec/models/fluentd/setting/in_http_spec.rb +0 -31
  118. data/spec/models/fluentd/setting/in_monitor_agent_spec.rb +0 -31
  119. data/spec/models/fluentd/setting/in_syslog_spec.rb +0 -98
  120. data/spec/models/fluentd/setting/in_tail_spec.rb +0 -53
  121. data/spec/models/fluentd/setting/out_elasticsearch_spec.rb +0 -31
  122. data/spec/models/fluentd/setting/out_mongo_spec.rb +0 -62
  123. data/spec/models/fluentd/setting/out_s3_spec.rb +0 -128
  124. data/spec/models/fluentd/setting/out_stdout_spec.rb +0 -31
  125. data/spec/models/fluentd/setting/out_tdlog_spec.rb +0 -46
  126. data/spec/models/fluentd_log_spec.rb +0 -171
  127. data/spec/models/fluentd_spec.rb +0 -164
  128. data/spec/models/plugin_spec.rb +0 -191
  129. data/spec/models/user_spec.rb +0 -59
  130. data/spec/spec_helper.rb +0 -85
  131. data/spec/support/config_histories.rb +0 -57
  132. data/spec/support/fluentd_agent_common_behavior.rb +0 -181
  133. data/spec/support/fluentd_agent_restart_strategy.rb +0 -94
  134. data/spec/support/javascript_macro.rb +0 -21
  135. data/spec/support/login_macro.rb +0 -10
  136. data/spec/support/stub_daemon.rb +0 -12
@@ -0,0 +1,48 @@
1
+ require "test_helper"
2
+
3
+ class UserTest < ActiveSupport::TestCase
4
+ setup do
5
+ @user = FactoryBot.build(:user)
6
+ end
7
+
8
+ sub_test_case "password" do
9
+ def set_password(current_password, password, password_confirmation)
10
+ @user.current_password = current_password
11
+ @user.password = password
12
+ @user.password_confirmation = password_confirmation
13
+ end
14
+
15
+ sub_test_case "when current password is correct" do
16
+ test "password/confirmation is 8 characters" do
17
+ set_password(@user.password, "a" * 8, "a" * 8)
18
+ assert do
19
+ @user.valid?
20
+ end
21
+ end
22
+
23
+ test "password is 7 characters" do
24
+ set_password(@user.password, "a" * 7, "a" * 7)
25
+ assert do
26
+ !@user.valid?
27
+ end
28
+ assert_equal([:password], @user.errors.keys)
29
+ end
30
+
31
+ test "password != password_confirmation" do
32
+ set_password(@user.password, "a" * 8, "b" * 8)
33
+ assert do
34
+ !@user.valid?
35
+ end
36
+ assert_equal([:password], @user.errors.keys)
37
+ end
38
+ end
39
+
40
+ test "current_password is wrong" do
41
+ set_password("invalid_password", "a" * 8, "a" * 8)
42
+ assert do
43
+ !@user.valid?
44
+ end
45
+ assert_equal([:current_password], @user.errors.keys)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,72 @@
1
+ require_relative "./stub_daemon"
2
+
3
+ module ConfigHistories
4
+ module DaemonHaveSomeConfigHistories
5
+ extend ActiveSupport::Concern
6
+ include ::StubDaemon
7
+
8
+ included do
9
+ def daemon
10
+ @daemon ||= stub_daemon(variant: "fluentd_gem")
11
+ end
12
+
13
+ setup do
14
+ config_contents = <<-CONFIG.strip_heredoc
15
+ <source>
16
+ @type forward
17
+ port 24224
18
+ </source>
19
+ CONFIG
20
+ new_config = <<-CONFIG.strip_heredoc
21
+ <source>
22
+ @type http
23
+ port 8899
24
+ </source>
25
+ CONFIG
26
+
27
+ three_hours_ago = Time.zone.now - 3.hours
28
+ Timecop.freeze(three_hours_ago)
29
+ FileUtils.rm_rf(daemon.agent.config_backup_dir)
30
+
31
+ 7.times do |i|
32
+ backup_time = three_hours_ago - (i+1).hours
33
+ FileUtils.touch(File.join(daemon.agent.config_backup_dir, "#{backup_time.strftime("%Y%m%d_%H%M%S")}.conf"))
34
+ end
35
+
36
+ Timecop.freeze(three_hours_ago + 1.hours)
37
+ daemon.agent.config_write(config_contents)
38
+
39
+ Timecop.freeze(three_hours_ago + 2.hours)
40
+ daemon.agent.config_write(new_config)
41
+
42
+ Timecop.freeze(three_hours_ago + 3.hours)
43
+ end
44
+
45
+ teardown do
46
+ FileUtils.rm_rf(daemon.agent.config_backup_dir)
47
+ Timecop.return
48
+ end
49
+ end
50
+ end
51
+
52
+ module DaemonHadBeenStartedOnce
53
+ extend ActiveSupport::Concern
54
+
55
+ included do
56
+ setup do
57
+ @backup_content = "Running backup file content"
58
+ File.open(daemon.agent.running_config_backup_file, "w") do |file|
59
+ file.write(@backup_content)
60
+ end
61
+ end
62
+
63
+ def backup_content
64
+ @backup_content
65
+ end
66
+
67
+ teardown do
68
+ FileUtils.rm_rf(daemon.agent.running_config_backup_dir)
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,26 @@
1
+ module ConfigurableDaemonSettings
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ test "show form" do
6
+ visit(__send__("daemon_setting_#{@type}_path"))
7
+ assert do
8
+ page.has_css?("input[name=\"setting[#{@form_name}]\"]")
9
+ end
10
+ end
11
+
12
+ test "Update config" do
13
+ assert do
14
+ !@daemon.agent.config.include?(@form_value)
15
+ end
16
+ visit(__send__("daemon_setting_#{@type}_path"))
17
+ within("form") do
18
+ fill_in(@form_name.capitalize, with: @form_value)
19
+ end
20
+ click_button(I18n.t("fluentd.common.finish"))
21
+ assert do
22
+ @daemon.agent.config.include?(@form_value)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,12 @@
1
+ module LoginMacro
2
+ def login_with(user, password: nil)
3
+ visit("/sessions/new")
4
+ within("form") do
5
+ fill_in("session_name", :with => user.name)
6
+ fill_in("session_password", :with => password || user.password)
7
+ end
8
+ click_button(I18n.t("terms.sign_in"))
9
+ end
10
+ end
11
+
12
+ ActionDispatch::IntegrationTest.include(LoginMacro)
@@ -0,0 +1,8 @@
1
+ module LoginRequired
2
+ def login_required(url)
3
+ visit(url)
4
+ assert_equal(new_sessions_path, current_path)
5
+ end
6
+ end
7
+
8
+ ActionDispatch::IntegrationTest.include(LoginRequired)
@@ -0,0 +1,14 @@
1
+ module StubDaemon
2
+ def stub_daemon(running: false, variant: "td-agent")
3
+ daemon = FactoryBot.build(:fluentd, variant: variant)
4
+ stub(Fluentd).instance { daemon }
5
+ any_instance_of(Fluentd::Agent::TdAgent) do |object|
6
+ stub(object).detached_command { true }
7
+ stub(object).running? { running }
8
+ end
9
+ daemon.agent.config_write("")
10
+ daemon
11
+ end
12
+ end
13
+
14
+ ActionDispatch::IntegrationTest.include(StubDaemon)
@@ -0,0 +1,13 @@
1
+ require "application_system_test_case"
2
+
3
+ class InForwardTest < ApplicationSystemTestCase
4
+ include ConfigurableDaemonSettings
5
+
6
+ setup do
7
+ login_with(FactoryBot.build(:user))
8
+ @type = "in_forward"
9
+ @form_name = "port"
10
+ @form_value = "12345"
11
+ @daemon = stub_daemon
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require "application_system_test_case"
2
+
3
+ class InHttpTest < ApplicationSystemTestCase
4
+ include ConfigurableDaemonSettings
5
+
6
+ setup do
7
+ login_with(FactoryBot.build(:user))
8
+ @type = "in_http"
9
+ @form_name = "port"
10
+ @form_value = "12345"
11
+ @daemon = stub_daemon
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require "application_system_test_case"
2
+
3
+ class InMonitorAgentTest < ApplicationSystemTestCase
4
+ include ConfigurableDaemonSettings
5
+
6
+ setup do
7
+ login_with(FactoryBot.build(:user))
8
+ @type = "in_monitor_agent"
9
+ @form_name = "port"
10
+ @form_value = "12345"
11
+ @daemon = stub_daemon
12
+ end
13
+ end
@@ -0,0 +1,32 @@
1
+ require "application_system_test_case"
2
+
3
+ class OutElasticsearchTest < ApplicationSystemTestCase
4
+ setup do
5
+ login_with(FactoryBot.build(:user))
6
+ @daemon = stub_daemon
7
+ @pattern = "test.out_forward.#{Time.now.to_i}.*"
8
+ end
9
+
10
+ test "show form" do
11
+ visit(daemon_setting_out_elasticsearch_path)
12
+ assert do
13
+ page.has_css?('input[name="setting[pattern]"]')
14
+ end
15
+ end
16
+
17
+ test "Update config" do
18
+ assert do
19
+ !@daemon.agent.config.include?(@pattern)
20
+ end
21
+ visit(daemon_setting_out_elasticsearch_path)
22
+ within("form") do
23
+ fill_in("Pattern", with: @pattern)
24
+ fill_in("Index name", with: "index")
25
+ fill_in("Type name", with: "type_name")
26
+ end
27
+ click_button(I18n.t("fluentd.common.finish"))
28
+ assert do
29
+ @daemon.agent.config.include?(@pattern)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,41 @@
1
+ require "application_system_test_case"
2
+ require "fluent/plugin/buf_file"
3
+
4
+ class OutForwardTest < ApplicationSystemTestCase
5
+ setup do
6
+ login_with(FactoryBot.build(:user))
7
+ @daemon = stub_daemon
8
+ @pattern = "test.out_forward.#{Time.now.to_i}.*"
9
+ end
10
+
11
+ test "show form" do
12
+ visit(daemon_setting_out_forward_path)
13
+ assert do
14
+ page.has_css?('input[name="setting[pattern]"]')
15
+ end
16
+ end
17
+
18
+ test "appendable server setting" do
19
+ visit(daemon_setting_out_forward_path)
20
+ assert_equal(1, all(".js-nested-column .js-append", visible: false).size)
21
+ all('.js-append').first.click
22
+ assert_equal(2, all(".js-nested-column .js-append", visible: false).size)
23
+ end
24
+
25
+ test "update config" do
26
+ assert do
27
+ !@daemon.agent.config.include?(@pattern)
28
+ end
29
+ visit(daemon_setting_out_forward_path)
30
+ within("form") do
31
+ fill_in("Pattern", with: @pattern)
32
+ fill_in("setting_server_0__host", with: "localhost")
33
+ fill_in("setting_server_0__port", with: "9999")
34
+ fill_in("Path", with: "/tmp/foo")
35
+ end
36
+ click_button(I18n.t("fluentd.common.finish"))
37
+ assert do
38
+ @daemon.agent.config.include?(@pattern)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,15 @@
1
+ require "application_system_test_case"
2
+
3
+ require "fluent/plugin/buf_file"
4
+
5
+ class OutStdoutTest < ApplicationSystemTestCase
6
+ include ConfigurableDaemonSettings
7
+
8
+ setup do
9
+ login_with(FactoryBot.build(:user))
10
+ @type = "out_stdout"
11
+ @form_name = "pattern"
12
+ @form_value = "stdout.**"
13
+ @daemon = stub_daemon
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require "application_system_test_case"
2
+
3
+ require "fluent/plugin/buf_file"
4
+
5
+ class OutTdlogTest < ApplicationSystemTestCase
6
+ include ConfigurableDaemonSettings
7
+
8
+ setup do
9
+ login_with(FactoryBot.build(:user))
10
+ @type = "out_tdlog"
11
+ @form_name = "apikey"
12
+ @form_value = "dummydummy"
13
+ @daemon = stub_daemon
14
+ end
15
+ end
@@ -0,0 +1,184 @@
1
+ require "application_system_test_case"
2
+
3
+ class SourceAndOutputTest < ApplicationSystemTestCase
4
+ setup do
5
+ login_with(FactoryBot.build(:user))
6
+ @daemon = stub_daemon
7
+ end
8
+
9
+ test "config is blank" do
10
+ @daemon.agent.config_write("")
11
+ visit(source_and_output_daemon_setting_path)
12
+
13
+ page.has_content?(I18n.t("fluentd.settings.source_and_output.setting_empty"))
14
+ page.has_css?(".input .empty")
15
+ page.has_css?(".output .empty")
16
+ end
17
+
18
+ sub_test_case "config is given" do
19
+ setup do
20
+ config = <<-CONFIG.strip_heredoc
21
+ <source>
22
+ # http://docs.fluentd.org/articles/in_forward
23
+ type forward
24
+ port 24224
25
+ </source>
26
+
27
+ <match debug.*>
28
+ # http://docs.fluentd.org/articles/out_stdout
29
+ type stdout
30
+ </match>
31
+
32
+ <match s3.*>
33
+ type s3
34
+ aws_key_id fofoaiofa
35
+ aws_sec_key aaaaaaaaaaaaaae
36
+ s3_bucket test
37
+ s3_endpoint s3-us-west-1.amazonaws.com
38
+ format out_file
39
+ include_time_key false
40
+ add_newline false
41
+ output_tag true
42
+ output_time true
43
+ store_as gzip
44
+ use_ssl true
45
+ buffer_type memory
46
+ </match>
47
+ CONFIG
48
+ @daemon.agent.config_write(config)
49
+ visit(source_and_output_daemon_setting_path)
50
+ end
51
+
52
+ test "elements" do
53
+ assert do
54
+ !page.has_content?(I18n.t("fluentd.settings.source_and_output.setting_empty"))
55
+ end
56
+ assert do
57
+ page.has_css?('.input .card .card-header')
58
+ end
59
+ assert do
60
+ page.has_css?('.output .card .card-header')
61
+ end
62
+ end
63
+
64
+ test ".card-body is hidden by default and click .card-header for display" do
65
+ assert do
66
+ !page.has_css?('.input .card .card-body')
67
+ end
68
+ assert do
69
+ !page.has_css?('.output .card .card-body')
70
+ end
71
+ all(".input .card .card-header").first.click
72
+ assert do
73
+ page.has_css?('.input .card .card-body')
74
+ end
75
+ all(".output .card .card-header").first.click
76
+ assert do
77
+ page.has_css?('.output .card .card-body')
78
+ end
79
+ end
80
+
81
+ test "display plugin name" do
82
+ within ".input" do
83
+ assert do
84
+ page.has_content?("forward")
85
+ end
86
+ end
87
+
88
+ within ".output" do
89
+ assert do
90
+ page.has_content?("stdout")
91
+ end
92
+ assert do
93
+ page.has_content?("s3")
94
+ end
95
+ end
96
+ end
97
+
98
+ sub_test_case "edit, update, delete" do
99
+ setup do
100
+ @config = <<-CONFIG.strip_heredoc
101
+ <source>
102
+ type forward
103
+ port 24224
104
+ </source>
105
+ CONFIG
106
+ @new_config = <<-CONFIG.strip_heredoc
107
+ <source>
108
+ @type http
109
+ port 8899
110
+ </source>
111
+ CONFIG
112
+ @daemon.agent.config_write(@config)
113
+ visit(source_and_output_daemon_setting_path)
114
+ all(".input .card .card-header").first.click
115
+ end
116
+
117
+ test "click edit button transform textarea, then click cancel button to reset" do
118
+ assert do
119
+ !page.has_css?(".input textarea")
120
+ end
121
+ find(".btn", text: I18n.t("terms.edit")).click
122
+ original_contents = page.evaluate_script(<<-JS)
123
+ document.querySelector(".CodeMirror").CodeMirror.getValue()
124
+ JS
125
+ assert_equal(@config, original_contents)
126
+ page.execute_script(<<-JS)
127
+ var cm = document.querySelector('.CodeMirror').CodeMirror;
128
+ cm.setValue(#{@new_config.to_json});
129
+ JS
130
+ find(".btn", text: I18n.t("terms.cancel")).click
131
+ contents = page.evaluate_script("document.querySelector('.input pre').textContent")
132
+ assert_equal(@config, contents)
133
+ assert_equal(@daemon.agent.config.strip, @config.strip)
134
+ end
135
+
136
+ test "click edit button transform textarea, then click update button to be stored" do
137
+ assert do
138
+ !page.has_css?(".input textarea")
139
+ end
140
+ find(".btn", text: I18n.t("terms.edit")).click
141
+ original_contents = page.evaluate_script(<<-JS)
142
+ document.querySelector(".CodeMirror").CodeMirror.getValue()
143
+ JS
144
+ assert_equal(@config, original_contents)
145
+ page.execute_script(<<-JS)
146
+ var cm = document.querySelector('.CodeMirror').CodeMirror;
147
+ cm.setValue(#{@new_config.to_json});
148
+ JS
149
+ find(".btn", text: I18n.t("terms.save")).click
150
+ contents = page.evaluate_script("document.querySelector('.input pre').textContent")
151
+ pend("contents does not include all lines under '.input pre'")
152
+ assert_equal(@new_config, contents)
153
+ assert_equal(@daemon.agent.config.strip, @new_config.strip)
154
+ end
155
+
156
+ test "click delete button transform textarea" do
157
+ assert do
158
+ page.has_css?(".input .card-body")
159
+ end
160
+ button = find(".btn", text: I18n.t('terms.destroy'))
161
+ page.accept_confirm do
162
+ button.click
163
+ end
164
+ assert do
165
+ !page.has_css?(".input .card-body")
166
+ end
167
+ assert_equal("", @daemon.agent.config.strip)
168
+ end
169
+
170
+ test "click delete button then cancel it" do
171
+ assert do
172
+ page.has_css?(".input .card-body")
173
+ end
174
+ page.dismiss_confirm("really?") do
175
+ find(".btn", text: I18n.t('terms.destroy')).click
176
+ end
177
+ assert do
178
+ page.has_css?(".input .card-body")
179
+ end
180
+ assert_equal(@config.strip, @daemon.agent.config.strip)
181
+ end
182
+ end
183
+ end
184
+ end