expressions + formatted string tests

This commit is contained in:
vakrilov
2016-12-21 16:36:58 +02:00
parent 8a4e6c4ba0
commit 291d36dba6
3 changed files with 42 additions and 42 deletions

View File

@ -45,9 +45,9 @@ allTests["COLOR"] = require("./color-tests");
allTests["DEPENDENCY-OBSERVABLE"] = require("./ui/dependency-observable-tests");
// allTests["BINDABLE"] = require("./ui/bindable-tests");
// allTests["BINDING-EXPRESSIONS"] = require("./ui/binding-expressions-tests");
allTests["BINDING-EXPRESSIONS"] = require("./ui/binding-expressions-tests");
allTests["XML-PARSER"] = require("./xml-parser-tests/xml-parser-tests");
// allTests["FORMATTEDSTRING"] = require("./text/formatted-string-tests");
allTests["FORMATTEDSTRING"] = require("./text/formatted-string-tests");
allTests["FILE-SYSTEM-ACCESS"] = require("./file-system-access-tests/file-system-access-tests");
allTests["FILE-NAME-RESOLVER"] = require("./file-name-resolver-tests/file-name-resolver-tests");
allTests["WEAK-EVENTS"] = require("./weak-event-listener-tests");

View File

@ -1,17 +1,17 @@
// >> formatted-string-require
import * as formattedStringModule from "text/formatted-string";
import * as spanModule from "text/span";
import { FormattedString } from "text/formatted-string";
import { Span } from "text/span";
// << formatted-string-require
import * as observable from "data/observable";
import { Observable } from "data/observable";
import { Label } from "ui/label";
import * as TKUnit from "../TKUnit";
import * as LabelModule from "ui/label";
export var test_FormattedString_RemovesEventListeners_for_spans = function () {
export function test_FormattedString_RemovesEventListeners_for_spans() {
// >> formatted-string-set
var label = new LabelModule.Label();
var formattedString = new formattedStringModule.FormattedString();
var firstSpan = new spanModule.Span();
const label = new Label();
const formattedString = new FormattedString();
const firstSpan = new Span();
firstSpan.fontSize = 15;
firstSpan.text = "LoremIpsum";
@ -19,37 +19,37 @@ export var test_FormattedString_RemovesEventListeners_for_spans = function () {
label.formattedText = formattedString;
// << formatted-string-set
TKUnit.assert(formattedString.spans.getItem(0).hasListeners(observable.Observable.propertyChangeEvent) === true, "Listener for spans collection change event is not attached!");
var removedSpan = formattedString.spans.pop();
TKUnit.assert(removedSpan.hasListeners(observable.Observable.propertyChangeEvent) === false, "Listener for spans collection change event is not removed!");
}
TKUnit.assert(formattedString.spans.getItem(0).hasListeners(Observable.propertyChangeEvent) === true, "Listener for spans collection change event is not attached!");
const removedSpan = formattedString.spans.pop();
TKUnit.assert(removedSpan.hasListeners(Observable.propertyChangeEvent) === false, "Listener for spans collection change event is not removed!");
};
export var test_FormattedTextProperty_IsChanged_When_SpanIsAdded = function () {
var formattedString = new formattedStringModule.FormattedString();
var formattedTextChanged = false;
formattedString.addEventListener(observable.Observable.propertyChangeEvent, () => {
export function test_FormattedTextProperty_IsChanged_When_SpanIsAdded() {
const formattedString = new FormattedString();
let formattedTextChanged = false;
formattedString.addEventListener(Observable.propertyChangeEvent, () => {
formattedTextChanged = true;
});
var firstSpan = new spanModule.Span();
const firstSpan = new Span();
firstSpan.fontSize = 15;
firstSpan.text = "LoremIpsum";
formattedString.spans.push(firstSpan);
TKUnit.assertTrue(formattedTextChanged, "FormattedText property is not changed.");
}
};
export var test_FormattedTextProperty_IsChanged_When_SpanIsChanged = function () {
var formattedString = new formattedStringModule.FormattedString();
var expectedValue = 17;
export function test_FormattedTextProperty_IsChanged_When_SpanIsChanged() {
const formattedString = new FormattedString();
const expectedValue = 17;
var firstSpan = new spanModule.Span();
const firstSpan = new Span();
firstSpan.fontSize = 15;
firstSpan.text = "LoremIpsum";
formattedString.spans.push(firstSpan);
var formattedTextChanged = false;
formattedString.addEventListener(observable.Observable.propertyChangeEvent, () => {
let formattedTextChanged = false;
formattedString.addEventListener(Observable.propertyChangeEvent, () => {
formattedTextChanged = true;
});
@ -59,23 +59,23 @@ export var test_FormattedTextProperty_IsChanged_When_SpanIsChanged = function ()
TKUnit.assertTrue(formattedTextChanged, "FormattedText property is not changed.");
TKUnit.assert(formattedString.spans.getItem(0).fontSize === expectedValue, "FormattedString internal span is not changed as expected");
}
};
export var test_FormattedTextProperty_DoNotCrash_When_KnownColorIsSetForForegroundColor = function () {
var formattedString = new formattedStringModule.FormattedString();
var expectedValue1 = "red";
var expectedValue2 = "blue";
export function test_FormattedTextProperty_DoNotCrash_When_KnownColorIsSetForForegroundColor() {
const formattedString = new FormattedString();
const expectedValue1 = "red";
const expectedValue2 = "blue";
var firstSpan = new spanModule.Span();
const firstSpan = new Span();
firstSpan.foregroundColor = <any>expectedValue1;
firstSpan.text = "LoremIpsum1";
formattedString.spans.push(firstSpan);
var secondSpan = new spanModule.Span();
const secondSpan = new Span();
secondSpan.backgroundColor = <any>expectedValue2;
secondSpan.text = "LoremIpsum2";
formattedString.spans.push(secondSpan);
TKUnit.assertEqual(formattedString.spans.getItem(0).foregroundColor.name, expectedValue1);
TKUnit.assertEqual(formattedString.spans.getItem(1).backgroundColor.name, expectedValue2);
}
};

View File

@ -20,25 +20,25 @@ enum FixedSize {
const zeroLength: Length = {
value: 0,
unit: "px"
}
};
export class Label extends TextBase implements LabelDefinition {
private _ios: TNSLabel;
public nativeView: TNSLabel;
private _fixedSize: FixedSize;
constructor() {
super();
this._ios = TNSLabel.new();
this._ios.userInteractionEnabled = true;
this.nativeView = TNSLabel.new();
this.nativeView.userInteractionEnabled = true;
}
get ios(): TNSLabel {
return this._ios;
return this.nativeView;
}
get _nativeView(): TNSLabel {
return this._ios;
return this.nativeView;
}
get textWrap(): boolean {
@ -106,7 +106,7 @@ export class Label extends TextBase implements LabelDefinition {
}
set [whiteSpaceProperty.native](value: WhiteSpace) {
let nativeView = this.nativeView;
switch(value){
switch (value) {
case WhiteSpace.NORMAL:
nativeView.lineBreakMode = NSLineBreakMode.ByWordWrapping;
nativeView.numberOfLines = 0;