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

166 lines
4.9 KiB
TypeScript

import { View } from "@nativescript/core/ui/core/view";
import { Button } from "@nativescript/core/ui/button";
import { StackLayout } from "@nativescript/core/ui/layouts/stack-layout/stack-layout";
import * as helper from "../../ui-helper";
import * as TKUnit from "../../tk-unit";
export function test_event_LayoutChanged_GetActualSize() {
const test = function (views: Array<View>) {
let buttonLayoutChanged = false;
views[1].on(View.layoutChangedEvent, (data) => {
buttonLayoutChanged = true;
});
TKUnit.waitUntilReady(() => buttonLayoutChanged, 5);
TKUnit.assert(views[1].getActualSize().height > 0);
TKUnit.assert(views[1].getActualSize().width > 0);
};
helper.do_PageTest_WithStackLayout_AndButton(test);
}
export function test_event_LayoutChanged_Listeners() {
const test = function (views: Array<View>) {
let buttonLayoutChanged = false;
views[1].on(View.layoutChangedEvent, (data) => {
buttonLayoutChanged = true;
});
TKUnit.waitUntilReady(() => buttonLayoutChanged, 5);
TKUnit.assertFalse(views[0].hasListeners(View.layoutChangedEvent));
TKUnit.assert(views[1].hasListeners(View.layoutChangedEvent));
};
helper.do_PageTest_WithStackLayout_AndButton(test);
}
export function test_event_LayoutChanged_IsRaised() {
helper.clearPage();
let newPage = helper.getCurrentPage();
let stackLayoutChanged = false;
let buttonLayoutChanged = false;
let stackLayout = new StackLayout();
let button = new Button();
stackLayout.on(View.layoutChangedEvent, (data) => {
stackLayoutChanged = true;
});
button.on(View.layoutChangedEvent, (data) => {
buttonLayoutChanged = true;
});
stackLayout.addChild(button);
newPage.content = stackLayout;
TKUnit.waitUntilReady(() => stackLayoutChanged && buttonLayoutChanged, 5);
TKUnit.assert(stackLayoutChanged);
TKUnit.assert(buttonLayoutChanged);
newPage.content = null;
}
export function test_event_LayoutChanged_IsRaised_ChildMarginChanged() {
const test = function (views: Array<View>) {
let stackLayoutChanged = false;
let buttonLayoutChanged = false;
views[1].on(View.layoutChangedEvent, (data) => {
stackLayoutChanged = true;
});
views[2].on(View.layoutChangedEvent, (data) => {
buttonLayoutChanged = true;
});
(<Button>views[2]).marginTop = 50;
TKUnit.waitUntilReady(() => buttonLayoutChanged, 5);
TKUnit.assert(stackLayoutChanged);
TKUnit.assert(buttonLayoutChanged);
};
helper.do_PageTest_WithStackLayout_AndButton(test);
}
export function test_event_LayoutChanged_IsRaised_ParentMarginChanged() {
const test = function (views: Array<View>) {
let stackLayoutChanged = false;
let buttonLayoutChanged = false;
views[1].on(View.layoutChangedEvent, (data) => {
stackLayoutChanged = true;
});
views[2].on(View.layoutChangedEvent, (data) => {
buttonLayoutChanged = true;
});
(<Button>views[2]).marginTop = 50;
TKUnit.waitUntilReady(() => buttonLayoutChanged, 5);
TKUnit.assert(stackLayoutChanged);
TKUnit.assert(buttonLayoutChanged);
};
helper.do_PageTest_WithStackLayout_AndButton(test);
}
export function test_event_LayoutChanged_IsNotRaised_TransformChanged() {
helper.do_PageTest_WithStackLayout_AndButton(([page, stack, button, ActionBar]) => {
let stackLayoutChangedCount = 0;
let buttonLayoutChangedCount = 0;
TKUnit.waitUntilReady(() => button.isLayoutValid);
TKUnit.waitUntilReady(() => stack.isLayoutValid);
stack.on(View.layoutChangedEvent, (data) => {
stackLayoutChangedCount++;
});
button.on(View.layoutChangedEvent, (data) => {
buttonLayoutChangedCount++;
});
button.translateX += 50;
button.translateY += 50;
button.rotate += 50;
TKUnit.waitUntilReady(() => button.isLayoutValid);
TKUnit.waitUntilReady(() => stack.isLayoutValid);
TKUnit.assertEqual(stackLayoutChangedCount, 0);
TKUnit.assertEqual(buttonLayoutChangedCount, 0);
});
}
export function test_event_LayoutChanged_IsRaised_StackLayout_SizeChanged() {
const test = function (views: Array<View>) {
let stackLayoutChanged = false;
let buttonLayoutChanged = false;
views[1].on(View.layoutChangedEvent, (data) => {
stackLayoutChanged = true;
});
views[2].on(View.layoutChangedEvent, (data) => {
buttonLayoutChanged = true;
});
(<StackLayout>views[1]).height = 100;
TKUnit.waitUntilReady(() => buttonLayoutChanged, 5);
TKUnit.assert(stackLayoutChanged);
TKUnit.assert(buttonLayoutChanged);
};
helper.do_PageTest_WithStackLayout_AndButton(test);
}