new MenuCommand(button, { type: 'flyout', flyout: menu });
LiveUnit.Assert.isTrue(mc.dispose);
LiveUnit.Assert.isTrue(mc.element.classList.contains("win-disposable"));
LiveUnit.Assert.isFalse(mc._disposed);
mc.dispose();
LiveUnit.Assert.isTrue(mc._disposed);
LiveUnit.Assert.isFalse(menu._disposed,
"MenuCommands do not instantiate the flyout and are not responsible for disposing it.");
mc.dispose();
}
// Tests that previous innerHTML is cleared when we instantiate a new button.
testMenuCommandRemovesOldInnerHTML = function () {
var button = document.createElement("button");
button.innerHTML = "";
LiveUnit.Assert.isTrue(button.querySelector("#testMenuCommandRemovesOldInnerHTML"));
var mc = new MenuCommand(button);
LiveUnit.Assert.isFalse(button.querySelector("#testMenuCommandRemovesOldInnerHTML"), "MenuCommand buttons should lose previous innerHTML on control Instantiation");
}
// Tests that a Flyout MenuCommand activates and shows its associated flyout when invoked, and deactivates again when the associated flyout is hidden.
testFlyoutCommandInvokeBehavior = function (complete) {
var subMenuElement = document.createElement('div');
document.body.appendChild(subMenuElement);
var subMenu = new Menu(subMenuElement);
var menuCommandElement = document.createElement('button');
document.body.appendChild(menuCommandElement);
var menuCommand = new MenuCommand(menuCommandElement, { type: 'flyout', flyout: subMenu });
var msg = "Flyout MenuCommand should not appear activated by default";
LiveUnit.LoggingCore.logComment("Test: " + msg);
LiveUnit.Assert.isFalse(WinJS.Utilities.hasClass(menuCommandElement, _Constants.menuCommandFlyoutActivatedClass), msg);
msg = "subMenu should not have 'aria-expanded' attribute while closed";
LiveUnit.LoggingCore.logComment("Test: " + msg);
LiveUnit.Assert.isFalse(subMenu.element.hasAttribute("aria-expanded"), msg);
function afterSubMenuShow() {
subMenu.removeEventListener("aftershow", afterSubMenuShow, false);
OverlayHelpers.Assert.verifyMenuFlyoutCommandActivated(menuCommand, msg);
msg = "subMenu should have 'aria-expanded' attribute with value === 'true' when opened by a menuCommand";
LiveUnit.LoggingCore.logComment("Test: " + msg);
LiveUnit.Assert.areEqual("true", subMenu.element.getAttribute("aria-expanded"), msg);
var msg = "Hiding a Flyout MenuCommand's associated flyout, by any means, should deactivate the MenuCommand."
LiveUnit.LoggingCore.logComment("Test: " + msg);
subMenu.hide();
};
function afterSubMenuHide() {
subMenu.removeEventListener("afterhide", afterSubMenuHide, false);
OverlayHelpers.Assert.verifyMenuFlyoutCommandDeactivated(menuCommand, msg);
msg = "subMenu should not have 'aria-expanded' attribute while closed";
LiveUnit.LoggingCore.logComment("Test: " + msg);
LiveUnit.Assert.isFalse(subMenu.element.hasAttribute("aria-expanded"), msg);
OverlayHelpers.disposeAndRemove(subMenuElement);
OverlayHelpers.disposeAndRemove(menuCommandElement);
complete();
};
subMenu.addEventListener("aftershow", afterSubMenuShow, false);
subMenu.addEventListener("afterhide", afterSubMenuHide, false);
var msg = "Invoking a Flyout MenuCommand, by any means, should activate it and show its associated Flyout."
LiveUnit.LoggingCore.logComment("Test: " + msg);
menuCommand._invoke();
}
// Tests that setting the hidden property, of an activated flyout MenuCommand to true, will deactivate it.
testHiddenPropertyDeactivatesFlyoutCommands = function (complete) {
var msg = "Setting the hidden property, of an activated flyout MenuCommand to true, should deactivate it.";
LiveUnit.LoggingCore.logComment("Test: " + msg);
verifyPropertyChangeDeactivatesFlyoutMenuCommand("hidden", true, msg).then(complete);
}
// Tests that disabling an activated flyout MenuCommand will deactivate it.
testDisabledPropertyDeactivatesFlyoutCommands = function (complete) {
var msg = "Disabling an activated flyout MenuCommand should deactivate it.";
LiveUnit.LoggingCore.logComment("Test: " + msg);
verifyPropertyChangeDeactivatesFlyoutMenuCommand("disabled", true, msg).then(complete);
}
// Tests that setting the flyout property of an activated flyout MenuCommand will deactivate it.
testFlyoutPropertyDeactivatesFlyoutCommands = function (complete) {
var msg = "Setting the flyout property of an activated flyout MenuCommand should deactivate it.";
LiveUnit.LoggingCore.logComment("Test: " + msg);
verifyPropertyChangeDeactivatesFlyoutMenuCommand("flyout", null, msg).then(complete);
}
}
}
// register the object as a test class by passing in the name
LiveUnit.registerTestClass("CorsicaTests.MenuCommandTests");