Skip to content

Commit b2cf286

Browse files
PanayotCankovPanayot Cankov
authored andcommitted
Fixed text decoration tests, Color will now store just a single argb info in 32bit unsigned int internally and covert to a/r/g/b or hex when necessary
1 parent ccde2a4 commit b2cf286

16 files changed

Lines changed: 321 additions & 351 deletions

File tree

.vscode/settings.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Place your settings in this file to overwrite default and user settings.
2+
{
3+
"search.exclude": {
4+
"**/node_modules": true,
5+
"**/bower_components": true,
6+
"**/platforms": true,
7+
"**/*.js": true,
8+
"**/*.js.map": true
9+
}
10+
}

apps/app/ui-tests-app/css/letter-spacing.xml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55
<Label text="labelLabel" style="letter-spacing: -0.1;" />
66
<Label text="labelLabel" style="letter-spacing: 0;" />
77
<Label text="labelLabel" style="letter-spacing: 0.1;" />
8+
<Label>
9+
<Span text="just bold" fontWeight="bold" />
10+
</Label>
811
</WrapLayout>
912
<Label text="labelLabel" style="text-transform: uppercase; text-decoration: underline line-through;letter-spacing: 0.1;" />
1013
<Label style="text-transform: uppercase; text-decoration: underline line-through;letter-spacing: 0.1;">
1114
<Label.formattedText>
1215
<FormattedString>
1316
<FormattedString.spans>
14-
<Span text="label" fontAttributes="Bold" foregroundColor="#0000ff" />
15-
<Span text="Label" fontAttributes="Italic" foregroundColor="#00ff00" />
17+
<Span text="label" fontWeight="bold" color="#0000ff" />
18+
<Span text="Label" fontStyle="italic" color="#00ff00" />
1619
</FormattedString.spans>
1720
</FormattedString>
1821
</Label.formattedText>
@@ -28,8 +31,8 @@
2831
<Button.formattedText>
2932
<FormattedString>
3033
<FormattedString.spans>
31-
<Span text="button" fontAttributes="Bold" foregroundColor="#0000ff" />
32-
<Span text="Button" fontAttributes="Italic" foregroundColor="#00ff00" />
34+
<Span text="button" fontWeight="bold" color="#0000ff" />
35+
<Span text="Button" fontStyle="italic" color="#00ff00" />
3336
</FormattedString.spans>
3437
</FormattedString>
3538
</Button.formattedText>
@@ -46,8 +49,8 @@
4649
<TextField.formattedText>
4750
<FormattedString>
4851
<FormattedString.spans>
49-
<Span text="text" fontAttributes="Bold" foregroundColor="#0000ff" />
50-
<Span text="Field" fontAttributes="Italic" foregroundColor="#00ff00" />
52+
<Span text="text" fontWeight="bold" color="#0000ff" />
53+
<Span text="Field" fontStyle="italic" color="#00ff00" />
5154
</FormattedString.spans>
5255
</FormattedString>
5356
</TextField.formattedText>
@@ -64,8 +67,8 @@
6467
<TextView.formattedText>
6568
<FormattedString>
6669
<FormattedString.spans>
67-
<Span text="text" fontAttributes="Bold" foregroundColor="#0000ff" />
68-
<Span text="View" fontAttributes="Italic" foregroundColor="#00ff00" />
70+
<Span text="text" fontWeight="bold" color="#0000ff" />
71+
<Span text="View" fontStyle="italic" color="#00ff00" />
6972
</FormattedString.spans>
7073
</FormattedString>
7174
</TextView.formattedText>

apps/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"version": "2.5.0"
1010
},
1111
"tns-android": {
12-
"version": "2.4.1"
12+
"version": "2.5.0"
1313
}
1414
},
1515
"dependencies": {

tests/app/color-tests.ts

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export var test_Hex_Color = function () {
1414
TKUnit.assertEqual(color.g, 0, "Color.g not properly parsed");
1515
TKUnit.assertEqual(color.b, 0, "Color.b not properly parsed");
1616
TKUnit.assertEqual(color.hex, "#FF0000", "Color.hex not properly parsed");
17-
TKUnit.assertEqual(color.argb, _parseArgb(255, 255, 0, 0), "Color.argb not properly parsed");
17+
TKUnit.assertEqual(color.argb, 0xFFFF0000, "Color.argb not properly parsed");
1818
}
1919

2020
export var test_ShortHex_Color = function () {
@@ -27,7 +27,7 @@ export var test_ShortHex_Color = function () {
2727
TKUnit.assertEqual(color.g, 136, "Color.g not properly parsed"); // 0x88 == 136
2828
TKUnit.assertEqual(color.b, 0, "Color.b not properly parsed");
2929
TKUnit.assertEqual(color.hex, "#FF8800", "Color.hex not properly parsed");
30-
TKUnit.assertEqual(color.argb, _parseArgb(255, 255, 136, 0), "Color.argb not properly parsed");
30+
TKUnit.assertEqual(color.argb, 0xFFFF8800, "Color.argb not properly parsed");
3131
}
3232

3333
export var test_Argb_Color = function () {
@@ -39,22 +39,21 @@ export var test_Argb_Color = function () {
3939
TKUnit.assertEqual(color.r, 255, "Color.r not properly parsed");
4040
TKUnit.assertEqual(color.g, 100, "Color.g not properly parsed");
4141
TKUnit.assertEqual(color.b, 100, "Color.b not properly parsed");
42-
TKUnit.assertEqual(color.hex, _buildHex(100, 255, 100, 100), "Color.hex not properly parsed");
43-
TKUnit.assertEqual(color.argb, _parseArgb(100, 255, 100, 100), "Color.argb not properly parsed");
42+
TKUnit.assertEqual(color.hex, "#64FF6464", "Color.hex not properly parsed");
43+
TKUnit.assertEqual(color.argb, 0x64FF6464, "Color.argb not properly parsed");
4444
}
4545

4646
export var test_ArgbInt_Color = function () {
4747
// >> color-rgb-single
4848
// Creates the color with 100 alpha, 100 red, 100 green, 100 blue
49-
var argb = (100 << 24) | (100 << 16) | (100 << 8) | 100;
50-
var color = new Color(argb);
49+
var color = new Color(0x64646464);
5150
// << color-rgb-single
5251
TKUnit.assertEqual(color.a, 100, "Color.a not properly parsed");
5352
TKUnit.assertEqual(color.r, 100, "Color.r not properly parsed");
5453
TKUnit.assertEqual(color.g, 100, "Color.g not properly parsed");
5554
TKUnit.assertEqual(color.b, 100, "Color.b not properly parsed");
56-
TKUnit.assertEqual(color.hex, _buildHex(100, 100, 100, 100), "Color.hex not properly parsed");
57-
TKUnit.assertEqual(color.argb, _parseArgb(100, 100, 100, 100), "Color.argb not properly parsed");
55+
TKUnit.assertEqual(color.hex, "#64646464", "Color.hex not properly parsed");
56+
TKUnit.assertEqual(color.argb, 0x64646464, "Color.argb not properly parsed");
5857
}
5958

6059
export var test_rgb_Color_CSS = function () {
@@ -69,13 +68,13 @@ export var test_rgb_Color_CSS = function () {
6968
TKUnit.assertEqual(color.r, 255, "Color.r not properly parsed");
7069
TKUnit.assertEqual(color.g, 100, "Color.g not properly parsed");
7170
TKUnit.assertEqual(color.b, 100, "Color.b not properly parsed");
72-
TKUnit.assertEqual(color.hex, _buildHex(255, 255, 100, 100), "Color.hex not properly parsed");
73-
TKUnit.assertEqual(color.argb, _parseArgb(255, 255, 100, 100), "Color.argb not properly parsed");
71+
TKUnit.assertEqual(color.hex, "#FF6464", "Color.hex not properly parsed");
72+
TKUnit.assertEqual(color.argb, 0xFFFF6464, "Color.argb not properly parsed");
7473
}
7574

7675
export var test_rgba_Color_CSS = function () {
7776
var alpha = 0.5;
78-
var expected = Math.round(alpha * 255);
77+
var expected = 0x80;
7978
// <snippet module="color" title="color">
8079
// ### Creating a Color from four RGB values
8180
// ``` JavaScript
@@ -87,24 +86,6 @@ export var test_rgba_Color_CSS = function () {
8786
TKUnit.assertEqual(color.r, 255, "Color.r not properly parsed");
8887
TKUnit.assertEqual(color.g, 100, "Color.g not properly parsed");
8988
TKUnit.assertEqual(color.b, 100, "Color.b not properly parsed");
90-
TKUnit.assertEqual(color.hex, _buildHex(expected, 255, 100, 100), "Color.hex not properly parsed");
91-
TKUnit.assertEqual(color.argb, _parseArgb(expected, 255, 100, 100), "Color.argb not properly parsed");
92-
}
93-
94-
var _buildHex = function (a: number, r: number, g: number, b: number): string {
95-
return "#" + _componentToHex(a) + _componentToHex(r) + _componentToHex(g) + _componentToHex(b);
96-
}
97-
98-
var _componentToHex = function (component: number): string {
99-
var hex = component.toString(16);
100-
if (hex.length === 1) {
101-
hex = "0" + hex;
102-
}
103-
104-
return hex;
105-
}
106-
107-
var _parseArgb = function (a: number, r: number, g: number, b: number): number {
108-
// Format is ARGB, so alpha takes the first 8 bits, red the next, green the next and the last 8 bits are for the blue component
109-
return (a << 24) | (r << 16) | (g << 8) | b;
89+
TKUnit.assertEqual(color.hex, "#80FF6464", "Color.hex not properly parsed");
90+
TKUnit.assertEqual(color.argb, 0x80FF6464, "Color.argb not properly parsed");
11091
}

tests/app/timer-tests.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,17 @@ export function test_setTimeout_callbackCalledAfterSpecifiedTime() {
5252

5353
TKUnit.waitUntilReady(() => completed, 1);
5454
timer.clearTimeout(id);
55-
TKUnit.assert(completed, "Callback should be called after specified time!");
55+
TKUnit.assert(completed, "Callback should be called after the specified time!");
5656
};
5757

5858
export function test_setTimeout_callbackNotCalled() {
5959
let completed = false;
60-
const id = timer.setTimeout(() => completed = true, 50);
6160

62-
TKUnit.wait(0.007);
61+
const id = timer.setTimeout(() => completed = true, 10);
6362
timer.clearTimeout(id);
64-
TKUnit.assert(!completed, "Callback should be called after specified time!");
63+
TKUnit.wait(30 / 1000);
64+
65+
TKUnit.assert(!completed, "Callback should not be called after the specified time!");
6566
};
6667

6768
export function test_setTimeout_shouldReturnNumber() {

tests/app/ui/button/button-tests.ts

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -180,58 +180,60 @@ var _testNativeFontSizeFromLocal = function (views: Array<viewModule.View>) {
180180
helper.assertAreClose(actualResult, expectedFontSize, "FontSizeFromLocal");
181181
}
182182

183-
var expectedColorHex = "#ffff0000";
183+
var actualColorHex = "#ffff0000";
184+
var expectedNormalizedColorHex = "#FF0000"
184185
var _testLocalColorFromCss = function (views: Array<viewModule.View>) {
185186
var button = <buttonModule.Button>views[0];
186187
var page = <pagesModule.Page>views[1];
187-
page.css = "button { color: " + expectedColorHex + "; }";
188+
page.css = "button { color: " + actualColorHex + "; }";
188189

189190
var actualResult = button.style.color.hex;
190-
TKUnit.assert(actualResult === expectedColorHex, "Actual: " + actualResult + "; Expected: " + expectedColorHex);
191+
TKUnit.assert(actualResult === expectedNormalizedColorHex, "Actual: " + actualResult + "; Expected: " + expectedNormalizedColorHex);
191192
}
192193

193194
var _testNativeColorFromCss = function (views: Array<viewModule.View>) {
194195
var button = <buttonModule.Button>views[0];
195196
var page = <pagesModule.Page>views[1];
196-
page.css = "button { color: " + expectedColorHex + "; }";
197+
page.css = "button { color: " + actualColorHex + "; }";
197198

198199
var actualResult = buttonTestsNative.getNativeColor(button).hex;
199-
TKUnit.assert(actualResult === expectedColorHex, "Actual: " + actualResult + "; Expected: " + expectedColorHex);
200+
TKUnit.assert(actualResult === expectedNormalizedColorHex, "Actual: " + actualResult + "; Expected: " + expectedNormalizedColorHex);
200201
}
201202

202203
var _testNativeColorFromLocal = function (views: Array<viewModule.View>) {
203204
var button = <buttonModule.Button>views[0];
204-
button.style.color = new colorModule.Color(expectedColorHex);
205+
button.style.color = new colorModule.Color(actualColorHex);
205206

206207
var actualResult = buttonTestsNative.getNativeColor(button).hex;
207-
TKUnit.assert(actualResult === expectedColorHex, "Actual: " + actualResult + "; Expected: " + expectedColorHex);
208+
TKUnit.assert(actualResult === expectedNormalizedColorHex, "Actual: " + actualResult + "; Expected: " + expectedNormalizedColorHex);
208209
}
209210

210-
var expectedBackgroundColorHex = "#ff00ff00";
211+
var actualBackgroundColorHex = "#FF00FF00";
212+
var expectedNormalizedBackgroundColorHex = "#00FF00";
211213
var _testLocalBackgroundColorFromCss = function (views: Array<viewModule.View>) {
212214
var button = <buttonModule.Button>views[0];
213215
var page = <pagesModule.Page>views[1];
214-
page.css = "button { background-color: " + expectedBackgroundColorHex + "; }";
216+
page.css = "button { background-color: " + actualBackgroundColorHex + "; }";
215217

216218
var actualResult = button.style.backgroundColor.hex;
217-
TKUnit.assert(actualResult === expectedBackgroundColorHex, "Actual: " + actualResult + "; Expected: " + expectedBackgroundColorHex);
219+
TKUnit.assert(actualResult === expectedNormalizedBackgroundColorHex, "Actual: " + actualResult + "; Expected: " + expectedNormalizedBackgroundColorHex);
218220
}
219221

220222
var _testNativeBackgroundColorFromCss = function (views: Array<viewModule.View>) {
221223
var button = <buttonModule.Button>views[0];
222224
var page = <pagesModule.Page>views[1];
223-
page.css = "button { background-color: " + expectedBackgroundColorHex + "; }";
225+
page.css = "button { background-color: " + actualBackgroundColorHex + "; }";
224226

225227
var actualResult = buttonTestsNative.getNativeBackgroundColor(button).hex;
226-
TKUnit.assert(actualResult === expectedBackgroundColorHex, "Actual: " + actualResult + "; Expected: " + expectedBackgroundColorHex);
228+
TKUnit.assert(actualResult === expectedNormalizedBackgroundColorHex, "Actual: " + actualResult + "; Expected: " + expectedNormalizedBackgroundColorHex);
227229
}
228230

229231
var _testNativeBackgroundColorFromLocal = function (views: Array<viewModule.View>) {
230232
var button = <buttonModule.Button>views[0];
231-
button.style.backgroundColor = new colorModule.Color(expectedBackgroundColorHex);
233+
button.style.backgroundColor = new colorModule.Color(actualBackgroundColorHex);
232234

233235
var actualResult = buttonTestsNative.getNativeBackgroundColor(button).hex;
234-
TKUnit.assert(actualResult === expectedBackgroundColorHex, "Actual: " + actualResult + "; Expected: " + expectedBackgroundColorHex);
236+
TKUnit.assert(actualResult === expectedNormalizedBackgroundColorHex, "Actual: " + actualResult + "; Expected: " + expectedNormalizedBackgroundColorHex);
235237
}
236238

237239
var expectedTextAlignment: "right" = "right";
@@ -261,41 +263,44 @@ export var test_StateHighlighted_also_fires_pressedState = function () {
261263
helper.buildUIAndRunTest(_createButtonFunc(), function (views: Array<viewModule.View>) {
262264
var view = <buttonModule.Button>views[0];
263265
var page = <pagesModule.Page>views[1];
264-
var expectedColor = "#ffff0000";
266+
var expectedColor = "#FFFF0000";
267+
var expectedNormalizedColor = "#FF0000";
265268
page.css = "button:pressed { background-color: " + expectedColor + "; }";
266269

267270
view._goToVisualState('highlighted');
268271

269272
var actualResult = buttonTestsNative.getNativeBackgroundColor(view);
270-
TKUnit.assert(actualResult.hex === expectedColor, "Actual: " + actualResult.hex + "; Expected: " + expectedColor);
273+
TKUnit.assert(actualResult.hex === expectedNormalizedColor, "Actual: " + actualResult.hex + "; Expected: " + expectedNormalizedColor);
271274
});
272275
}
273276

274277
export var test_StateHighlighted_also_fires_activeState = function () {
275278
helper.buildUIAndRunTest(_createButtonFunc(), function (views: Array<viewModule.View>) {
276279
var view = <buttonModule.Button>views[0];
277280
var page = <pagesModule.Page>views[1];
278-
var expectedColor = "#ffff0000";
281+
var expectedColor = "#FFFF0000";
282+
var expectedNormalizedColor = "#FF0000";
279283
page.css = "button:active { background-color: " + expectedColor + "; }";
280284

281285
view._goToVisualState('highlighted');
282286

283287
var actualResult = buttonTestsNative.getNativeBackgroundColor(view);
284-
TKUnit.assert(actualResult.hex === expectedColor, "Actual: " + actualResult.hex + "; Expected: " + expectedColor);
288+
TKUnit.assert(actualResult.hex === expectedNormalizedColor, "Actual: " + actualResult.hex + "; Expected: " + expectedNormalizedColor);
285289
});
286290
}
287291

288292
export var test_applying_disabled_visual_State_when_button_is_disable = function () {
289293
helper.buildUIAndRunTest(_createButtonFunc(), function (views: Array<viewModule.View>) {
290294
var view = <buttonModule.Button>views[0];
291295
var page = <pagesModule.Page>views[1];
292-
var expectedColor = "#ffff0000";
296+
var expectedColor = "#FFFF0000";
297+
var expectedNormalizedColor = "#FF0000";
293298
page.css = "button:disabled { background-color: " + expectedColor + "; }";
294299

295300
view.isEnabled = false;
296301

297302
var actualResult = buttonTestsNative.getNativeBackgroundColor(view);
298-
TKUnit.assert(actualResult.hex === expectedColor, "Actual: " + actualResult.hex + "; Expected: " + expectedColor);
303+
TKUnit.assert(actualResult.hex === expectedNormalizedColor, "Actual: " + actualResult.hex + "; Expected: " + expectedNormalizedColor);
299304
});
300305
}
301306

tests/app/ui/label/label-tests.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ export class LabelTest extends testModule.UITest<LabelModule.Label> {
193193
const label = this.testView;
194194

195195
const fontSize = 14;
196-
const color = "#ffff0000";
197-
const backgroundColor = "#ff00ff00";
196+
const color = "#FFFF0000";
197+
const backgroundColor = "#FF00FF00";
198198
const testCss = [".title {background-color: ", backgroundColor, "; ",
199199
"color: ", color, "; ",
200200
"font-size: ", fontSize, ";}"].join("");
@@ -471,14 +471,15 @@ export class LabelTest extends testModule.UITest<LabelModule.Label> {
471471
let view = this.testView;
472472
let page = this.testPage;
473473
this.waitUntilTestElementIsLoaded();
474-
let expectedColor = "#ffff0000";
474+
let expectedColor = "#FFFF0000";
475+
let expectedNormalizedColor = "#FF0000";
475476

476477
page.css = "label:disabled { background-color: " + expectedColor + "; }";
477478

478479
view.isEnabled = false;
479480

480481
let actualResult = labelTestsNative.getNativeBackgroundColor(view);
481-
TKUnit.assert(actualResult.hex === expectedColor, "Actual: " + actualResult.hex + "; Expected: " + expectedColor);
482+
TKUnit.assert(actualResult.hex === expectedNormalizedColor, "Actual: " + actualResult.hex + "; Expected: " + expectedNormalizedColor);
482483
};
483484

484485
public test_IntegrationTest_Transform_Decoration_Spacing_WithoutFormattedText_DoesNotCrash() {

0 commit comments

Comments
 (0)