Files
NativeScript/tests/app/ui/layouts/layout-tests-helper.ts
Alexander Vakrilov cc97a16800 feat: Scoped Packages (#7911)
* chore: move tns-core-modules to nativescript-core

* chore: preparing compat generate script

* chore: add missing definitions

* chore: no need for http-request to be private

* chore: packages chore

* test: generate tests for tns-core-modules

* chore: add anroid module for consistency

* chore: add .npmignore

* chore: added privateModulesWhitelist

* chore(webpack): added bundle-entry-points

* chore: scripts

* chore: tests changed to use @ns/core

* test: add scoped-packages test project

* test: fix types

* test: update test project

* chore: build scripts

* chore: update build script

* chore: npm scripts cleanup

* chore: make the compat pgk work with old wp config

* test: generate diff friendly tests

* chore: create barrel exports

* chore: move files after rebase

* chore: typedoc config

* chore: compat mode

* chore: review of barrels

* chore: remove tns-core-modules import after rebase

* chore: dev workflow setup

* chore: update developer-workflow

* docs: experiment with API extractor

* chore: api-extractor and barrel exports

* chore: api-extractor configs

* chore: generate d.ts rollup with api-extractor

* refactor: move methods inside Frame

* chore: fic tests to use Frame static methods

* refactor: create Builder class

* refactor: use Builder class in tests

* refactor: include Style in ui barrel

* chore: separate compat build script

* chore: fix tslint errors

* chore: update NATIVESCRIPT_CORE_ARGS

* chore: fix compat pack

* chore: fix ui-test-app build with linked modules

* chore: Application, ApplicationSettings, Connectivity and Http

* chore: export Trace, Profiling and Utils

* refactor: Static create methods for ImageSource

* chore: fix deprecated usages of ImageSource

* chore: move Span and FormattedString to ui

* chore: add events-args and ImageSource to index files

* chore: check for CLI >= 6.2 when building for IOS

* chore: update travis build

* chore: copy Pod file to compat package

* chore: update error msg ui-tests-app

* refactor: Apply suggestions from code review

Co-Authored-By: Martin Yankov <m.i.yankov@gmail.com>

* chore: typings and refs

* chore: add missing d.ts files for public API

* chore: adress code review FB

* chore: update api-report

* chore: dev-workflow for other apps

* chore: api update

* chore: update api-report
2019-10-17 00:45:33 +03:00

111 lines
5.6 KiB
TypeScript

import { View, Length } from "@nativescript/core/ui/core/view";
import * as TKUnit from "../../tk-unit";
import { layout } from "@nativescript/core/utils/utils";
import round = layout.round;
export const dipToDp = layout.toDevicePixels;
const EPS = 1;
export function left(view: View): number { return round(dipToDp(view.getLocationInWindow().x)); }
export function top(view: View): number { return round(dipToDp(view.getLocationInWindow().y)); }
export function right(view: View): number { return left(view) + width(view); }
export function bottom(view: View): number { return top(view) + height(view); }
export function height(view: View): number {
return round(dipToDp(view.getActualSize().height));
}
export function width(view: View): number {
return round(dipToDp(view.getActualSize().width));
}
export function paddingLeft(view: View): number { return Length.toDevicePixels(view.style.paddingLeft, 0) + Length.toDevicePixels(view.parent.style.paddingLeft, 0) + (<View>view.parent).getSafeAreaInsets().left; }
export function paddingTop(view: View): number { return top(view) + Length.toDevicePixels(view.style.paddingTop, 0); }
export function paddingRight(view: View): number { return right(view) - Length.toDevicePixels(view.style.paddingRight, 0); }
export function paddingBottom(view: View): number { return bottom(view) - Length.toDevicePixels(view.style.paddingBottom, 0); }
export function equal<T>(a: T, b: T, message?: string) {
message ? TKUnit.assertEqual(a, b, message) : TKUnit.assertEqual(a, b);
}
export function closeEnough(a: number, b: number, message?: string) {
message ? TKUnit.assertTrue(Math.abs(a - b) <= EPS, message) : TKUnit.assertTrue(Math.abs(a - b) <= EPS);
}
export function lessOrCloseEnough(a: number, b: number, message?: string) {
const less = a < b;
const close = Math.abs(a - b) <= EPS;
message ? TKUnit.assertTrue(less || close, message) : TKUnit.assertTrue(less || close);
}
export function greaterOrCloseEnough(a: number, b: number, message?: string) {
const greater = a > b;
const close = Math.abs(a - b) <= EPS;
message ? TKUnit.assertTrue(greater || close, message) : TKUnit.assertTrue(greater || close);
}
export function notEqual<T>(a: T, b: T, message?: string) {
message ? TKUnit.assertNotEqual(a, b, message) : TKUnit.assertNotEqual(a, b);
}
export function check(exp: boolean, message?: string) {
message ? TKUnit.assert(exp, message) : TKUnit.assert(exp);
}
export function heightEqual(view1: View, view2: View, message?: string) {
equal(height(view1), height(view2), message || `Expected height of ${view1}:${height(view1)} to equal height of ${view2}:${height(view2)}.`);
}
export function widthEqual(view1: View, view2: View, message?: string) {
equal(width(view1), width(view2), message || `Expected width of ${view1}:${width(view1)} to equal width of ${view2}:${width(view2)}.`);
}
export function isLeftAlignedWith(view1: View, view2: View, message?: string) {
TKUnit.assertEqual(left(view1), left(view2), message || `${view1}:${left(view1)} is not left-aligned with ${view2}:${left(view2)}`);
}
export function isRightAlignedWith(view1: View, view2: View, message?: string) {
TKUnit.assertEqual(right(view1), right(view2), message || `${view1}:${right(view1)} is not right-aligned with ${view2}:${right(view2)}`);
}
export function isTopAlignedWith(view1: View, view2: View, message?: string) {
TKUnit.assertEqual(top(view1), top(view2), message || `${view1}:${top(view1)} is not top-aligned with ${view2}:${top(view2)}`);
}
export function isBottomAlignedWith(view1: View, view2: View, message?: string) {
TKUnit.assertEqual(bottom(view1), bottom(view2), message || `${view1}:${bottom(view1)} is not bottom-aligned with ${view2}:${bottom(view2)}`);
}
export function isLeftOf(view1: View, view2: View, message?: string) {
TKUnit.assert(right(view1) <= left(view2), message || `${view1}.right:${right(view1)} is not left of ${view2}.left:${left(view2)}`);
}
export function isAbove(view1: View, view2: View, message?: string) {
TKUnit.assert(bottom(view1) <= top(view2), message || `${view1}.bottom:${bottom(view1)} is not above ${view2}.top:${top(view2)}`);
}
export function isRightOf(view1: View, view2: View, message?: string) {
TKUnit.assert(left(view1) >= right(view2), message || `${view1}.left:${left(view1)} is not right of ${view2}.right:${right(view2)}`);
}
export function isBelow(view1: View, view2: View, distance?: number, message?: string) {
TKUnit.assert(top(view1) >= bottom(view2), message || `${view1}.top:${top(view1)} is not below ${view2}.bottom:${bottom(view1)}`);
}
export function isLeftWith(view1: View, view2: View, distance: number, message?: string) {
TKUnit.assertTrue(Math.abs(left(view1) + distance - left(view2)) <= EPS, message || `${view1}.left:${left(view1)} is not ${distance} of ${view2}.left:${left(view2)}`);
}
export function isAboveWith(view1: View, view2: View, distance: number, message?: string) {
TKUnit.assertTrue(Math.abs(bottom(view1) + distance - bottom(view2)) <= EPS, message || `${view1}.bottom:${bottom(view1)} is not ${distance} of ${view2}.bottom:${bottom(view2)}`);
}
export function isRightWith(view1: View, view2: View, distance: number, message?: string) {
TKUnit.assertTrue(Math.abs(right(view1) + distance - right(view2)) <= EPS, message || `${view1}.right:${right(view1)} is not ${distance} of ${view2}.right:${right(view2)}`);
}
export function isBelowWith(view1: View, view2: View, distance: number, message?: string) {
TKUnit.assertTrue(Math.abs(top(view1) + distance - top(view2)) <= EPS, message || `${view1}.top:${top(view1)} is not ${distance} of ${view2}.top:${top(view2)}`);
}