def ng_serve(self, prod=False):
     NG.serve(project=self.app_name, prod=prod)
     self.chrome.open(DEFAULT_WEB_URL)
     welcome_element = self.chrome.driver.find_element_by_xpath('//h1')
     assert 'Welcome to' in welcome_element.text, 'Failed to find welcome message.'
     Log.info('Welcome page served successfully.')
     NG.kill()
    def setUpClass(cls):
        TnsTest.setUpClass()
        NG.kill()
        Folder.clean(cls.app_path)

        # Create app
        NG.new(collection=NS_SCHEMATICS, project=cls.app_name, shared=False)
        TnsAssert.created(app_name=cls.app_name, app_data=None)
    def setUpClass(cls):
        TnsTest.setUpClass()
        NG.kill()
        Folder.clean(cls.app_path)

        # Create app
        NG.new(collection=NS_SCHEMATICS, project=cls.app_name, shared=False)
        # TODO: Rollback theme=False when schematics use @nativescript/theme
        TnsAssert.created(app_name=cls.app_name, app_data=None, theme=False)
    def test_003_generate_component_in_existing_modules(self):
        result = NG.exec_command(command='g m module-test2', cwd=self.app_path)
        assert 'CREATE app/module-test2/module-test2.module.ts' in result.output

        result = NG.exec_command(command='g c module-test2/component-name', cwd=self.app_path)
        assert 'CREATE app/module-test2/component-name/component-name.component.html' in result.output
        assert 'CREATE app/module-test2/component-name/component-name.component.ts' in result.output
        assert 'CREATE app/module-test2/component-name/component-name.component.css' in result.output
        assert 'UPDATE app/module-test2/module-test2.module.ts' in result.output
Exemple #5
0
 def ng_serve(self, prod=False):
     NG.serve(project=self.app_name, prod=prod)
     self.chrome.open(DEFAULT_WEB_URL)
     if "Angular CLI: 8.3" in NG.exec_command(command="version").output:
         element = self.chrome.driver.find_element(
             By.XPATH, '//*[contains(text(), "TestApp app is running!")]')
     else:
         element = self.chrome.driver.find_element(
             By.XPATH, '//*[contains(text(), "Welcome")]')
     assert element.is_displayed(), 'Failed to serve default NG project.'
     Log.info('Default NG web project loaded!')
     NG.kill()
Exemple #6
0
 def test_004_generate_master_detail(self):
     result = NG.exec_command(
         command='g master-detail --master=dogs --detail=dog',
         cwd=self.app_path)
     assert 'CREATE src/app/dogs/dog-detail/dog-detail.component.html' in result.output
     assert 'CREATE src/app/dogs/dog-detail/dog-detail.component.tns.html' in result.output
     assert 'CREATE src/app/dogs/dogs/dogs.component.html' in result.output
     assert 'CREATE src/app/dogs/dogs/dogs.component.tns.html' in result.output
     assert 'data.service.ts' in result.output
     assert 'dogs.module.ts' in result.output
Exemple #7
0
 def test_001_generate_component(self):
     result = NG.exec_command(command='g c component-test',
                              cwd=self.app_path)
     assert 'CREATE src/app/component-test/component-test.component.html' in result.output
     assert 'CREATE src/app/component-test/component-test.component.ts' in result.output
     assert 'CREATE src/app/component-test/component-test.component.css' in result.output
     assert 'CREATE src/app/component-test/component-test.component.tns.css' in result.output
     assert 'CREATE src/app/component-test/component-test.component.tns.html' in result.output
     assert 'UPDATE src/app/app.module.ts' in result.output
     assert 'UPDATE src/app/app.module.tns.ts' in result.output
 def test_300_help_ng_new(self):
     output = NG.exec_command('new --collection={0} --help'.format(NS_SCHEMATICS)).output
     assert '--sample' in output
     assert 'Specifies whether a sample master detail should be generated' in output
     assert '--shared' in output
     assert 'Specifies whether to generate a shared project or a {N} only' in output
     assert '--source-dir (-sd)' in output
     assert 'The path of the source directory' in output
     assert '--style' in output
     assert 'The file extension to be used for style files. Supported are css and scss' in output
     assert '--theme' in output
     assert 'Specifies whether the {N} theme for styling should be included' in output
     assert '--webpack' in output
     assert 'Specifies whether the new application has webpack set up' in output
Exemple #9
0
    def create_app(app_data, shared, sample, theme, style, prefix, source_dir, webpack):
        # Create shared project with sample data
        result = NG.new(collection=NS_SCHEMATICS, project=NGNewTests.app_name, theme=theme, shared=shared,
                        sample=sample, style=style, prefix=prefix, source_dir=source_dir, webpack=webpack)

        # Verify valid {N} app is created
        # Temporary do not assert theme is created because in schematics we still use nativescript-theme-core@1
        # TODO: Replace with theme=theme when schematics use @nativescript/theme
        TnsAssert.created(app_name=NGNewTests.app_name, app_data=app_data, theme=False, webpack=webpack)
        assert 'Directory is already under version control. Skipping initialization of git.' in result.output, \
            'Git init should be skipped because app is created already existing repo (the one with tests).'

        # Check sample
        if sample:
            # TODO: Implement it
            pass

        # Check theme
        if theme:
            assert App.is_dependency(app_name=NGNewTests.app_name, dependency='@nativescript/theme')
        else:
            assert not App.is_dependency(app_name=NGNewTests.app_name, dependency='@nativescript/theme')

        # Check styling
        if style is None or style is StylingType.CSS:
            assert 'app.css' in result.output
        else:
            assert 'app.android.scss' in result.output
            assert 'app.ios.scss' in result.output
            assert '_app-common.scss' in result.output

        # Check webpack
        if webpack:
            assert App.is_dev_dependency(app_name=NGNewTests.app_name, dependency='nativescript-dev-webpack')
        else:
            assert not App.is_dev_dependency(app_name=NGNewTests.app_name, dependency='nativescript-dev-webpack')

        # Check prefix
        if prefix is None:
            prefix = 'app'
        path = os.path.join(Settings.TEST_RUN_HOME, NGNewTests.app_name, 'angular.json')
        actual_prefix = JsonUtils.read(file_path=path)['projects'][NGNewTests.app_name]['prefix']
        assert str(actual_prefix) == prefix, 'Prefix not set in angular.json'

        # Check source dir exists (applicable only for shared projects).
        if shared:
            if source_dir is None:
                source_dir = 'src'
            assert Folder.exists(os.path.join(Settings.TEST_RUN_HOME, NGNewTests.app_name, source_dir))
    def test_02_add_nativescript(self):
        # Add {N} to existing web project
        result = NG.add(project=self.app_name,
                        schematics_package=Settings.Packages.NS_SCHEMATICS)

        # Verify output
        assert 'Adding @nativescript/schematics to angular.json' in result.output
        assert 'Adding {N} files' in result.output
        assert 'Adding NativeScript specific exclusions to .gitignore' in result.output
        assert 'Adding NativeScript run scripts to package.json' in result.output
        assert 'Modifying web tsconfig' in result.output
        assert 'Adding Sample Shared Component' in result.output
        assert 'Adding npm dependencies' in result.output

        # NG Serve (to check web is not broken by {N})
        self.ng_serve(prod=False)
        self.chrome.open(
            url='https://google.com/ncr'
        )  # change url to be sure next serve do not assert previous serve
    def workflow(app_name, device, platform, shared):
        # Create an app
        app_path = TnsPaths.get_app_path(app_name=app_name)
        Folder.clean(app_path)
        NG.new(collection=NS_SCHEMATICS, project=app_name, shared=shared)
        TnsAssert.created(app_name=app_name, app_data=None)

        # Run app initially
        text = 'TAP'
        if shared:
            text = 'Welcome to'
        result = Tns.run(app_name=app_name, platform=platform, emulator=True, hmr=True)
        strings = TnsLogs.run_messages(app_name=app_name, platform=platform, bundle=True, hmr=True, app_type=AppType.NG)
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=300)
        device.wait_for_text(text=text)

        # Generate module and component
        NG.exec_command(command='g m module-test', cwd=app_path)
        NG.exec_command(command='g c module-test/component-test', cwd=app_path)

        # Update app.modules.ts
        app_module_name = 'app.module.ts'
        app_module_path = os.path.join(app_path, 'app', app_module_name)
        if shared:
            app_module_name = 'app.module.tns.ts'
            app_module_path = os.path.join(app_path, 'src', 'app', app_module_name)
        old_string = "import { HomeComponent } from './home/home.component';"
        new_string = "import { ComponentTestComponent } from './module-test/component-test/component-test.component';"
        File.replace(path=app_module_path, old_string=old_string, new_string=new_string)
        File.replace(path=app_module_path, old_string='HomeComponent,', new_string='ComponentTestComponent,')

        # Update app-routing.module.ts
        app_routing_module_name = 'app-routing.module.ts'
        app_routing_module_path = os.path.join(app_path, 'app', app_routing_module_name)
        if shared:
            app_routing_module_name = 'app.routes.ts'
            app_routing_module_path = os.path.join(app_path, 'src', 'app', app_routing_module_name)
        old_string = "import { HomeComponent } from './home/home.component';"
        new_string = "import { ComponentTestComponent } from './module-test/component-test/component-test.component';"
        File.replace(path=app_routing_module_path, old_string=old_string, new_string=new_string)
        File.replace(path=app_routing_module_path, old_string='HomeComponent', new_string='ComponentTestComponent')

        # Verify app is updated
        logs = [app_module_name.replace('.tns', ''), app_routing_module_name.replace('.tns', ''),
                'Successfully synced application']
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=logs, timeout=120)
        device.wait_for_text(text='component-test works!')
Exemple #12
0
 def setUp(self):
     TnsRunTest.setUp(self)
     NG.kill()
     Folder.clean(self.app_path)
 def test_002_generate_module(self):
     result = NG.exec_command(command='g m module-test', cwd=self.app_path)
     assert 'CREATE app/module-test/module-test.module.ts' in result.output
 def tearDown(self):
     NG.kill()
     TnsTest.tearDown(self)
 def setUp(self):
     TnsTest.setUpClass()
     NG.kill()
Exemple #16
0
 def setUp(self):
     TnsRunTest.setUp(self)
     NG.kill()
Exemple #17
0
 def setUpClass(cls):
     TnsRunTest.setUpClass()
     NG.kill()
     NG.new(collection=None, project=cls.app_name)
     cls.chrome = Chrome()
 def setUpClass(cls):
     TnsRunTest.setUpClass()
     NG.kill()
Exemple #19
0
 def test_010_shared(self):
     NGNewTests.create_and_run(shared=True)
     NG.serve(project=self.app_name)
     NG.kill()
     NGNewTests.build_release()
     NG.serve(project=self.app_name, prod=True)