|
| 1 | +""" |
| 2 | +Tests for `ng g` during livesync. |
| 3 | +""" |
| 4 | +import os |
| 5 | +import unittest |
| 6 | + |
| 7 | +from core.base_test.tns_run_test import TnsRunTest |
| 8 | +from core.enums.app_type import AppType |
| 9 | +from core.enums.os_type import OSType |
| 10 | +from core.enums.platform_type import Platform |
| 11 | +from core.settings import Settings |
| 12 | +from core.utils.file_utils import Folder, File |
| 13 | +from products.angular.ng import NG, NS_SCHEMATICS |
| 14 | +from products.nativescript.tns import Tns |
| 15 | +from products.nativescript.tns_assert import TnsAssert |
| 16 | +from products.nativescript.tns_logs import TnsLogs |
| 17 | +from products.nativescript.tns_paths import TnsPaths |
| 18 | + |
| 19 | + |
| 20 | +class NGGenE2ETestsNS(TnsRunTest): |
| 21 | + app_name = Settings.AppName.DEFAULT |
| 22 | + app_path = TnsPaths.get_app_path(app_name=app_name) |
| 23 | + |
| 24 | + @classmethod |
| 25 | + def setUpClass(cls): |
| 26 | + TnsRunTest.setUpClass() |
| 27 | + NG.kill() |
| 28 | + |
| 29 | + def setUp(self): |
| 30 | + TnsRunTest.setUp(self) |
| 31 | + NG.kill() |
| 32 | + |
| 33 | + def tearDown(self): |
| 34 | + NG.kill() |
| 35 | + TnsRunTest.tearDown(self) |
| 36 | + |
| 37 | + def test_100_ns_generate_during_run_android(self): |
| 38 | + NGGenE2ETestsNS.workflow(app_name=self.app_name, device=self.emu, platform=Platform.ANDROID, shared=False) |
| 39 | + |
| 40 | + @unittest.skipIf(Settings.HOST_OS != OSType.OSX, 'Skip iOS tests on non macOS machines.') |
| 41 | + def test_100_ns_generate_during_run_ios(self): |
| 42 | + NGGenE2ETestsNS.workflow(app_name=self.app_name, device=self.sim, platform=Platform.IOS, shared=False) |
| 43 | + |
| 44 | + def test_200_shared_generate_during_run_android(self): |
| 45 | + NGGenE2ETestsNS.workflow(app_name=self.app_name, device=self.emu, platform=Platform.ANDROID, shared=True) |
| 46 | + |
| 47 | + @unittest.skipIf(Settings.HOST_OS != OSType.OSX, 'Skip iOS tests on non macOS machines.') |
| 48 | + def test_200_shared_generate_during_run_ios(self): |
| 49 | + NGGenE2ETestsNS.workflow(app_name=self.app_name, device=self.sim, platform=Platform.IOS, shared=True) |
| 50 | + |
| 51 | + @staticmethod |
| 52 | + def workflow(app_name, device, platform, shared): |
| 53 | + # Create an app |
| 54 | + app_path = TnsPaths.get_app_path(app_name=app_name) |
| 55 | + Folder.clean(app_path) |
| 56 | + NG.new(collection=NS_SCHEMATICS, project=app_name, shared=shared) |
| 57 | + TnsAssert.created(app_name=app_name, app_data=None) |
| 58 | + |
| 59 | + # Run app initially |
| 60 | + text = 'TAP' |
| 61 | + if shared: |
| 62 | + text = 'Welcome to' |
| 63 | + result = Tns.run(app_name=app_name, platform=platform, emulator=True, hmr=True) |
| 64 | + strings = TnsLogs.run_messages(app_name=app_name, platform=platform, bundle=True, hmr=True, app_type=AppType.NG) |
| 65 | + TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=300) |
| 66 | + device.wait_for_text(text=text) |
| 67 | + |
| 68 | + # Generate module and component |
| 69 | + NG.exec_command(command='g m module-test', cwd=app_path) |
| 70 | + NG.exec_command(command='g c module-test/component-test', cwd=app_path) |
| 71 | + |
| 72 | + # Update app.modules.ts |
| 73 | + app_module_name = 'app.module.ts' |
| 74 | + app_module_path = os.path.join(app_path, 'app', app_module_name) |
| 75 | + if shared: |
| 76 | + app_module_name = 'app.module.tns.ts' |
| 77 | + app_module_path = os.path.join(app_path, 'src', 'app', app_module_name) |
| 78 | + old_string = "import { HomeComponent } from './home/home.component';" |
| 79 | + new_string = "import { ComponentTestComponent } from './module-test/component-test/component-test.component';" |
| 80 | + File.replace(path=app_module_path, old_string=old_string, new_string=new_string) |
| 81 | + File.replace(path=app_module_path, old_string='HomeComponent,', new_string='ComponentTestComponent,') |
| 82 | + |
| 83 | + # Update app-routing.module.ts |
| 84 | + app_routing_module_name = 'app-routing.module.ts' |
| 85 | + app_routing_module_path = os.path.join(app_path, 'app', app_routing_module_name) |
| 86 | + if shared: |
| 87 | + app_routing_module_name = 'app.routes.ts' |
| 88 | + app_routing_module_path = os.path.join(app_path, 'src', 'app', app_routing_module_name) |
| 89 | + old_string = "import { HomeComponent } from './home/home.component';" |
| 90 | + new_string = "import { ComponentTestComponent } from './module-test/component-test/component-test.component';" |
| 91 | + File.replace(path=app_routing_module_path, old_string=old_string, new_string=new_string) |
| 92 | + File.replace(path=app_routing_module_path, old_string='HomeComponent', new_string='ComponentTestComponent') |
| 93 | + |
| 94 | + # Verify app is updated |
| 95 | + logs = [app_module_name.replace('.tns', ''), app_routing_module_name.replace('.tns', ''), |
| 96 | + 'Successfully synced application'] |
| 97 | + TnsLogs.wait_for_log(log_file=result.log_file, string_list=logs, timeout=120) |
| 98 | + device.wait_for_text(text='component-test works!') |
0 commit comments