Skip to content

Commit 049e40b

Browse files
author
Nataliya Hristova
authored
Merge pull request #298 from NativeScript/Natalia-Hristova/ios-issue-1149
feat: add test for ios issue 1149
2 parents 9cc3399 + 8fd8e1b commit 049e40b

File tree

2 files changed

+60
-8
lines changed

2 files changed

+60
-8
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const Observable = require("tns-core-modules/data/observable").Observable;
2+
3+
function getMessage(counter) {
4+
if (counter <= 0) {
5+
return "Hoorraaay! You unlocked the NativeScript clicker achievement!";
6+
} else {
7+
return `${counter} taps left`;
8+
}
9+
}
10+
11+
function createViewModel() {
12+
const viewModel = new Observable();
13+
viewModel.counter = 42;
14+
viewModel.message = getMessage(viewModel.counter);
15+
16+
const url = NSURL.URLWithString("https://www.google.com/");
17+
18+
const downloadPhotoTask = NSURLSession.sharedSession.downloadTaskWithURLCompletionHandler(url, () => {
19+
console.log("response1: ", downloadPhotoTask.performSelector("response"));
20+
console.log("response2: ", downloadPhotoTask.response);
21+
});
22+
downloadPhotoTask.resume();
23+
24+
viewModel.onTap = () => {
25+
viewModel.counter--;
26+
viewModel.set("message", getMessage(viewModel.counter));
27+
};
28+
29+
return viewModel;
30+
}
31+
32+
exports.createViewModel = createViewModel;

tests/runtimes/ios/ios_runtime_tests.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def test_201_test_init_mocha_js_stacktrace(self):
6969

7070
def test_380_tns_run_ios_plugin_dependencies(self):
7171
"""
72-
issue https://github.com/NativeScript/ios-runtime/issues/890
72+
https://github.com/NativeScript/ios-runtime/issues/890
7373
Check app is running when reference plugin A - plugin A depends on plugin B which depends on plugin C.
7474
Plugin A has dependency only to plugin B.
7575
Old behavior (version < 4.0.0) was in plugin A to reference plugin B and C.
@@ -133,8 +133,8 @@ def test_385_methods_with_same_name_and_different_parameters(self):
133133

134134
def test_386_check_native_crash_will_not_crash_when_discardUncaughtJsExceptions_used(self):
135135
"""
136-
Test native crash will not crash the app when discardUncaughtJsExceptions used
137-
https://github.com/NativeScript/ios-runtime/issues/1051
136+
Test native crash will not crash the app when discardUncaughtJsExceptions used
137+
https://github.com/NativeScript/ios-runtime/issues/1051
138138
"""
139139
File.copy(os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'ios', 'files', 'ios-runtime-1051', 'app.js'),
140140
os.path.join(APP_PATH, 'app', 'app.js'), True)
@@ -161,9 +161,9 @@ def test_386_check_native_crash_will_not_crash_when_discardUncaughtJsExceptions_
161161

162162
def test_387_test_pointers_and_conversions_to_string(self):
163163
"""
164-
Test pointers and conversions to strings
165-
https://github.com/NativeScript/ios-runtime/pull/1069
166-
https://github.com/NativeScript/ios-runtime/issues/921
164+
Test pointers and conversions to strings
165+
https://github.com/NativeScript/ios-runtime/pull/1069
166+
https://github.com/NativeScript/ios-runtime/issues/921
167167
"""
168168
File.copy(os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'ios', 'files', 'ios-runtime-921', 'special-value',
169169
'main-view-model.js'),
@@ -268,7 +268,27 @@ def test_390_check_correct_name_of_internal_class_is_returned(self):
268268
period=5)
269269
assert result, 'NSStringFromClass function returns INCORRECT name of iOS internal class!'
270270

271-
def test_391_tns_run_ios_console_time(self):
271+
def test_391_native_properties_provided_by_internal_classes_are_available(self):
272+
"""
273+
Test native properties provided by internal classes are available
274+
https://github.com/NativeScript/ios-runtime/issues/1149
275+
"""
276+
277+
File.copy(os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'ios', 'files', 'ios-runtime-1149',
278+
'main-view-model.js'),
279+
os.path.join(APP_PATH, 'app', 'main-view-model.js'), True)
280+
281+
log = Tns.run_ios(app_name=APP_NAME, emulator=True)
282+
283+
# Verify app is running on device
284+
Device.wait_for_text(self.sim, text='Tap the button')
285+
286+
strings = ['response1: <NSHTTPURLResponse:', 'response2: <NSHTTPURLResponse:', 'Status Code: 200']
287+
result = Wait.until(lambda: all(string in File.read(log.log_file) for string in strings), timeout=300,
288+
period=5)
289+
assert result, 'It seems that native properties provided by internal classes are not available'
290+
291+
def test_398_tns_run_ios_console_time(self):
272292
Folder.clean(os.path.join(TEST_RUN_HOME, APP_NAME))
273293
Tns.create(app_name=APP_NAME, template=Template.HELLO_WORLD_NG.local_package, update=True)
274294
Tns.platform_add_ios(APP_NAME, framework_path=IOS.FRAMEWORK_PATH)
@@ -294,7 +314,7 @@ def test_391_tns_run_ios_console_time(self):
294314
console_time = ['CONSOLE INFO startup:']
295315
TnsLogs.wait_for_log(log_file=result.log_file, string_list=console_time)
296316

297-
def test_392_tns_run_ios_console_dir(self):
317+
def test_399_tns_run_ios_console_dir(self):
298318
# NOTE: This test depends on creation of app in test_391_tns_run_ios_console_time
299319
# Replace app.component.ts to use console.time() and console.timeEnd()
300320

0 commit comments

Comments
 (0)