mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
test: refactoring and formatting
This commit is contained in:
committed by
Martin Yankov
parent
96b5cb23a8
commit
9c3ed73646
@@ -12,13 +12,15 @@ import { ios as iosUtils } from "tns-core-modules/utils/utils";
|
|||||||
import * as commonTests from "./common-layout-tests";
|
import * as commonTests from "./common-layout-tests";
|
||||||
import * as helper from "../helper";
|
import * as helper from "../helper";
|
||||||
import { parse } from "tns-core-modules/ui/builder";
|
import { parse } from "tns-core-modules/ui/builder";
|
||||||
import { dipToDp, left, top, right, bottom, height, width,
|
import {
|
||||||
|
dipToDp, left, top, right, bottom, height, width,
|
||||||
paddingLeft, paddingTop, paddingRight, paddingBottom,
|
paddingLeft, paddingTop, paddingRight, paddingBottom,
|
||||||
equal, closeEnough, notEqual, check,
|
equal, closeEnough, notEqual, check,
|
||||||
heightEqual, widthEqual,
|
heightEqual, widthEqual,
|
||||||
isLeftAlignedWith, isRightAlignedWith, isTopAlignedWith, isBottomAlignedWith,
|
isLeftAlignedWith, isRightAlignedWith, isTopAlignedWith, isBottomAlignedWith,
|
||||||
isLeftOf, isRightOf, isBelow, isAbove,
|
isLeftOf, isRightOf, isBelow, isAbove,
|
||||||
isLeftWith, isAboveWith, isRightWith, isBelowWith } from "./layout-tests-helper";
|
isLeftWith, isAboveWith, isRightWith, isBelowWith
|
||||||
|
} from "./layout-tests-helper";
|
||||||
|
|
||||||
export class SafeAreaTests extends testModule.UITest<any> {
|
export class SafeAreaTests extends testModule.UITest<any> {
|
||||||
|
|
||||||
@@ -26,7 +28,6 @@ export class SafeAreaTests extends testModule.UITest<any> {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Start Refactor
|
|
||||||
private executeSnippet<U extends { root: view.View }>(ui: U, setup: (ui: U) => void, test: (ui: U) => void): void {
|
private executeSnippet<U extends { root: view.View }>(ui: U, setup: (ui: U) => void, test: (ui: U) => void): void {
|
||||||
function waitUntilTestElementLayoutIsValid(view: view.View, timeoutSec?: number): void {
|
function waitUntilTestElementLayoutIsValid(view: view.View, timeoutSec?: number): void {
|
||||||
TKUnit.waitUntilReady(() => {
|
TKUnit.waitUntilReady(() => {
|
||||||
@@ -44,11 +45,19 @@ export class SafeAreaTests extends testModule.UITest<any> {
|
|||||||
private noop() {
|
private noop() {
|
||||||
// no operation
|
// no operation
|
||||||
};
|
};
|
||||||
// TODO: End Refactor
|
|
||||||
|
|
||||||
// Common
|
// Common
|
||||||
|
private getViews(template: string) {
|
||||||
|
let root = parse(template);
|
||||||
|
return {
|
||||||
|
root,
|
||||||
|
child0: root.getViewById("child0") as view.View,
|
||||||
|
child1: root.getViewById("child1") as view.View
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
private layout_in_full_screen_test(layout: view.View) {
|
private layout_in_full_screen_test(layout: view.View) {
|
||||||
const fullScreenOrigin = { x: 0, y: 0};
|
const fullScreenOrigin = { x: 0, y: 0 };
|
||||||
if (platform.isIOS && iosUtils.MajorVersion < 11) {
|
if (platform.isIOS && iosUtils.MajorVersion < 11) {
|
||||||
const safeAreaOrigin = layout.parent.nativeViewProtected.safeAreaLayoutGuide.layoutFrame.origin;
|
const safeAreaOrigin = layout.parent.nativeViewProtected.safeAreaLayoutGuide.layoutFrame.origin;
|
||||||
fullScreenOrigin.x += dipToDp(safeAreaOrigin.x);
|
fullScreenOrigin.x += dipToDp(safeAreaOrigin.x);
|
||||||
@@ -68,21 +77,13 @@ export class SafeAreaTests extends testModule.UITest<any> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Absolute
|
// Absolute
|
||||||
private getAbsoluteViews(template: string) {
|
|
||||||
let root = parse(template);
|
|
||||||
return {
|
|
||||||
root,
|
|
||||||
child0: root.getViewById("child0") as view.View,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
public test_absolute_in_full_screen() {
|
public test_absolute_in_full_screen() {
|
||||||
const snippet = `
|
const snippet = `
|
||||||
<AbsoluteLayout id="abs" backgroundColor="Crimson"></AbsoluteLayout>
|
<AbsoluteLayout id="abs" backgroundColor="Crimson"></AbsoluteLayout>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
this.executeSnippet(
|
this.executeSnippet(
|
||||||
this.getAbsoluteViews(snippet),
|
this.getViews(snippet),
|
||||||
this.noop,
|
this.noop,
|
||||||
({ root }) => { this.layout_in_full_screen_test(root); }
|
({ root }) => { this.layout_in_full_screen_test(root); }
|
||||||
);
|
);
|
||||||
@@ -99,7 +100,7 @@ export class SafeAreaTests extends testModule.UITest<any> {
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
this.executeSnippet(
|
this.executeSnippet(
|
||||||
this.getAbsoluteViews(snippet),
|
this.getViews(snippet),
|
||||||
this.noop,
|
this.noop,
|
||||||
({ root, child0 }) => {
|
({ root, child0 }) => {
|
||||||
const insets = root.getSafeAreaInsets();
|
const insets = root.getSafeAreaInsets();
|
||||||
@@ -128,7 +129,7 @@ export class SafeAreaTests extends testModule.UITest<any> {
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
this.executeSnippet(
|
this.executeSnippet(
|
||||||
this.getAbsoluteViews(snippet),
|
this.getViews(snippet),
|
||||||
this.noop,
|
this.noop,
|
||||||
({ root, child0 }) => {
|
({ root, child0 }) => {
|
||||||
isLeftAlignedWith(root, child0);
|
isLeftAlignedWith(root, child0);
|
||||||
@@ -243,16 +244,19 @@ export class SafeAreaTests extends testModule.UITest<any> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Flexbox
|
||||||
|
|
||||||
|
|
||||||
// Grid
|
// Grid
|
||||||
private getGridViews (template: string) {
|
private getGridViews(template: string) {
|
||||||
let root = parse(template);
|
let root = parse(template);
|
||||||
return {
|
return {
|
||||||
root,
|
root,
|
||||||
grid: root.getViewById("grid") as GridLayout,
|
grid: root.getViewById("grid") as GridLayout,
|
||||||
cells: [
|
cells: [
|
||||||
[ root.getViewById("cell00") as view.View, root.getViewById("cell01") as view.View, root.getViewById("cell02") as view.View ],
|
[root.getViewById("cell00") as view.View, root.getViewById("cell01") as view.View, root.getViewById("cell02") as view.View],
|
||||||
[ root.getViewById("cell10") as view.View, root.getViewById("cell11") as view.View, root.getViewById("cell12") as view.View ],
|
[root.getViewById("cell10") as view.View, root.getViewById("cell11") as view.View, root.getViewById("cell12") as view.View],
|
||||||
[ root.getViewById("cell20") as view.View, root.getViewById("cell21") as view.View, root.getViewById("cell22") as view.View ]
|
[root.getViewById("cell20") as view.View, root.getViewById("cell21") as view.View, root.getViewById("cell22") as view.View]
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -337,7 +341,7 @@ export class SafeAreaTests extends testModule.UITest<any> {
|
|||||||
this.executeSnippet(
|
this.executeSnippet(
|
||||||
this.getGridViews(snippet),
|
this.getGridViews(snippet),
|
||||||
this.noop,
|
this.noop,
|
||||||
({ root, grid, cells }) => {
|
({ root, grid, cells }) => {
|
||||||
isLeftAlignedWith(grid, cells[0][0]);
|
isLeftAlignedWith(grid, cells[0][0]);
|
||||||
isLeftAlignedWith(grid, cells[1][0]);
|
isLeftAlignedWith(grid, cells[1][0]);
|
||||||
isLeftAlignedWith(grid, cells[2][0]);
|
isLeftAlignedWith(grid, cells[2][0]);
|
||||||
@@ -368,22 +372,13 @@ export class SafeAreaTests extends testModule.UITest<any> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Stack
|
// Stack
|
||||||
private getStackViews(template: string) {
|
|
||||||
let root = parse(template);
|
|
||||||
return {
|
|
||||||
root,
|
|
||||||
child0: root.getViewById("child0") as view.View,
|
|
||||||
child1: root.getViewById("child1") as view.View
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
public test_stack_in_full_screen() {
|
public test_stack_in_full_screen() {
|
||||||
const snippet = `
|
const snippet = `
|
||||||
<StackLayout id="stack" backgroundColor="Crimson"></StackLayout>
|
<StackLayout id="stack" backgroundColor="Crimson"></StackLayout>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
this.executeSnippet(
|
this.executeSnippet(
|
||||||
this.getStackViews(snippet),
|
this.getViews(snippet),
|
||||||
this.noop,
|
this.noop,
|
||||||
({ root }) => { this.layout_in_full_screen_test(root); }
|
({ root }) => { this.layout_in_full_screen_test(root); }
|
||||||
);
|
);
|
||||||
@@ -423,7 +418,7 @@ export class SafeAreaTests extends testModule.UITest<any> {
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
this.executeSnippet(
|
this.executeSnippet(
|
||||||
this.getStackViews(snippet),
|
this.getViews(snippet),
|
||||||
this.noop,
|
this.noop,
|
||||||
({ root, child0, child1 }) => {
|
({ root, child0, child1 }) => {
|
||||||
const insets = root.getSafeAreaInsets();
|
const insets = root.getSafeAreaInsets();
|
||||||
@@ -483,7 +478,7 @@ export class SafeAreaTests extends testModule.UITest<any> {
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
this.executeSnippet(
|
this.executeSnippet(
|
||||||
this.getStackViews(snippet),
|
this.getViews(snippet),
|
||||||
this.noop,
|
this.noop,
|
||||||
({ root, child0, child1 }) => {
|
({ root, child0, child1 }) => {
|
||||||
const insets = root.getSafeAreaInsets();
|
const insets = root.getSafeAreaInsets();
|
||||||
@@ -562,9 +557,9 @@ export class SafeAreaTests extends testModule.UITest<any> {
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
this.executeSnippet(
|
this.executeSnippet(
|
||||||
this.getStackViews(snippet),
|
this.getViews(snippet),
|
||||||
this.noop,
|
this.noop,
|
||||||
({ root, child0, child1 }) => {
|
({ root, child0 }) => {
|
||||||
isLeftAlignedWith(root, child0);
|
isLeftAlignedWith(root, child0);
|
||||||
isTopAlignedWith(root, child0);
|
isTopAlignedWith(root, child0);
|
||||||
isRightAlignedWith(root, child0);
|
isRightAlignedWith(root, child0);
|
||||||
@@ -573,22 +568,13 @@ export class SafeAreaTests extends testModule.UITest<any> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Wrap
|
// Wrap
|
||||||
private getWrapViews(template: string) {
|
|
||||||
let root = parse(template);
|
|
||||||
return {
|
|
||||||
root,
|
|
||||||
child0: root.getViewById("child0") as view.View,
|
|
||||||
child1: root.getViewById("child1") as view.View,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
public test_wrap_in_full_screen() {
|
public test_wrap_in_full_screen() {
|
||||||
const snippet = `
|
const snippet = `
|
||||||
<WrapLayout id="wrap" backgroundColor="Crimson"></WrapLayout>
|
<WrapLayout id="wrap" backgroundColor="Crimson"></WrapLayout>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
this.executeSnippet(
|
this.executeSnippet(
|
||||||
this.getWrapViews(snippet),
|
this.getViews(snippet),
|
||||||
this.noop,
|
this.noop,
|
||||||
({ root }) => { this.layout_in_full_screen_test(root); }
|
({ root }) => { this.layout_in_full_screen_test(root); }
|
||||||
);
|
);
|
||||||
@@ -603,7 +589,7 @@ export class SafeAreaTests extends testModule.UITest<any> {
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
this.executeSnippet(
|
this.executeSnippet(
|
||||||
this.getWrapViews(snippet),
|
this.getViews(snippet),
|
||||||
this.noop,
|
this.noop,
|
||||||
({ root, child0, child1 }) => {
|
({ root, child0, child1 }) => {
|
||||||
const insets = root.getSafeAreaInsets();
|
const insets = root.getSafeAreaInsets();
|
||||||
@@ -626,7 +612,7 @@ export class SafeAreaTests extends testModule.UITest<any> {
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
this.executeSnippet(
|
this.executeSnippet(
|
||||||
this.getWrapViews(snippet),
|
this.getViews(snippet),
|
||||||
this.noop,
|
this.noop,
|
||||||
({ root, child0, child1 }) => {
|
({ root, child0, child1 }) => {
|
||||||
const insets = root.getSafeAreaInsets();
|
const insets = root.getSafeAreaInsets();
|
||||||
@@ -722,16 +708,15 @@ export class SafeAreaTests extends testModule.UITest<any> {
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
this.executeSnippet(
|
this.executeSnippet(
|
||||||
this.getWrapViews(snippet),
|
this.getViews(snippet),
|
||||||
this.noop,
|
this.noop,
|
||||||
({ root, child0, child1 }) => {
|
({ root, child0 }) => {
|
||||||
isLeftAlignedWith(root, child0);
|
isLeftAlignedWith(root, child0);
|
||||||
isTopAlignedWith(root, child0);
|
isTopAlignedWith(root, child0);
|
||||||
isRightAlignedWith(root, child0);
|
isRightAlignedWith(root, child0);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createTestCase(): SafeAreaTests {
|
export function createTestCase(): SafeAreaTests {
|
||||||
|
|||||||
Reference in New Issue
Block a user