# 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
