return function()local W=require(script.Parent.Parent.createElement)local R=require(script.Parent.Parent.createFragment)local z=require(script.Parent.Parent.Type)local b=require(script.Parent)describe("\105\116\101\114\097\116\101\069\108\101\109\101\110\116\115",function()it("\115\104\111\117\108\100 \105\116\101\114\097\116\101 \111\110\099\101 \102\111\114 \097 \115\105\110\103\108\101 \099\104\105\108\100",function()local R=W("\084\101\120\116\076\097\098\101\108")local z=b.iterateElements(R)local w,I=z();(expect(w)).to.equal(b.UseParentKey);(expect(I)).to.equal(R)w=z();(expect(w)).to.equal(nil)end)it("\115\104\111\117\108\100 \105\116\101\114\097\116\101 \111\118\101\114 \116\097\098\108\101\115",function()local R={a=W("\084\101\120\116\076\097\098\101\108");b=W("\084\101\120\116\076\097\098\101\108")}local w={}local I=0 for W,R in b.iterateElements(R)do(expect(typeof(W))).to.equal("\115\116\114\105\110\103");(expect(z.of(R))).to.equal(z.Element)w[R]=W I=I+1 end;(expect(I)).to.equal(2);(expect(w[R.a])).to.equal("\097");(expect(w[R.b])).to.equal("\098")end)it("\115\104\111\117\108\100 \114\101\116\117\114\110 \097 \122\101\114\111-\101\108\101\109\101\110\116 \105\116\101\114\097\116\111\114 \102\111\114 \098\111\111\108\101\097\110\115",function()local W=b.iterateElements(false);(expect(W())).to.equal(nil)end)it("\115\104\111\117\108\100 \114\101\116\117\114\110 \097 \122\101\114\111-\101\108\101\109\101\110\116 \105\116\101\114\097\116\111\114 \102\111\114 \110\105\108",function()local W=b.iterateElements(nil);(expect(W())).to.equal(nil)end)it("\115\104\111\117\108\100 \116\104\114\111\119 \105\102 \103\105\118\101\110 \097\110 \105\108\108\101\103\097\108 \118\097\108\117\101",function()(expect(function()b.iterateElements(1)end)).to.throw()end)end)describe("\103\101\116\069\108\101\109\101\110\116\066\121\075\101\121",function()it("\115\104\111\117\108\100 \114\101\116\117\114\110 \110\105\108 \102\111\114 \098\111\111\108\101\097\110\115",function()(expect(b.getElementByKey(true,"\116\101\115\116"))).to.equal(nil)end)it("\115\104\111\117\108\100 \114\101\116\117\114\110 \110\105\108 \102\111\114 \110\105\108",function()(expect(b.getElementByKey(nil,"\116\101\115\116"))).to.equal(nil)end)describe("\115\105\110\103\108\101 \101\108\101\109\101\110\116\115",function()local R=W("\084\101\120\116\076\097\098\101\108")it("\115\104\111\117\108\100 \114\101\116\117\114\110 \116\104\101 \101\108\101\109\101\110\116 \105\102 \116\104\101 \107\101\121 \105\115 \085\115\101\080\097\114\101\110\116\075\101\121",function()(expect(b.getElementByKey(R,b.UseParentKey))).to.equal(R)end)it("\115\104\111\117\108\100 \114\101\116\117\114\110 \110\105\108 \105\102 \116\104\101 \107\101\121 \105\115 \110\111\116 \085\115\101\080\097\114\101\110\116\075\101\121",function()(expect(b.getElementByKey(R,"\116\101\115\116"))).to.equal(nil)end)end)it("\115\104\111\117\108\100 \114\101\116\117\114\110 \116\104\101 \099\111\114\114\101\115\112\111\110\100\105\110\103 \101\108\101\109\101\110\116 \102\114\111\109 \097 \116\097\098\108\101",function()local R={a=W("\084\101\120\116\076\097\098\101\108"),b=W("\084\101\120\116\076\097\098\101\108")};(expect(b.getElementByKey(R,"\097"))).to.equal(R.a);(expect(b.getElementByKey(R,"\098"))).to.equal(R.b)end)it("\115\104\111\117\108\100 \114\101\116\117\114\110 \110\105\108 \105\102 \116\104\101 \107\101\121 \100\111\101\115 \110\111\116 \101\120\105\115\116",function()local W=R({});(expect(b.getElementByKey(W,"\097"))).to.equal(nil)end)end)end
return function()
	local createElement = require(script.Parent.Parent.createElement)
	local createFragment = require(script.Parent.Parent.createFragment)
	local Type = require(script.Parent.Parent.Type)

	local ElementUtils = require(script.Parent)

	describe("iterateElements", function()
		it("should iterate once for a single child", function()
			local child = createElement("TextLabel")
			local iterator = ElementUtils.iterateElements(child)
			local iteratedKey, iteratedChild = iterator()
			-- For single elements, the key should be UseParentKey
			expect(iteratedKey).to.equal(ElementUtils.UseParentKey)
			expect(iteratedChild).to.equal(child)

			iteratedKey = iterator()
			expect(iteratedKey).to.equal(nil)
		end)

		it("should iterate over tables", function()
			local children = {
				a = createElement("TextLabel"),
				b = createElement("TextLabel"),
			}

			local seenChildren = {}
			local count = 0

			for key, child in ElementUtils.iterateElements(children) do
				expect(typeof(key)).to.equal("string")
				expect(Type.of(child)).to.equal(Type.Element)
				seenChildren[child] = key
				count = count + 1
			end

			expect(count).to.equal(2)
			expect(seenChildren[children.a]).to.equal("a")
			expect(seenChildren[children.b]).to.equal("b")
		end)

		it("should return a zero-element iterator for booleans", function()
			local booleanIterator = ElementUtils.iterateElements(false)
			expect(booleanIterator()).to.equal(nil)
		end)

		it("should return a zero-element iterator for nil", function()
			local nilIterator = ElementUtils.iterateElements(nil)
			expect(nilIterator()).to.equal(nil)
		end)

		it("should throw if given an illegal value", function()
			expect(function()
				ElementUtils.iterateElements(1)
			end).to.throw()
		end)
	end)

	describe("getElementByKey", function()
		it("should return nil for booleans", function()
			expect(ElementUtils.getElementByKey(true, "test")).to.equal(nil)
		end)

		it("should return nil for nil", function()
			expect(ElementUtils.getElementByKey(nil, "test")).to.equal(nil)
		end)

		describe("single elements", function()
			local element = createElement("TextLabel")

			it("should return the element if the key is UseParentKey", function()
				expect(ElementUtils.getElementByKey(element, ElementUtils.UseParentKey)).to.equal(element)
			end)

			it("should return nil if the key is not UseParentKey", function()
				expect(ElementUtils.getElementByKey(element, "test")).to.equal(nil)
			end)
		end)

		it("should return the corresponding element from a table", function()
			local children = {
				a = createElement("TextLabel"),
				b = createElement("TextLabel"),
			}

			expect(ElementUtils.getElementByKey(children, "a")).to.equal(children.a)
			expect(ElementUtils.getElementByKey(children, "b")).to.equal(children.b)
		end)

		it("should return nil if the key does not exist", function()
			local children = createFragment({})

			expect(ElementUtils.getElementByKey(children, "a")).to.equal(nil)
		end)
	end)
end
