Files
NativeScript/tests/app/ui/layouts/common-layout-tests.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

157 lines
6.6 KiB
TypeScript

import * as TKUnit from "../../tk-unit";
import * as layoutHelper from "./layout-helper";
import * as testModule from "../../ui-test";
import { LayoutBase, unsetValue, PercentLength } from "@nativescript/core/ui/layouts/layout-base";
import * as platform from "@nativescript/core/platform";
function getNativeLayoutParams(nativeView: android.view.View): org.nativescript.widgets.CommonLayoutParams {
var lp = <org.nativescript.widgets.CommonLayoutParams>nativeView.getLayoutParams();
if (!(lp instanceof org.nativescript.widgets.CommonLayoutParams)) {
lp = new org.nativescript.widgets.CommonLayoutParams();
}
return lp;
}
export function percent_support_nativeLayoutParams_are_correct(test: testModule.UITest<LayoutBase>) {
if (platform.device.os !== platform.platformNames.android) {
return;
}
let layout = test.testView;
layout.width = { value: 200, unit: "px" };
layout.height = { value: 200, unit: "px" };
let btn = new layoutHelper.MyButton();
btn.width = { value: 100, unit: "px" };
btn.height = { value: 100, unit: "px" };
btn.margin = "10%";
layout.addChild(btn);
test.waitUntilTestElementLayoutIsValid();
let lp = getNativeLayoutParams(btn.nativeViewProtected);
TKUnit.assertEqual(lp.width, 100, "width");
TKUnit.assertEqual(lp.widthPercent, -1, "widthPercent");
TKUnit.assertEqual(lp.height, 100, "height");
TKUnit.assertEqual(lp.heightPercent, -1, "heightPercent");
TKUnit.assertEqual(lp.topMargin, 0, "topMargin");
TKUnit.assertTrue(lp.topMarginPercent > 0, "topMarginPercent");
TKUnit.assertEqual(lp.leftMargin, 0, "leftMargin");
TKUnit.assertTrue(lp.leftMarginPercent > 0, "leftMarginPercent");
TKUnit.assertEqual(lp.rightMargin, 0, "rightMargin");
TKUnit.assertTrue(lp.rightMarginPercent > 0, "rightMarginPercent");
TKUnit.assertEqual(lp.bottomMargin, 0, "bottomMargin");
TKUnit.assertTrue(lp.bottomMarginPercent > 0, "bottomMarginPercent");
(<any>btn).width = "50%";
(<any>btn).height = "50%";
test.waitUntilTestElementLayoutIsValid();
TKUnit.assertEqual(lp.width, -1, "width");
TKUnit.assertEqual(lp.widthPercent, 0.5, "widthPercent");
TKUnit.assertEqual(lp.height, -1, "height");
TKUnit.assertEqual(lp.heightPercent, 0.5, "heightPercent");
btn.margin = "0";
btn.height = unsetValue;
btn.style.width = unsetValue;
test.waitUntilTestElementLayoutIsValid();
TKUnit.assertEqual(lp.width, -1, "width");
TKUnit.assertEqual(lp.widthPercent, -1, "widthPercent");
TKUnit.assertEqual(lp.height, -1, "height");
TKUnit.assertEqual(lp.heightPercent, -1, "heightPercent");
TKUnit.assertEqual(lp.topMargin, 0, "topMargin");
TKUnit.assertEqual(lp.topMarginPercent, -1, "topMarginPercent");
TKUnit.assertEqual(lp.leftMargin, 0, "leftMargin");
TKUnit.assertEqual(lp.leftMarginPercent, -1, "leftMarginPercent");
TKUnit.assertEqual(lp.rightMargin, 0, "rightMargin");
TKUnit.assertEqual(lp.rightMarginPercent, -1, "rightMarginPercent");
TKUnit.assertEqual(lp.bottomMargin, 0, "bottomMargin");
TKUnit.assertEqual(lp.bottomMarginPercent, -1, "bottomMarginPercent");
}
export function percent_support_children_test(test: testModule.UITest<LayoutBase>) {
let layout: LayoutBase = test.testView;
layout.removeChildren();
layout.width = { value: 200, unit: "px" };
layout.height = { value: 200, unit: "px" };
let btn = new layoutHelper.MyButton();
btn.horizontalAlignment = "left";
btn.verticalAlignment = "top";
(<any>btn).width = "50%";
(<any>btn).height = "50%";
btn.margin = "10%";
btn.text = "1";
layout.addChild(btn);
test.waitUntilTestElementLayoutIsValid();
TKUnit.assertEqual(btn.getMeasuredWidth(), 100, "Button MeasuredWidth incorrect");
TKUnit.assertEqual(btn.getMeasuredHeight(), 100, "Button MeasuredHeight incorrect");
let bounds = btn._getCurrentLayoutBounds();
TKUnit.assertEqual(bounds.left, 20, "TopLeft layout LEFT incorrect");
TKUnit.assertEqual(bounds.top, 20, "TopLeft layout TOP incorrect");
TKUnit.assertEqual(bounds.right, 120, "TopLeft layout RIGHT incorrect");
TKUnit.assertEqual(bounds.bottom, 120, "TopLeft layout BOTTOM incorrect");
btn.horizontalAlignment = "center";
btn.verticalAlignment = "middle";
test.waitUntilTestElementLayoutIsValid();
bounds = btn._getCurrentLayoutBounds();
TKUnit.assertEqual(bounds.left, 50, "Center layout LEFT incorrect");
TKUnit.assertEqual(bounds.top, 50, "Center layout TOP incorrect");
TKUnit.assertEqual(bounds.right, 150, "Center layout RIGHT incorrect");
TKUnit.assertEqual(bounds.bottom, 150, "Center layout BOTTOM incorrect");
btn.horizontalAlignment = "stretch";
btn.verticalAlignment = "stretch";
test.waitUntilTestElementLayoutIsValid();
bounds = btn._getCurrentLayoutBounds();
TKUnit.assertEqual(bounds.left, 50, "Stretch layout LEFT incorrect");
TKUnit.assertEqual(bounds.top, 50, "Stretch layout TOP incorrect");
TKUnit.assertEqual(bounds.right, 150, "Stretch layout RIGHT incorrect");
TKUnit.assertEqual(bounds.bottom, 150, "Stretch layout BOTTOM incorrect");
btn.horizontalAlignment = "right";
btn.verticalAlignment = "bottom";
test.waitUntilTestElementLayoutIsValid();
bounds = btn._getCurrentLayoutBounds();
TKUnit.assertEqual(bounds.left, 200 - 100 - 20, "BottomRight layout LEFT incorrect");
TKUnit.assertEqual(bounds.top, 200 - 100 - 20, "BottomRight layout TOP incorrect");
TKUnit.assertEqual(bounds.right, 200 - 20, "BottomRight layout RIGHT incorrect");
TKUnit.assertEqual(bounds.bottom, 200 - 20, "BottomRight layout BOTTOM incorrect");
//reset values.
btn.height = unsetValue;
btn.width = unsetValue;
btn.margin = "0";
btn.horizontalAlignment = "stretch";
btn.verticalAlignment = "stretch";
btn.height = unsetValue;
TKUnit.assertTrue(PercentLength.equals(btn.marginLeft, 0));
TKUnit.assertTrue(PercentLength.equals(btn.marginTop, 0));
TKUnit.assertTrue(PercentLength.equals(btn.marginRight, 0));
TKUnit.assertTrue(PercentLength.equals(btn.marginBottom, 0));
TKUnit.assertTrue(PercentLength.equals(btn.width, "auto"));
TKUnit.assertTrue(PercentLength.equals(btn.height, "auto"));
test.waitUntilTestElementLayoutIsValid();
bounds = btn._getCurrentLayoutBounds();
TKUnit.assertEqual(bounds.left, 0, "Reset Stretch layout LEFT incorrect");
TKUnit.assertEqual(bounds.top, 0, "Reset Stretch layout TOP incorrect");
TKUnit.assertEqual(bounds.right, 200, "Reset Stretch layout RIGHT incorrect");
TKUnit.assertEqual(bounds.bottom, 200, "Reset Stretch layout BOTTOM incorrect");
}