public IEnumerator SelectItem() { var mst = new MultiSelectTests(); yield return(mst.CheckDefaults()); yield return(mst.Show()); Assert.IsNotNull(mst.Option1, "Expected to find Option1"); Assert.IsNotNull(mst.Toggle1, "Expected to find toggle component"); Assert.IsTrue(mst.Toggle1.isOn, string.Format("Expected toggle1 {0} to be on but it was {1}", mst.Toggle1.name, mst.Toggle1.isOn)); Assert.IsNotNull(mst.Option2, "Expected to find Option2"); Assert.IsNotNull(mst.Toggle2, "Expected to find toggle component"); Assert.IsFalse(mst.Toggle2.isOn, "Expected toggle2 to be off"); Assert.AreEqual(0, mst.Dropdown.value); Assert.IsTrue(1 == mst.Dropdown.SelectedCount); Assert.IsTrue(mst.Dropdown.options[0].selected, "Expected options[0].selected to be true"); Assert.IsFalse(mst.Dropdown.options[1].selected, "Expected options[1].selected to be false"); Assert.IsFalse(mst.Dropdown.options[2].selected, "Expected options[2].selected to be false"); Assert.IsNotNull(mst.Option3, "Expected to find Option3"); Assert.IsNotNull(mst.Toggle3, "Expected to find toggle component"); Assert.IsFalse(mst.Toggle3.isOn, "Expected toggle3 to be off"); // // Click option 3 to turn it on, turning option 1 off // yield return(mst.ClickOption(mst.Option3)); yield return(mst.Show()); Assert.AreEqual(2, mst.Dropdown.value); Assert.IsTrue(1 == mst.Dropdown.SelectedCount); Assert.IsFalse(mst.Dropdown.options[0].selected, "Expected options[0].selected to be false"); Assert.IsFalse(mst.Dropdown.options[1].selected, "Expected options[1].selected to be false"); Assert.IsTrue(mst.Dropdown.options[2].selected, "Expected options[2].selected to be true"); yield return(mst.Show()); // // Click option 2 to turn it on, turning option 3 off // yield return(mst.ClickOption(mst.Option2)); yield return(mst.Show()); Assert.AreEqual(1, mst.Dropdown.value); Assert.IsTrue(1 == mst.Dropdown.SelectedCount); Assert.IsFalse(mst.Dropdown.options[0].selected, "Expected options[0].selected to be false"); Assert.IsTrue(mst.Dropdown.options[1].selected, "Expected options[1].selected to be true"); Assert.IsFalse(mst.Dropdown.options[2].selected, "Expected options[2].selected to be false"); }
public IEnumerator Events() { var mst = new MultiSelectTests(); yield return(mst.CheckDefaults()); // // Set up the event handlers // var deselected = uint.MaxValue; mst.Dropdown.onItemDeselected.AddListener((i) => { deselected = i; }); var selected = uint.MaxValue; mst.Dropdown.onItemSelected.AddListener((i) => { selected = i; }); var oldValue = mst.Dropdown.value; Assert.AreEqual(0, oldValue, "Expected old value to be 0"); Assert.IsTrue(mst.Dropdown.SelectedCount == 1, "Expected one item to be selected"); var newValue = uint.MaxValue; mst.Dropdown.onValueChanged.AddListener((i) => { newValue = i; }); yield return(mst.Show()); yield return(mst.ClickOption(mst.Option2)); yield return(mst.Show()); Assert.AreEqual(1, mst.Dropdown.value, "Expected value to be 1"); Assert.IsFalse(mst.Toggle1.isOn, "Expected toggle 1 to be off"); Assert.IsTrue(mst.Toggle2.isOn, "Expected toggle 2 to be on"); Assert.IsFalse(mst.Toggle3.isOn, "Expected toggle 3 to be off"); Assert.AreEqual(0, deselected, "Expected onItemDeselected to be called with index 0"); Assert.AreEqual(1, selected, "Expected onItemSelected to be called with index 1"); Assert.AreEqual(1, newValue, "Expected onValueChanged to be called with value 1"); }
public IEnumerator SetValue() { var mst = new MultiSelectTests(); yield return(mst.CheckDefaults()); Assert.AreEqual(0, mst.Dropdown.value, "Expected value to be zero"); mst.Dropdown.value = 2; yield return(new WaitForSeconds(0.5f)); yield return(mst.Show()); Assert.AreEqual(2, mst.Dropdown.value, "Expected value to be 2"); Assert.IsFalse(mst.Toggle1.isOn, "Expected toggle 1 to be off"); Assert.IsFalse(mst.Toggle2.isOn, "Expected toggle 2 to be off"); Assert.IsTrue(mst.Toggle3.isOn, "Expected toggle 3 to be on"); }