mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 21:01:34 +08:00
Merge pull request #1110 from NativeScript/hhristov/page-layout-tests
Added test to verify that page layout is correct when page properties…
This commit is contained in:
@ -30,13 +30,15 @@ import ViewModule = require("ui/core/view");
|
||||
import helper = require("../helper");
|
||||
import ObservableModule = require("data/observable");
|
||||
import enumsModule = require("ui/enums");
|
||||
import fs = require("file-system");
|
||||
|
||||
var imagePath = __dirname + "../../logo.png";
|
||||
var imagePath = fs.path.join(__dirname, "../../logo.png");
|
||||
|
||||
export var test_Image_Members = function () {
|
||||
var image = new ImageModule.Image();
|
||||
TKUnit.assert(types.isUndefined(image.src), "Image.src is defined");
|
||||
TKUnit.assert(types.isDefined(image.isLoading), "Image.isLoading is not defined");
|
||||
TKUnit.assert(image.isLoading === false, "Image.isLoading is default value should be false.");
|
||||
}
|
||||
|
||||
/* TODO: We need a way to programmatically add an image to resources and then load it from, otherwise we do not know if there is such resource in the target native app.
|
||||
@ -69,12 +71,29 @@ export var test_SettingImageSrc = function (done) {
|
||||
// ### How to create an image and set its src.
|
||||
// ``` JavaScript
|
||||
var image = new ImageModule.Image();
|
||||
image.src = "https://www.google.bg/images/srpr/logo11w.png";
|
||||
image.src = "https://www.google.com/images/errors/logo_sm_2.png";
|
||||
// ```
|
||||
// </snippet>
|
||||
|
||||
image.src = null;
|
||||
|
||||
var testModel = new ObservableModule.Observable();
|
||||
testModel.set("imageIsLoading", true);
|
||||
testModel.set("imageIsLoading", false);
|
||||
|
||||
let handler = function (data: ObservableModule.PropertyChangeData) {
|
||||
testModel.off(ObservableModule.Observable.propertyChangeEvent, handler);
|
||||
|
||||
try {
|
||||
let imageIsLoaded = !!image.imageSource;
|
||||
TKUnit.assertTrue(!image.isLoading, "Image.isLoading should be false.");
|
||||
TKUnit.assertTrue(!testModel.get("imageIsLoading"), "imageIsLoading on viewModel should be false.");
|
||||
TKUnit.assertTrue(imageIsLoaded, "imageIsLoading should be true.");
|
||||
done(null);
|
||||
}
|
||||
catch (e) {
|
||||
done(e);
|
||||
}
|
||||
};
|
||||
|
||||
image.bind({
|
||||
sourceProperty: "imageIsLoading",
|
||||
@ -82,23 +101,10 @@ export var test_SettingImageSrc = function (done) {
|
||||
twoWay: true
|
||||
}, testModel);
|
||||
|
||||
var imageIsLoaded = false;
|
||||
|
||||
var testFunc = function (views: Array<ViewModule.View>) {
|
||||
var testImage = <ImageModule.Image> views[0];
|
||||
imageIsLoaded = !!testImage.imageSource;
|
||||
try {
|
||||
TKUnit.assert(testModel.get("imageIsLoading") === false, "Expected: false, Actual: " + testModel.get("imageIsLoading"));
|
||||
TKUnit.assert(imageIsLoaded === true, "Expected: true, Actual: " + imageIsLoaded);
|
||||
done(null);
|
||||
}
|
||||
catch (e) {
|
||||
done(e);
|
||||
}
|
||||
}
|
||||
|
||||
// wait for a second in order to download the image.
|
||||
setTimeout(() => { helper.buildUIAndRunTest(image, testFunc) }, 3000);
|
||||
image.src = "https://www.google.com/images/errors/logo_sm_2.png";
|
||||
testModel.on(ObservableModule.Observable.propertyChangeEvent, handler);
|
||||
TKUnit.assertTrue(image.isLoading, "Image.isLoading should be true.");
|
||||
TKUnit.assertTrue(testModel.get("imageIsLoading"), "model.isLoading should be true.");
|
||||
}
|
||||
|
||||
export var test_SettingImageSrcToFileWithinApp = function (done) {
|
||||
@ -110,13 +116,11 @@ export var test_SettingImageSrcToFileWithinApp = function (done) {
|
||||
// ```
|
||||
// </snippet>
|
||||
|
||||
var imageIsLoaded = false;
|
||||
|
||||
var testFunc = function (views: Array<ViewModule.View>) {
|
||||
var testImage = <ImageModule.Image> views[0];
|
||||
imageIsLoaded = !!testImage.imageSource;
|
||||
TKUnit.waitUntilReady(() => !testImage.isLoading, 3);
|
||||
try {
|
||||
TKUnit.assert(imageIsLoaded === true, "Expected: true, Actual: " + imageIsLoaded);
|
||||
TKUnit.assertTrue(!testImage.isLoading, "isLoading should be false.");
|
||||
done(null);
|
||||
}
|
||||
catch (e) {
|
||||
@ -124,8 +128,7 @@ export var test_SettingImageSrcToFileWithinApp = function (done) {
|
||||
}
|
||||
}
|
||||
|
||||
// wait for a second in order to download the image.
|
||||
setTimeout(() => { helper.buildUIAndRunTest(image, testFunc) }, 3000);
|
||||
helper.buildUIAndRunTest(image, testFunc);
|
||||
}
|
||||
|
||||
export var test_SettingStretch_AspectFit = function () {
|
||||
|
@ -5,6 +5,7 @@ import LabelModule = require("ui/label");
|
||||
import helper = require("../helper");
|
||||
import view = require("ui/core/view");
|
||||
import frame = require("ui/frame");
|
||||
import uiUtils = require("ui/utils");
|
||||
|
||||
global.moduleMerge(PageTestCommon, exports);
|
||||
|
||||
@ -18,7 +19,7 @@ export function test_NavigateToNewPage_InnerControl() {
|
||||
|
||||
helper.navigate(pageFactory);
|
||||
helper.goBack();
|
||||
|
||||
|
||||
var label = <LabelModule.Label>testPage.content;
|
||||
|
||||
TKUnit.assert(label._context === undefined, "InnerControl._context should be undefined after navigate back.");
|
||||
@ -106,4 +107,48 @@ export function test_WhenShowingModalPageUnloadedIsNotFiredForTheMasterPage() {
|
||||
finally {
|
||||
helper.goBack();
|
||||
}
|
||||
}
|
||||
|
||||
export function test_page_no_anctionBar_measure_no_spanUnderBackground_measure_layout_size_isCorrect() {
|
||||
let page = new PageModule.Page();
|
||||
page.backgroundSpanUnderStatusBar = true;
|
||||
page.actionBarHidden = true;
|
||||
let lbl = new LabelModule.Label();
|
||||
page.content = lbl;
|
||||
|
||||
try {
|
||||
helper.navigate(() => { return page; });
|
||||
TKUnit.waitUntilReady(() => { return page.isLayoutValid; });
|
||||
TKUnit.assertTrue(page.isLoaded, "page NOT loaded!");
|
||||
|
||||
let bounds = page._getCurrentLayoutBounds();
|
||||
let pageHeight = bounds.bottom - bounds.top;
|
||||
let frameBounds = page.frame._getCurrentLayoutBounds();
|
||||
let frameHeight = frameBounds.bottom - frameBounds.top;
|
||||
TKUnit.assertEqual(pageHeight, frameHeight, "Page height should match Frame height.");
|
||||
|
||||
let contentHeight = lbl._getCurrentLayoutBounds().bottom - lbl._getCurrentLayoutBounds().top;
|
||||
let statusBarHeight = uiUtils.ios.getStatusBarHeight();
|
||||
TKUnit.assertEqual(contentHeight, frameHeight - statusBarHeight, "Page.content height should match Frame height - statusBar height.");
|
||||
|
||||
page.backgroundSpanUnderStatusBar = false;
|
||||
TKUnit.waitUntilReady(() => { return page.isLayoutValid; });
|
||||
pageHeight = page._getCurrentLayoutBounds().bottom - page._getCurrentLayoutBounds().top;
|
||||
TKUnit.assertEqual(pageHeight, frameHeight - statusBarHeight, "Page should be given Frame height - statusBar height.");
|
||||
|
||||
contentHeight = lbl._getCurrentLayoutBounds().bottom - lbl._getCurrentLayoutBounds().top;
|
||||
TKUnit.assertEqual(contentHeight, pageHeight, "Page.content height should match Page height.");
|
||||
|
||||
page.actionBarHidden = false;
|
||||
TKUnit.waitUntilReady(() => { return page.isLayoutValid; });
|
||||
|
||||
pageHeight = page._getCurrentLayoutBounds().bottom - page._getCurrentLayoutBounds().top;
|
||||
TKUnit.assertEqual(pageHeight, frameHeight - statusBarHeight, "Page should be given Frame height - statusBar height.");
|
||||
|
||||
contentHeight = lbl._getCurrentLayoutBounds().bottom - lbl._getCurrentLayoutBounds().top;
|
||||
TKUnit.assertTrue(contentHeight < pageHeight, "Page.content be given less space than Page when ActionBar is shown.");
|
||||
}
|
||||
finally {
|
||||
helper.goBack();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user