local K=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local H=require(K.Packages.Dex)return function()describe("\068\101\115\116\114\111\121\080\114\101\109\097\100\101\067\104\105\108\100\114\101\110",function()it("\068\101\115\116\114\111\121\115 \097\108\108 \099\104\105\108\100\114\101\110 \111\102 \097 \109\111\117\110\116\101\100 \105\110\115\116\097\110\099\101 \119\105\116\104 \110\111 \102\105\108\116\101\114",function()local K=Instance.new("\070\114\097\109\101")for H=1,3,1 do local x=Instance.new("\070\114\097\109\101")x.Name="\067\104\105\108\100"..H x.Parent=K end local x=H.Premade("\070\114\097\109\101")x:DestroyPremadeChildren();(H.Root(K)):Render(x);(expect(#K:GetChildren())).to.equal(0)end)it("\068\101\115\116\114\111\121\115 \097\108\108 \099\104\105\108\100\114\101\110 \111\102 \097 \109\111\117\110\116\101\100 \105\110\115\116\097\110\099\101 \119\105\116\104 \110\097\109\101 \102\105\108\116\101\114",function()local K=Instance.new("\070\114\097\109\101")for H=1,3,1 do local x=Instance.new("\070\114\097\109\101")x.Name="\067\104\105\108\100"..H x.Parent=K end local x=H.Premade("\070\114\097\109\101")x:DestroyPremadeChildren("\067\104\105\108\100\050");(H.Root(K)):Render(x);(expect(#K:GetChildren())).to.equal(2)local d=K:GetChildren()table.sort(d,function(K,H)return K.Name<H.Name end);(expect(d[1].Name)).to.equal("\067\104\105\108\100\049");(expect(d[2].Name)).to.equal("\067\104\105\108\100\051")end)it("\068\101\115\116\114\111\121\115 \097\108\108 \099\104\105\108\100\114\101\110 \111\102 \097 \109\111\117\110\116\101\100 \105\110\115\116\097\110\099\101 \119\105\116\104 \112\114\101\100\105\099\097\116\101 \102\105\108\116\101\114",function()local K=Instance.new("\070\114\097\109\101")for H=1,3,1 do local x=Instance.new("\070\114\097\109\101")x.Name="\067\104\105\108\100"..H x.LayoutOrder=H x.Parent=K end local x=H.Premade("\070\114\097\109\101")x:DestroyPremadeChildren(function(K)if K:IsA("\070\114\097\109\101")then return K.LayoutOrder==3 end return false end);(H.Root(K)):Render(x);(expect(#K:GetChildren())).to.equal(2)local d=K:GetChildren()table.sort(d,function(K,H)return K.Name<H.Name end);(expect(d[1].Name)).to.equal("\067\104\105\108\100\049");(expect(d[2].Name)).to.equal("\067\104\105\108\100\050")end)end)end
--!strict
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Dex = require(ReplicatedStorage.Packages.Dex)

return function()
    describe("DestroyPremadeChildren", function()
        it("Destroys all children of a mounted instance with no filter", function()
            local host = Instance.new("Frame")
            for i = 1, 3 do
                local child = Instance.new("Frame")
                child.Name = "Child" .. i
                child.Parent = host
            end
            
            local parent = Dex.Premade("Frame")
            parent:DestroyPremadeChildren()

            Dex.Root(host):Render(parent)

            expect(#host:GetChildren()).to.equal(0)
        end)
        it("Destroys all children of a mounted instance with name filter", function()
            local host = Instance.new("Frame")
            for i = 1, 3 do
                local child = Instance.new("Frame")
                child.Name = "Child" .. i
                child.Parent = host
            end
            
            local parent = Dex.Premade("Frame")
            parent:DestroyPremadeChildren("Child2")

            Dex.Root(host):Render(parent)

            expect(#host:GetChildren()).to.equal(2)
            local children = host:GetChildren()
            table.sort(children, function(a, b)
                return a.Name < b.Name
            end)

            expect(children[1].Name).to.equal("Child1")
            expect(children[2].Name).to.equal("Child3")
        end)
        it("Destroys all children of a mounted instance with predicate filter", function()
            local host = Instance.new("Frame")
            for i = 1, 3 do
                local child = Instance.new("Frame")
                child.Name = "Child" .. i
                child.LayoutOrder = i
                child.Parent = host
            end
            
            local parent = Dex.Premade("Frame")
            parent:DestroyPremadeChildren(function(child)
                if child:IsA("Frame") then
                    return child.LayoutOrder == 3
                end
                return false
            end)
            
            Dex.Root(host):Render(parent)

            expect(#host:GetChildren()).to.equal(2)
            local children = host:GetChildren()
            table.sort(children, function(a, b)
                return a.Name < b.Name
            end)

            expect(children[1].Name).to.equal("Child1")
            expect(children[2].Name).to.equal("Child2")
        end)
    end)
end
