mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 20:11:24 +08:00
Add visibility property to ActionItem
Adding the resource to the project file. Fix.
This commit is contained in:
@ -177,6 +177,12 @@ export function assertTrue(test: boolean, message?: string) {
|
||||
}
|
||||
};
|
||||
|
||||
export function assertFalse(test: boolean, message?: string) {
|
||||
if (test !== false) {
|
||||
throw new Error(message);
|
||||
}
|
||||
};
|
||||
|
||||
export function assertNotEqual(actual: any, expected: any, message?: string) {
|
||||
|
||||
var equals = false;
|
||||
@ -223,6 +229,12 @@ export function assertNull(actual: any, message?: string) {
|
||||
}
|
||||
};
|
||||
|
||||
export function assertNotNull(actual: any, message?: string) {
|
||||
if (actual === null || actual === undefined) {
|
||||
throw new Error(message + " Actual: " + actual + " is null/undefined");
|
||||
}
|
||||
};
|
||||
|
||||
export function areClose(actual: number, expected: number, delta: number): boolean {
|
||||
if (isNaN(actual) || Math.abs(actual - expected) > delta) {
|
||||
return false;
|
||||
|
@ -313,4 +313,20 @@ export function test_Setting_ActionItemsWithNumberAsText_doesnt_thrown() {
|
||||
finally {
|
||||
helper.goBack();
|
||||
}
|
||||
}
|
||||
|
||||
export function createPageAndNavigate() {
|
||||
var page: PageModule.Page;
|
||||
var pageFactory = function (): PageModule.Page {
|
||||
page = new PageModule.Page();
|
||||
|
||||
var label = new LabelModule.Label();
|
||||
label.text = "Text";
|
||||
page.content = label;
|
||||
return page;
|
||||
};
|
||||
|
||||
helper.navigate(pageFactory);
|
||||
|
||||
return page;
|
||||
}
|
@ -1,2 +1,45 @@
|
||||
import actionTestsCommon = require("./action-bar-tests-common");
|
||||
global.moduleMerge(actionTestsCommon, exports);
|
||||
import helper = require("../helper");
|
||||
import TKUnit = require("../../TKUnit");
|
||||
import { ActionItem } from "ui/action-bar";
|
||||
import { Visibility } from "ui/enums";
|
||||
import fs = require("file-system");
|
||||
|
||||
global.moduleMerge(actionTestsCommon, exports);
|
||||
|
||||
export function test_actionItem_visibility() {
|
||||
var actionItem = new ActionItem();
|
||||
actionItem.text = "Test";
|
||||
var page = actionTestsCommon.createPageAndNavigate();
|
||||
try {
|
||||
page.actionBar.actionItems.addItem(actionItem);
|
||||
var toolbar = <android.support.v7.widget.Toolbar>(<any>page.actionBar)._toolbar;
|
||||
var menu = toolbar.getMenu();
|
||||
|
||||
TKUnit.assertTrue(menu.hasVisibleItems(), "Visibility does not work");
|
||||
actionItem.visibility = Visibility.collapse;
|
||||
TKUnit.assertFalse(menu.hasVisibleItems(), "Visibility does not work");
|
||||
}
|
||||
finally {
|
||||
helper.goBack();
|
||||
}
|
||||
}
|
||||
|
||||
export function test_navigationButton_visibility() {
|
||||
var actionItem = new ActionItem();
|
||||
actionItem.icon = "~/small-image.png";
|
||||
var page = actionTestsCommon.createPageAndNavigate();
|
||||
try {
|
||||
page.actionBar.navigationButton = actionItem;
|
||||
|
||||
var toolbar = <android.support.v7.widget.Toolbar>(<any>page.actionBar)._toolbar;
|
||||
var menu = toolbar.getMenu();
|
||||
|
||||
TKUnit.assertNotNull(toolbar.getNavigationIcon(), "Visibility does not work");
|
||||
actionItem.visibility = Visibility.collapse;
|
||||
TKUnit.assertNull(toolbar.getNavigationIcon(), "Visibility does not work");
|
||||
}
|
||||
finally {
|
||||
helper.goBack();
|
||||
}
|
||||
}
|
@ -5,9 +5,12 @@ import LabelModule = require("ui/label");
|
||||
import helper = require("../helper");
|
||||
import view = require("ui/core/view");
|
||||
import actionBar = require("ui/action-bar");
|
||||
import { Visibility } from "ui/enums";
|
||||
|
||||
global.moduleMerge(actionTestsCommon, exports);
|
||||
|
||||
var ASYNC = 0.2;
|
||||
|
||||
export function test_NavBar_isVisible_when_MenuItems_areSet() {
|
||||
|
||||
var page: PageModule.Page;
|
||||
@ -80,4 +83,58 @@ export function test_NavBarItemsAreClearedFromNativeWhenClearedFromNativeScript(
|
||||
page.off(view.View.loadedEvent, handler);
|
||||
helper.goBack();
|
||||
}
|
||||
}
|
||||
|
||||
export function test_actionItem_visibility() {
|
||||
var actionItem = new actionBar.ActionItem();
|
||||
actionItem.text = "Test";
|
||||
actionItem.ios.position = "left";
|
||||
var page = actionTestsCommon.createPageAndNavigate();
|
||||
|
||||
try {
|
||||
page.actionBar.actionItems.addItem(actionItem);
|
||||
|
||||
var viewController = (<UIViewController>page.ios);
|
||||
var navigationItem: UINavigationItem = viewController.navigationItem;
|
||||
|
||||
var leftBarButtonItemsCount = navigationItem.leftBarButtonItems ? navigationItem.leftBarButtonItems.count : 0;
|
||||
TKUnit.assertEqual(leftBarButtonItemsCount, 1, "Visibility does not work");
|
||||
actionItem.visibility = Visibility.collapse;
|
||||
|
||||
TKUnit.waitUntilReady(() => {
|
||||
leftBarButtonItemsCount = navigationItem.leftBarButtonItems ? navigationItem.leftBarButtonItems.count : 0;
|
||||
|
||||
return leftBarButtonItemsCount === 0;
|
||||
});
|
||||
|
||||
leftBarButtonItemsCount = navigationItem.leftBarButtonItems ? navigationItem.leftBarButtonItems.count : 0;
|
||||
TKUnit.assertEqual(leftBarButtonItemsCount, 0, "Visibility does not work");
|
||||
}
|
||||
finally {
|
||||
helper.goBack();
|
||||
}
|
||||
}
|
||||
|
||||
export function test_navigationButton_visibility() {
|
||||
var actionItem = new actionBar.ActionItem();
|
||||
actionItem.text = "Test";
|
||||
var page = actionTestsCommon.createPageAndNavigate();
|
||||
try {
|
||||
page.actionBar.navigationButton = actionItem;
|
||||
|
||||
var viewController = (<UIViewController>page.ios);
|
||||
var navigationItem: UINavigationItem = viewController.navigationItem;
|
||||
|
||||
TKUnit.assertFalse(navigationItem.hidesBackButton, "Visibility does not work");
|
||||
actionItem.visibility = Visibility.collapse;
|
||||
|
||||
TKUnit.waitUntilReady(() => {
|
||||
return navigationItem.hidesBackButton;
|
||||
});
|
||||
|
||||
TKUnit.assertTrue(navigationItem.hidesBackButton, "Visibility does not work");
|
||||
}
|
||||
finally {
|
||||
helper.goBack();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user