local y=import("\046\047\083\099\114\101\101\110\071\117\105")local Y=import("\046\046\047\116\121\112\101\115\047\085\068\105\109\050")local V=import("\046\046\047\102\117\110\099\116\105\111\110\115\047\116\121\112\101\111\102")local J=import("\046\046\047\069\110\117\109\047\083\105\122\101\067\111\110\115\116\114\097\105\110\116")local H=import("\046\047\071\117\105\079\098\106\101\099\116")local function D(y)return{y.X,y.Y}end describe("\105\110\115\116\097\110\099\101\115\046\071\117\105\079\098\106\101\099\116",function()it("\115\104\111\117\108\100 \105\110\115\116\097\110\116\105\097\116\101",function()local y=H:new()assert.not_nil(y)end)it("\115\104\111\117\108\100 \104\097\118\101 \112\114\111\112\101\114\116\105\101\115 \100\101\102\105\110\101\100",function()local y=H:new()assert.equal(V(y.Active),"\098\111\111\108\101\097\110")assert.equal(V(y.AnchorPoint),"\086\101\099\116\111\114\050")assert.equal(V(y.BackgroundColor3),"\067\111\108\111\114\051")assert.equal(V(y.BackgroundTransparency),"\110\117\109\098\101\114")assert.equal(V(y.BorderColor3),"\067\111\108\111\114\051")assert.equal(V(y.BorderSizePixel),"\110\117\109\098\101\114")assert.equal(V(y.ClipsDescendants),"\098\111\111\108\101\097\110")assert.equal(V(y.InputBegan),"\082\066\088\083\099\114\105\112\116\083\105\103\110\097\108")assert.equal(V(y.InputEnded),"\082\066\088\083\099\114\105\112\116\083\105\103\110\097\108")assert.equal(V(y.LayoutOrder),"\110\117\109\098\101\114")assert.equal(V(y.MouseEnter),"\082\066\088\083\099\114\105\112\116\083\105\103\110\097\108")assert.equal(V(y.MouseLeave),"\082\066\088\083\099\114\105\112\116\083\105\103\110\097\108")assert.equal(V(y.Position),"\085\068\105\109\050")assert.equal(V(y.Selectable),"\098\111\111\108\101\097\110")assert.equal(V(y.Size),"\085\068\105\109\050")assert.equal(V(y.SizeConstraint),"\069\110\117\109\073\116\101\109")assert.equal(y.SizeConstraint.EnumType,J)assert.equal(V(y.Visible),"\098\111\111\108\101\097\110")assert.equal(V(y.ZIndex),"\110\117\109\098\101\114")end)describe("\065\098\115\111\108\117\116\101\080\111\115\105\116\105\111\110",function()it("\115\104\111\117\108\100 \114\101\116\117\114\110 \040\048\044 \048\041 \119\104\101\110 \105\116 \105\115 \110\111\116 \097 \099\104\105\108\100 \111\102 \083\099\114\101\101\110\071\117\105",function()local y=H:new()y.Size=Y.new(0,320,0,240)local V=H:new()V.Size=Y.new(.5,20,.5,20)V.Parent=y assert.are.same(D(y.AbsolutePosition),{0,0})assert.are.same(D(V.AbsolutePosition),{0;0})end)it("\115\104\111\117\108\100 \112\114\111\112\097\103\097\116\101 \112\111\115\105\116\105\111\110 \102\114\111\109 \097 \083\099\114\101\101\110\071\117\105",function()local V=y:new()local J=V.AbsoluteSize local v=H:new()v.Parent=V v.Position=Y.new(.1,50,.2,100)v.Size=Y.new(.5,100,.1,200)local b=v.AbsolutePosition local z=v.AbsoluteSize assert.are.same(D(b),{.1*J.X+50,.2*J.Y+100})local o=H:new()o.Parent=v o.Position=Y.new(.5,0,.2,10)o.Size=Y.new(2,50,4,10)local x=o.AbsolutePosition assert.are.same(D(x),{b.X+.5*z.X,(b.Y+.2*z.Y)+10})end)end)describe("\065\098\115\111\108\117\116\101\083\105\122\101",function()it("\115\104\111\117\108\100 \114\101\116\117\114\110 \040\048\044 \048\041 \119\104\101\110 \105\116 \105\115 \110\111\116 \097 \099\104\105\108\100 \111\102 \083\099\114\101\101\110\071\117\105",function()local y=H:new()y.Size=Y.new(0,320,0,240)local V=H:new()V.Size=Y.new(.5,20,.5,20)V.Parent=y assert.are.same(D(y.AbsoluteSize),{0;0})assert.are.same(D(V.AbsoluteSize),{0;0})end)it("\115\104\111\117\108\100 \112\114\111\112\097\103\097\116\101 \115\105\122\101 \102\114\111\109 \097 \083\099\114\101\101\110\071\117\105",function()local V=y:new()local J=V.AbsoluteSize local v=H:new()v.Parent=V v.Size=Y.new(.5,100,.1,200)local b=v.AbsoluteSize assert.are.same(D(b),{.5*J.X+100;.1*J.Y+200})local z=H:new()z.Parent=v z.Size=Y.new(2,50,4,10)local o=z.AbsoluteSize assert.are.same(D(o),{2*b.X+50;4*b.Y+10})end)end)end)
local ScreenGui = import("./ScreenGui")
local UDim2 = import("../types/UDim2")
local typeof = import("../functions/typeof")
local SizeConstraint = import("../Enum/SizeConstraint")

local GuiObject = import("./GuiObject")

local function extractVector2(v)
	return { v.X, v.Y }
end

describe("instances.GuiObject", function()
	it("should instantiate", function()
		local instance = GuiObject:new()

		assert.not_nil(instance)
	end)

	it("should have properties defined", function()
		local instance = GuiObject:new()

		assert.equal(typeof(instance.Active), "boolean")
		assert.equal(typeof(instance.AnchorPoint), "Vector2")
		assert.equal(typeof(instance.BackgroundColor3), "Color3")
		assert.equal(typeof(instance.BackgroundTransparency), "number")
		assert.equal(typeof(instance.BorderColor3), "Color3")
		assert.equal(typeof(instance.BorderSizePixel), "number")
		assert.equal(typeof(instance.ClipsDescendants), "boolean")
		assert.equal(typeof(instance.InputBegan), "RBXScriptSignal")
		assert.equal(typeof(instance.InputEnded), "RBXScriptSignal")
		assert.equal(typeof(instance.LayoutOrder), "number")
		assert.equal(typeof(instance.MouseEnter), "RBXScriptSignal")
		assert.equal(typeof(instance.MouseLeave), "RBXScriptSignal")
		assert.equal(typeof(instance.Position), "UDim2")
		assert.equal(typeof(instance.Selectable), "boolean")
		assert.equal(typeof(instance.Size), "UDim2")
		assert.equal(typeof(instance.SizeConstraint), "EnumItem")
		assert.equal(instance.SizeConstraint.EnumType, SizeConstraint)
		assert.equal(typeof(instance.Visible), "boolean")
		assert.equal(typeof(instance.ZIndex), "number")
	end)

	describe("AbsolutePosition", function()
		it("should return (0, 0) when it is not a child of ScreenGui", function()
			local parent = GuiObject:new()
			parent.Size = UDim2.new(0, 320, 0, 240)

			local child = GuiObject:new()
			child.Size = UDim2.new(0.5, 20, 0.5, 20)
			child.Parent = parent

			assert.are.same(extractVector2(parent.AbsolutePosition), {0, 0})
			assert.are.same(extractVector2(child.AbsolutePosition), {0, 0})
		end)

		it("should propagate position from a ScreenGui", function()
			local screenGui = ScreenGui:new()
			local screenGuiSize = screenGui.AbsoluteSize

			local parent = GuiObject:new()
			parent.Parent = screenGui
			parent.Position = UDim2.new(0.1, 50, 0.2, 100)
			parent.Size = UDim2.new(0.5, 100, 0.1, 200)

			local parentAbsolutePosition = parent.AbsolutePosition
			local parentAbsoluteSize = parent.AbsoluteSize
			assert.are.same(
				extractVector2(parentAbsolutePosition),
				{
					0.1 * screenGuiSize.X + 50,
					0.2 * screenGuiSize.Y + 100,
				}
			)

			local child = GuiObject:new()
			child.Parent = parent
			child.Position = UDim2.new(0.5, 0, 0.2, 10)
			child.Size = UDim2.new(2, 50, 4, 10)

			local childAbsolutePosition = child.AbsolutePosition
			assert.are.same(
				extractVector2(childAbsolutePosition),
				{
					parentAbsolutePosition.X + 0.5 * parentAbsoluteSize.X,
					parentAbsolutePosition.Y + 0.2 * parentAbsoluteSize.Y + 10,
				}
			)
		end)
	end)

	describe("AbsoluteSize", function()
		it("should return (0, 0) when it is not a child of ScreenGui", function()
			local parent = GuiObject:new()
			parent.Size = UDim2.new(0, 320, 0, 240)

			local child = GuiObject:new()
			child.Size = UDim2.new(0.5, 20, 0.5, 20)
			child.Parent = parent

			assert.are.same(extractVector2(parent.AbsoluteSize), {0, 0})
			assert.are.same(extractVector2(child.AbsoluteSize), {0, 0})
		end)

		it("should propagate size from a ScreenGui", function()
			local screenGui = ScreenGui:new()
			local screenGuiSize = screenGui.AbsoluteSize

			local parent = GuiObject:new()
			parent.Parent = screenGui
			parent.Size = UDim2.new(0.5, 100, 0.1, 200)

			local parentAbsoluteSize = parent.AbsoluteSize
			assert.are.same(
				extractVector2(parentAbsoluteSize),
				{
					0.5 * screenGuiSize.X + 100,
					0.1 * screenGuiSize.Y + 200,
				}
			)

			local child = GuiObject:new()
			child.Parent = parent
			child.Size = UDim2.new(2, 50, 4, 10)

			local childAbsoluteSize = child.AbsoluteSize
			assert.are.same(
				extractVector2(childAbsoluteSize),
				{
					2 * parentAbsoluteSize.X + 50,
					4 * parentAbsoluteSize.Y + 10,
				}
			)
		end)
	end)
end)
