~singpolyma/sgx-jmp

ref: 2f7a1b60192a14c86ef9a1f727ea9369cfedc2c6 sgx-jmp/test/test_xep0122_field.rb -rw-r--r-- 1.1 KiB
2f7a1b60Stephen Paul Weber Merge branch 'more-tel-selection-coverage' 11 months 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
# frozen_string_literal: true

require "test_helper"
require "xep0122_field"

class XEP0122FieldTest < Minitest::Test
	def test_field
		field = XEP0122Field.new(
			"xs:decimal",
			range: (0..3),
			var: "v",
			label: "l",
			type: "text-single"
		).field

		example = Nokogiri::XML::Builder.new { |xml|
			xml.field(
				xmlns: "jabber:x:data",
				var: "v",
				type: "text-single",
				label: "l"
			) do
				xml.validate(
					xmlns: "http://jabber.org/protocol/xdata-validate",
					datatype: "xs:decimal"
				) do
					xml.range(min: 0, max: 3)
				end
			end
		}

		assert_equal example.doc.root.to_xml, field.to_xml
	end

	def test_field_no_range
		field = XEP0122Field.new(
			"xs:decimal",
			var: "v",
			label: "l",
			type: "text-single"
		).field

		example = Nokogiri::XML::Builder.new { |xml|
			xml.field(
				xmlns: "jabber:x:data",
				var: "v",
				type: "text-single",
				label: "l"
			) do
				xml.validate(
					xmlns: "http://jabber.org/protocol/xdata-validate",
					datatype: "xs:decimal"
				) do
					xml.basic
				end
			end
		}

		assert_equal example.doc.root.to_xml, field.to_xml
	end
end