mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Merge pull request #307 from NativeScript/hhristov/ui-test-class
Add base UITest class Fix Image.src failing test
This commit is contained in:
@@ -135,6 +135,7 @@
|
||||
<TypeScriptCompile Include="apps\tests\platform-tests.ts" />
|
||||
<TypeScriptCompile Include="apps\tests\fps-meter-tests.ts" />
|
||||
<TypeScriptCompile Include="apps\tests\trace-tests.ts" />
|
||||
<TypeScriptCompile Include="apps\tests\ui-test.ts" />
|
||||
<TypeScriptCompile Include="apps\tests\ui\time-picker\time-picker-tests-native.android.ts">
|
||||
<DependentUpon>time-picker-tests-native.d.ts</DependentUpon>
|
||||
</TypeScriptCompile>
|
||||
@@ -1561,7 +1562,7 @@
|
||||
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
|
||||
</WebProjectProperties>
|
||||
</FlavorProperties>
|
||||
<UserProperties ui_2layouts_2wrap-layout_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2layouts_2grid-layout_2package_1json__JSONSchema="" ui_2layouts_2dock-layout_2package_1json__JSONSchema="" ui_2layouts_2absolute-layout_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2layouts_2linear-layout_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2web-view_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2content-view_2package_1json__JSONSchema="http://json.schemastore.org/package" apps_2gallery-app_2package_1json__JSONSchema="http://json.schemastore.org/package" apps_2absolute-layout-demo_2package_1json__JSONSchema="http://json.schemastore.org/package" apps_2editable-text-demo_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2scroll-view_2package_1json__JSONSchema="http://json.schemastore.org/package" />
|
||||
<UserProperties ui_2scroll-view_2package_1json__JSONSchema="http://json.schemastore.org/package" apps_2editable-text-demo_2package_1json__JSONSchema="http://json.schemastore.org/package" apps_2absolute-layout-demo_2package_1json__JSONSchema="http://json.schemastore.org/package" apps_2gallery-app_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2content-view_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2web-view_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2layouts_2linear-layout_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2layouts_2absolute-layout_2package_1json__JSONSchema="http://json.schemastore.org/package" ui_2layouts_2dock-layout_2package_1json__JSONSchema="" ui_2layouts_2grid-layout_2package_1json__JSONSchema="" ui_2layouts_2wrap-layout_2package_1json__JSONSchema="http://json.schemastore.org/package" />
|
||||
</VisualStudio>
|
||||
</ProjectExtensions>
|
||||
</Project>
|
||||
@@ -19,14 +19,30 @@ var sdkVersion = parseInt(platform.device.sdkVersion);
|
||||
|
||||
trace.enable();
|
||||
|
||||
export interface TestInfoEntry {
|
||||
testFunc: () => void;
|
||||
instance: Object;
|
||||
isTest: boolean;
|
||||
testName: string;
|
||||
isPassed: boolean;
|
||||
errorMessage: string;
|
||||
testTimeout: number;
|
||||
}
|
||||
|
||||
export var write = function write(message: string, type?: number) {
|
||||
//console.log(message);
|
||||
trace.write(message, trace.categories.Test, type);
|
||||
}
|
||||
|
||||
var runTest = function (testInfo) {
|
||||
var runTest = function (testInfo: TestInfoEntry) {
|
||||
try {
|
||||
testInfo.testFunc();
|
||||
if (testInfo.instance) {
|
||||
testInfo.testFunc.apply(testInfo.instance);
|
||||
}
|
||||
else {
|
||||
testInfo.testFunc();
|
||||
}
|
||||
|
||||
if (testInfo.isTest) {
|
||||
write("--- [" + testInfo.testName + "] OK", trace.messageType.info);
|
||||
testInfo.isPassed = true;
|
||||
@@ -54,11 +70,11 @@ export interface TestModuleRunResult {
|
||||
failed: Array<TestFailure>;
|
||||
}
|
||||
|
||||
var testsQueue;
|
||||
var testsQueue: Array<TestInfoEntry>;
|
||||
var defaultTimeout = 5000;
|
||||
|
||||
// testInfo : {testFunc: func, testName: string, isTest: boolean, isPassed: boolean, errorMessage: string}
|
||||
function runAsync(testInfo, recursiveIndex, testTimeout?) {
|
||||
function runAsync(testInfo: TestInfoEntry, recursiveIndex: number, testTimeout?: number) {
|
||||
var error;
|
||||
var isDone = false;
|
||||
var handle;
|
||||
@@ -104,22 +120,29 @@ function runAsync(testInfo, recursiveIndex, testTimeout?) {
|
||||
}
|
||||
}
|
||||
|
||||
testInfo.testFunc(doneCallback);
|
||||
if (testInfo.instance) {
|
||||
testInfo.testFunc.apply(testInfo.instance, [doneCallback]);
|
||||
}
|
||||
else {
|
||||
var func: any = testInfo.testFunc;
|
||||
func(doneCallback);
|
||||
}
|
||||
|
||||
setTimeout(checkFinished, 0);
|
||||
}
|
||||
|
||||
// tests : Array<{testFunc: func, testName: string, isTest: boolean, isPassed: boolean, errorMessage: string}>
|
||||
export var runTests = function (tests, recursiveIndex) {
|
||||
export var runTests = function (tests: Array<TestInfoEntry>, recursiveIndex) {
|
||||
testsQueue = tests;
|
||||
|
||||
var i;
|
||||
for (i = recursiveIndex; i < testsQueue.length; i++) {
|
||||
if (testsQueue[i].testFunc.length > 0) {
|
||||
return runAsync(testsQueue[i], i);
|
||||
var testEntry = testsQueue[i];
|
||||
if (testEntry.testFunc.length > 0) {
|
||||
return runAsync(testEntry, i);
|
||||
}
|
||||
else {
|
||||
runTest(testsQueue[i]);
|
||||
runTest(testEntry);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -170,6 +193,12 @@ export function assertEqual(actual: any, expected: any, message?: string) {
|
||||
}
|
||||
};
|
||||
|
||||
export function assertNull(actual: any, message?: string) {
|
||||
if (actual !== null && actual !== undefined) {
|
||||
throw new Error(message + " Actual: " + actual + " is not null/undefined");
|
||||
}
|
||||
};
|
||||
|
||||
export function assertAreClose(actual: number, expected: number, delta: number, message?: string) {
|
||||
if (isNaN(actual) || Math.abs(actual - expected) > delta) {
|
||||
throw new Error(message + " Numbers are not close enough. Actual: " + actual + " Expected: " + expected + " Delta: " + delta);
|
||||
|
||||
@@ -20,7 +20,7 @@ class MyTraceWriter implements trace.TraceWriter {
|
||||
|
||||
trace.addWriter(new MyTraceWriter());
|
||||
trace.enable();
|
||||
trace.setCategories(trace.categories.Test + "," + trace.categories.Error);
|
||||
trace.addCategories(trace.categories.Test + "," + trace.categories.Error);
|
||||
|
||||
var textView = new textViewModule.TextView();
|
||||
textView.editable = false;
|
||||
|
||||
@@ -4,7 +4,7 @@ import bm = require("ui/button");
|
||||
import listViewDef = require("ui/list-view");
|
||||
import trace = require("trace");
|
||||
trace.enable();
|
||||
trace.setCategories(trace.categories.Test + "," + trace.categories.Error);
|
||||
trace.addCategories(trace.categories.Test + "," + trace.categories.Error);
|
||||
|
||||
export function createPage() {
|
||||
var data: string[] = [""];
|
||||
|
||||
@@ -20,8 +20,8 @@ import dockModule = require("ui/layouts/dock-layout");
|
||||
// <Button dock="right" text = "right" style ="background-color: lightgreen; margin: 5;"/ >
|
||||
// <Button dock="bottom" text = "bottom" style ="background-color: lightpink; margin: 5;"/ >
|
||||
// <Button text="fill" style ="background-color: wheat; margin: 5;"/ >
|
||||
// < / DockLayout >
|
||||
//< / Page>
|
||||
// </DockLayout >
|
||||
//</Page>
|
||||
//```
|
||||
// </snippet>
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import TKUnit = require("./TKUnit");
|
||||
import trace = require("trace");
|
||||
import frameModule = require("ui/frame");
|
||||
import platform = require("platform");
|
||||
import uiTestModule = require("./ui-test");
|
||||
|
||||
frameModule.Frame.defaultAnimatedNavigation = false;
|
||||
|
||||
@@ -87,7 +88,28 @@ var testsWithLongDelay = {
|
||||
}
|
||||
|
||||
var running = false;
|
||||
var testsQueue = [];
|
||||
var testsQueue = new Array<TestInfo>();
|
||||
|
||||
function printRunTestStats() {
|
||||
var j;
|
||||
var testsCount = 0;
|
||||
var failedTestCount = 0;
|
||||
var failedTestInfo = [];
|
||||
for (j = 0; j < testsQueue.length; j++) {
|
||||
if (testsQueue[j].isTest) {
|
||||
testsCount++;
|
||||
if (!testsQueue[j].isPassed) {
|
||||
failedTestCount++;
|
||||
failedTestInfo.push(testsQueue[j].testName + " FAILED: " + testsQueue[j].errorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
TKUnit.write("=== ALL TESTS COMPLETE === " + (testsCount - failedTestCount) + " OK, " + failedTestCount + " failed", trace.messageType.info);
|
||||
for (j = 0; j < failedTestInfo.length; j++) {
|
||||
TKUnit.write(failedTestInfo[j], trace.messageType.error);
|
||||
}
|
||||
}
|
||||
|
||||
export var runAll = function (moduleName?: string) {
|
||||
if (running) {
|
||||
// TODO: We may schedule pending run requests
|
||||
@@ -109,25 +131,30 @@ export var runAll = function (moduleName?: string) {
|
||||
// }
|
||||
//};
|
||||
//testsQueue.push(new TestInfo(moduleStart(name)));
|
||||
if (testModule.setUpModule) {
|
||||
testsQueue.push(new TestInfo(testModule.setUpModule));
|
||||
|
||||
var test = testModule.createTestCase ? testModule.createTestCase() : testModule;
|
||||
|
||||
if (test.setUpModule) {
|
||||
testsQueue.push(new TestInfo(test.setUpModule, test));
|
||||
}
|
||||
for (var testName in testModule) {
|
||||
var testFunction = testModule[testName];
|
||||
|
||||
for (var testName in test) {
|
||||
var testFunction = test[testName];
|
||||
if ((typeof (testFunction) === "function") && (testName.substring(0, 4) == "test")) {
|
||||
if (testModule.setUp) {
|
||||
testsQueue.push(new TestInfo(testModule.setUp));
|
||||
if (test.setUp) {
|
||||
testsQueue.push(new TestInfo(test.setUp, test));
|
||||
}
|
||||
var testTimeout = testsWithLongDelay[testName];
|
||||
testsQueue.push(new TestInfo(testFunction, true, name + "." + testName, false, testTimeout));
|
||||
if (testModule.tearDown) {
|
||||
testsQueue.push(new TestInfo(testModule.tearDown));
|
||||
testsQueue.push(new TestInfo(testFunction, test, true, name + "." + testName, false, null, testTimeout));
|
||||
if (test.tearDown) {
|
||||
testsQueue.push(new TestInfo(test.tearDown, test));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (testModule.tearDownModule) {
|
||||
testsQueue.push(new TestInfo(testModule.tearDownModule));
|
||||
if (test.tearDownModule) {
|
||||
testsQueue.push(new TestInfo(test.tearDownModule, test));
|
||||
}
|
||||
|
||||
//var moduleEnd = function (moduleName) {
|
||||
// return function () {
|
||||
// TKUnit.write("--- " + moduleName + " TESTS COMPLETE --- ", trace.messageType.info);
|
||||
@@ -136,50 +163,26 @@ export var runAll = function (moduleName?: string) {
|
||||
//testsQueue.push(new TestInfo(moduleEnd(name)));
|
||||
}
|
||||
|
||||
var printRunTestStats = function () {
|
||||
var j;
|
||||
var testsCount = 0;
|
||||
var failedTestCount = 0;
|
||||
var failedTestInfo = [];
|
||||
for (j = 0; j < testsQueue.length; j++) {
|
||||
if (testsQueue[j].isTest) {
|
||||
testsCount++;
|
||||
if (!testsQueue[j].isPassed) {
|
||||
failedTestCount++;
|
||||
failedTestInfo.push(testsQueue[j].testName + " FAILED: " + testsQueue[j].errorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
TKUnit.write("=== ALL TESTS COMPLETE === " + (testsCount - failedTestCount) + " OK, " + failedTestCount + " failed", trace.messageType.info);
|
||||
for (j = 0; j < failedTestInfo.length; j++) {
|
||||
TKUnit.write(failedTestInfo[j], trace.messageType.error);
|
||||
}
|
||||
};
|
||||
|
||||
testsQueue.push(new TestInfo(printRunTestStats));
|
||||
testsQueue.push(new TestInfo(function () { testsQueue = []; running = false; }));
|
||||
|
||||
TKUnit.runTests(testsQueue, 0);
|
||||
}
|
||||
|
||||
interface TestInfoEntry {
|
||||
testFunc: any;
|
||||
isTest: boolean;
|
||||
testName: string;
|
||||
isPassed: boolean;
|
||||
errorMessage: string;
|
||||
}
|
||||
|
||||
class TestInfo implements TestInfoEntry {
|
||||
|
||||
class TestInfo implements TKUnit.TestInfoEntry {
|
||||
testFunc: () => void;
|
||||
instance: any;
|
||||
isTest: boolean;
|
||||
testName: string;
|
||||
isPassed: boolean;
|
||||
errorMessage: string;
|
||||
testTimeout: number;
|
||||
|
||||
constructor(testFunc, isTest?, testName?, isPassed?, errorMessage?, testTimeout?) {
|
||||
constructor(testFunc, testInstance?: any, isTest?, testName?, isPassed?, errorMessage?, testTimeout?) {
|
||||
this.testFunc = testFunc;
|
||||
this.instance = testInstance || null;
|
||||
this.isTest = isTest || false;
|
||||
this.testName = testName || "";
|
||||
this.isPassed = isPassed || false;
|
||||
|
||||
82
apps/tests/ui-test.ts
Normal file
82
apps/tests/ui-test.ts
Normal file
@@ -0,0 +1,82 @@
|
||||
import pageModule = require("ui/page");
|
||||
import navHelper = require("./ui/helper");
|
||||
import viewModule = require("ui/core/view");
|
||||
import trace = require("trace");
|
||||
import TKUnit = require("./TKUnit");
|
||||
|
||||
export class UITest<T extends viewModule.View> implements trace.TraceWriter {
|
||||
|
||||
private _testPage: pageModule.Page;
|
||||
private _testView: T;
|
||||
private _errorMessage;
|
||||
|
||||
public get errorMessage(): string {
|
||||
return this._errorMessage;
|
||||
}
|
||||
|
||||
public get testPage(): pageModule.Page {
|
||||
return this._testPage;
|
||||
}
|
||||
|
||||
public get testView(): T {
|
||||
return this._testView;
|
||||
}
|
||||
|
||||
public waitUntilTestElementIsLoaded(timeoutSec?: number): void {
|
||||
TKUnit.waitUntilReady(() => {
|
||||
return this.testView.isLoaded;
|
||||
}, timeoutSec || 1);
|
||||
}
|
||||
|
||||
public waitUntilTestElementLayoutIsValid(timeoutSec?: number): void {
|
||||
TKUnit.waitUntilReady(() => {
|
||||
return this.testView.isLayoutValid;
|
||||
}, timeoutSec || 1);
|
||||
}
|
||||
|
||||
public create(): T {
|
||||
throw new Error(this + " should implement Create method.");
|
||||
}
|
||||
|
||||
public setUpModule(): void {
|
||||
|
||||
var pageFactory = () => {
|
||||
var page = new pageModule.Page();
|
||||
this._testPage = page;
|
||||
return page;
|
||||
};
|
||||
|
||||
trace.addWriter(this);
|
||||
trace.enable();
|
||||
navHelper.navigate(pageFactory);
|
||||
}
|
||||
|
||||
public tearDownModule() {
|
||||
this._testPage = null;
|
||||
this._testView = null;
|
||||
trace.removeWriter(this);
|
||||
navHelper.goBack();
|
||||
}
|
||||
|
||||
public setUp() {
|
||||
this._testView = this.create();
|
||||
this._testPage.content = this._testView;
|
||||
}
|
||||
|
||||
public tearDown() {
|
||||
this._testPage.content = null;
|
||||
this._testPage.bindingContext = null;
|
||||
this._testPage.css = "";
|
||||
this._errorMessage = undefined;
|
||||
}
|
||||
|
||||
public write(message: any, category: string, type?: number): void {
|
||||
if (category === trace.categories.Error) {
|
||||
this._errorMessage = message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function createTestCase(): UITest<viewModule.View> {
|
||||
return null;
|
||||
}
|
||||
@@ -35,7 +35,7 @@ var imagePath = __dirname + "../../logo.png";
|
||||
|
||||
export var test_Image_Members = function () {
|
||||
var image = new ImageModule.Image();
|
||||
TKUnit.assert(types.isDefined(image.src), "Image.src is not defined");
|
||||
TKUnit.assert(types.isUndefined(image.src), "Image.src is defined");
|
||||
TKUnit.assert(types.isDefined(image.isLoading), "Image.isLoading is not defined");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import TKUnit = require("../../TKUnit");
|
||||
import testModule = require("../../ui-test");
|
||||
|
||||
// <snippet module="ui/label" title="Label">
|
||||
// # Label
|
||||
// Using a label requires the Label module.
|
||||
@@ -15,44 +17,30 @@ import LabelModule = require("ui/label");
|
||||
|
||||
// </snippet>
|
||||
import types = require("utils/types");
|
||||
import view = require("ui/core/view");
|
||||
import colorModule = require("color");
|
||||
import helper = require("../helper");
|
||||
import utils = require("utils/utils");
|
||||
import observableModule = require("data/observable");
|
||||
import bindable = require("ui/core/bindable");
|
||||
import page = require("ui/page");
|
||||
import textBase = require("ui/text-base");
|
||||
import enums = require("ui/enums");
|
||||
import labelTestsNative = require("./label-tests-native");
|
||||
import trace = require("trace");
|
||||
import fs = require("file-system");
|
||||
|
||||
var errorMessage;
|
||||
var errorTraceWriter = {
|
||||
write: function (message, category, messageType) {
|
||||
if (category === trace.categories.Error) {
|
||||
errorMessage = message;
|
||||
}
|
||||
}
|
||||
export class LabelTest extends testModule.UITest<LabelModule.Label> {
|
||||
|
||||
public create(): LabelModule.Label {
|
||||
var label = new LabelModule.Label();
|
||||
label.text = "Label";
|
||||
return label;
|
||||
}
|
||||
|
||||
export var setUp = function () {
|
||||
trace.addWriter(errorTraceWriter);
|
||||
}
|
||||
|
||||
export var tearDown = function () {
|
||||
trace.removeWriter(errorTraceWriter);
|
||||
errorMessage = undefined;
|
||||
}
|
||||
|
||||
export var test_Label_Members = function () {
|
||||
public test_Label_Members() {
|
||||
var label = new LabelModule.Label();
|
||||
TKUnit.assert(types.isDefined(label.text), "Label.text is not defined");
|
||||
TKUnit.assert(types.isDefined(label.textWrap), "Label.textWrap is not defined");
|
||||
}
|
||||
|
||||
export var test_Set_Text_TNS = function () {
|
||||
public snippet_Set_Text_TNS() {
|
||||
// <snippet module="ui/label" title="Label">
|
||||
// ### How to set label text content
|
||||
// ``` JavaScript
|
||||
@@ -61,75 +49,75 @@ export var test_Set_Text_TNS = function () {
|
||||
label.text = expectedValue;
|
||||
// ```
|
||||
// </snippet>
|
||||
|
||||
var actual = label._getValue(textBase.TextBase.textProperty);
|
||||
TKUnit.assert(actual === expectedValue, "The current value: " + actual + " is not equal the espectedValue: " + expectedValue);
|
||||
}
|
||||
|
||||
export var test_Set_Text_Native = function () {
|
||||
public snippet_Set_TextWrap_TNS() {
|
||||
// <snippet module="ui/label" title="Label">
|
||||
// ### How to turn on text wrapping for a label
|
||||
// ``` JavaScript
|
||||
var label = new LabelModule.Label();
|
||||
label.textWrap = true;
|
||||
// ```
|
||||
// </snippet>
|
||||
}
|
||||
|
||||
var test = function (views: Array<view.View>) {
|
||||
var testLabel = <LabelModule.Label>views[0];
|
||||
public test_Set_Text_TNS() {
|
||||
var label = this.testView;
|
||||
var expectedValue = "Expected Value";
|
||||
label.text = expectedValue;
|
||||
|
||||
var actual = label._getValue(textBase.TextBase.textProperty);
|
||||
TKUnit.assertEqual(actual, expectedValue, "Text not equal");
|
||||
}
|
||||
|
||||
public test_Set_Text_Native() {
|
||||
var testLabel = this.testView;
|
||||
var expectedValue = "Expected Value";
|
||||
|
||||
testLabel.text = expectedValue;
|
||||
var actualNative;
|
||||
if (testLabel.android) {
|
||||
actualNative = testLabel.android.getText();
|
||||
}
|
||||
else {
|
||||
if (testLabel.ios) {
|
||||
actualNative = testLabel.ios.text;
|
||||
}
|
||||
TKUnit.assert(actualNative === expectedValue, "Expected: " + expectedValue + ", Actual: " + actualNative);
|
||||
}
|
||||
else {
|
||||
this.waitUntilTestElementIsLoaded();
|
||||
actualNative = testLabel.android.getText();
|
||||
}
|
||||
|
||||
helper.buildUIAndRunTest(label, test);
|
||||
TKUnit.assertEqual(actualNative, expectedValue, "Native text not equal");
|
||||
}
|
||||
|
||||
export var test_measuredWidth_is_not_clipped = function () {
|
||||
var label = new LabelModule.Label();
|
||||
public test_measuredWidth_is_not_clipped() {
|
||||
var label = this.testView;
|
||||
label.horizontalAlignment = "left";
|
||||
label.text = "i";
|
||||
label.fontSize = 9;
|
||||
|
||||
if (label.ios) {
|
||||
|
||||
var test = function (views: Array<view.View>) {
|
||||
|
||||
TKUnit.waitUntilReady(() => { return label.isLayoutValid; });
|
||||
this.waitUntilTestElementLayoutIsValid();
|
||||
|
||||
var expectedValue = 3;
|
||||
var measuredWidth = label.getMeasuredWidth();
|
||||
TKUnit.assertEqual(measuredWidth, expectedValue, "measuredWidth should not be rounded down.");
|
||||
}
|
||||
|
||||
helper.buildUIAndRunTest(label, test);
|
||||
}
|
||||
}
|
||||
|
||||
export var test_Set_TextWrap_TNS = function () {
|
||||
// <snippet module="ui/label" title="Label">
|
||||
// ### How to turn on text wrapping for a label
|
||||
// ``` JavaScript
|
||||
var label = new LabelModule.Label();
|
||||
public test_Set_TextWrap_TNS() {
|
||||
var label = this.testView;
|
||||
label.textWrap = true;
|
||||
// ```
|
||||
// </snippet>
|
||||
|
||||
var actual = label._getValue(LabelModule.Label.textWrapProperty);
|
||||
TKUnit.assert(actual === true, "Expected: " + true + ", Actual: " + actual);
|
||||
TKUnit.assertEqual(actual, true);
|
||||
}
|
||||
|
||||
export var test_Set_TextWrap_Native = function () {
|
||||
var label = new LabelModule.Label();
|
||||
|
||||
var test = function (views: Array<view.View>) {
|
||||
var testLabel = <LabelModule.Label>views[0];
|
||||
|
||||
public test_Set_TextWrap_Native() {
|
||||
var testLabel = this.testView;
|
||||
testLabel.textWrap = true;
|
||||
this.waitUntilTestElementLayoutIsValid();
|
||||
|
||||
var expectedLineBreakMode;
|
||||
var expectedLinesNumber;
|
||||
var expectedLinesNumber = 1;
|
||||
var actualLineBreakMode;
|
||||
var actualLinesNumber;
|
||||
var actualEllipsize;
|
||||
@@ -141,36 +129,31 @@ export var test_Set_TextWrap_Native = function () {
|
||||
actualLinesNumber = testLabel.android.getLineCount();
|
||||
actualHorizontalScrolling = testLabel.android.canScrollHorizontally(-1) || testLabel.android.canScrollHorizontally(1);
|
||||
actualTransformationMethod = testLabel.android.getTransformationMethod();
|
||||
TKUnit.assert(actualEllipsize === null, "Expected: " + null + ", Actual: " + actualEllipsize);
|
||||
TKUnit.assert(actualLinesNumber === 0, "Expected: " + 0 + ", Actual: " + actualLinesNumber);
|
||||
TKUnit.assert(actualHorizontalScrolling === false, "Expected: " + false + ", Actual: " + actualHorizontalScrolling);
|
||||
TKUnit.assert(actualTransformationMethod === null, "Expected: " + null + ", Actual: " + actualTransformationMethod);
|
||||
TKUnit.assertNull(actualEllipsize);
|
||||
TKUnit.assertEqual(actualLinesNumber, expectedLinesNumber, "actualLinesNumber");
|
||||
TKUnit.assertEqual(actualHorizontalScrolling, false);
|
||||
TKUnit.assertNull(actualTransformationMethod);
|
||||
}
|
||||
else {
|
||||
expectedLineBreakMode = NSLineBreakMode.NSLineBreakByWordWrapping;
|
||||
expectedLinesNumber = 0;
|
||||
actualLineBreakMode = testLabel.ios.lineBreakMode;
|
||||
actualLinesNumber = testLabel.ios.numberOfLines;
|
||||
|
||||
TKUnit.assert(actualLineBreakMode === expectedLineBreakMode, "Expected: " + expectedLineBreakMode + ", Actual: " + actualLineBreakMode);
|
||||
TKUnit.assert(actualLinesNumber === expectedLinesNumber, "Expected: " + expectedLinesNumber + ", Actual: " + actualLinesNumber);
|
||||
TKUnit.assertEqual(actualLineBreakMode, expectedLineBreakMode);
|
||||
TKUnit.assertEqual(actualLinesNumber, expectedLinesNumber);
|
||||
}
|
||||
}
|
||||
|
||||
helper.buildUIAndRunTest(label, test);
|
||||
}
|
||||
|
||||
export var test_Set_TextWrapFirstTrueThenFalse_Native = function () {
|
||||
var label = new LabelModule.Label();
|
||||
|
||||
var test = function (views: Array<view.View>) {
|
||||
var testLabel = <LabelModule.Label>views[0];
|
||||
|
||||
public test_Set_TextWrapFirstTrueThenFalse_Native() {
|
||||
var testLabel = this.testView;
|
||||
testLabel.textWrap = true;
|
||||
label.textWrap = false;
|
||||
this.waitUntilTestElementLayoutIsValid();
|
||||
|
||||
testLabel.textWrap = false;
|
||||
this.waitUntilTestElementLayoutIsValid();
|
||||
|
||||
var expectedLineBreakMode;
|
||||
var expectedLinesNumber;
|
||||
var expectedLinesNumber = 1;
|
||||
var actualLineBreakMode;
|
||||
var actualLinesNumber;
|
||||
var actualEllipsize;
|
||||
@@ -182,27 +165,24 @@ export var test_Set_TextWrapFirstTrueThenFalse_Native = function () {
|
||||
actualLinesNumber = testLabel.android.getLineCount();
|
||||
actualHorizontalScrolling = testLabel.android.canScrollHorizontally(-1) || testLabel.android.canScrollHorizontally(1);
|
||||
actualTransformationMethod = testLabel.android.getTransformationMethod();
|
||||
TKUnit.assert(actualEllipsize === android.text.TextUtils.TruncateAt.END, "Expected: " + android.text.TextUtils.TruncateAt.END + ", Actual: " + actualEllipsize);
|
||||
TKUnit.assert(actualLinesNumber === 0, "Expected: " + 0 + ", Actual: " + actualLinesNumber);
|
||||
TKUnit.assert(actualHorizontalScrolling === false, "Expected: " + false + ", Actual: " + actualHorizontalScrolling);
|
||||
|
||||
TKUnit.assertEqual(actualEllipsize, android.text.TextUtils.TruncateAt.END, "Ellipsize");
|
||||
TKUnit.assertEqual(actualHorizontalScrolling, false, "HorizontalScrolling");
|
||||
TKUnit.assert(("" + actualTransformationMethod).indexOf("SingleLineTransformationMethod") > -1, "Expected: SingleLineTransformationMethod, Actual: " + actualTransformationMethod);
|
||||
}
|
||||
else {
|
||||
expectedLineBreakMode = NSLineBreakMode.NSLineBreakByTruncatingTail;
|
||||
expectedLinesNumber = 1;
|
||||
actualLineBreakMode = testLabel.ios.lineBreakMode;
|
||||
actualLinesNumber = testLabel.ios.numberOfLines;
|
||||
|
||||
TKUnit.assert(actualLineBreakMode === expectedLineBreakMode, "Expected: " + expectedLineBreakMode + ", Actual: " + actualLineBreakMode);
|
||||
TKUnit.assert(actualLinesNumber === expectedLinesNumber, "Expected: " + expectedLinesNumber + ", Actual: " + actualLinesNumber);
|
||||
TKUnit.assertEqual(actualLineBreakMode, expectedLineBreakMode, "LineBreakMode");
|
||||
}
|
||||
}
|
||||
|
||||
helper.buildUIAndRunTest(label, test);
|
||||
TKUnit.assertEqual(actualLinesNumber, expectedLinesNumber, "LinesNumber");
|
||||
}
|
||||
|
||||
export var test_SetStyleProperties_via_css_class_Native = function () {
|
||||
var label = new LabelModule.Label();
|
||||
public test_SetStyleProperties_via_css_class_Native() {
|
||||
var label = this.testView;
|
||||
|
||||
var fontSize = 14;
|
||||
var color = "#ffff0000";
|
||||
@@ -229,12 +209,14 @@ export var test_SetStyleProperties_via_css_class_Native = function () {
|
||||
var actualBackgroundColor;
|
||||
var expBackgroundColor;
|
||||
|
||||
var testFunc = function (views: Array<view.View>) {
|
||||
var testLabel = <LabelModule.Label>views[0];
|
||||
this.testPage.css = testCss;
|
||||
this.waitUntilTestElementIsLoaded();
|
||||
var testLabel = label;
|
||||
|
||||
if (testLabel.android) {
|
||||
actualTextSize = testLabel.android.getTextSize();
|
||||
expSize = android.util.TypedValue.applyDimension(android.util.TypedValue.COMPLEX_UNIT_DIP, fontSize, testLabel.android.getContext().getResources().getDisplayMetrics());
|
||||
var density = utils.layout.getDisplayDensity();
|
||||
expSize = fontSize * density;
|
||||
TKUnit.assertEqual(actualTextSize, expSize, "Wrong native FontSize");
|
||||
|
||||
actualColors = testLabel.android.getTextColors();
|
||||
@@ -244,7 +226,7 @@ export var test_SetStyleProperties_via_css_class_Native = function () {
|
||||
|
||||
actualBackgroundColor = (<android.graphics.drawable.ColorDrawable>testLabel.android.getBackground()).getColor();
|
||||
expBackgroundColor = android.graphics.Color.parseColor(backgroundColor);
|
||||
TKUnit.assert(actualBackgroundColor === expBackgroundColor, "Expected: " + expBackgroundColor + ", Actual: " + actualBackgroundColor);
|
||||
TKUnit.assertEqual(actualBackgroundColor, expBackgroundColor);
|
||||
}
|
||||
else {
|
||||
// iOS
|
||||
@@ -253,19 +235,16 @@ export var test_SetStyleProperties_via_css_class_Native = function () {
|
||||
|
||||
normalColor = utils.ios.getColor(testLabel.ios.textColor);
|
||||
expColor = new colorModule.Color(color);
|
||||
TKUnit.assert(normalColor.hex === expColor.hex, "Expected: " + expColor.hex + ", Actual: " + normalColor.hex);
|
||||
TKUnit.assertEqual(normalColor.hex, expColor.hex);
|
||||
|
||||
actualBackgroundColor = utils.ios.getColor(testLabel.ios.backgroundColor);
|
||||
expBackgroundColor = new colorModule.Color(backgroundColor);
|
||||
TKUnit.assert(actualBackgroundColor.hex === expBackgroundColor.hex, "Expected: " + expBackgroundColor.hex + ", Actual: " + actualBackgroundColor.hex);
|
||||
TKUnit.assertEqual(actualBackgroundColor.hex, expBackgroundColor.hex);
|
||||
}
|
||||
}
|
||||
|
||||
helper.buildUIAndRunTest(label, testFunc, testCss);
|
||||
}
|
||||
|
||||
export var test_SetStyleProperties_via_css_type_TNS = function () {
|
||||
var label = new LabelModule.Label();
|
||||
public test_SetStyleProperties_via_css_type_TNS() {
|
||||
var label = this.testView;
|
||||
var fontSize = 14;
|
||||
var color = "#10C2B0";
|
||||
var backgroundColor = "#C6C6C6";
|
||||
@@ -273,35 +252,32 @@ export var test_SetStyleProperties_via_css_type_TNS = function () {
|
||||
"color: ", color, "; ",
|
||||
"font-size: ", fontSize, ";}"].join("");
|
||||
|
||||
var testFunc = function (views: Array<view.View>) {
|
||||
var testLabel = <LabelModule.Label> views[0];
|
||||
this.testPage.css = testCss;
|
||||
this.waitUntilTestElementIsLoaded();
|
||||
|
||||
// <snippet module="ui/label" title="Label">
|
||||
// ### How to style a label via css type
|
||||
// ``` JavaScript
|
||||
testLabel.text = "The quick brown fox jumps over the lazy dog.";
|
||||
label.text = "The quick brown fox jumps over the lazy dog.";
|
||||
//// in order to style label with a "type style scope" just put a similar css entry
|
||||
//// testLabel.parentPage.css = "label {background-color: #C6C6C6; color: #10C2B0; font-size: 14;}";
|
||||
//// all labels within the parent page will be styled according to css values
|
||||
// ```
|
||||
// </snippet>
|
||||
var expectedBackgroundColor = new colorModule.Color(backgroundColor);
|
||||
var actualBackgroundColor = testLabel.style.backgroundColor;
|
||||
TKUnit.assert(expectedBackgroundColor.hex === actualBackgroundColor.hex, "Expected: " + expectedBackgroundColor.hex + ", Actual: " + actualBackgroundColor.hex);
|
||||
var actualBackgroundColor = label.style.backgroundColor;
|
||||
TKUnit.assertEqual(expectedBackgroundColor.hex, actualBackgroundColor.hex);
|
||||
|
||||
var expectedColor = new colorModule.Color(color);
|
||||
var actualColor = testLabel.style.color;
|
||||
TKUnit.assert(expectedColor.hex === actualColor.hex, "Expected: " + expectedColor.hex + ", Actual: " + actualColor.hex);
|
||||
var actualColor = label.style.color;
|
||||
TKUnit.assertEqual(expectedColor.hex, actualColor.hex);
|
||||
|
||||
var actualFontSize = testLabel.style.fontSize;
|
||||
TKUnit.assert(14 === actualFontSize, "Expected: " + fontSize + ", Actual: " + actualFontSize);
|
||||
var actualFontSize = label.style.fontSize;
|
||||
TKUnit.assertEqual(actualFontSize, 14);
|
||||
}
|
||||
|
||||
helper.buildUIAndRunTest(label, testFunc, testCss);
|
||||
}
|
||||
|
||||
export var test_SetStyleProperties_via_css_id = function () {
|
||||
var label = new LabelModule.Label();
|
||||
public test_SetStyleProperties_via_css_id() {
|
||||
var label = this.testView;
|
||||
var fontSize = 14;
|
||||
var color = "#10C2B0";
|
||||
var backgroundColor = "#C6C6C6";
|
||||
@@ -309,6 +285,9 @@ export var test_SetStyleProperties_via_css_id = function () {
|
||||
"color: ", color, "; ",
|
||||
"font-size: ", fontSize, ";}"].join("");
|
||||
|
||||
this.testPage.css = testCss;
|
||||
this.waitUntilTestElementIsLoaded();
|
||||
|
||||
// <snippet module="ui/label" title="Label">
|
||||
// ### How to style a label via css control identifier
|
||||
// ``` JavaScript
|
||||
@@ -319,25 +298,19 @@ export var test_SetStyleProperties_via_css_id = function () {
|
||||
// ```
|
||||
// </snippet>
|
||||
|
||||
var testFunc = function (views: Array<view.View>) {
|
||||
var testLabel = <LabelModule.Label> views[0];
|
||||
|
||||
var expectedBackgroundColor = new colorModule.Color(backgroundColor);
|
||||
var actualBackgroundColor = testLabel.style.backgroundColor;
|
||||
TKUnit.assert(expectedBackgroundColor.hex === actualBackgroundColor.hex, "Expected: " + expectedBackgroundColor.hex + ", Actual: " + actualBackgroundColor.hex);
|
||||
var actualBackgroundColor = label.style.backgroundColor;
|
||||
TKUnit.assertEqual(expectedBackgroundColor.hex, actualBackgroundColor.hex);
|
||||
|
||||
var expectedColor = new colorModule.Color(color);
|
||||
var actualColor = testLabel.style.color;
|
||||
TKUnit.assert(expectedColor.hex === actualColor.hex, "Expected: " + expectedColor.hex + ", Actual: " + actualColor.hex);
|
||||
var actualColor = label.style.color;
|
||||
TKUnit.assertEqual(expectedColor.hex, actualColor.hex);
|
||||
|
||||
var actualFontSize = testLabel.style.fontSize;
|
||||
TKUnit.assert(fontSize === actualFontSize, "Expected: " + fontSize + ", Actual: " + actualFontSize);
|
||||
}
|
||||
|
||||
helper.buildUIAndRunTest(label, testFunc, testCss);
|
||||
var actualFontSize = label.style.fontSize;
|
||||
TKUnit.assertEqual(fontSize, actualFontSize);
|
||||
}
|
||||
|
||||
export var test_BindingToText = function () {
|
||||
public test_BindingToText() {
|
||||
// <snippet module="ui/label" title="Label">
|
||||
// ### How to bind text property of a label to an observable model
|
||||
// ``` JavaScript
|
||||
@@ -354,14 +327,13 @@ export var test_BindingToText = function () {
|
||||
// ```
|
||||
// </snippet>
|
||||
|
||||
TKUnit.assert(label.text === expValue, "Expected: " + expValue + ", Actual: " + label.text);
|
||||
TKUnit.assertEqual(label.text, expValue);
|
||||
}
|
||||
|
||||
export var test_BindingToText_Native = function () {
|
||||
var label = new LabelModule.Label();
|
||||
public test_BindingToText_Native() {
|
||||
var label = this.testView;
|
||||
this.waitUntilTestElementIsLoaded();
|
||||
|
||||
var testFunc = function (views: Array<view.View>) {
|
||||
var testLabel = <LabelModule.Label> views[0];
|
||||
var expValue = "Expected Value";
|
||||
var sourceModel = new observableModule.Observable();
|
||||
var bindingOptions: bindable.BindingOptions = {
|
||||
@@ -369,185 +341,159 @@ export var test_BindingToText_Native = function () {
|
||||
targetProperty: "text"
|
||||
};
|
||||
sourceModel.set("sourceProperty", expValue);
|
||||
testLabel.bind(bindingOptions, sourceModel);
|
||||
label.bind(bindingOptions, sourceModel);
|
||||
|
||||
var actualNative;
|
||||
if (testLabel.android) {
|
||||
actualNative = testLabel.android.getText();
|
||||
if (label.android) {
|
||||
actualNative = label.android.getText();
|
||||
}
|
||||
else if (testLabel.ios) {
|
||||
actualNative = testLabel.ios.text;
|
||||
}
|
||||
TKUnit.assert(actualNative === expValue, "Expected: " + expValue + ", Actual: " + actualNative);
|
||||
else if (label.ios) {
|
||||
actualNative = label.ios.text;
|
||||
}
|
||||
|
||||
helper.buildUIAndRunTest(label, testFunc);
|
||||
TKUnit.assertEqual(actualNative, expValue);
|
||||
}
|
||||
|
||||
export var test_BindingToText_WithBindingContext = function () {
|
||||
var label = new LabelModule.Label();
|
||||
|
||||
var testFunc = function (views: Array<view.View>) {
|
||||
var testLabel = <LabelModule.Label> views[0];
|
||||
public test_BindingToText_WithBindingContext() {
|
||||
var label = this.testView;
|
||||
this.waitUntilTestElementIsLoaded();
|
||||
|
||||
var firstExpValue = "Expected Value";
|
||||
var bindingOptions: bindable.BindingOptions = {
|
||||
sourceProperty: "sourceProperty",
|
||||
targetProperty: "text"
|
||||
};
|
||||
testLabel.bind(bindingOptions);
|
||||
var parentPage = <page.Page>views[1];
|
||||
label.bind(bindingOptions);
|
||||
var firstSourceObject = new observableModule.Observable();
|
||||
firstSourceObject.set("sourceProperty", firstExpValue);
|
||||
|
||||
parentPage.bindingContext = firstSourceObject;
|
||||
TKUnit.assert(testLabel.text === firstExpValue, "Expected: " + firstExpValue + ", Actual: " + testLabel.text);
|
||||
this.testPage.bindingContext = firstSourceObject;
|
||||
TKUnit.assertEqual(label.text, firstExpValue);
|
||||
|
||||
var secondExpValue = "Second value";
|
||||
var secondSourceObject = new observableModule.Observable();
|
||||
secondSourceObject.set("sourceProperty", secondExpValue);
|
||||
parentPage.bindingContext = secondSourceObject;
|
||||
this.testPage.bindingContext = secondSourceObject;
|
||||
|
||||
TKUnit.assert(testLabel.text === secondExpValue, "Expected: " + secondExpValue + ", Actual: " + testLabel.text);
|
||||
}
|
||||
|
||||
helper.buildUIAndRunTest(label, testFunc);
|
||||
TKUnit.assertEqual(label.text, secondExpValue);
|
||||
}
|
||||
|
||||
export var test_BindingToText_BindingContext_SetingLocalValue = function () {
|
||||
var label = new LabelModule.Label();
|
||||
|
||||
var testFunc = function (views: Array<view.View>) {
|
||||
var testLabel = <LabelModule.Label> views[0];
|
||||
public test_BindingToText_BindingContext_SetingLocalValue() {
|
||||
var label = this.testView;
|
||||
this.waitUntilTestElementIsLoaded();
|
||||
|
||||
var firstExpValue = "Expected Value";
|
||||
var bindingOptions: bindable.BindingOptions = {
|
||||
sourceProperty: "sourceProperty",
|
||||
targetProperty: "text"
|
||||
};
|
||||
testLabel.bind(bindingOptions);
|
||||
var parentPage = <page.Page>views[1];
|
||||
label.bind(bindingOptions);
|
||||
var firstSourceObject = new observableModule.Observable();
|
||||
firstSourceObject.set("sourceProperty", firstExpValue);
|
||||
|
||||
parentPage.bindingContext = firstSourceObject;
|
||||
TKUnit.assert(testLabel.text === firstExpValue, "Expected: " + firstExpValue + ", Actual: " + testLabel.text);
|
||||
this.testPage.bindingContext = firstSourceObject;
|
||||
TKUnit.assertEqual(label.text, firstExpValue);
|
||||
|
||||
var secondExpValue = "Second value";
|
||||
testLabel.text = secondExpValue;
|
||||
TKUnit.assert(testLabel.text === secondExpValue, "Expected: " + secondExpValue + ", Actual: " + testLabel.text);
|
||||
label.text = secondExpValue;
|
||||
TKUnit.assertEqual(label.text, secondExpValue);
|
||||
|
||||
firstSourceObject.set("sourceProperty", "some value");
|
||||
// after setting a value one way binding should be gone.
|
||||
TKUnit.assert(testLabel.text === secondExpValue, "Expected: " + secondExpValue + ", Actual: " + testLabel.text);
|
||||
}
|
||||
|
||||
helper.buildUIAndRunTest(label, testFunc);
|
||||
TKUnit.assertEqual(label.text, secondExpValue);
|
||||
}
|
||||
|
||||
var _createLabelFunc = function (): LabelModule.Label {
|
||||
var label = new LabelModule.Label();
|
||||
label.text = "Label";
|
||||
return label;
|
||||
private expectedTextAlignment = enums.TextAlignment.right;
|
||||
public testLocalTextAlignmentFromCss() {
|
||||
var label = this.testView;
|
||||
this.testPage.css = "label { text-align: " + this.expectedTextAlignment + "; }";
|
||||
this.waitUntilTestElementIsLoaded();
|
||||
TKUnit.assertEqual(label.style.textAlignment, this.expectedTextAlignment);
|
||||
}
|
||||
|
||||
var expectedTextAlignment = enums.TextAlignment.right;
|
||||
export var testLocalTextAlignmentFromCss = function () {
|
||||
helper.buildUIAndRunTest(_createLabelFunc(), function (views: Array<view.View>) {
|
||||
var view = <LabelModule.Label>views[0];
|
||||
var page = <page.Page>views[1];
|
||||
page.css = "label { text-align: " + expectedTextAlignment + "; }";
|
||||
public testLocalTextAlignmentFromCssWhenAddingCss() {
|
||||
var view = this.testView;
|
||||
var page = this.testPage;
|
||||
this.waitUntilTestElementIsLoaded();
|
||||
page.addCss("label { text-align: " + this.expectedTextAlignment + "; }");
|
||||
|
||||
var actualResult = view.style.textAlignment;
|
||||
TKUnit.assert(actualResult === expectedTextAlignment, "Actual: " + actualResult + "; Expected: " + expectedTextAlignment);
|
||||
});
|
||||
}
|
||||
|
||||
export var testLocalTextAlignmentFromCssWhenAddingCss = function () {
|
||||
helper.buildUIAndRunTest(_createLabelFunc(), function (views: Array<view.View>) {
|
||||
var view = <LabelModule.Label>views[0];
|
||||
var page = <page.Page>views[1];
|
||||
page.addCss("label { text-align: " + expectedTextAlignment + "; }");
|
||||
|
||||
var actualResult = view.style.textAlignment;
|
||||
TKUnit.assert(actualResult === expectedTextAlignment, "Actual: " + actualResult + "; Expected: " + expectedTextAlignment);
|
||||
TKUnit.assertEqual(actualResult, this.expectedTextAlignment);
|
||||
|
||||
page.addCss("label { text-align: " + enums.TextAlignment.left + "; }");
|
||||
TKUnit.assert(view.style.textAlignment === view.style.textAlignment, "Actual: " + view.style.textAlignment + "; Expected: " + view.style.textAlignment);
|
||||
});
|
||||
TKUnit.assertEqual(view.style.textAlignment, view.style.textAlignment);
|
||||
}
|
||||
|
||||
export var testLocalTextAlignmentFromCssWhenAddingCssAllSelectorsAreApplied = function () {
|
||||
helper.buildUIAndRunTest(_createLabelFunc(), function (views: Array<view.View>) {
|
||||
var view = <LabelModule.Label>views[0];
|
||||
public testLocalTextAlignmentFromCssWhenAddingCssAllSelectorsAreApplied() {
|
||||
var view = this.testView;
|
||||
var page = this.testPage;
|
||||
this.waitUntilTestElementIsLoaded();
|
||||
|
||||
view.id = "testLabel";
|
||||
var page = <page.Page>views[1];
|
||||
page.addCss("#testLabel { text-align: " + expectedTextAlignment + "; }");
|
||||
page.addCss("#testLabel { text-align: " + this.expectedTextAlignment + "; }");
|
||||
page.addCss("label { text-align: " + enums.TextAlignment.left + "; }");
|
||||
|
||||
var actualResult = view.style.textAlignment;
|
||||
// actual result is taken from #testLabel tag, because it has a greater priority (id vs type).
|
||||
TKUnit.assert(actualResult === expectedTextAlignment, "Actual: " + actualResult + "; Expected: " + expectedTextAlignment);
|
||||
});
|
||||
TKUnit.assertEqual(actualResult, this.expectedTextAlignment);
|
||||
}
|
||||
|
||||
export var testLocalTextAlignmentFromCssWhenAddingCssFileAllSelectorsAreApplied = function () {
|
||||
helper.buildUIAndRunTest(_createLabelFunc(), function (views: Array<view.View>) {
|
||||
var view = <LabelModule.Label>views[0];
|
||||
public testLocalTextAlignmentFromCssWhenAddingCssFileAllSelectorsAreApplied() {
|
||||
var view = this.testView;
|
||||
var page = this.testPage;
|
||||
this.waitUntilTestElementIsLoaded();
|
||||
|
||||
view.id = "testLabel";
|
||||
var page = <page.Page>views[1];
|
||||
page.addCss("#testLabel { text-align: " + expectedTextAlignment + "; }");
|
||||
page.addCss("#testLabel { text-align: " + this.expectedTextAlignment + "; }");
|
||||
page.addCssFile(fs.path.join(__dirname, "label-tests.css"));
|
||||
|
||||
var actualResult = view.style.textAlignment;
|
||||
// actual result is taken from #testLabel tag, because it has a greater priority (id vs type).
|
||||
TKUnit.assert(actualResult === expectedTextAlignment, "Actual: " + actualResult + "; Expected: " + expectedTextAlignment);
|
||||
TKUnit.assert(view.style.backgroundColor.hex === "#FF0000", "Actual: " + view.style.backgroundColor.hex + "; Expected: #FF0000");
|
||||
});
|
||||
TKUnit.assertEqual(actualResult, this.expectedTextAlignment);
|
||||
TKUnit.assertEqual(view.style.backgroundColor.hex, "#FF0000");
|
||||
}
|
||||
|
||||
export var testNativeTextAlignmentFromCss = function () {
|
||||
helper.buildUIAndRunTest(_createLabelFunc(), function (views: Array<view.View>) {
|
||||
var view = <LabelModule.Label>views[0];
|
||||
var page = <page.Page>views[1];
|
||||
page.css = "label { text-align: " + expectedTextAlignment + "; }";
|
||||
public testNativeTextAlignmentFromCss() {
|
||||
var view = this.testView;
|
||||
var page = this.testPage;
|
||||
this.waitUntilTestElementIsLoaded();
|
||||
|
||||
page.css = "label { text-align: " + this.expectedTextAlignment + "; }";
|
||||
var actualResult = labelTestsNative.getNativeTextAlignment(view);
|
||||
TKUnit.assert(actualResult, this.expectedTextAlignment);
|
||||
}
|
||||
|
||||
public testNativeTextAlignmentFromLocal() {
|
||||
var view = this.testView;
|
||||
this.waitUntilTestElementIsLoaded();
|
||||
|
||||
view.style.textAlignment = this.expectedTextAlignment;
|
||||
|
||||
var actualResult = labelTestsNative.getNativeTextAlignment(view);
|
||||
TKUnit.assert(actualResult === expectedTextAlignment, "Actual: " + actualResult + "; Expected: " + expectedTextAlignment);
|
||||
});
|
||||
TKUnit.assertEqual(actualResult, this.expectedTextAlignment);
|
||||
}
|
||||
|
||||
export var testNativeTextAlignmentFromLocal = function () {
|
||||
helper.buildUIAndRunTest(_createLabelFunc(), function (views: Array<view.View>) {
|
||||
var view = <LabelModule.Label>views[0];
|
||||
view.style.textAlignment = expectedTextAlignment;
|
||||
public testErrorMessageWhenWrongCssIsAddedWithFile() {
|
||||
var view = this.testView;
|
||||
var page = this.testPage;
|
||||
this.waitUntilTestElementIsLoaded();
|
||||
|
||||
var actualResult = labelTestsNative.getNativeTextAlignment(view);
|
||||
TKUnit.assert(actualResult === expectedTextAlignment, "Actual: " + actualResult + "; Expected: " + expectedTextAlignment);
|
||||
});
|
||||
}
|
||||
|
||||
export var testErrorMessageWhenWrongCssIsAddedWithFile = function () {
|
||||
helper.buildUIAndRunTest(_createLabelFunc(), function (views: Array<view.View>) {
|
||||
var view = <LabelModule.Label>views[0];
|
||||
view.id = "testLabel";
|
||||
var page = <page.Page>views[1];
|
||||
errorMessage = undefined;
|
||||
page.addCssFile(fs.path.join(__dirname, "label-tests-wrong.css"));
|
||||
|
||||
TKUnit.assertNotEqual(errorMessage, undefined);
|
||||
});
|
||||
TKUnit.assertNotEqual(this.errorMessage, undefined);
|
||||
}
|
||||
|
||||
}
|
||||
public testErrorMessageWhenWrongCssIsAdded() {
|
||||
var view = this.testView;
|
||||
var page = this.testPage;
|
||||
this.waitUntilTestElementIsLoaded();
|
||||
|
||||
export var testErrorMessageWhenWrongCssIsAdded = function () {
|
||||
helper.buildUIAndRunTest(_createLabelFunc(), function (views: Array<view.View>) {
|
||||
var view = <LabelModule.Label>views[0];
|
||||
view.id = "testLabel";
|
||||
var page = <page.Page>views[1];
|
||||
errorMessage = undefined;
|
||||
page.addCss("label { < !--Test wrong comment-- > background-color: red; }");
|
||||
|
||||
TKUnit.assertNotEqual(errorMessage, undefined);
|
||||
});
|
||||
TKUnit.assertNotEqual(this.errorMessage, undefined);
|
||||
}
|
||||
}
|
||||
|
||||
export function createTestCase(): LabelTest {
|
||||
return new LabelTest();
|
||||
}
|
||||
|
||||
6
trace/trace.d.ts
vendored
6
trace/trace.d.ts
vendored
@@ -35,6 +35,12 @@ declare module "trace" {
|
||||
*/
|
||||
export function setCategories(categories: string);
|
||||
|
||||
/**
|
||||
* Adds categories to existing categories the module will trace.
|
||||
* @param categories The comma-separated list of categories. If not specified all messages from all categories will be traced.
|
||||
*/
|
||||
export function addCategories(categories: string);
|
||||
|
||||
/**
|
||||
* Writes a message using the available writers.
|
||||
* @param message The message to be written.
|
||||
|
||||
@@ -32,6 +32,11 @@ export function clearWriters() {
|
||||
}
|
||||
|
||||
export function setCategories(categories: string) {
|
||||
_categories = {};
|
||||
addCategories(categories);
|
||||
}
|
||||
|
||||
export function addCategories(categories: string) {
|
||||
var split = categories.split(",");
|
||||
_categories = {};
|
||||
|
||||
|
||||
@@ -126,18 +126,18 @@ export class Page extends contentView.ContentView implements dts.Page, view.AddA
|
||||
return;
|
||||
}
|
||||
|
||||
this._styleScope.ensureSelectors();
|
||||
this._styleScope.ensureSelectors();
|
||||
|
||||
var scope = this._styleScope;
|
||||
var checkSelectors = (view: view.View): boolean => {
|
||||
scope.applySelectors(view);
|
||||
return true;
|
||||
}
|
||||
var scope = this._styleScope;
|
||||
var checkSelectors = (view: view.View): boolean => {
|
||||
scope.applySelectors(view);
|
||||
return true;
|
||||
}
|
||||
|
||||
checkSelectors(this);
|
||||
view.eachDescendant(this, checkSelectors);
|
||||
checkSelectors(this);
|
||||
view.eachDescendant(this, checkSelectors);
|
||||
|
||||
this._cssApplied = true;
|
||||
this._cssApplied = true;
|
||||
}
|
||||
|
||||
private _resetCssValues() {
|
||||
@@ -251,7 +251,7 @@ export class MenuItem extends bindable.Bindable implements dts.MenuItem {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
get android(): dts.AndroidMenuItemOptions {
|
||||
return this._android;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user