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["DEPENDENCY-OBSERVABLE"] = require("./ui/dependency-observable-tests");
// allTests["BINDABLE"] = require("./ui/bindable-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["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-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["FILE-NAME-RESOLVER"] = require("./file-name-resolver-tests/file-name-resolver-tests");
allTests["WEAK-EVENTS"] = require("./weak-event-listener-tests"); allTests["WEAK-EVENTS"] = require("./weak-event-listener-tests");

View File

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

View File

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