import TKUnit = require("../../TKUnit");
import LabelModule = require("ui/label");
import helper = require("../helper");
import builder = require("ui/builder");
import button = require("ui/button");
import PageModule = require("ui/page");
//
// # ActionBar
// Using a ActionBar requires the action-bar module.
// ``` JavaScript
import actionBarModule = require("ui/action-bar");
// ```
//
// ## Setting Title and Icon
//```XML
//
//
// {%raw%}{%endraw%}
//
// ...
//
//```
//The icon can only be set in Android platform. Following the design guides it is automatically hidden in Lollipop versions (API level >= 20). You explicitly control its visibility with the `android.iconVisibility' property.
//
//
// ## Setting Custom Title View
//```XML
//
//
//
//
//
//
//
//
//
//
//
//
// ...
//
//```
//
// ## Setting Action Items
//```XML
//
//
//
//
//
//
//
//
//
//
// ...
//
//```
//
//The position option is platform specific. The available values are as follows:
// * **Android** - `actionBar`, `actionBarIfRoom` and `popup`. The default is `actionBar`.
// * **iOS** - `left` and `right`. The default is `left`.
//
// ## Setting Navigation Button
//```XML
//
//
//
//
//
// ...
//
//```
//
//
export function test_actionItem_inherit_bindingContext() {
var page: PageModule.Page;
var label: LabelModule.Label;
var context = { text: "item" };
var pageFactory = function (): PageModule.Page {
page = new PageModule.Page();
page.bindingContext = context;
var actionItem = new actionBarModule.ActionItem();
actionItem.bind({
sourceProperty: "text",
targetProperty: "text"
});
page.actionBar.actionItems.addItem(actionItem);
label = new LabelModule.Label();
label.text = "Text";
page.content = label;
return page;
};
helper.navigate(pageFactory);
try {
TKUnit.assertEqual(page.actionBar.actionItems.getItemAt(0).text, "item", "actionItem.text");
}
finally {
helper.goBack();
}
}
export function test_actionBar_inherit_bindingContext_inXML() {
var p = builder.parse(
" ");
p.bindingContext = { myProp: "success" };
TKUnit.assertEqual(p.actionBar.title, "success", "actionBar.title");
};
export function test_actionItem_inherit_bindingContext_inXML() {
var p = builder.parse(
" " +
"" +
" ");
p.bindingContext = { myProp: "success" };
var actionItem = p.actionBar.actionItems.getItemAt(0);
TKUnit.assertEqual(actionItem.text, "success", "actionItem.text");
};
export function test_navigationButton_inherit_bindingContext_inXML() {
var p = builder.parse(
" " +
"" +
" ");
p.bindingContext = { myProp: "success" };
var navButton = p.actionBar.navigationButton;
TKUnit.assertEqual(navButton.text, "success", "actionItem.text");
};
export function test_titleView_inherit_bindingContext_inXML() {
var p = builder.parse(
" " +
"" +
" ");
p.bindingContext = { myProp: "success" };
var centerBtn = p.actionBar.titleView;
TKUnit.assert(centerBtn instanceof button.Button, "cneterView not loaded correctly");
TKUnit.assertEqual(centerBtn.text, "success", "actionItem.text");
};
export function test_titleView_inXML() {
var p = builder.parse(
" " +
"" +
" ");
var centerBtn = p.actionBar.titleView;
TKUnit.assert(centerBtn instanceof button.Button, "cneterView not loaded correctly");
};
export function test_titleView_inXML_short_definition() {
var p = builder.parse(
" " +
"" +
" ");
var centerBtn = p.actionBar.titleView;
TKUnit.assert(centerBtn instanceof button.Button, "cneterView not loaded correctly");
};
export function test_Setting_ActionItems_doesnt_thrown() {
var page: PageModule.Page;
var label: LabelModule.Label;
var gotException = false;
var pageFactory = function (): PageModule.Page {
page = new PageModule.Page();
var actionItem = new actionBarModule.ActionItem();
actionItem.text = "Item";
page.actionBar.actionItems.addItem(actionItem);
label = new LabelModule.Label();
label.text = "Text";
page.content = label;
return page;
};
try {
helper.navigate(pageFactory);
}
catch (e) {
gotException = true;
}
try {
TKUnit.assert(!gotException, "Expected: false, Actual: " + gotException);
}
finally {
helper.goBack();
}
}