This repository has been archived by the owner on Aug 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
test_web_overrides.rb
executable file
·107 lines (83 loc) · 2.73 KB
/
test_web_overrides.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env ruby
$: << File.expand_path('..', File.dirname(__FILE__))
require 'vendor/environment'
require 'fileutils'
require 'fcntl'
require 'net/http'
require 'uri'
require 'test/unit'
require 'json'
require 'rubygems' if RUBY_VERSION < '1.9'
require 'nokogiri'
class TC_WebOverridesTest < Test::Unit::TestCase
def setup
@rq_port = (ENV['RQ_PORT'] || 3333).to_i
end
def teardown
FileUtils.rm_f('queue/test/form.json')
end
def test_web_form_not_hidden
uri_str = "http://127.0.0.1:#{@rq_port}/q/test/new_message"
res = Net::HTTP.get_response(URI.parse(uri_str))
assert_equal("200", res.code)
result = res.body
doc = Nokogiri::HTML(result)
# Verify that all elements are hidden
flds = doc.css("div.field")
submit = flds.pop
flds.each { | fld |
assert_nil(fld['style'])
}
end
def test_web_form_hidden
File.open('queue/test/form.json', 'w') { |f|
f.write('{ "default" : "hidden" }')
}
uri_str = "http://127.0.0.1:#{@rq_port}/q/test/new_message"
res = Net::HTTP.get_response(URI.parse(uri_str))
assert_equal("200", res.code)
result = res.body
doc = Nokogiri::HTML(result)
# Verify that all elements are hidden
flds = doc.css("div.field")
submit = flds.pop
flds.each { | fld |
assert_equal('display: none;', fld['style'])
}
end
def test_web_form_overriden
File.open('queue/test/form.json', 'w') { |f|
f.write('{ "default" : "hidden" ,')
f.write(' "mesg_param1" : {')
f.write(' "label" : "Cluster ID", ')
f.write(' "help" : "The unique cluster identifier in cyclops" ')
f.write(' },')
f.write(' "mesg_param3" : {')
f.write(' "label" : "Branch", ')
f.write(' "help" : "Branch to push to this cluster when it is ready" ')
f.write(' }')
f.write('}')
}
uri_str = "http://127.0.0.1:#{@rq_port}/q/test/new_message"
res = Net::HTTP.get_response(URI.parse(uri_str))
assert_equal("200", res.code)
result = res.body
doc = Nokogiri::HTML(result)
# Verify that all elements are hidden
flds = doc.css("div.field")
submit = flds.pop
flds.each { | fld |
if 'mesg_param1_field' == fld['id']
assert_nil(fld['style'])
assert_equal("Cluster ID", fld.at_css('label').inner_text)
assert_equal("The unique cluster identifier in cyclops", fld.at_css('p.note').inner_text)
elsif 'mesg_param3_field' == fld['id']
assert_nil(fld['style'])
assert_equal("Branch", fld.at_css('label').inner_text)
assert_equal("Branch to push to this cluster when it is ready", fld.at_css('p.note').inner_text)
else
assert_equal('display: none;', fld['style'])
end
}
end
end