-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
builder-tests.ts
50 lines (40 loc) · 2.05 KB
/
builder-tests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { Builder } from "@nativescript/core/ui/builder";
import { sanitizeModuleName } from "@nativescript/core/ui/builder/module-name-sanitizer";
import { assertEqual, assertNull, assertThrows, assertNotNull } from "../../tk-unit";
const COMPONENT_MODULE = "ui/builder/component-module";
const MISSING_MODULE = "ui/builder/missing-module";
const labelId = "label";
function getViewComponent(moduleName: string) {
return Builder.createViewFromEntry({ moduleName });
}
export function test_view_is_module_root_component() {
const view = getViewComponent(COMPONENT_MODULE);
const actualModule = view._moduleName;
assertEqual(actualModule, COMPONENT_MODULE, `View<${view}> is NOT root component of module <${COMPONENT_MODULE}>.`);
}
export function test_view_is_NOT_module_root_component() {
const view = getViewComponent(COMPONENT_MODULE);
const nestedView = view.getViewById(`${labelId}`);
const undefinedModule = nestedView._moduleName;
assertNull(undefinedModule, `View<${nestedView}> should NOT be a root component of a module.`);
}
export function test_create_view_from_entry_from_missing_module_throws() {
assertThrows(() => getViewComponent(MISSING_MODULE),
"Loading component from a missing module SHOULD throw an error.");
}
export function test_create_view_from_entry_with_path_with_slash() {
const view = getViewComponent("/" + COMPONENT_MODULE);
assertNotNull(view, `Module starting with "/" could not be loaded`);
}
export function test_create_view_from_entry_with_path_with_tilde() {
const view = getViewComponent("~/" + COMPONENT_MODULE);
assertNotNull(view, `Module starting with "~/" could not be loaded`);
}
export function test_sanitize_module_name_with_removable_extension() {
const moduleName = sanitizeModuleName("./xml-declaration/mainPage.xml");
assertEqual(moduleName, "./xml-declaration/mainPage");
}
export function test_sanitize_module_name_with_non_removable_extension() {
const moduleName = sanitizeModuleName("app/views/main.page");
assertEqual(moduleName, "app/views/main.page");
}