~singpolyma/sgx-jmp

ref: d8cb729a32b91afb11284d141a5beaf76a279de9 sgx-jmp/test/test_form_template.rb -rw-r--r-- 1.6 KiB
d8cb729aStephen Paul Weber CustomerFwd uses ValueSemantics, translates old XMPP-SIP URI 2 years ago
                                                                                
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
# frozen_string_literal: true

require "test_helper"
require "form_template"

class FormTemplateTest < Minitest::Test
	def test_form_one_field
		template = FormTemplate.new(<<~TEMPLATE)
			form!
			title "TITLE"
			instructions "INSTRUCTIONS"
			field(var: "thevar", label: "thelabel")
		TEMPLATE
		form = template.render
		assert_equal :form, form.type
		assert_equal "TITLE", form.title
		assert_equal "INSTRUCTIONS", form.instructions
		assert_equal 1, form.fields.length
		assert_equal "thevar", form.fields[0].var
		assert_equal "thelabel", form.fields[0].label
	end

	def test_form_two_fields
		template = FormTemplate.new(<<~TEMPLATE)
			form!
			field(var: "thevar", label: "thelabel")
			field(var: "thevar2", label: "thelabel2")
		TEMPLATE
		form = template.render
		assert_equal 2, form.fields.length
		assert_equal "thevar", form.fields[0].var
		assert_equal "thelabel", form.fields[0].label
		assert_equal "thevar2", form.fields[1].var
		assert_equal "thelabel2", form.fields[1].label
	end

	def test_result_no_fields
		template = FormTemplate.new(<<~TEMPLATE)
			result!
			title "TITLE"
			instructions "INSTRUCTIONS"
		TEMPLATE
		form = template.render
		assert_equal :result, form.type
		assert_equal "TITLE", form.title
		assert_equal "INSTRUCTIONS", form.instructions
	end

	def test_no_type
		template = FormTemplate.new(<<~TEMPLATE)
			title "TITLE"
			instructions "INSTRUCTIONS"
		TEMPLATE
		assert_raises { template.render }
	end

	def test_custom_xml
		template = FormTemplate.new(<<~TEMPLATE)
			form!
			xml.whoever @arg
		TEMPLATE
		form = template.render(arg: "abc")
		assert_equal "abc", form.at("whoever").content
	end
end