Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
import { ApplicationSettings as appSettings } from '@nativescript/core';
import * as TKUnit from '../tk-unit';

var stringKey: string = 'stringKey';
var boolKey: string = 'boolKey';
var numberKey: string = 'numberKey';
var noStringKey: string = 'noStringKey';
var noBoolKey: string = 'noBoolKey';
var noNumberKey: string = 'noNumberKey';

export var testBoolean = function () {
const stringKey: string = 'stringKey';
const boolKey: string = 'boolKey';
const numberKey: string = 'numberKey';
const noStringKey: string = 'noStringKey';
const noBoolKey: string = 'noBoolKey';
const noNumberKey: string = 'noNumberKey';

export const testBoolean = function () {
appSettings.setBoolean(boolKey, false);
var boolValueBefore = appSettings.getBoolean(boolKey);
const boolValueBefore = appSettings.getBoolean(boolKey);
TKUnit.assert(false === boolValueBefore, 'Cannot set boolean to false, currently it is: ' + appSettings.getBoolean(boolKey));

appSettings.setBoolean('boolKey', true);
var boolValue = appSettings.getBoolean('boolKey', false);
const boolValue = appSettings.getBoolean('boolKey', false);

TKUnit.assert(true === boolValue, 'Cannot set boolean to true');

TKUnit.assert(true === appSettings.getBoolean(boolKey), 'Cannot set boolean to true (no default)');
};

export var testString = function () {
export const testString = function () {
appSettings.setString('stringKey', 'String value');
var stringValue = appSettings.getString('stringKey');
const stringValue = appSettings.getString('stringKey');

TKUnit.assert('String value' === stringValue, 'Cannot set string value');
};

export var testNumber = function () {
export const testNumber = function () {
appSettings.setNumber('numberKey', 54.321);
var value = parseFloat(appSettings.getNumber('numberKey').toFixed(3));
const value = parseFloat(appSettings.getNumber('numberKey').toFixed(3));

TKUnit.assert(54.321 === value, 'Cannot set number value 54.321 != ' + value);
};

export var testDefaults = function () {
var defaultValue = appSettings.getString('noStringKey', 'No string value');
export const testDefaults = function () {
const defaultValue = appSettings.getString('noStringKey', 'No string value');
// will return "No string value" if there is no value for "noStringKey"

TKUnit.assert('No string value' === defaultValue, 'Bad default string value');
TKUnit.assert(true === appSettings.getBoolean(noBoolKey, true), 'Bad default boolean value');
TKUnit.assert(123.45 === appSettings.getNumber(noNumberKey, 123.45), 'Bad default number value');
};

export var testDefaultsWithNoDefaultValueProvided = function () {
var defaultValue = appSettings.getString('noStringKey');
export const testDefaultsWithNoDefaultValueProvided = function () {
const defaultValue = appSettings.getString('noStringKey');
// will return undefined if there is no value for "noStringKey"

TKUnit.assertEqual(defaultValue, undefined, 'Default string value is not undefined');
Expand All @@ -54,8 +54,8 @@ export var testDefaultsWithNoDefaultValueProvided = function () {
TKUnit.assertEqual(appSettings.getNumber(noNumberKey), undefined, 'Default number value is not undefined');
};

export var testHasKey = function () {
var hasKey = appSettings.hasKey('noBoolKey');
export const testHasKey = function () {
const hasKey = appSettings.hasKey('noBoolKey');
// will return false if there is no value for "noBoolKey"

TKUnit.assert(!hasKey, 'There is a key: ' + noBoolKey);
Expand All @@ -67,7 +67,7 @@ export var testHasKey = function () {
TKUnit.assert(!appSettings.hasKey(numberKey), 'There is no key: ' + numberKey);
};

export var testRemove = function () {
export const testRemove = function () {
appSettings.remove('boolKey');

TKUnit.assert(!appSettings.hasKey(boolKey), 'Failed to remove key: ' + boolKey);
Expand All @@ -79,36 +79,36 @@ export var testRemove = function () {
TKUnit.assert(!appSettings.hasKey(numberKey), 'Failed to remove key: ' + numberKey);
};

export var testClear = function () {
export const testClear = function () {
appSettings.clear();

TKUnit.assert(!appSettings.hasKey(boolKey), 'Failed to remove key: ' + boolKey);
TKUnit.assert(!appSettings.hasKey(stringKey), 'Failed to remove key: ' + stringKey);
TKUnit.assert(!appSettings.hasKey(numberKey), 'Failed to remove key: ' + numberKey);
};

export var testFlush = function () {
export const testFlush = function () {
appSettings.setString(stringKey, 'String value');

var flushed = appSettings.flush();
const flushed = appSettings.flush();
// will return boolean indicating whether flush to disk was successful

TKUnit.assert(flushed, 'Flush failed: ' + flushed);
TKUnit.assert(appSettings.hasKey(stringKey), 'There is no key: ' + stringKey);
};

export var testAllKeys = function () {
export const testAllKeys = function () {
appSettings.setString(stringKey, 'String value');
appSettings.setBoolean(boolKey, true);
appSettings.setNumber(numberKey, 22);

var allKeys = appSettings.getAllKeys();
const allKeys = appSettings.getAllKeys();
TKUnit.assert(allKeys.indexOf(stringKey) !== -1, `${stringKey} is missing from .allKeys()`);
TKUnit.assert(allKeys.indexOf(boolKey) !== -1, `${boolKey} is missing from .allKeys()`);
TKUnit.assert(allKeys.indexOf(numberKey) !== -1, `${numberKey} is missing from .allKeys()`);
};

export var testInvalidKey = function () {
export const testInvalidKey = function () {
try {
appSettings.hasKey(undefined);
TKUnit.assert(false, 'There is a key undefined');
Expand All @@ -134,7 +134,7 @@ export var testInvalidKey = function () {
appSettings.hasKey('string');
};

export var testInvalidValue = function () {
export const testInvalidValue = function () {
try {
// @ts-ignore
appSettings.setBoolean(boolKey, 'str');
Expand Down
6 changes: 3 additions & 3 deletions apps/automated/src/application/application-tests.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import * as TKUnit from '../tk-unit';
export * from './application-tests-common';

// >> application-app-android
let androidApp = Application.android;
const androidApp = Application.android;
// << application-app-android

// >> application-app-android-context
let context = Application.android.context;
const context = Application.android.context;
//// get the Files (Documents) folder (directory)
let dir = context.getFilesDir();
const dir = context.getFilesDir();
// << application-app-android-context

// >> application-app-android-current
Expand Down
7 changes: 4 additions & 3 deletions apps/automated/src/application/application-tests.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ export * from './application-tests-common';

// >> application-ios-observer
//// Add the notification observer
let observer;
if (Application.ios) {
var observer = Application.ios.addNotificationObserver(UIDeviceBatteryLevelDidChangeNotification, function onReceiveCallback(notification: NSNotification) {
var percent = UIDevice.currentDevice.batteryLevel * 100;
var message = 'Battery: ' + percent + '%';
observer = Application.ios.addNotificationObserver(UIDeviceBatteryLevelDidChangeNotification, function onReceiveCallback(notification: NSNotification) {
const percent = UIDevice.currentDevice.batteryLevel * 100;
const message = 'Battery: ' + percent + '%';
////console.log(message);
});
}
Expand Down
50 changes: 25 additions & 25 deletions apps/automated/src/color/color-tests-common.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// >> color-require
import * as colorModule from '@nativescript/core/color';
var Color = colorModule.Color;
const Color = colorModule.Color;
// << color-require
import * as TKUnit from '../tk-unit';

export var test_Hex_Color = function () {
export const test_Hex_Color = function () {
// >> color-hex
// Creates the red color
var color = new Color('#FF0000');
const color = new Color('#FF0000');
// << color-hex
TKUnit.assertEqual(color.a, 255, 'Color.a not properly parsed');
TKUnit.assertEqual(color.r, 255, 'Color.r not properly parsed');
Expand All @@ -17,10 +17,10 @@ export var test_Hex_Color = function () {
TKUnit.assertEqual(color.argb, 0xffff0000, 'Color.argb not properly parsed');
};

export var test_Hex_rgba_Color = function () {
export const test_Hex_rgba_Color = function () {
// >> color-hex-rgba
// Creates the red color
var color = new Color('#FF0000FF');
const color = new Color('#FF0000FF');
// << color-hex-rgba
TKUnit.assertEqual(color.a, 255, 'Color.a not properly parsed');
TKUnit.assertEqual(color.r, 255, 'Color.r not properly parsed');
Expand All @@ -30,10 +30,10 @@ export var test_Hex_rgba_Color = function () {
TKUnit.assertEqual(color.argb, 0xffff0000, 'Color.argb not properly parsed');
};

export var test_ShortHex_Color = function () {
export const test_ShortHex_Color = function () {
// >> color-hex-short
// Creates the color #FF8800
var color = new Color('#F80');
const color = new Color('#F80');
// << color-hex-short
TKUnit.assertEqual(color.a, 255, 'Color.a not properly parsed');
TKUnit.assertEqual(color.r, 255, 'Color.r not properly parsed');
Expand All @@ -43,10 +43,10 @@ export var test_ShortHex_Color = function () {
TKUnit.assertEqual(color.argb, 0xffff8800, 'Color.argb not properly parsed');
};

export var test_ShortHex_rgba_Color = function () {
export const test_ShortHex_rgba_Color = function () {
// >> color-hex-short-rgba
// Creates the color #FF8800
var color = new Color('#F80F');
const color = new Color('#F80F');
// << color-hex-short-rgba
TKUnit.assertEqual(color.a, 255, 'Color.a not properly parsed');
TKUnit.assertEqual(color.r, 255, 'Color.r not properly parsed');
Expand All @@ -56,10 +56,10 @@ export var test_ShortHex_rgba_Color = function () {
TKUnit.assertEqual(color.argb, 0xffff8800, 'Color.argb not properly parsed');
};

export var test_Argb_Color = function () {
export const test_Argb_Color = function () {
// >> color-rgb
// Creates the color with 100 alpha, 255 red, 100 green, 100 blue
var color = new Color(100, 255, 100, 100);
const color = new Color(100, 255, 100, 100);
// << color-rgb
TKUnit.assertEqual(color.a, 100, 'Color.a not properly parsed');
TKUnit.assertEqual(color.r, 255, 'Color.r not properly parsed');
Expand All @@ -69,10 +69,10 @@ export var test_Argb_Color = function () {
TKUnit.assertEqual(color.argb, 0x64ff6464, 'Color.argb not properly parsed');
};

export var test_ArgbInt_Color = function () {
export const test_ArgbInt_Color = function () {
// >> color-rgb-single
// Creates the color with 100 alpha, 100 red, 100 green, 100 blue
var color = new Color(0x64646464);
const color = new Color(0x64646464);
// << color-rgb-single
TKUnit.assertEqual(color.a, 100, 'Color.a not properly parsed');
TKUnit.assertEqual(color.r, 100, 'Color.r not properly parsed');
Expand All @@ -82,12 +82,12 @@ export var test_ArgbInt_Color = function () {
TKUnit.assertEqual(color.argb, 0x64646464, 'Color.argb not properly parsed');
};

export var test_rgb_Color_CSS = function () {
export const test_rgb_Color_CSS = function () {
// <snippet module="color" title="color">
// ### Creating a Color from four RGB values
// ``` JavaScript
// Creates the color with 255 red, 100 green, 100 blue
var color = new Color('rgb(255, 100, 100)');
const color = new Color('rgb(255, 100, 100)');
// ```
// </snippet>
TKUnit.assertEqual(color.a, 255, 'Color.a not properly parsed');
Expand All @@ -98,14 +98,14 @@ export var test_rgb_Color_CSS = function () {
TKUnit.assertEqual(color.argb, 0xffff6464, 'Color.argb not properly parsed');
};

export var test_rgb_Color_CSS_lvl4 = function () {
var alpha = 0.5;
var expected = 0x80;
export const test_rgb_Color_CSS_lvl4 = function () {
const alpha = 0.5;
const expected = 0x80;
// <snippet module="color" title="color">
// ### Creating a Color from four RGB values
// ``` JavaScript
// Creates the color with 255 red, 100 green, 100 blue
var color = new Color(`rgb(255 100 100 / ${alpha})`);
const color = new Color(`rgb(255 100 100 / ${alpha})`);
// ```
// </snippet>
TKUnit.assertEqual(color.a, expected, 'Color.a not properly parsed');
Expand All @@ -116,14 +116,14 @@ export var test_rgb_Color_CSS_lvl4 = function () {
TKUnit.assertEqual(color.argb, 0x80ff6464, 'Color.argb not properly parsed');
};

export var test_rgba_Color_CSS = function () {
var alpha = 0.5;
var expected = 0x80;
export const test_rgba_Color_CSS = function () {
const alpha = 0.5;
const expected = 0x80;
// <snippet module="color" title="color">
// ### Creating a Color from four RGB values
// ``` JavaScript
// Creates the color with 255 red, 100 green, 100 blue and 0 alpha
var color = new Color(`rgba(255, 100, 100, ${alpha})`);
const color = new Color(`rgba(255, 100, 100, ${alpha})`);
// ```
// </snippet>
TKUnit.assertEqual(color.a, expected, 'Color.a not properly parsed');
Expand All @@ -134,8 +134,8 @@ export var test_rgba_Color_CSS = function () {
TKUnit.assertEqual(color.argb, 0x80ff6464, 'Color.argb not properly parsed');
};

export var test_Color_isValid = function () {
var color = new Color('#FF0000');
export const test_Color_isValid = function () {
const color = new Color('#FF0000');

TKUnit.assertEqual(Color.isValid(color), true, 'Failed to validate color instance');
TKUnit.assertEqual(Color.isValid('#FFF'), true, 'Failed to validate 3-digit hex color');
Expand Down
6 changes: 3 additions & 3 deletions apps/automated/src/connectivity/connectivity-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import * as connectivity from '@nativescript/core/connectivity';
// << connectivity-require

export var test_DummyTestForSnippetOnly0 = function () {
export const test_DummyTestForSnippetOnly0 = function () {
// >> connectivity-type
var connectionType = connectivity.getConnectionType();
const connectionType = connectivity.getConnectionType();
switch (connectionType) {
case connectivity.connectionType.none:
//console.log("No connection");
Expand All @@ -19,7 +19,7 @@ export var test_DummyTestForSnippetOnly0 = function () {
// << connectivity-type
};

export var test_DummyTestForSnippetOnly1 = function () {
export const test_DummyTestForSnippetOnly1 = function () {
// >> connectivity-monitoring
connectivity.startMonitoring(function onConnectionTypeChanged(newConnectionType: number) {
switch (newConnectionType) {
Expand Down
12 changes: 6 additions & 6 deletions apps/automated/src/console/console-tests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export var test_DummyTestForSnippetOnly0 = function () {
export const test_DummyTestForSnippetOnly0 = function () {
// >> console-log
console.log('Hello, world!');
console.info('I am NativeScript');
Expand All @@ -7,7 +7,7 @@ export var test_DummyTestForSnippetOnly0 = function () {
// << console-log
};

export var test_DummyTestForSnippetOnly1 = function () {
export const test_DummyTestForSnippetOnly1 = function () {
// >> console-time
console.time('LoadTime');
// << console-time
Expand All @@ -16,20 +16,20 @@ export var test_DummyTestForSnippetOnly1 = function () {
// << console-timeend
};

export var test_DummyTestForSnippetOnly2 = function () {
export const test_DummyTestForSnippetOnly2 = function () {
// >> console-assert
console.assert(2 === 2, '2 equals 2');
// << console-assert
};

export var test_DummyTestForSnippetOnly3 = function () {
export const test_DummyTestForSnippetOnly3 = function () {
// >> console-dir
var obj = { name: 'John', age: 34 };
const obj = { name: 'John', age: 34 };
console.dir(obj);
// << console-dir
};

export var test_DummyTestForSnippetOnly5 = function () {
export const test_DummyTestForSnippetOnly5 = function () {
// >> console-trace
console.trace();
// << console-trace
Expand Down
Loading
Loading