1
+ '''
2
+ Tests for the livesync command in context of Android emulator
3
+ '''
4
+
5
+ # C0103 - Invalid %s name "%s"
6
+ # C0111 - Missing docstring
7
+ # R0201 - Method could be a function
8
+ # pylint: disable=C0103, C0111, R0201
9
+
10
+ import os , shutil , time , unittest
11
+
12
+ from helpers ._os_lib import cat_app_file_on_emulator , cleanup_folder , replace
13
+ from helpers ._tns_lib import ANDROID_RUNTIME_PATH , create_project_add_platform , run , livesync
14
+ from helpers .device import given_running_emulator , stop_emulators
15
+ from helpers .simulator import stop_simulators
16
+
17
+
18
+ class LiveSyncWindows (unittest .TestCase ):
19
+
20
+ @classmethod
21
+ def setUpClass (cls ):
22
+
23
+ # setup emulator
24
+ stop_emulators ()
25
+ stop_simulators ()
26
+
27
+ def setUp (self ):
28
+
29
+ print ""
30
+ print "#####"
31
+ print self .id ()
32
+ print "#####"
33
+ print ""
34
+
35
+ given_running_emulator ()
36
+ cleanup_folder ('TNS_App' )
37
+
38
+ def tearDown (self ):
39
+ cleanup_folder ('TNS_App' )
40
+
41
+ @classmethod
42
+ def tearDownClass (cls ):
43
+ stop_emulators ()
44
+
45
+ def test_001_livesync_android_xml_js_css_tns_files (self ):
46
+ create_project_add_platform (
47
+ proj_name = "TNS_App" ,
48
+ platform = "android" ,
49
+ framework_path = ANDROID_RUNTIME_PATH )
50
+ run (platform = "android" , device = "emulator-5554" , path = "TNS_App" )
51
+
52
+ replace ("TNS_App/app/main-page.xml" , "TAP" , "TEST" )
53
+ replace ("TNS_App/app/main-view-model.js" , "taps" , "clicks" )
54
+ replace ("TNS_App/app/app.css" , "30" , "20" )
55
+
56
+ replace ("TNS_App/node_modules/tns-core-modules/LICENSE" , "2015" , "9999" )
57
+ replace (
58
+ "TNS_App/node_modules/tns-core-modules/application/application-common.js" ,
59
+ "(\" globals\" );" ,
60
+ "(\" globals\" ); // test" )
61
+
62
+ livesync (
63
+ platform = "android" ,
64
+ emulator = True ,
65
+ device = "emulator-5554" ,
66
+ path = "TNS_App" )
67
+
68
+ output = cat_app_file_on_emulator ("TNSApp" , "app/main-page.xml" )
69
+ assert "<Button text=\" TEST\" tap=\" {{ tapAction }}\" />" in output
70
+ output = cat_app_file_on_emulator ("TNSApp" , "app/main-view-model.js" )
71
+ assert "this.set(\" message\" , this.counter + \" clicks left\" );" in output
72
+ output = cat_app_file_on_emulator ("TNSApp" , "app/app.css" )
73
+ assert "font-size: 20;" in output
74
+
75
+ output = cat_app_file_on_emulator ("TNSApp" , "app/tns_modules/LICENSE" )
76
+ assert "Copyright (c) 9999 Telerik AD" in output
77
+ output = cat_app_file_on_emulator ("TNSApp" , \
78
+ "app/tns_modules/application/application-common.js" )
79
+ assert "require(\" globals\" ); // test" in output
80
+
81
+ def test_201_livesync_android_add_files (self ):
82
+ create_project_add_platform (
83
+ proj_name = "TNS_App" ,
84
+ platform = "android" ,
85
+ framework_path = ANDROID_RUNTIME_PATH )
86
+ run (platform = "android" , device = "emulator-5554" , path = "TNS_App" )
87
+
88
+ shutil .copyfile ("TNS_App/app/main-page.xml" , "TNS_App/app/test.xml" )
89
+ shutil .copyfile ("TNS_App/app/main-page.js" , "TNS_App/app/test.js" )
90
+ shutil .copyfile ("TNS_App/app/app.css" , "TNS_App/app/test.css" )
91
+
92
+ os .makedirs ("TNS_App/app/test" )
93
+ shutil .copyfile (
94
+ "TNS_App/app/main-view-model.js" ,
95
+ "TNS_App/app/test/main-view-model.js" )
96
+ livesync (platform = "android" , device = "emulator-5554" , path = "TNS_App" )
97
+
98
+ time .sleep (1 )
99
+ output = cat_app_file_on_emulator ("TNSApp" , "app/test.xml" )
100
+ assert "<Button text=\" TAP\" tap=\" {{ tapAction }}\" />" in output
101
+ output = cat_app_file_on_emulator ("TNSApp" , "app/test.js" )
102
+ assert "page.bindingContext = vmModule.mainViewModel;" in output
103
+ output = cat_app_file_on_emulator ("TNSApp" , "app/test.css" )
104
+ assert "color: #284848;" in output
105
+ output = cat_app_file_on_emulator ("TNSApp" , "app/test/main-view-model.js" )
106
+ assert "HelloWorldModel.prototype.tapAction" in output
107
+
108
+ def test_301_livesync_before_run (self ):
109
+ create_project_add_platform (
110
+ proj_name = "TNS_App" ,
111
+ platform = "android" ,
112
+ framework_path = ANDROID_RUNTIME_PATH )
113
+ replace ("TNS_App/app/main-page.xml" , "TAP" , "TEST" )
114
+ livesync (platform = "android" , device = "emulator-5554" , path = "TNS_App" )
115
+
116
+ time .sleep (3 )
117
+ output = cat_app_file_on_emulator ("TNSApp" , "app/main-page.xml" )
118
+ assert "<Button text=\" TEST\" tap=\" {{ tapAction }}\" />" in output
119
+
0 commit comments