Skip to content

Dtodorov/page templates tests #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Nov 14, 2017
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/iPhone7N/blankPageScreen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/iPhone7N/loginPageScreen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/iPhone7N/signupPageScreen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions tests/pageTemplates/addPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
'use strict';

const pathToPackage = require("global-modules-path").getPath("nativescript", "tns");

const tns = require(pathToPackage);

const checkFlavor = (flavor) => {
if (typeof flavor !== "string") {
return new Error("Flavor fust be string");
}
const isAngular= flavor.indexOf("ng") > -1;
const isTypeScript = flavor.indexOf("ts") > -1;
const isJs = flavor.indexOf("js") > -1;

if (isAngular) {
flavor = "Angular & TypeScript";
console.log("Flavor === ", flavor);
} else if (isTypeScript) {
flavor = "TypeScript";
console.log("Flavor === ", flavor);
} else if (isJs) {
flavor = "JavaScript";
console.log("Flavor === ", flavor);
} else {
return new Error("Invalid flavor!!!"); // TODO Print help with valid flavors
}

return(flavor);
}

const pageAction = () => {
const args = process.argv.slice(2, 6);
let appFlavor = '';
try {
appFlavor = checkFlavor(args[2]);
} catch(error) {
console.error(error);
}

const newPageName = args[0];
const options = {
displayName: args[1],
templateFlavor: appFlavor
}
const appPath = args[3];

tns.nsStarterKitsApplicationService.addPage(newPageName, options, appPath)
.then(function(details){
console.log('Details=== ', details)
})
.catch(function(err){
console.error('Error=== ', err)
})
};

Promise.all(tns.extensibilityService.loadExtensions())
.then(pageAction, pageAction);
57 changes: 57 additions & 0 deletions tests/pageTemplates/addPageNext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
'use strict';

const pathToPackage = require("global-modules-path").getPath("nativescript", "tns");

const tns = require(pathToPackage);

const checkFlavor = (flavor) => {
if (typeof flavor !== "string") {
return new Error("Flavor fust be string");
}
const isAngular= flavor.indexOf("ng") > -1;
const isTypeScript = flavor.indexOf("ts") > -1;
const isJs = flavor.indexOf("js") > -1;

if (isAngular) {
flavor = "Angular & TypeScript";
console.log("Flavor === ", flavor);
} else if (isTypeScript) {
flavor = "TypeScript";
console.log("Flavor === ", flavor);
} else if (isJs) {
flavor = "JavaScript";
console.log("Flavor === ", flavor);
} else {
return new Error("Invalid flavor!!!"); // TODO Print help with valid flavors
}

return(flavor);
}

const pageAction = () => {
const args = process.argv.slice(2, 6);
let appFlavor = '';
try {
appFlavor = checkFlavor(args[2]);
} catch(error) {
console.error(error);
}

const newPageName = args[0];
const options = {
displayName: args[1],
templateFlavor: appFlavor
}
const appPath = args[3];

tns.nsStarterKitsApplicationService.addPage(newPageName, options, appPath, "next")
.then(function(details){
console.log('Details=== ', details)
})
.catch(function(err){
console.error('Error=== ', err)
})
};

Promise.all(tns.extensibilityService.loadExtensions())
.then(pageAction, pageAction);
163 changes: 163 additions & 0 deletions tests/pageTemplates/page_templates_tests_android.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
"""
Verify pages templates looks ok
"""

import fileinput
import sys
import unittest

from nose_parameterized import parameterized

from core.base_class.BaseClass import BaseClass
from core.device.device import Device
from core.device.emulator import Emulator
from core.npm.npm import Npm
from core.osutils.command import *
from core.osutils.folder import Folder
from core.settings.settings import EMULATOR_ID, EMULATOR_NAME, TEST_RUN_HOME
from core.tns.tns import Tns


class PageTemplatesTestsAndroid(BaseClass):
folder = os.path.join(TEST_RUN_HOME, 'tests', 'pageTemplates')
log = ""

@classmethod
def setUpClass(cls):
logfile = os.path.join('out', cls.__name__ + '.txt')
BaseClass.setUpClass(logfile)
Emulator.stop()
Emulator.ensure_available()
Folder.cleanup(cls.app_name)
Folder.cleanup("extensions")
File.remove("user-settings.json")
output = Tns.run_tns_command(
command='extension install nativescript-starter-kits --profileDir ' + TEST_RUN_HOME)
assert "Successfully installed extension nativescript-starter-kits" in output
assert "Successfully loaded extension nativescript-starter-kits" in output
Tns.run_tns_command(command='usage-reporting disable --profileDir ' + TEST_RUN_HOME)
Tns.run_tns_command(command='error-reporting disable --profileDir ' + TEST_RUN_HOME)
Npm.install(package='global-modules-path', option='--save', folder=cls.folder)

base_url = "https://github.com/nativescript/"
Tns.create_app(app_name="blank-js", attributes={"--template": base_url + "template-blank"})
Tns.create_app(app_name="blank-ts", attributes={"--template": base_url + "template-blank-ts"})
Tns.create_app(app_name="blank-ng", attributes={"--template": base_url + "template-blank-ng"})

def setUp(self):
BaseClass.setUp(self)

def tearDown(self):
Tns.kill()
BaseClass.tearDown(self)

@classmethod
def tearDownClass(cls):
BaseClass.tearDownClass()

@parameterized.expand([
('login', 'loginPageScreen'),
('blank', 'blankPageScreen'),
('signup', 'signupPageScreen')
])
def test_javascript(self, page_type, expected_image):
self.log = Tns.run_android(attributes={'--path': 'blank-js', '--emulator': ''}, wait=False,
assert_success=False)
strings = ['Successfully synced', EMULATOR_ID]
Tns.wait_for_log(log_file=self.log, string_list=strings, timeout=150, check_interval=10)

# Add page to application
print(os.path)
cmd = 'node {addPageScript} {pageName} {page_type} js blank-js'.format(
addPageScript=os.path.join(self.folder, 'addPageNext.js'), pageName=page_type, page_type=page_type)
run(cmd)
strings = ['Successfully synced application', 'Successfully transferred', page_type, EMULATOR_ID]
Tns.wait_for_log(log_file=self.log, string_list=strings, timeout=150, check_interval=10)

# Set new page for home app page
text_to_search = 'application.start({ moduleName:'
text_to_replace = "application.start({ moduleName: " + "\"{name}/{name}-page\"".format(name=page_type) + \
" });\n"
for line in fileinput.input("blank-js/app/app.js", inplace=True):
if line.strip().startswith(text_to_search):
line = text_to_replace
sys.stdout.write(line)

strings = ['Successfully synced application', 'Successfully transferred', 'app.js', EMULATOR_ID]
Tns.wait_for_log(log_file=self.log, string_list=strings, timeout=150, check_interval=10)

# Verify android looks ok
Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID, expected_image=expected_image,
tolerance=3.0)

@parameterized.expand([
('login', 'loginPageScreen'),
('blank', 'blankPageScreen'),
('signup', 'signupPageScreen')
])
def test_typescript(self, page_type, expected_image):
self.log = Tns.run_android(attributes={'--path': 'blank-ts', '--emulator': ''}, wait=False,
assert_success=False)
strings = ['Successfully synced', EMULATOR_ID]
Tns.wait_for_log(log_file=self.log, string_list=strings, timeout=150, check_interval=10)

# Add page to application
print(os.path)
cmd = 'node {addPageScript} {pageName} {page_type} ts blank-ts'.format(
addPageScript=os.path.join(self.folder, 'addPageNext.js'), pageName=page_type, page_type=page_type)
run(cmd)
strings = ['Successfully synced application', 'Successfully transferred', page_type, EMULATOR_ID]
Tns.wait_for_log(log_file=self.log, string_list=strings, timeout=150, check_interval=10)

# Set new page for home app page
text_to_search = 'app.start({ moduleName:'
text_to_replace = "app.start({ moduleName: " + "\"{name}/{name}-page\"".format(name=page_type) + "});\n"

for line in fileinput.input("blank-ts/app/app.ts", inplace=True):
if line.strip().startswith(text_to_search):
line = text_to_replace
sys.stdout.write(line)

# Verify android looks ok
Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID, expected_image=expected_image,
tolerance=3.0)

@parameterized.expand([
('login', 'loginPageScreen'),
('blank', 'blankPageScreen'),
('signup', 'signupPageScreen'),
])
def test_angular(self, page_type, expected_image):
self.log = Tns.run_android(attributes={'--path': 'blank-ng', '--emulator': ''}, wait=False,
assert_success=False)
strings = ['Successfully synced', EMULATOR_ID]
Tns.wait_for_log(log_file=self.log, string_list=strings, timeout=150, check_interval=10)

# Add page to application
print(os.path)
cmd = 'node {addPageScript} {pageName} {page_type} ng blank-ng'.format(
addPageScript=os.path.join(self.folder, 'addPageNext.js'), pageName=page_type, page_type=page_type)
run(cmd)
strings = ['Successfully synced application', 'Successfully transferred', page_type, EMULATOR_ID]
Tns.wait_for_log(log_file=self.log, string_list=strings, timeout=150, check_interval=10)

# Set new page for home app page
text_to_search = '{ path: "", redirectTo: '
text_to_replace = "{ path: \"\", redirectTo: \"" + "/{name}\"".format(name=page_type) + \
", pathMatch: \"full\" },\n"
for line in fileinput.input("blank-ng/app/app-routing.module.ts", inplace=True):
if line.strip().startswith(text_to_search):
line = text_to_replace
sys.stdout.write(line)

text_to_search = "loadChildren:"
text_to_replace = "{" + "path: \"{name}\",".format(
name=page_type) + " loadChildren: \"./{name}/{name}.module#{name}Module\"".format(name=page_type) + "}\n"
for line in fileinput.input("blank-ng/app/app-routing.module.ts", inplace=True):
if line.strip().startswith(text_to_search):
line = text_to_replace
sys.stdout.write(line)

# Verify android looks ok
Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID, expected_image=expected_image,
tolerance=3.0)
Loading