mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
* Remove Bindable. Fix Observable & ObservableArray tests Fix formattedString text Change implementation of Span, FormattedString & TextBase properties valueChange called before native setter * revetred formattedString tests asserts - formattedText update text property again properties - when getting value we now use always property name instead of key (using key could return undefined for property that is set to its default value) updated fontSize & fontInternal properties on all controls fix font properties so that fontInternal is reset if the new font is the same as Font.default * fix tslint errors
79 lines
3.0 KiB
TypeScript
79 lines
3.0 KiB
TypeScript
// >> formatted-string-require
|
|
import { FormattedString } from "text/formatted-string";
|
|
import { Span } from "text/span";
|
|
// << formatted-string-require
|
|
|
|
import { Observable } from "data/observable";
|
|
import { Label } from "ui/label";
|
|
import * as TKUnit from "../TKUnit";
|
|
|
|
export function test_FormattedString_RemovesEventListeners_for_spans() {
|
|
// >> formatted-string-set
|
|
const label = new Label();
|
|
const formattedString = new FormattedString();
|
|
const firstSpan = new Span();
|
|
|
|
firstSpan.fontSize = 15;
|
|
firstSpan.text = "LoremIpsum";
|
|
formattedString.spans.push(firstSpan);
|
|
label.formattedText = formattedString;
|
|
// << formatted-string-set
|
|
|
|
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 function test_FormattedTextProperty_IsChanged_When_SpanIsAdded() {
|
|
const formattedString = new FormattedString();
|
|
let formattedTextChanged = false;
|
|
formattedString.addEventListener(Observable.propertyChangeEvent, () => {
|
|
formattedTextChanged = true;
|
|
});
|
|
|
|
const firstSpan = new Span();
|
|
firstSpan.fontSize = 15;
|
|
firstSpan.text = "LoremIpsum";
|
|
formattedString.spans.push(firstSpan);
|
|
|
|
TKUnit.assertTrue(formattedTextChanged, "FormattedText property is not changed.");
|
|
};
|
|
|
|
export function test_FormattedTextProperty_IsChanged_When_SpanIsChanged() {
|
|
const formattedString = new FormattedString();
|
|
const expectedValue = 17;
|
|
|
|
const firstSpan = new Span();
|
|
firstSpan.fontSize = 15;
|
|
firstSpan.text = "LoremIpsum";
|
|
formattedString.spans.push(firstSpan);
|
|
|
|
let formattedTextChanged = false;
|
|
formattedString.addEventListener(Observable.propertyChangeEvent, () => {
|
|
formattedTextChanged = true;
|
|
});
|
|
|
|
firstSpan.fontSize = expectedValue;
|
|
|
|
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 function test_FormattedTextProperty_DoNotCrash_When_KnownColorIsSetForForegroundColor() {
|
|
const formattedString = new FormattedString();
|
|
const expectedValue1 = "red";
|
|
const expectedValue2 = "blue";
|
|
|
|
const firstSpan = new Span();
|
|
firstSpan.color = <any>expectedValue1;
|
|
firstSpan.text = "LoremIpsum1";
|
|
formattedString.spans.push(firstSpan);
|
|
|
|
const secondSpan = new Span();
|
|
secondSpan.backgroundColor = <any>expectedValue2;
|
|
secondSpan.text = "LoremIpsum2";
|
|
formattedString.spans.push(secondSpan);
|
|
|
|
TKUnit.assertEqual(formattedString.spans.getItem(0).color.name, expectedValue1);
|
|
TKUnit.assertEqual(formattedString.spans.getItem(1).backgroundColor.name, expectedValue2);
|
|
}; |