local a=require("\078\101\120\117\115\085\110\105\116\084\101\115\116\105\110\103")local L=require((game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")):WaitForChild("\078\101\120\117\115\080\108\117\103\105\110\070\114\097\109\101\119\111\114\107"))local b=L:GetResource("\085\073\046\067\111\108\108\097\112\115\097\098\108\101\076\105\115\116\046\067\111\110\115\116\114\097\105\110\116\046\078\101\120\117\115\077\117\108\116\105\067\111\110\115\116\114\097\105\110\116")a:RegisterUnitTest("\067\111\110\115\116\114\117\099\116\111\114",function(a)local L=b.new()a:AssertEquals(L.ClassName,"\078\101\120\117\115\077\117\108\116\105\067\111\110\115\116\114\097\105\110\116","\067\108\097\115\115 \110\097\109\101 \105\115 \105\110\099\111\114\114\101\099\116\046")a:AssertEquals(L.Name,"\078\101\120\117\115\077\117\108\116\105\067\111\110\115\116\114\097\105\110\116","\078\097\109\101 \105\115 \105\110\099\111\114\114\101\099\116\046")a:AssertEquals(tostring(L),"\078\101\120\117\115\077\117\108\116\105\067\111\110\115\116\114\097\105\110\116","\078\097\109\101 \105\115 \105\110\099\111\114\114\101\099\116\046")end)a:RegisterUnitTest("\079\110\101\083\101\108\101\099\116\105\111\110",function(a)local Y=b.new()local T=L.new("\076\105\115\116\083\101\108\101\099\116\105\111\110\067\111\110\115\116\114\097\105\110\116")Y:AddConstraint(T)local X,R=L.new("\067\111\108\108\097\112\115\097\098\108\101\076\105\115\116\070\114\097\109\101"),L.new("\067\111\108\108\097\112\115\097\098\108\101\076\105\115\116\070\114\097\109\101")local A,N=L.new("\067\111\108\108\097\112\115\097\098\108\101\076\105\115\116\070\114\097\109\101"),L.new("\067\111\108\108\097\112\115\097\098\108\101\076\105\115\116\070\114\097\109\101")Y:AddListFrame(X)Y:AddListFrame(R)Y:AddListFrame(A)X.Selected=true a:AssertTrue(X.Selected,"\070\114\097\109\101 \105\115 \110\111\116 \115\101\108\101\099\116\101\100\046")a:AssertFalse(R.Selected,"\070\114\097\109\101 \105\115 \115\101\108\101\099\116\101\100\046")a:AssertFalse(A.Selected,"\070\114\097\109\101 \105\115 \115\101\108\101\099\116\101\100\046")R.Selected=true a:AssertFalse(X.Selected,"\070\114\097\109\101 \105\115 \115\101\108\101\099\116\101\100\046")a:AssertTrue(R.Selected,"\070\114\097\109\101 \105\115 \110\111\116 \115\101\108\101\099\116\101\100\046")a:AssertFalse(A.Selected,"\070\114\097\109\101 \105\115 \115\101\108\101\099\116\101\100\046")N.Selected=true Y:AddListFrame(N)a:AssertFalse(X.Selected,"\070\114\097\109\101 \105\115 \115\101\108\101\099\116\101\100\046")a:AssertTrue(R.Selected,"\070\114\097\109\101 \105\115 \110\111\116 \115\101\108\101\099\116\101\100\046")a:AssertFalse(A.Selected,"\070\114\097\109\101 \105\115 \115\101\108\101\099\116\101\100\046")a:AssertFalse(N.Selected,"\070\114\097\109\101 \105\115 \115\101\108\101\099\116\101\100\046")end)a:RegisterUnitTest("\077\117\108\116\105\112\108\101\083\101\108\101\099\116\105\111\110",function(a)local Y=b.new()local T=L.new("\076\105\115\116\083\101\108\101\099\116\105\111\110\067\111\110\115\116\114\097\105\110\116")T.AllowMultipleSelections=true Y:AddConstraint(T)local X,R=L.new("\067\111\108\108\097\112\115\097\098\108\101\076\105\115\116\070\114\097\109\101"),L.new("\067\111\108\108\097\112\115\097\098\108\101\076\105\115\116\070\114\097\109\101")local A,N=L.new("\067\111\108\108\097\112\115\097\098\108\101\076\105\115\116\070\114\097\109\101"),L.new("\067\111\108\108\097\112\115\097\098\108\101\076\105\115\116\070\114\097\109\101")Y:AddListFrame(X)Y:AddListFrame(R)Y:AddListFrame(A)X.Selected=true N.Selected=true Y:AddListFrame(N)a:AssertTrue(X.Selected,"\070\114\097\109\101 \105\115 \110\111\116 \115\101\108\101\099\116\101\100\046")a:AssertFalse(R.Selected,"\070\114\097\109\101 \105\115 \115\101\108\101\099\116\101\100\046")a:AssertFalse(A.Selected,"\070\114\097\109\101 \105\115 \115\101\108\101\099\116\101\100\046")a:AssertTrue(N.Selected,"\070\114\097\109\101 \105\115 \110\111\116 \115\101\108\101\099\116\101\100\046")T.AllowMultipleSelections=false a:AssertTrue(X.Selected,"\070\114\097\109\101 \105\115 \110\111\116 \115\101\108\101\099\116\101\100\046")a:AssertFalse(R.Selected,"\070\114\097\109\101 \105\115 \115\101\108\101\099\116\101\100\046")a:AssertFalse(A.Selected,"\070\114\097\109\101 \105\115 \115\101\108\101\099\116\101\100\046")a:AssertFalse(N.Selected,"\070\114\097\109\101 \105\115 \115\101\108\101\099\116\101\100\046")end)return true
--[[
TheNexusAvenger

Tests the NexusMultiConstraint class.
--]]

local NexusUnitTesting = require("NexusUnitTesting")

local NexusPluginFramework = require(game:GetService("ReplicatedStorage"):WaitForChild("NexusPluginFramework"))
local NexusMultiConstraint = NexusPluginFramework:GetResource("UI.CollapsableList.Constraint.NexusMultiConstraint")



--[[
Test that the constructor works without failing.
--]]
NexusUnitTesting:RegisterUnitTest("Constructor",function(UnitTest)
	local CuT = NexusMultiConstraint.new()
	UnitTest:AssertEquals(CuT.ClassName,"NexusMultiConstraint","Class name is incorrect.")
	UnitTest:AssertEquals(CuT.Name,"NexusMultiConstraint","Name is incorrect.")
	UnitTest:AssertEquals(tostring(CuT),"NexusMultiConstraint","Name is incorrect.")
end)

--[[
Tests that only one can be selected.
--]]
NexusUnitTesting:RegisterUnitTest("OneSelection",function(UnitTest)
	--Create the component under testing.
	local CuT = NexusMultiConstraint.new()
	local Constraint = NexusPluginFramework.new("ListSelectionConstraint")
	CuT:AddConstraint(Constraint)
	
	--Create 4 frames and add 3 of them.
	local Frame1,Frame2 = NexusPluginFramework.new("CollapsableListFrame"),NexusPluginFramework.new("CollapsableListFrame")
	local Frame3,Frame4 = NexusPluginFramework.new("CollapsableListFrame"),NexusPluginFramework.new("CollapsableListFrame")
	CuT:AddListFrame(Frame1)
	CuT:AddListFrame(Frame2)
	CuT:AddListFrame(Frame3)
	
	--Select 1 frame and assert they are correct.
	Frame1.Selected = true
	UnitTest:AssertTrue(Frame1.Selected,"Frame is not selected.")
	UnitTest:AssertFalse(Frame2.Selected,"Frame is selected.")
	UnitTest:AssertFalse(Frame3.Selected,"Frame is selected.")
	
	--Select another frame and assert it is selected.
	Frame2.Selected = true
	UnitTest:AssertFalse(Frame1.Selected,"Frame is selected.")
	UnitTest:AssertTrue(Frame2.Selected,"Frame is not selected.")
	UnitTest:AssertFalse(Frame3.Selected,"Frame is selected.")
	
	--Assert adding a selected frame late disables the selection.
	Frame4.Selected = true
	CuT:AddListFrame(Frame4)
	UnitTest:AssertFalse(Frame1.Selected,"Frame is selected.")
	UnitTest:AssertTrue(Frame2.Selected,"Frame is not selected.")
	UnitTest:AssertFalse(Frame3.Selected,"Frame is selected.")
	UnitTest:AssertFalse(Frame4.Selected,"Frame is selected.")
end)

--[[
Tests that multiple can be selected.
--]]
NexusUnitTesting:RegisterUnitTest("MultipleSelection",function(UnitTest)
	--Create the component under testing.
	local CuT = NexusMultiConstraint.new()
	local Constraint = NexusPluginFramework.new("ListSelectionConstraint")
	Constraint.AllowMultipleSelections = true
	CuT:AddConstraint(Constraint)
	
	--Create 4 frames and add 3 of them.
	local Frame1,Frame2 = NexusPluginFramework.new("CollapsableListFrame"),NexusPluginFramework.new("CollapsableListFrame")
	local Frame3,Frame4 = NexusPluginFramework.new("CollapsableListFrame"),NexusPluginFramework.new("CollapsableListFrame")
	CuT:AddListFrame(Frame1)
	CuT:AddListFrame(Frame2)
	CuT:AddListFrame(Frame3)
	Frame1.Selected = true
	Frame4.Selected = true
	
	--Add the 4th frame and assert the selections weren't changed.
	CuT:AddListFrame(Frame4)
	UnitTest:AssertTrue(Frame1.Selected,"Frame is not selected.")
	UnitTest:AssertFalse(Frame2.Selected,"Frame is selected.")
	UnitTest:AssertFalse(Frame3.Selected,"Frame is selected.")
	UnitTest:AssertTrue(Frame4.Selected,"Frame is not selected.")
	
	--Make only 1 selection valid and assert only the first frame was selected.
	Constraint.AllowMultipleSelections = false
	UnitTest:AssertTrue(Frame1.Selected,"Frame is not selected.")
	UnitTest:AssertFalse(Frame2.Selected,"Frame is selected.")
	UnitTest:AssertFalse(Frame3.Selected,"Frame is selected.")
	UnitTest:AssertFalse(Frame4.Selected,"Frame is selected.")
end)



return true