local B=require("\046\046\047\082\101\097\099\116\069\108\101\109\101\110\116")local L=require("\064\112\107\103\047\064\106\115\100\111\116\108\117\097\047\106\101\115\116-\103\108\111\098\097\108\115")local a=L.expect local e=L.describe local z=L.it local A=(require("\064\112\107\103\047\064\106\115\100\111\116\108\117\097\047\115\104\097\114\101\100")).isValidElementType local W=(require("\064\112\107\103\047\064\106\115\100\111\116\108\117\097\047\115\104\097\114\101\100")).ReactSymbols local S e("\099\114\101\097\116\101\115 \118\097\108\105\100 \082\101\097\099\116 \101\108\101\109\101\110\116\115",function()z("\102\114\111\109 \115\116\114\105\110\103\115",function()S=B.createElement("\084\101\120\116\076\097\098\101\108");(a(S)).toBeDefined();(a(B.isValidElement(S))).toEqual(true);(a(S["\036\036\116\121\112\101\111\102"])).toEqual(W.REACT_ELEMENT_TYPE);(a(A(S))).toBe(false)end)z("\102\114\111\109 \102\117\110\099\116\105\111\110\115",function()S=B.createElement(function()return nil end);(a(S)).toBeDefined();(a(B.isValidElement(S))).toEqual(true);(a(A(S))).toBe(false)end)end)e("\107\101\121\115",function()z("\115\104\111\117\108\100 \108\101\097\118\101 \110\117\109\098\101\114 \107\101\121\115 \097\115 \110\117\109\098\101\114",function()S=B.createElement("\070\114\097\109\101",{key=2,Size=UDim2.new(1,0,1,0)});(a(S.key)).toEqual(2)end)z("\115\104\111\117\108\100 \099\111\110\118\101\114\116 \116\097\098\108\101 \107\101\121\115 \116\111 \115\116\114\105\110\103",function()local L={}S=B.createElement("\070\114\097\109\101",{key=L,Size=UDim2.new(1,0,1,0)});(a(S.key)).toEqual(tostring(L))end)z("\115\104\111\117\108\100 \108\101\097\118\101 \115\116\114\105\110\103 \107\101\121\115 \097\115 \115\116\114\105\110\103\115",function()S=B.createElement("\070\114\097\109\101",{key="\104\101\108\108\111";Size=UDim2.new(1,0,1,0)});(a(S.key)).toEqual("\104\101\108\108\111")end)z("\115\104\111\117\108\100 \104\097\118\101 \101\108\101\109\101\110\116\046\107\101\121 \061\061 \110\105\108 \105\102 \110\111 \107\101\121 \105\115 \112\097\115\115\101\100",function()S=B.createElement("\070\114\097\109\101",{Size=UDim2.new(1,0,1,0)});(a(S.key)).toEqual(nil)end)end)e("\115\104\111\117\108\100 \097\099\099\101\112\116",function()z("\112\114\111\112\115",function()S=B.createElement("\083\116\114\105\110\103\086\097\108\117\101",{Value="\070\111\111"});(a(S)).toBeDefined();(a(S.props.Value)).toEqual("\070\111\111");(a(S.props.children)).never.toBeDefined()end)z("\097 \099\104\105\108\100 \097\110\100 \112\114\111\112\115",function()local L=B.createElement("\073\110\116\086\097\108\117\101")S=B.createElement("\083\116\114\105\110\103\086\097\108\117\101",{Value="\070\111\111"},L);(a(S)).toBeDefined();(a(S.props.Value)).toEqual("\070\111\111");(a(S.props.children)).toBeDefined();(a(S.props.children)).toEqual(L)end)z("\097 \099\104\105\108\100 \097\110\100 \110\111 \112\114\111\112\115",function()local L=B.createElement("\073\110\116\086\097\108\117\101")S=B.createElement("\083\116\114\105\110\103\086\097\108\117\101",nil,L);(a(S)).toBeDefined();(a(S.props.Value)).toEqual(nil);(a(S.props.children)).toBeDefined();(a(S.props.children)).toEqual(L)end)z("\109\117\108\116\105\112\108\101 \099\104\105\108\100\114\101\110 \097\110\100 \110\111 \112\114\111\112\115",function()local L=B.createElement("\073\110\116\086\097\108\117\101")local e=B.createElement("\083\116\114\105\110\103\086\097\108\117\101")S=B.createElement("\083\116\114\105\110\103\086\097\108\117\101",nil,L,e);(a(S)).toBeDefined();(a(S.props.Value)).toEqual(nil);(a(S.props.children)).toBeDefined();(a(S.props.children)).toEqual({L;e})end)z("\097 \116\097\098\108\101 \111\102 \099\104\105\108\100\114\101\110 \097\110\100 \110\111 \112\114\111\112\115",function()local L=B.createElement("\073\110\116\086\097\108\117\101")local e=B.createElement("\083\116\114\105\110\103\086\097\108\117\101")S=B.createElement("\083\116\114\105\110\103\086\097\108\117\101",nil,{Child1=L,Child2=e});(a(S)).toBeDefined();(a(S.props.Value)).toEqual(nil);(a(S.props.children)).toBeDefined();(a(S.props.children)).toEqual({Child1=L,Child2=e})end)z("\097 \102\097\108\115\101 \118\097\108\117\101 \102\111\114 \097 \098\111\111\108\101\097\110 \112\114\111\112",function()S=B.createElement("\066\111\111\108\086\097\108\117\101",{Value=false});(a(S)).toBeDefined();(a(S.props.Value)).toEqual(false)end)end)
--!strict
-- ROBLOX upstream: https://github.com/facebook/react/blob/702fad4b1b48ac8f626ed3f35e8f86f5ea728084/packages/react/src/__tests__/ReactElement-test.js

local ReactElement = require("../ReactElement")
local JestGlobals = require("@pkg/@jsdotlua/jest-globals")
local jestExpect = JestGlobals.expect
local describe = JestGlobals.describe
local it = JestGlobals.it
local isValidElementType = require("@pkg/@jsdotlua/shared").isValidElementType
local ReactSymbols = require("@pkg/@jsdotlua/shared").ReactSymbols
local element

describe("creates valid React elements", function()
	it("from strings", function()
		element = ReactElement.createElement("TextLabel")
		jestExpect(element).toBeDefined()
		jestExpect(ReactElement.isValidElement(element)).toEqual(true)
		jestExpect(element["$$typeof"]).toEqual(ReactSymbols.REACT_ELEMENT_TYPE)
		-- isValidElement considers basic ELEMENT_TYPE to be false
		jestExpect(isValidElementType(element)).toBe(false)
	end)

	it("from functions", function()
		element = ReactElement.createElement(function()
			return nil
		end)
		jestExpect(element).toBeDefined()
		jestExpect(ReactElement.isValidElement(element)).toEqual(true)
		-- isValidElement considers basic ELEMENT_TYPE to be false
		jestExpect(isValidElementType(element)).toBe(false)
	end)
end)

describe("keys", function()
	it("should leave number keys as number", function()
		element = ReactElement.createElement("Frame", {
			key = 2,
			Size = UDim2.new(1, 0, 1, 0),
		})

		jestExpect(element.key).toEqual(2)
	end)

	it("should convert table keys to string", function()
		local tableKey = {}
		element = ReactElement.createElement("Frame", {
			key = tableKey,
			Size = UDim2.new(1, 0, 1, 0),
		})

		jestExpect(element.key).toEqual(tostring(tableKey))
	end)

	it("should leave string keys as strings", function()
		element = ReactElement.createElement("Frame", {
			key = "hello",
			Size = UDim2.new(1, 0, 1, 0),
		})

		jestExpect(element.key).toEqual("hello")
	end)

	it("should have element.key == nil if no key is passed", function()
		element = ReactElement.createElement("Frame", {
			Size = UDim2.new(1, 0, 1, 0),
		})

		jestExpect(element.key).toEqual(nil)
	end)
end)

describe("should accept", function()
	it("props", function()
		element = ReactElement.createElement("StringValue", { Value = "Foo" })

		jestExpect(element).toBeDefined()
		jestExpect(element.props.Value).toEqual("Foo")
		jestExpect(element.props.children).never.toBeDefined()
	end)

	it("a child and props", function()
		local child = ReactElement.createElement("IntValue")

		element = ReactElement.createElement("StringValue", { Value = "Foo" }, child)

		jestExpect(element).toBeDefined()
		jestExpect(element.props.Value).toEqual("Foo")
		jestExpect(element.props.children).toBeDefined()
		jestExpect(element.props.children).toEqual(child)
	end)

	it("a child and no props", function()
		local child = ReactElement.createElement("IntValue")

		element = ReactElement.createElement("StringValue", nil, child)

		jestExpect(element).toBeDefined()
		jestExpect(element.props.Value).toEqual(nil)
		jestExpect(element.props.children).toBeDefined()
		jestExpect(element.props.children).toEqual(child)
	end)

	it("multiple children and no props", function()
		local child1 = ReactElement.createElement("IntValue")
		local child2 = ReactElement.createElement("StringValue")

		element = ReactElement.createElement("StringValue", nil, child1, child2)

		jestExpect(element).toBeDefined()
		jestExpect(element.props.Value).toEqual(nil)
		jestExpect(element.props.children).toBeDefined()
		jestExpect(element.props.children).toEqual({ child1, child2 })
	end)

	it("a table of children and no props", function()
		local child1 = ReactElement.createElement("IntValue")
		local child2 = ReactElement.createElement("StringValue")

		element = ReactElement.createElement("StringValue", nil, {
			Child1 = child1,
			Child2 = child2,
		})

		jestExpect(element).toBeDefined()
		jestExpect(element.props.Value).toEqual(nil)
		jestExpect(element.props.children).toBeDefined()
		jestExpect(element.props.children).toEqual({
			Child1 = child1,
			Child2 = child2,
		})
	end)

	it("a false value for a boolean prop", function()
		element = ReactElement.createElement("BoolValue", { Value = false })

		jestExpect(element).toBeDefined()
		jestExpect(element.props.Value).toEqual(false)
	end)
end)
