|
| 1 | +import os |
| 2 | +import unittest |
1 | 3 | from core.base_test.tns_test import TnsTest
|
| 4 | +from core.base_test.tns_run_test import TnsRunTest |
| 5 | +from core.enums.os_type import OSType |
| 6 | +from core.enums.platform_type import Platform |
| 7 | +from core.settings import Settings |
| 8 | +from core.utils.file_utils import File, Folder |
| 9 | +from data.sync.hello_world_ng import preview_sync_hello_world_ng |
| 10 | +from data.templates import Template |
| 11 | +from products.nativescript.tns import Tns |
| 12 | +from products.nativescript.preview_helpers import Preview |
2 | 13 |
|
3 | 14 |
|
4 |
| -class TnsRunPreviewNGTests(TnsTest): |
| 15 | +class TnsPreviewNGTests(TnsRunTest): |
| 16 | + app_name = Settings.AppName.DEFAULT |
| 17 | + source_project_dir = os.path.join(Settings.TEST_RUN_HOME, app_name) |
| 18 | + target_project_dir = os.path.join(Settings.TEST_RUN_HOME, 'data', 'temp', app_name) |
5 | 19 |
|
6 | 20 | @classmethod
|
7 | 21 | def setUpClass(cls):
|
8 |
| - TnsTest.setUpClass() |
| 22 | + TnsRunTest.setUpClass() |
| 23 | + |
| 24 | + # Download Preview and Playground packages |
| 25 | + Preview.get_app_packages() |
| 26 | + |
| 27 | + # Install Preview and Playground |
| 28 | + Preview.install_preview_app(cls.emu, Platform.ANDROID) |
| 29 | + if Settings.HOST_OS is OSType.OSX: |
| 30 | + Preview.install_preview_app(cls.sim, Platform.IOS) |
| 31 | + Preview.install_playground_app(cls.sim, Platform.IOS) |
| 32 | + |
| 33 | + # Create app |
| 34 | + Tns.create(app_name=cls.app_name, template=Template.HELLO_WORLD_NG.local_package, update=True) |
| 35 | + src = os.path.join(Settings.TEST_RUN_HOME, 'assets', 'logs', 'hello-world-ng', 'main.ts') |
| 36 | + target = os.path.join(Settings.TEST_RUN_HOME, cls.app_name, 'src') |
| 37 | + File.copy(src=src, target=target) |
| 38 | + src = os.path.join(Settings.TEST_RUN_HOME, 'assets', 'logs', 'hello-world-ng', 'items.component.ts') |
| 39 | + target = os.path.join(Settings.TEST_RUN_HOME, cls.app_name, 'src', 'app', 'item') |
| 40 | + File.copy(src=src, target=target) |
| 41 | + |
| 42 | + # Copy TestApp to data folder. |
| 43 | + Folder.copy(source=cls.source_project_dir, target=cls.target_project_dir) |
| 44 | + |
| 45 | + def setUp(self): |
| 46 | + TnsTest.setUp(self) |
| 47 | + # "src" folder of TestApp will be restored before each test. |
| 48 | + # This will ensure failures in one test do not cause common failures. |
| 49 | + source_src = os.path.join(self.target_project_dir, 'src') |
| 50 | + target_src = os.path.join(self.source_project_dir, 'src') |
| 51 | + Folder.clean(target_src) |
| 52 | + Folder.copy(source=source_src, target=target_src) |
| 53 | + |
| 54 | + |
| 55 | +class PreviewNGTests(TnsPreviewNGTests): |
| 56 | + |
| 57 | + def test_100_preview_android(self): |
| 58 | + """Preview project on emulator. Make valid changes in TS, CSS and HTML""" |
| 59 | + preview_sync_hello_world_ng(app_name=self.app_name, platform=Platform.ANDROID, |
| 60 | + device=self.emu, instrumented=True) |
| 61 | + |
| 62 | + @unittest.skipIf(Settings.HOST_OS != OSType.OSX, 'iOS tests can be executed only on macOS.') |
| 63 | + def test_100_preview_ios(self): |
| 64 | + """Preview project on simulator. Make valid changes in TS, CSS and HTML""" |
| 65 | + preview_sync_hello_world_ng(app_name=self.app_name, platform=Platform.IOS, |
| 66 | + device=self.sim, instrumented=True) |
| 67 | + |
| 68 | + def test_200_preview_android_bundle(self): |
| 69 | + """Preview project on emulator with --bundle. Make valid changes in TS, CSS and HTML""" |
| 70 | + preview_sync_hello_world_ng(app_name=self.app_name, platform=Platform.ANDROID, |
| 71 | + device=self.emu, instrumented=True, bundle=True) |
| 72 | + |
| 73 | + @unittest.skipIf(Settings.HOST_OS != OSType.OSX, 'iOS tests can be executed only on macOS.') |
| 74 | + def test_200_preview_ios_hmr(self): |
| 75 | + """Preview project on simulator with --bundle. Make valid changes in TS, CSS and HTML""" |
| 76 | + preview_sync_hello_world_ng(app_name=self.app_name, platform=Platform.IOS, |
| 77 | + device=self.sim, instrumented=True, bundle=True) |
| 78 | + |
| 79 | + def test_205_preview_android_hmr(self): |
| 80 | + """Preview project on emulator with --hmr. Make valid changes in TS, CSS and HTML""" |
| 81 | + preview_sync_hello_world_ng(app_name=self.app_name, platform=Platform.ANDROID, |
| 82 | + device=self.emu, instrumented=True, hmr=True) |
| 83 | + |
| 84 | + @unittest.skipIf(Settings.HOST_OS != OSType.OSX, 'iOS tests can be executed only on macOS.') |
| 85 | + def test_205_preview_ios_hmr(self): |
| 86 | + """Preview project on simulator with --hmr. Make valid changes in TS, CSS and HTML""" |
| 87 | + preview_sync_hello_world_ng(app_name=self.app_name, platform=Platform.IOS, |
| 88 | + device=self.sim, instrumented=True, hmr=True) |
0 commit comments