From fc01f8e79f7b0484c8fc85549f42e3bf430f99e3 Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Wed, 10 May 2023 22:08:01 +0200 Subject: [PATCH] refactor: Application modules to classes --- .prettierrc.json | 10 +- apps/automated/package.json | 1 + .../application/application-tests-common.ts | 9 +- .../application/application-tests.android.ts | 48 +- .../src/file-system/file-system-tests.ts | 117 ++- .../src/image-source/image-source-tests.ts | 46 +- apps/automated/src/livesync/livesync-tests.ts | 143 ++- apps/automated/src/main.ts | 285 +++++- apps/automated/src/pages/page5.ts | 49 +- apps/automated/src/test-runner.ts | 92 +- .../src/ui/core/bindable/bindable-tests.ts | 477 +++++++-- apps/automated/src/ui/image/image-tests.ts | 106 +- .../src/ui/list-picker/list-picker-tests.ts | 129 ++- .../src/ui/root-view/reset-root-view-tests.ts | 72 +- .../src/ui/tab-view/tab-view-root-tests.ts | 130 ++- .../src/ui/view/view-tests-common.ts | 349 +++++-- apps/automated/webpack.config.js | 20 +- .../accessibility/accessibility-css-helper.ts | 39 +- .../accessibility-service.android.ts | 132 ++- .../accessibility-service.ios.ts | 38 +- .../core/accessibility/font-scale.android.ts | 7 +- packages/core/accessibility/font-scale.ios.ts | 18 +- packages/core/accessibility/index.android.ts | 369 +++++-- packages/core/accessibility/index.ios.ts | 115 ++- .../application-settings/index.android.ts | 7 +- .../core/application/application-common.ts | 549 ++++++---- .../application/application-interfaces.ts | 167 ++- packages/core/application/index.android.ts | 949 ++++++++---------- packages/core/application/index.d.ts | 682 +------------ packages/core/application/index.ios.ts | 864 ++++++++-------- packages/core/connectivity/index.android.ts | 39 +- .../file-system/file-system-access.android.ts | 172 +++- packages/core/file-system/index.ts | 102 +- packages/core/image-source/index.android.ts | 104 +- packages/core/index.d.ts | 75 +- packages/core/index.ts | 74 +- packages/core/module-name-resolver/index.ts | 31 +- .../non-bundle-workflow-compat.ts | 40 +- packages/core/platform/index.android.ts | 40 +- packages/core/tsconfig.lib.json | 10 +- packages/core/ui/action-bar/index.android.ts | 116 ++- packages/core/ui/core/view/index.android.ts | 401 ++++++-- packages/core/ui/dialogs/index.ios.ts | 154 ++- packages/core/ui/frame/activity.android.ts | 46 +- packages/core/ui/frame/index.android.ts | 451 +++++++-- .../core/ui/styling/background.android.ts | 66 +- packages/core/ui/styling/style-scope.ts | 292 ++++-- packages/core/ui/tab-view/index.android.ts | 149 ++- packages/core/utils/android/index.ts | 40 +- tsconfig.base.json | 2 +- 50 files changed, 5438 insertions(+), 2985 deletions(-) diff --git a/.prettierrc.json b/.prettierrc.json index 098f6bab3..958685113 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -1,6 +1,6 @@ { - "useTabs": true, - "printWidth": 600, - "tabWidth": 2, - "singleQuote": true -} \ No newline at end of file + "useTabs": true, + "printWidth": 90, + "tabWidth": 2, + "singleQuote": true +} diff --git a/apps/automated/package.json b/apps/automated/package.json index 0de8f239a..9ed1314a9 100644 --- a/apps/automated/package.json +++ b/apps/automated/package.json @@ -14,6 +14,7 @@ "@nativescript/android": "~8.5.0", "@nativescript/ios": "~8.5.0", "@nativescript/webpack": "file:../../dist/packages/nativescript-webpack.tgz", + "circular-dependency-plugin": "^5.2.2", "typescript": "~4.9.5" }, "gitHead": "c06800e52ee1a184ea2dffd12a6702aaa43be4e3", diff --git a/apps/automated/src/application/application-tests-common.ts b/apps/automated/src/application/application-tests-common.ts index dba7f33ff..440ecb35e 100644 --- a/apps/automated/src/application/application-tests-common.ts +++ b/apps/automated/src/application/application-tests-common.ts @@ -1,5 +1,4 @@ -import * as app from '@nativescript/core/application'; -import { isAndroid, isIOS, Device, Application, platformNames } from '@nativescript/core'; +import { isAndroid, isIOS, Device, Application, platformNames } from '@nativescript/core'; import * as TKUnit from '../tk-unit'; @@ -11,9 +10,9 @@ if (isAndroid) { export function testInitialized() { if (Device.os === platformNames.android) { - TKUnit.assert(app.android, 'Application module not properly intialized'); + TKUnit.assert(Application.android, 'Application module not properly intialized'); } else if (Device.os === platformNames.ios) { - TKUnit.assert(app.ios, 'Application module not properly intialized'); + TKUnit.assert(Application.ios, 'Application module not properly intialized'); } } @@ -23,5 +22,5 @@ export function testDisplayedEvent() { } export function testOrientation() { - TKUnit.assert(Application.orientation(), 'Orientation not initialized.'); + TKUnit.assert(Application.orientation, 'Orientation not initialized.'); } diff --git a/apps/automated/src/application/application-tests.android.ts b/apps/automated/src/application/application-tests.android.ts index 80f899652..7e5d803a2 100644 --- a/apps/automated/src/application/application-tests.android.ts +++ b/apps/automated/src/application/application-tests.android.ts @@ -23,31 +23,55 @@ if (androidApp.foregroundActivity === androidApp.startActivity) { // >> application-app-android-broadcast //// Register the broadcast receiver if (androidApp) { - Application.android.registerBroadcastReceiver(android.content.Intent.ACTION_BATTERY_CHANGED, function onReceiveCallback(context: android.content.Context, intent: android.content.Intent) { - const level = intent.getIntExtra(android.os.BatteryManager.EXTRA_LEVEL, -1); - const scale = intent.getIntExtra(android.os.BatteryManager.EXTRA_SCALE, -1); - const percent = (level / scale) * 100.0; - ////console.log("Battery: " + percent + "%"); - }); + Application.android.registerBroadcastReceiver( + android.content.Intent.ACTION_BATTERY_CHANGED, + function onReceiveCallback( + context: android.content.Context, + intent: android.content.Intent + ) { + const level = intent.getIntExtra(android.os.BatteryManager.EXTRA_LEVEL, -1); + const scale = intent.getIntExtra(android.os.BatteryManager.EXTRA_SCALE, -1); + const percent = (level / scale) * 100.0; + ////console.log("Battery: " + percent + "%"); + } + ); } //// When no longer needed, unregister the broadcast receiver if (androidApp) { - Application.android.unregisterBroadcastReceiver(android.content.Intent.ACTION_BATTERY_CHANGED); + Application.android.unregisterBroadcastReceiver( + android.content.Intent.ACTION_BATTERY_CHANGED + ); } // << application-app-android-broadcast export function testAndroidApplicationInitialized() { TKUnit.assert(Application.android, 'Android application not initialized.'); TKUnit.assert(Application.android.context, 'Android context not initialized.'); - TKUnit.assert(Application.android.foregroundActivity, 'Android foregroundActivity not initialized.'); - TKUnit.assert(Application.android.foregroundActivity.isNativeScriptActivity, 'Android foregroundActivity.isNativeScriptActivity is false.'); - TKUnit.assert(Application.android.startActivity, 'Android startActivity not initialized.'); + TKUnit.assert( + Application.android.foregroundActivity, + 'Android foregroundActivity not initialized.' + ); + // @ts-expect-error + TKUnit.assert( + Application.android.foregroundActivity.isNativeScriptActivity, + 'Android foregroundActivity.isNativeScriptActivity is false.' + ); + TKUnit.assert( + Application.android.startActivity, + 'Android startActivity not initialized.' + ); TKUnit.assert(Application.android.nativeApp, 'Android nativeApp not initialized.'); TKUnit.assert(Application.android.orientation, 'Android orientation not initialized.'); TKUnit.assert(Application.android.packageName, 'Android packageName not initialized.'); - TKUnit.assert(Application.android.systemAppearance, 'Android system appearance not initialized.'); + TKUnit.assert( + Application.android.systemAppearance, + 'Android system appearance not initialized.' + ); } export function testSystemAppearance() { - TKUnit.assert(Application.android.systemAppearance, 'System appearance not initialized.'); + TKUnit.assert( + Application.android.systemAppearance, + 'System appearance not initialized.' + ); } diff --git a/apps/automated/src/file-system/file-system-tests.ts b/apps/automated/src/file-system/file-system-tests.ts index d6a30e99b..ef6bdae2f 100644 --- a/apps/automated/src/file-system/file-system-tests.ts +++ b/apps/automated/src/file-system/file-system-tests.ts @@ -4,8 +4,7 @@ import * as fs from '@nativescript/core/file-system'; // << file-system-require import * as TKUnit from '../tk-unit'; -import * as appModule from '@nativescript/core/application'; -import { isIOS, Device, platformNames, isAndroid } from '@nativescript/core'; +import { Application, isIOS, Device, platformNames, isAndroid } from '@nativescript/core'; export var testPathNormalize = function () { // >> file-system-normalize @@ -211,7 +210,10 @@ export var testFileReadWriteBinary = function () { if (Device.os === platformNames.ios) { TKUnit.assertTrue(source.isEqualToData(destination)); } else { - TKUnit.assertEqual(new java.io.File(sourceFile.path).length(), new java.io.File(destinationFile.path).length()); + TKUnit.assertEqual( + new java.io.File(sourceFile.path).length(), + new java.io.File(destinationFile.path).length() + ); } destinationFile.removeSync(); @@ -239,7 +241,10 @@ export var testFileReadWriteBinaryAsync = function () { if (Device.os === platformNames.ios) { TKUnit.assertTrue(source.isEqualToData(destination)); } else { - TKUnit.assertEqual(new java.io.File(sourceFile.path).length(), new java.io.File(destinationFile.path).length()); + TKUnit.assertEqual( + new java.io.File(sourceFile.path).length(), + new java.io.File(destinationFile.path).length() + ); } destinationFile.removeSync(); @@ -272,13 +277,19 @@ export var testGetKnownFolders = function () { var documents = fs.knownFolders.documents(); // >> (hide) TKUnit.assert(documents, 'Could not retrieve the Documents known folder.'); - TKUnit.assert(documents.isKnown, 'The Documents folder should have its isKnown property set to true.'); + TKUnit.assert( + documents.isKnown, + 'The Documents folder should have its isKnown property set to true.' + ); // << (hide) // Getting the application's 'temp' folder. var temp = fs.knownFolders.temp(); // >> (hide) TKUnit.assert(temp, 'Could not retrieve the Temporary known folder.'); - TKUnit.assert(temp.isKnown, 'The Temporary folder should have its isKnown property set to true.'); + TKUnit.assert( + temp.isKnown, + 'The Temporary folder should have its isKnown property set to true.' + ); // << (hide) // << file-system-known-folders }; @@ -296,13 +307,30 @@ function _testIOSSpecificKnownFolder(knownFolderName: string) { if (isIOS) { testFunc(); if (knownFolder) { - TKUnit.assertTrue(knownFolder.isKnown, `The ${knownFolderName} folder should have its "isKnown" property set to true.`); - TKUnit.assertNotNull(createdFile, `Could not create a new file in the ${knownFolderName} known folder.`); - TKUnit.assertTrue(fs.File.exists(createdFile.path), `Could not create a new file in the ${knownFolderName} known folder.`); - TKUnit.assertEqual(createdFile.readTextSync(), 'some text', `The contents of the new file created in the ${knownFolderName} known folder are not as expected.`); + TKUnit.assertTrue( + knownFolder.isKnown, + `The ${knownFolderName} folder should have its "isKnown" property set to true.` + ); + TKUnit.assertNotNull( + createdFile, + `Could not create a new file in the ${knownFolderName} known folder.` + ); + TKUnit.assertTrue( + fs.File.exists(createdFile.path), + `Could not create a new file in the ${knownFolderName} known folder.` + ); + TKUnit.assertEqual( + createdFile.readTextSync(), + 'some text', + `The contents of the new file created in the ${knownFolderName} known folder are not as expected.` + ); } } else { - TKUnit.assertThrows(testFunc, `Trying to retrieve the ${knownFolderName} known folder on a platform different from iOS should throw!`, `The "${knownFolderName}" known folder is available on iOS only!`); + TKUnit.assertThrows( + testFunc, + `Trying to retrieve the ${knownFolderName} known folder on a platform different from iOS should throw!`, + `The "${knownFolderName}" known folder is available on iOS only!` + ); } } @@ -412,7 +440,10 @@ export var testGetParent = function () { // The parent folder of the file would be the documents folder. var parent = file.parent; // >> (hide) - TKUnit.assert(documents === parent, 'The parent folder should be the Documents folder.'); + TKUnit.assert( + documents === parent, + 'The parent folder should be the Documents folder.' + ); file.remove(); // << (hide) // << file-system-parent @@ -590,7 +621,11 @@ export var testFolderClear = function () { ); // >> (hide) folder.getEntities().then(function (entities) { - TKUnit.assertEqual(entities.length, 0, `${entities.length} entities left after clearing a folder.`); + TKUnit.assertEqual( + entities.length, + 0, + `${entities.length} entities left after clearing a folder.` + ); folder.remove(); }); // << (hide) @@ -600,7 +635,7 @@ export var testFolderClear = function () { // misc export var testKnownFolderRename = function () { // You can rename known folders in android - so skip this test. - if (!appModule.android) { + if (!Application.android) { var folder = fs.knownFolders.documents(); folder.rename('Something').then( function (result) { @@ -634,7 +669,10 @@ export function test_FSEntity_Properties() { TKUnit.assert(file.extension === '.txt', 'FileEntity.extension not working.'); TKUnit.assert(file.isLocked === false, 'FileEntity.isLocked not working.'); - TKUnit.assert(file.lastModified instanceof Date, 'FileEntity.lastModified not working.'); + TKUnit.assert( + file.lastModified instanceof Date, + 'FileEntity.lastModified not working.' + ); TKUnit.assert(file.size === 0, 'FileEntity.size not working.'); TKUnit.assert(file.name === 'Test_File.txt', 'FileEntity.name not working.'); TKUnit.assert(file.parent === documents, 'FileEntity.parent not working.'); @@ -673,7 +711,12 @@ export function test_UnlockAfterWrite(done) { export function test_CreateParentOnNewFile(done) { var documentsFolderName = fs.knownFolders.documents().path; - var tempFileName = fs.path.join(documentsFolderName, 'folder1', 'folder2', 'Test_File_Create_Parent.txt'); + var tempFileName = fs.path.join( + documentsFolderName, + 'folder1', + 'folder2', + 'Test_File_Create_Parent.txt' + ); var file = fs.File.fromPath(tempFileName); file .writeText('Hello World!') @@ -688,11 +731,17 @@ export function test_FolderClear_RemovesEmptySubfolders(done) { let documents = fs.knownFolders.documents(); let rootFolder = documents.getFolder('rootFolder'); let emptySubfolder = rootFolder.getFolder('emptySubfolder'); - TKUnit.assertTrue(fs.Folder.exists(emptySubfolder.path), 'emptySubfolder should exist before parent folder is cleared.'); + TKUnit.assertTrue( + fs.Folder.exists(emptySubfolder.path), + 'emptySubfolder should exist before parent folder is cleared.' + ); rootFolder .clear() .then(() => { - TKUnit.assertFalse(fs.File.exists(emptySubfolder.path), 'emptySubfolder should not exist after parent folder was cleared.'); + TKUnit.assertFalse( + fs.File.exists(emptySubfolder.path), + 'emptySubfolder should not exist after parent folder was cleared.' + ); rootFolder.remove(); done(); }) @@ -701,10 +750,14 @@ export function test_FolderClear_RemovesEmptySubfolders(done) { export function test_FileCopy(done) { const now = Date.now(); - const tempFile = fs.File.fromPath(fs.path.join(fs.knownFolders.temp().path, `${now}.txt`)); + const tempFile = fs.File.fromPath( + fs.path.join(fs.knownFolders.temp().path, `${now}.txt`) + ); const content = 'Hello World: ' + now; tempFile.writeTextSync(content); - const tempCopy = fs.File.fromPath(fs.path.join(fs.knownFolders.temp().path, `${now}-copy.txt`)); + const tempCopy = fs.File.fromPath( + fs.path.join(fs.knownFolders.temp().path, `${now}-copy.txt`) + ); tempFile .copy(tempCopy.path) .then(() => { @@ -735,18 +788,30 @@ export function testAndroidCreate() { }; if (isAndroid) { const file = testFunc(); - TKUnit.assertEqual(file.readTextSync(), 'some text', `The contents of the new file created in the 'AndroidDirectory.DOWNLOADS' folder are not as expected.`); + TKUnit.assertEqual( + file.readTextSync(), + 'some text', + `The contents of the new file created in the 'AndroidDirectory.DOWNLOADS' folder are not as expected.` + ); file.removeSync(); TKUnit.assertTrue(!fs.File.exists(file.path)); } else { - TKUnit.assertThrows(testFunc, `Trying to retrieve createFile on a platform different from Android should throw!`, `createFile is available on Android only!`); + TKUnit.assertThrows( + testFunc, + `Trying to retrieve createFile on a platform different from Android should throw!`, + `createFile is available on Android only!` + ); } } export function test_FileAppend(done) { const content = 'Hello World'; - const hello_world = global.isIOS ? NSString.stringWithString(content).dataUsingEncoding(NSUTF8StringEncoding) : new java.lang.String(content).getBytes('UTF-8'); - const file = fs.File.fromPath(fs.path.join(fs.knownFolders.temp().path, `${Date.now()}-app.txt`)); + const hello_world = global.isIOS + ? NSString.stringWithString(content).dataUsingEncoding(NSUTF8StringEncoding) + : new java.lang.String(content).getBytes('UTF-8'); + const file = fs.File.fromPath( + fs.path.join(fs.knownFolders.temp().path, `${Date.now()}-app.txt`) + ); file .appendText('Hello') .then(() => file.appendText(' World')) @@ -765,7 +830,9 @@ export function test_FileAppend(done) { export function test_FileAppendText(done) { const content = 'Hello World'; - const file = fs.File.fromPath(fs.path.join(fs.knownFolders.temp().path, `${Date.now()}-app.txt`)); + const file = fs.File.fromPath( + fs.path.join(fs.knownFolders.temp().path, `${Date.now()}-app.txt`) + ); file .appendText('Hello') .then(() => file.appendText(' World')) diff --git a/apps/automated/src/image-source/image-source-tests.ts b/apps/automated/src/image-source/image-source-tests.ts index f46acce80..98c73596d 100644 --- a/apps/automated/src/image-source/image-source-tests.ts +++ b/apps/automated/src/image-source/image-source-tests.ts @@ -1,11 +1,8 @@ import { ImageSource } from '@nativescript/core/image-source'; import * as imageAssetModule from '@nativescript/core/image-asset'; import * as fs from '@nativescript/core/file-system'; -import * as app from '@nativescript/core/application'; import * as TKUnit from '../tk-unit'; -import { Font } from '@nativescript/core/ui/styling/font'; -import { Color } from '@nativescript/core/color'; -import * as utils from '@nativescript/core/utils'; +import { Application, Font, Color, Utils } from '@nativescript/core'; const imagePath = '~/assets/logo.png'; const splashscreenPath = '~/assets/splashscreen.png'; @@ -23,14 +20,22 @@ export function testFromResource() { export function testDrawableSetNativeSource() { if (global.isAndroid) { - const context = utils.ad.getApplicationContext() as android.content.Context; + const context = Utils.android.getApplicationContext() as android.content.Context; const rDrawable = `${context.getPackageName()}.R$drawable`; const rClazz = java.lang.Class.forName(`${rDrawable}`); const iconId = rClazz.getDeclaredField('icon').get(null) as java.lang.Integer; - const splashScreenId = rClazz.getDeclaredField('splash_screen').get(null) as java.lang.Integer; + const splashScreenId = rClazz + .getDeclaredField('splash_screen') + .get(null) as java.lang.Integer; - const icon = androidx.appcompat.content.res.AppCompatResources.getDrawable(context, iconId?.intValue?.() ?? 0); - const splashScreen = androidx.appcompat.content.res.AppCompatResources.getDrawable(context, splashScreenId?.intValue?.() ?? 0); + const icon = androidx.appcompat.content.res.AppCompatResources.getDrawable( + context, + iconId?.intValue?.() ?? 0 + ); + const splashScreen = androidx.appcompat.content.res.AppCompatResources.getDrawable( + context, + splashScreenId?.intValue?.() ?? 0 + ); let type = icon?.getClass?.().toString?.() ?? ''; @@ -253,14 +258,16 @@ export function testFromAssetWithBiggerScaling(done) { export function testNativeFields() { const img = ImageSource.fromFileSync(imagePath); - if (app.android) { + if (Application.android) { TKUnit.assert(img.android != null, 'Image.android not updated.'); - } else if (app.ios) { + } else if (Application.ios) { TKUnit.assert(img.ios != null, 'Image.ios not updated.'); } } -const fullAndroidPng = 'iVBORw0KGgoAAAANSUhEUgAAAAQAAAAECAIAAAAmkwkpAAAAA3NCSVQICAjb4U/gAAAAFUlEQVQImWP8z4AAjAz/kTnIPGQAAG86AwGcuMlCAAAAAElFTkSuQmCC'; -const fullIosPng = 'iVBORw0KGgoAAAANSUhEUgAAAAQAAAAECAIAAAAmkwkpAAAAAXNSR0IArs4c6QAAABxpRE9UAAAAAgAAAAAAAAACAAAAKAAAAAIAAAACAAAARiS4uJEAAAASSURBVBgZYvjPwABHSMz/DAAAAAD//0GWpK0AAAAOSURBVGNgYPiPhBgQAACEvQv1D5y/pAAAAABJRU5ErkJggg=='; +const fullAndroidPng = + 'iVBORw0KGgoAAAANSUhEUgAAAAQAAAAECAIAAAAmkwkpAAAAA3NCSVQICAjb4U/gAAAAFUlEQVQImWP8z4AAjAz/kTnIPGQAAG86AwGcuMlCAAAAAElFTkSuQmCC'; +const fullIosPng = + 'iVBORw0KGgoAAAANSUhEUgAAAAQAAAAECAIAAAAmkwkpAAAAAXNSR0IArs4c6QAAABxpRE9UAAAAAgAAAAAAAAACAAAAKAAAAAIAAAACAAAARiS4uJEAAAASSURBVBgZYvjPwABHSMz/DAAAAAD//0GWpK0AAAAOSURBVGNgYPiPhBgQAACEvQv1D5y/pAAAAABJRU5ErkJggg=='; const jpgImageAsBase64String = '/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/wAARCAAEAAQDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD+Pz/h5j+1Z/z9fBr/AMRt+AH/AM7uiiiv9fV9E36KOn/HMX0f+n/NlvDT/p3/ANUv/V3vrf8AP1nueaf8LOa9P+ZjjP8Ap3/0/wD6u99b/wD/2Q=='; @@ -315,9 +322,9 @@ export function testLoadFromBase64Encode_JPEG() { export function testLoadFromBase64Encode_PNG() { let img: ImageSource; - if (app.android) { + if (Application.android) { img = ImageSource.fromBase64Sync(fullAndroidPng); - } else if (app.ios) { + } else if (Application.ios) { img = ImageSource.fromBase64Sync(fullIosPng); } @@ -328,7 +335,11 @@ export function testLoadFromBase64Encode_PNG() { export function testLoadFromFontIconCode() { let img: ImageSource; - img = ImageSource.fromFontIconCodeSync('F10B', Font.default.withFontFamily('FontAwesome'), new Color('red')); + img = ImageSource.fromFontIconCodeSync( + 'F10B', + Font.default.withFontFamily('FontAwesome'), + new Color('red') + ); TKUnit.assert(img !== null, 'Actual: ' + img); TKUnit.assert(img.width !== null, 'img.width'); @@ -342,5 +353,8 @@ export function testResize() { const resized = img.resize(newSize); - TKUnit.assert(resized.width === newSize || resized.height === newSize, 'Image not resized correctly'); + TKUnit.assert( + resized.width === newSize || resized.height === newSize, + 'Image not resized correctly' + ); } diff --git a/apps/automated/src/livesync/livesync-tests.ts b/apps/automated/src/livesync/livesync-tests.ts index 427e30112..c89481ff7 100644 --- a/apps/automated/src/livesync/livesync-tests.ts +++ b/apps/automated/src/livesync/livesync-tests.ts @@ -1,12 +1,7 @@ import * as helper from '../ui-helper'; import * as TKUnit from '../tk-unit'; -import * as app from '@nativescript/core/application'; -import * as frame from '@nativescript/core/ui/frame'; -import { Color } from '@nativescript/core/color'; -import { Builder } from '@nativescript/core/ui/builder'; -import { Page } from '@nativescript/core/ui/page'; -import { Frame } from '@nativescript/core/ui/frame'; +import { Application, Frame, Page, Builder, Color } from '@nativescript/core'; const LIVESYNC_FOLDER = 'livesync/'; @@ -40,12 +35,14 @@ const modalViewCssFileName = `${LIVESYNC_FOLDER}livesync-modal-view-page.css`; const green = new Color('green'); export function setUp() { - const labelPage = Builder.createViewFromEntry({ moduleName: labelPageModuleName }); + const labelPage = ( + Builder.createViewFromEntry({ moduleName: labelPageModuleName }) + ); helper.navigate(() => labelPage); } export function tearDown() { - app.setCssFileName(appCssFileName); + Application.setCssFileName(appCssFileName); } export function test_onLiveSync_ModuleContext_AppStyle_AppNewCss() { @@ -138,61 +135,107 @@ export function test_onLiveSync_ModalViewClosed_StyleScss() { _test_onLiveSync_ModalViewClosed({ type: 'style', path: modalViewScssPageFileName }); } -function _test_onLiveSync_ModuleContext_AppStyle(appStyleFileName: string, livesyncStyleFileName: string) { +function _test_onLiveSync_ModuleContext_AppStyle( + appStyleFileName: string, + livesyncStyleFileName: string +) { const pageBeforeNavigation = helper.getCurrentPage(); - const buttonPage = Builder.createViewFromEntry({ moduleName: buttonPageModuleName }); + const buttonPage = ( + Builder.createViewFromEntry({ moduleName: buttonPageModuleName }) + ); helper.navigateWithHistory(() => buttonPage); - app.setCssFileName(appStyleFileName); + Application.setCssFileName(appStyleFileName); const pageBeforeLiveSync = helper.getCurrentPage(); livesync({ type: 'style', path: livesyncStyleFileName }); const pageAfterLiveSync = helper.getCurrentPage(); - TKUnit.waitUntilReady(() => pageAfterLiveSync.getViewById('button').style.color.toString() === green.toString()); + TKUnit.waitUntilReady( + () => + pageAfterLiveSync.getViewById('button').style.color.toString() === green.toString() + ); TKUnit.assertTrue(pageAfterLiveSync.frame.canGoBack(), 'Can NOT go back!'); TKUnit.assertEqual(pageAfterLiveSync, pageBeforeLiveSync, 'Pages are different!'); - TKUnit.assertTrue(pageAfterLiveSync._cssState.isSelectorsLatestVersionApplied(), 'Latest selectors version is NOT applied!'); + TKUnit.assertTrue( + pageAfterLiveSync._cssState.isSelectorsLatestVersionApplied(), + 'Latest selectors version is NOT applied!' + ); helper.goBack(); const pageAfterNavigationBack = helper.getCurrentPage(); - TKUnit.assertEqual(pageAfterNavigationBack.getViewById('label').style.color, green, 'App styles NOT applied on back navigation!'); - TKUnit.assertEqual(pageBeforeNavigation, pageAfterNavigationBack, 'Pages are different'); - TKUnit.assertTrue(pageAfterNavigationBack._cssState.isSelectorsLatestVersionApplied(), 'Latest selectors version is NOT applied!'); + TKUnit.assertEqual( + pageAfterNavigationBack.getViewById('label').style.color, + green, + 'App styles NOT applied on back navigation!' + ); + TKUnit.assertEqual( + pageBeforeNavigation, + pageAfterNavigationBack, + 'Pages are different' + ); + TKUnit.assertTrue( + pageAfterNavigationBack._cssState.isSelectorsLatestVersionApplied(), + 'Latest selectors version is NOT applied!' + ); } function _test_onLiveSync_ModuleContext(context: ModuleContext) { - const buttonPage = Builder.createViewFromEntry({ moduleName: buttonPageModuleName }); + const buttonPage = ( + Builder.createViewFromEntry({ moduleName: buttonPageModuleName }) + ); helper.navigateWithHistory(() => buttonPage); livesync({ type: context.type, path: context.path }); TKUnit.waitUntilReady(() => !!Frame.topmost()); const topmostFrame = Frame.topmost(); - TKUnit.waitUntilReady(() => topmostFrame.currentPage && topmostFrame.currentPage.isLoaded && !topmostFrame.canGoBack()); + TKUnit.waitUntilReady( + () => + topmostFrame.currentPage && + topmostFrame.currentPage.isLoaded && + !topmostFrame.canGoBack() + ); TKUnit.assertTrue(topmostFrame.currentPage.getViewById('label').isLoaded); } function _test_onLiveSync_ModuleReplace(context: ModuleContext) { const pageBeforeNavigation = helper.getCurrentPage(); - const buttonPage = Builder.createViewFromEntry({ moduleName: buttonPageModuleName }); + const buttonPage = ( + Builder.createViewFromEntry({ moduleName: buttonPageModuleName }) + ); helper.navigateWithHistory(() => buttonPage); livesync({ type: context.type, path: context.path }); const topmostFrame = Frame.topmost(); waitUntilLivesyncComplete(topmostFrame); - TKUnit.assertTrue(topmostFrame.currentPage.getViewById('button').isLoaded, 'Button page is NOT loaded!'); + TKUnit.assertTrue( + topmostFrame.currentPage.getViewById('button').isLoaded, + 'Button page is NOT loaded!' + ); TKUnit.assertEqual(topmostFrame.backStack.length, 1, 'Backstack is clean!'); TKUnit.assertTrue(topmostFrame.canGoBack(), 'Can NOT go back!'); helper.goBack(); const pageAfterBackNavigation = helper.getCurrentPage(); - TKUnit.assertTrue(topmostFrame.currentPage.getViewById('label').isLoaded, 'Label page is NOT loaded!'); + TKUnit.assertTrue( + topmostFrame.currentPage.getViewById('label').isLoaded, + 'Label page is NOT loaded!' + ); TKUnit.assertEqual(topmostFrame.backStack.length, 0, 'Backstack is NOT clean!'); - TKUnit.assertEqual(pageBeforeNavigation, pageAfterBackNavigation, 'Pages are different!'); + TKUnit.assertEqual( + pageBeforeNavigation, + pageAfterBackNavigation, + 'Pages are different!' + ); } -function _test_onLiveSync_ModuleContext_TypeStyle(styleModuleName: string, livesyncStyleFileName: string) { +function _test_onLiveSync_ModuleContext_TypeStyle( + styleModuleName: string, + livesyncStyleFileName: string +) { const pageBeforeNavigation = helper.getCurrentPage(); - const buttonPage = Builder.createViewFromEntry({ moduleName: buttonPageModuleName }); + const buttonPage = ( + Builder.createViewFromEntry({ moduleName: buttonPageModuleName }) + ); helper.navigateWithHistory(() => buttonPage); const pageBeforeLiveSync = helper.getCurrentPage(); @@ -203,20 +246,35 @@ function _test_onLiveSync_ModuleContext_TypeStyle(styleModuleName: string, lives waitUntilLivesyncComplete(topmostFrame); const pageAfterLiveSync = helper.getCurrentPage(); - TKUnit.waitUntilReady(() => pageAfterLiveSync.getViewById('button').style.color.toString() === green.toString()); + TKUnit.waitUntilReady( + () => + pageAfterLiveSync.getViewById('button').style.color.toString() === green.toString() + ); TKUnit.assertTrue(pageAfterLiveSync.frame.canGoBack(), 'Can NOT go back!'); TKUnit.assertEqual(topmostFrame.backStack.length, 1, 'Backstack is clean!'); - TKUnit.assertTrue(pageAfterLiveSync._cssState.isSelectorsLatestVersionApplied(), 'Latest selectors version is NOT applied!'); + TKUnit.assertTrue( + pageAfterLiveSync._cssState.isSelectorsLatestVersionApplied(), + 'Latest selectors version is NOT applied!' + ); helper.goBack(); const pageAfterNavigationBack = helper.getCurrentPage(); - TKUnit.assertEqual(pageBeforeNavigation, pageAfterNavigationBack, 'Pages are different!'); - TKUnit.assertTrue(pageAfterNavigationBack._cssState.isSelectorsLatestVersionApplied(), 'Latest selectors version is NOT applied!'); + TKUnit.assertEqual( + pageBeforeNavigation, + pageAfterNavigationBack, + 'Pages are different!' + ); + TKUnit.assertTrue( + pageAfterNavigationBack._cssState.isSelectorsLatestVersionApplied(), + 'Latest selectors version is NOT applied!' + ); } function _test_onLiveSync_ModuleReplace_Multiple(context: ModuleContext[]) { const pageBeforeNavigation = helper.getCurrentPage(); - const buttonPage = Builder.createViewFromEntry({ moduleName: buttonPageModuleName }); + const buttonPage = ( + Builder.createViewFromEntry({ moduleName: buttonPageModuleName }) + ); helper.navigateWithHistory(() => buttonPage); context.forEach((item) => { @@ -225,25 +283,42 @@ function _test_onLiveSync_ModuleReplace_Multiple(context: ModuleContext[]) { const topmostFrame = Frame.topmost(); waitUntilLivesyncComplete(topmostFrame); - TKUnit.assertTrue(topmostFrame.currentPage.getViewById('button').isLoaded, 'Button page is NOT loaded!'); + TKUnit.assertTrue( + topmostFrame.currentPage.getViewById('button').isLoaded, + 'Button page is NOT loaded!' + ); TKUnit.assertEqual(topmostFrame.backStack.length, 1, 'Backstack is clean!'); TKUnit.assertTrue(topmostFrame.canGoBack(), 'Can NOT go back!'); helper.goBack(); const pageAfterBackNavigation = helper.getCurrentPage(); - TKUnit.assertTrue(topmostFrame.currentPage.getViewById('label').isLoaded, 'Label page is NOT loaded!'); + TKUnit.assertTrue( + topmostFrame.currentPage.getViewById('label').isLoaded, + 'Label page is NOT loaded!' + ); TKUnit.assertEqual(topmostFrame.backStack.length, 0, 'Backstack is NOT clean!'); - TKUnit.assertEqual(pageBeforeNavigation, pageAfterBackNavigation, 'Pages are different!'); + TKUnit.assertEqual( + pageBeforeNavigation, + pageAfterBackNavigation, + 'Pages are different!' + ); } function _test_onLiveSync_ModalViewClosed(context: ModuleContext) { - const modalViewPage = Builder.createViewFromEntry({ moduleName: modalViewPageModuleName }); + const modalViewPage = ( + Builder.createViewFromEntry({ moduleName: modalViewPageModuleName }) + ); helper.navigateWithHistory(() => modalViewPage); livesync({ type: context.type, path: context.path }); TKUnit.waitUntilReady(() => !!Frame.topmost()); const topmostFrame = Frame.topmost(); - TKUnit.waitUntilReady(() => topmostFrame.currentPage && topmostFrame.currentPage.isLoaded && topmostFrame.canGoBack()); + TKUnit.waitUntilReady( + () => + topmostFrame.currentPage && + topmostFrame.currentPage.isLoaded && + topmostFrame.canGoBack() + ); TKUnit.assertTrue(topmostFrame._getRootModalViews().length === 0); } diff --git a/apps/automated/src/main.ts b/apps/automated/src/main.ts index acb8fc89c..b19757686 100644 --- a/apps/automated/src/main.ts +++ b/apps/automated/src/main.ts @@ -5,13 +5,162 @@ if (typeof NSDate !== 'undefined') { start = java.lang.System.currentTimeMillis(); } -import { Application, ApplicationEventData, UnhandledErrorEventData, DiscardedErrorEventData, AndroidActivityBundleEventData, AndroidActivityEventData, AndroidApplication, AndroidActivityNewIntentEventData, AndroidActivityResultEventData, AndroidActivityBackPressedEventData } from '@nativescript/core'; +// Utils.android.dismissSoftInput(); +// Utils.ad.dismissSoftInput(); + +// Utils.ios.animateWithSpring(); + +// Utils.android.isRealDevice() + +// isAndroid +// const { +// GC, +// SDK_VERSION, +// RESOURCE_PREFIX, +// FILE_PREFIX, +// isFontIconURI, +// isDataURI, +// isFileOrResourcePath, +// getFileExtension, +// executeOnMainThread, +// executeOnUIThread, +// mainThreadify, +// isMainThread, +// dispatchToMainThread, +// queueMacrotask, +// queueGC, +// debounce, +// throttle, +// releaseNativeObject, +// convertString, +// escapeRegexSymbols, + +// getModuleName, +// openFile, +// openUrl, +// isRealDevice, + +// layout, +// android, +// // legacy (a lot of plugins use the shorthand "ad" Utils.ad instead of Utils.android) +// ad, +// ios, +// dataSerialize, +// dataDeserialize, +// numberHasDecimals, +// numberIs64Bit, +// setTimeout, +// setInterval, +// clearInterval, +// clearTimeout, +// Source, +// ClassInfo, +// getClass, +// getBaseClasses, +// getClassInfo, +// isBoolean, +// isDefined, +// isFunction, +// isNullOrUndefined, +// isNumber, +// isObject, +// isString, +// isUndefined, +// toUIString, +// verifyCallback, +// dismissSoftInput, +// dismissKeyboard, +// copyToClipboard, +// isEmoji, +// getDurationWithDampingFromSpring, + +// // wtf +// } = Utils; + +// const { +// launchEvent, +// displayedEvent, +// uncaughtErrorEvent, +// discardedErrorEvent, +// suspendEvent, +// resumeEvent, +// exitEvent, +// foregroundEvent, +// backgroundEvent, +// lowMemoryEvent, +// orientationChangedEvent, +// systemAppearanceChangedEvent, +// systemAppearanceChanged, +// fontScaleChangedEvent, +// setMaxRefreshRate, + +// getMainEntry, +// getRootView, +// resetRootView, +// getResources, +// setResources, +// setCssFileName, +// getCssFileName, +// loadAppCss, +// addCss, +// on, +// off, +// notify, +// hasListeners, +// run, +// orientation, +// getNativeApplication, +// hasLaunched, +// systemAppearance, +// setAutoSystemAppearanceChanged, +// android: appAndroid, +// inBackground, +// suspended, +// ios: iosApp, +// // get android() { +// // ensureNativeApplication(); +// // return appAndroid; +// // }, +// // get ios() { +// // ensureNativeApplication(); +// // return iosApp; +// // }, +// // get suspended() { +// // return suspended; +// // }, +// // get inBackground() { +// // return inBackground; +// // }, +// } = Application; + +// Application.suspendEvent + +import { + Application, + ApplicationEventData, + UnhandledErrorEventData, + DiscardedErrorEventData, + AndroidActivityBundleEventData, + AndroidActivityEventData, + AndroidApplication, + AndroidActivityNewIntentEventData, + AndroidActivityResultEventData, + AndroidActivityBackPressedEventData, +} from '@nativescript/core'; + +// import { Application } from "@nativescript/core/application-new"; + +// Application.AndroidApplication +// Application2.AndroidApplication if (Application.ios) { // Observe application notifications. - Application.ios.addNotificationObserver(UIApplicationDidFinishLaunchingNotification, (notification: NSNotification) => { - console.log('UIApplicationDidFinishLaunchingNotification: ' + notification); - }); + Application.ios.addNotificationObserver( + UIApplicationDidFinishLaunchingNotification, + (notification: NSNotification) => { + console.log('UIApplicationDidFinishLaunchingNotification: ' + notification); + } + ); } // Common events for both Android and iOS. @@ -30,7 +179,9 @@ Application.on(Application.displayedEvent, function (args: ApplicationEventData) Application.on(Application.launchEvent, function (args: ApplicationEventData) { if (args.android) { // For Android applications, args.android is an android.content.Intent class. - console.log('Launched Android application with the following intent: ' + args.android + '.'); + console.log( + 'Launched Android application with the following intent: ' + args.android + '.' + ); } else if (args.ios !== undefined) { // For iOS applications, args.ios is NSDictionary (launchOptions). console.log('Launched iOS application with options: ' + args.ios); @@ -92,46 +243,108 @@ Application.on(Application.discardedErrorEvent, function (args: DiscardedErrorEv // Android activity events. if (Application.android) { - Application.android.on(AndroidApplication.activityCreatedEvent, function (args: AndroidActivityBundleEventData) { - console.log('Event: ' + args.eventName + ', Activity: ' + args.activity + ', Bundle: ' + args.bundle); - }); + Application.android.on( + Application.android.activityCreatedEvent, + function (args: AndroidActivityBundleEventData) { + console.log( + 'Event: ' + + args.eventName + + ', Activity: ' + + args.activity + + ', Bundle: ' + + args.bundle + ); + } + ); - Application.android.on(AndroidApplication.activityDestroyedEvent, function (args: AndroidActivityEventData) { - console.log('Event: ' + args.eventName + ', Activity: ' + args.activity); - }); + Application.android.on( + Application.android.activityDestroyedEvent, + function (args: AndroidActivityEventData) { + console.log('Event: ' + args.eventName + ', Activity: ' + args.activity); + } + ); - Application.android.on(AndroidApplication.activityStartedEvent, function (args: AndroidActivityEventData) { - console.log('Event: ' + args.eventName + ', Activity: ' + args.activity); - }); + Application.android.on( + Application.android.activityStartedEvent, + function (args: AndroidActivityEventData) { + console.log('Event: ' + args.eventName + ', Activity: ' + args.activity); + } + ); - Application.android.on(AndroidApplication.activityPausedEvent, function (args: AndroidActivityEventData) { - console.log('Event: ' + args.eventName + ', Activity: ' + args.activity); - }); + Application.android.on( + Application.android.activityPausedEvent, + function (args: AndroidActivityEventData) { + console.log('Event: ' + args.eventName + ', Activity: ' + args.activity); + } + ); - Application.android.on(AndroidApplication.activityResumedEvent, function (args: AndroidActivityEventData) { - console.log('Event: ' + args.eventName + ', Activity: ' + args.activity); - }); + Application.android.on( + Application.android.activityResumedEvent, + function (args: AndroidActivityEventData) { + console.log('Event: ' + args.eventName + ', Activity: ' + args.activity); + } + ); - Application.android.on(AndroidApplication.activityStoppedEvent, function (args: AndroidActivityEventData) { - console.log('Event: ' + args.eventName + ', Activity: ' + args.activity); - }); + Application.android.on( + Application.android.activityStoppedEvent, + function (args: AndroidActivityEventData) { + console.log('Event: ' + args.eventName + ', Activity: ' + args.activity); + } + ); - Application.android.on(AndroidApplication.saveActivityStateEvent, function (args: AndroidActivityBundleEventData) { - console.log('Event: ' + args.eventName + ', Activity: ' + args.activity + ', Bundle: ' + args.bundle); - }); + Application.android.on( + Application.android.saveActivityStateEvent, + function (args: AndroidActivityBundleEventData) { + console.log( + 'Event: ' + + args.eventName + + ', Activity: ' + + args.activity + + ', Bundle: ' + + args.bundle + ); + } + ); - Application.android.on(AndroidApplication.activityResultEvent, function (args: AndroidActivityResultEventData) { - console.log('Event: ' + args.eventName + ', Activity: ' + args.activity + ', requestCode: ' + args.requestCode + ', resultCode: ' + args.resultCode + ', Intent: ' + args.intent); - }); + Application.android.on( + Application.android.activityResultEvent, + function (args: AndroidActivityResultEventData) { + console.log( + 'Event: ' + + args.eventName + + ', Activity: ' + + args.activity + + ', requestCode: ' + + args.requestCode + + ', resultCode: ' + + args.resultCode + + ', Intent: ' + + args.intent + ); + } + ); - Application.android.on(AndroidApplication.activityBackPressedEvent, function (args: AndroidActivityBackPressedEventData) { - console.log('Event: ' + args.eventName + ', Activity: ' + args.activity); - // Set args.cancel = true to cancel back navigation and do something custom. - }); + Application.android.on( + Application.android.activityBackPressedEvent, + function (args: AndroidActivityBackPressedEventData) { + console.log('Event: ' + args.eventName + ', Activity: ' + args.activity); + // Set args.cancel = true to cancel back navigation and do something custom. + } + ); - Application.android.on(AndroidApplication.activityNewIntentEvent, function (args: AndroidActivityNewIntentEventData) { - console.log('Event: ' + args.eventName + ', Activity: ' + args.activity + ', Intent: ' + args.intent); - }); + Application.android.on( + Application.android.activityNewIntentEvent, + function (args: AndroidActivityNewIntentEventData) { + console.log( + 'Event: ' + + args.eventName + + ', Activity: ' + + args.activity + + ', Intent: ' + + args.intent + ); + } + ); } let time; diff --git a/apps/automated/src/pages/page5.ts b/apps/automated/src/pages/page5.ts index 55c0945ca..349e272a9 100644 --- a/apps/automated/src/pages/page5.ts +++ b/apps/automated/src/pages/page5.ts @@ -1,8 +1,5 @@ -import * as gridModule from '@nativescript/core/ui/layouts/grid-layout'; -import * as pages from '@nativescript/core/ui/page'; -import * as buttons from '@nativescript/core/ui/button'; -import * as app from '@nativescript/core/application'; import * as platform from '@nativescript/core/platform'; +import { Application, Page, Button, GridLayout } from '@nativescript/core'; function printDeviceInfoAndroid() { console.log('android.os.Build.DEVICE = ' + android.os.Build.DEVICE); //android.os.Build.DEVICE = hammerhead @@ -10,7 +7,9 @@ function printDeviceInfoAndroid() { console.log('android.os.Build.VERSION.SDK_INT = ' + android.os.Build.VERSION.SDK_INT); //android.os.Build.VERSION.SDK_INT = 19 console.log('android.os.Build.VERSION.CODENAME = ' + android.os.Build.VERSION.CODENAME); //android.os.Build.VERSION.CODENAME = REL console.log('android.os.Build.VERSION.RELEASE = ' + android.os.Build.VERSION.RELEASE); //android.os.Build.VERSION.RELEASE = 4.4.4 - var metrics: android.util.DisplayMetrics = app.android.context.getResources().getDisplayMetrics(); + var metrics: android.util.DisplayMetrics = Application.android.context + .getResources() + .getDisplayMetrics(); console.log('metrics.density = ' + metrics.density); //metrics.density = 3 console.log('metrics.scaledDensity = ' + metrics.scaledDensity); //metrics.scaledDensity = 3 console.log('metrics.densityDpi = ' + metrics.densityDpi); //metrics.densityDpi = 480 @@ -19,11 +18,16 @@ function printDeviceInfoAndroid() { console.log('metrics.widthPixels = ' + metrics.widthPixels); //metrics.widthPixels = 1080 console.log('metrics.heightPixels = ' + metrics.heightPixels); //metrics.heightPixels = 1776 - var config = app.android.context.getResources().getConfiguration(); + var config = Application.android.context.getResources().getConfiguration(); console.log('config.screenWidthDp = ' + config.screenWidthDp); console.log('config.screenHeightDp = ' + config.screenHeightDp); console.log('config.smallestScreenWidthDp = ' + config.smallestScreenWidthDp); - console.log('config.orientation = ' + (config.orientation === android.content.res.Configuration.ORIENTATION_PORTRAIT ? 'portrait' : 'ladscape')); + console.log( + 'config.orientation = ' + + (config.orientation === android.content.res.Configuration.ORIENTATION_PORTRAIT + ? 'portrait' + : 'ladscape') + ); } function printDeviceInfoIOS() { @@ -37,7 +41,12 @@ function printDeviceInfoIOS() { console.log('device.batteryLevel = ' + device.batteryLevel); //device.batteryLevel = -1 var screen = UIScreen.mainScreen; console.log('screen = ' + screen); - console.log('screen.nativeBounds = ' + screen.nativeBounds.size.width + ', ' + screen.nativeBounds.size.height); //screen.nativeBounds = 640, 1136 + console.log( + 'screen.nativeBounds = ' + + screen.nativeBounds.size.width + + ', ' + + screen.nativeBounds.size.height + ); //screen.nativeBounds = 640, 1136 console.log('screen.scale = ' + screen.scale); //screen.scale = 2 console.log('screen.nativeScale = ' + screen.nativeScale); //screen.nativeScale = 2 } @@ -49,15 +58,23 @@ function printTNSInfo() { console.log('platform.Device.sdkVersion = ' + platform.Device.sdkVersion); console.log('platform.Device.deviceType = ' + platform.Device.deviceType); - console.log('platform.Screen.mainScreen.widthDIPs = ' + platform.Screen.mainScreen.widthDIPs); - console.log('platform.Screen.mainScreen.heightDIPs = ' + platform.Screen.mainScreen.heightDIPs); + console.log( + 'platform.Screen.mainScreen.widthDIPs = ' + platform.Screen.mainScreen.widthDIPs + ); + console.log( + 'platform.Screen.mainScreen.heightDIPs = ' + platform.Screen.mainScreen.heightDIPs + ); console.log('platform.Screen.mainScreen.scale = ' + platform.Screen.mainScreen.scale); - console.log('platform.Screen.mainScreen.widthPixels = ' + platform.Screen.mainScreen.widthPixels); - console.log('platform.Screen.mainScreen.heightPixels = ' + platform.Screen.mainScreen.heightPixels); + console.log( + 'platform.Screen.mainScreen.widthPixels = ' + platform.Screen.mainScreen.widthPixels + ); + console.log( + 'platform.Screen.mainScreen.heightPixels = ' + platform.Screen.mainScreen.heightPixels + ); } function print() { - if (app.android) { + if (Application.android) { printDeviceInfoAndroid(); } else { printDeviceInfoIOS(); @@ -67,10 +84,10 @@ function print() { //print(); export function createPage() { - var page = new pages.Page(); - var grid = new gridModule.GridLayout(); + var page = new Page(); + var grid = new GridLayout(); - var btn = new buttons.Button(); + var btn = new Button(); btn.text = 'print'; btn.on('tap', (d) => { print(); diff --git a/apps/automated/src/test-runner.ts b/apps/automated/src/test-runner.ts index 3e97b5673..db6b25a5b 100644 --- a/apps/automated/src/test-runner.ts +++ b/apps/automated/src/test-runner.ts @@ -2,7 +2,20 @@ import * as TKUnit from './tk-unit'; import './ui-test'; -import { isIOS, isAndroid, Application, Device, platformNames, Trace, Button, Frame, StackLayout, Page, TextView, Utils } from '@nativescript/core'; +import { + isIOS, + isAndroid, + Application, + Device, + platformNames, + Trace, + Button, + Frame, + StackLayout, + Page, + TextView, + Utils, +} from '@nativescript/core'; Frame.defaultAnimatedNavigation = false; export function isRunningOnEmulator(): boolean { @@ -155,8 +168,8 @@ if (isIOS && Utils.ios.MajorVersion > 10) { allTests['SAFEAREA-WEBVIEW'] = webViewSafeAreaTests; } -import * as rootViewsCssClassesTests from './ui/styling/root-views-css-classes-tests'; -allTests['ROOT-VIEWS-CSS-CLASSES'] = rootViewsCssClassesTests; +// import * as rootViewsCssClassesTests from './ui/styling/root-views-css-classes-tests'; +// allTests['ROOT-VIEWS-CSS-CLASSES'] = rootViewsCssClassesTests; import * as stylePropertiesTests from './ui/styling/style-properties-tests'; allTests['STYLE-PROPERTIES'] = stylePropertiesTests; @@ -345,7 +358,12 @@ function printRunTestStats() { const totalTime = (TKUnit.time() - startTime).toFixed(2); - let finalMessage = `\n` + `=== ALL TESTS COMPLETE ===\n` + `${allTests.length - failedTestCount} OK, ${failedTestCount} failed\n` + `DURATION: ${totalTime} ms\n` + `=== END OF TESTS ===\n`; + let finalMessage = + `\n` + + `=== ALL TESTS COMPLETE ===\n` + + `${allTests.length - failedTestCount} OK, ${failedTestCount} failed\n` + + `DURATION: ${totalTime} ms\n` + + `=== END OF TESTS ===\n`; TKUnit.write(finalMessage, Trace.messageType.info); @@ -370,17 +388,29 @@ function generateTestFile(allTests: TestInfo[]) { let testName = testCase.testName; let duration = (testCase.duration / 1000).toFixed(2); - testCases.push(``); + testCases.push( + `` + ); if (!testCase.isPassed) { failedTestCount++; - testCases.push(``); + testCases.push( + `` + ); } testCases.push(``); }); const totalTime = (TKUnit.time() - startTime).toFixed(2); - const result = ['', ``, ...testCases, '', ''].join(''); + const result = [ + '', + ``, + ...testCases, + '', + '', + ].join(''); return result; } @@ -425,7 +455,14 @@ function startLog(): void { function log(): void { let testsName: string = this.name; let duration = TKUnit.time() - this.start; - TKUnit.write(testsName + ' COMPLETED for ' + duration.toFixed(2) + ' BACKSTACK DEPTH: ' + Frame.topmost().backStack.length, Trace.messageType.info); + TKUnit.write( + testsName + + ' COMPLETED for ' + + duration.toFixed(2) + + ' BACKSTACK DEPTH: ' + + Frame.topmost().backStack.length, + Trace.messageType.info + ); } function getAllProperties(obj: any) { @@ -433,7 +470,10 @@ function getAllProperties(obj: any) { let currentObj = obj; do { Object.getOwnPropertyNames(currentObj).map((item) => properties.add(item)); - } while ((currentObj = Object.getPrototypeOf(currentObj)) && currentObj !== Object.prototype); + } while ( + (currentObj = Object.getPrototypeOf(currentObj)) && + currentObj !== Object.prototype + ); return [...properties.keys()]; } @@ -467,7 +507,13 @@ export function runAll(testSelector?: string) { } } - console.log('TESTS: ' + singleModuleName ? singleModuleName : '' + ' ' + singleTestName ? singleTestName : ''); + console.log( + 'TESTS: ' + singleModuleName + ? singleModuleName + : '' + ' ' + singleTestName + ? singleTestName + : '' + ); testsQueue.push( new TestInfo(() => { @@ -501,8 +547,19 @@ export function runAll(testSelector?: string) { if (test.setUp) { testsQueue.push(new TestInfo(test.setUp, test)); } - const testTimeout = testsWithLongDelay[testName] || testsSuitesWithLongDelay[name]; - testsQueue.push(new TestInfo(testFunction, test, true, name + '.' + testName, false, null, testTimeout)); + const testTimeout = + testsWithLongDelay[testName] || testsSuitesWithLongDelay[name]; + testsQueue.push( + new TestInfo( + testFunction, + test, + true, + name + '.' + testName, + false, + null, + testTimeout + ) + ); if (test.tearDown) { testsQueue.push(new TestInfo(test.tearDown, test)); } @@ -535,7 +592,16 @@ class TestInfo implements TKUnit.TestInfoEntry { testTimeout: number; duration: number; - constructor(testFunc, testInstance?: any, isTest?, testName?, isPassed?, errorMessage?, testTimeout?, duration?) { + constructor( + testFunc, + testInstance?: any, + isTest?, + testName?, + isPassed?, + errorMessage?, + testTimeout?, + duration? + ) { this.testFunc = testFunc; this.instance = testInstance || null; this.isTest = isTest || false; diff --git a/apps/automated/src/ui/core/bindable/bindable-tests.ts b/apps/automated/src/ui/core/bindable/bindable-tests.ts index 28f87fabe..a290927f9 100644 --- a/apps/automated/src/ui/core/bindable/bindable-tests.ts +++ b/apps/automated/src/ui/core/bindable/bindable-tests.ts @@ -1,18 +1,24 @@ -import { Observable, fromObject, fromObjectRecursive } from '@nativescript/core/data/observable'; +import { + Observable, + fromObject, + fromObjectRecursive, +} from '@nativescript/core/data/observable'; import { ViewBase } from '@nativescript/core/ui/core/view-base'; import { BindingOptions } from '@nativescript/core/ui/core/bindable'; import * as TKUnit from '../../../tk-unit'; import * as types from '@nativescript/core/utils/types'; import * as helper from '../../../ui-helper'; import * as bindingBuilder from '@nativescript/core/ui/builder/binding-builder'; -import * as appModule from '@nativescript/core/application'; -import { Trace } from '@nativescript/core'; -import { View } from '@nativescript/core/ui/core/view'; -import { Button } from '@nativescript/core/ui/button'; -import { Page } from '@nativescript/core/ui/page'; -import { StackLayout } from '@nativescript/core/ui/layouts/stack-layout'; -import { Label } from '@nativescript/core/ui/label'; -import { TextField } from '@nativescript/core/ui/text-field'; +import { + Application, + View, + Button, + Page, + StackLayout, + Label, + TextField, + Trace, +} from '@nativescript/core'; declare var WeakRef: any; // // For information and examples how to use bindings please refer to special [**Data binding**](../../../../bindings.md) topic. @@ -49,11 +55,17 @@ export function test_Bindable_Bind_ToTarget_OneWay() { const obj = new Label(); obj.bind(options, model); - TKUnit.assert(obj.get('text') === 'John', "Expected result after binding is [test value] === 'John'"); + TKUnit.assert( + obj.get('text') === 'John', + "Expected result after binding is [test value] === 'John'" + ); model.set('name', 'Changed'); - TKUnit.assert(obj.get('text') === 'Changed', "Expected result after binding is [test value] === 'Changed'"); + TKUnit.assert( + obj.get('text') === 'Changed', + "Expected result after binding is [test value] === 'Changed'" + ); } export function test_Bindable_Bind_ToTarget_TwoWay() { @@ -70,11 +82,19 @@ export function test_Bindable_Bind_ToTarget_TwoWay() { obj.bind(options, model); obj.set('text', 'Changed'); - TKUnit.assertEqual(model.get('name'), 'Changed', 'Two-way binding not updating the source when target is changed.'); + TKUnit.assertEqual( + model.get('name'), + 'Changed', + 'Two-way binding not updating the source when target is changed.' + ); model.set('name', 'John'); - TKUnit.assertEqual(obj.get('text'), 'John', 'Two-way binding not updating the target when source is changed.'); + TKUnit.assertEqual( + obj.get('text'), + 'John', + 'Two-way binding not updating the target when source is changed.' + ); } export function test_Bindable_Bind_ToBindingContext_OneWay() { @@ -91,7 +111,10 @@ export function test_Bindable_Bind_ToBindingContext_OneWay() { obj.set('text', 'local'); obj.bindingContext = model; - TKUnit.assert(obj.get('text') === 'John', 'Binding to a context does not update the target property.'); + TKUnit.assert( + obj.get('text') === 'John', + 'Binding to a context does not update the target property.' + ); } export function test_Bindable_Bind_ToBindingContext_TwoWay() { @@ -110,11 +133,19 @@ export function test_Bindable_Bind_ToBindingContext_TwoWay() { obj.set('text', 'local'); obj.bindingContext = model; - TKUnit.assertEqual(obj.get('text'), 'John', 'Binding to a context does not update the target property.'); + TKUnit.assertEqual( + obj.get('text'), + 'John', + 'Binding to a context does not update the target property.' + ); obj.set('text', 'local'); - TKUnit.assertEqual(model.get('name'), 'local', 'Two-way binding to a context does not update the source property.'); + TKUnit.assertEqual( + model.get('name'), + 'local', + 'Two-way binding to a context does not update the source property.' + ); } export function test_Bindable_Unbind() { @@ -150,7 +181,11 @@ export function test_bind_NoSource_WillUse_BindingContext() { }); const button =