|
1 | | -import * as frameModule from "tns-core-modules/ui/frame"; |
2 | | -import * as TKUnit from "../../TKUnit"; |
3 | | -import * as uiUtils from "tns-core-modules/ui/utils"; |
4 | | -import { PercentLength, unsetValue } from "tns-core-modules/ui/core/view"; |
5 | | - |
6 | | -export function test_percent_width_and_height_set_to_page_support() { |
7 | | - let topFrame = frameModule.topmost(); |
8 | | - let currentPage = topFrame.currentPage; |
9 | | - |
10 | | - (<any>currentPage).width = "50%"; |
11 | | - (<any>currentPage).height = "50%"; |
12 | | - |
13 | | - TKUnit.waitUntilReady(() => { |
14 | | - return currentPage.isLayoutValid; |
15 | | - }, 1); |
16 | | - |
17 | | - let topFrameWidth = topFrame.getMeasuredWidth(); |
18 | | - let topFrameHeight = topFrame.getMeasuredHeight(); |
19 | | - |
20 | | - let currentPageWidth = currentPage.getMeasuredWidth(); |
21 | | - let currentPageHeight = currentPage.getMeasuredHeight(); |
22 | | - |
23 | | - TKUnit.assertEqual(currentPageWidth, Math.round(topFrameWidth / 2), "Current page measuredWidth incorrect"); |
24 | | - TKUnit.assertEqual(currentPageHeight, Math.round(topFrameHeight / 2), "Current page measuredHeight incorrect"); |
25 | | - |
26 | | - //reset values. |
27 | | - currentPage.height = unsetValue; |
28 | | - currentPage.width = unsetValue; |
29 | | - |
30 | | - TKUnit.assertTrue(PercentLength.equals(currentPage.width, "auto")); |
31 | | - TKUnit.assertTrue(PercentLength.equals(currentPage.height, "auto")); |
32 | | -} |
33 | | - |
34 | | -export function test_percent_margin_set_to_page_support() { |
35 | | - percent_margin_set_to_page_support(false); |
36 | | -} |
37 | | - |
38 | | -export function test_percent_margin_set_to_page_support_with_backgroundSpanUnderStatusBar() { |
39 | | - percent_margin_set_to_page_support(true); |
40 | | -} |
41 | | - |
42 | | -function percent_margin_set_to_page_support(backgroundSpanUnderStatusBar: boolean) { |
43 | | - const topFrame = frameModule.topmost(); |
44 | | - const currentPage = topFrame.currentPage; |
45 | | - |
46 | | - const topFrameWidth = topFrame.getMeasuredWidth(); |
47 | | - const topFrameHeight = topFrame.getMeasuredHeight(); |
48 | | - const statusBar = backgroundSpanUnderStatusBar ? 0 : uiUtils.ios.getStatusBarHeight(); |
49 | | - |
50 | | - currentPage.margin = "10%"; |
51 | | - currentPage.backgroundSpanUnderStatusBar = backgroundSpanUnderStatusBar; |
52 | | - |
53 | | - TKUnit.waitUntilReady(() => { |
54 | | - return currentPage.isLayoutValid; |
55 | | - }, 1); |
56 | | - |
57 | | - const currentPageWidth = currentPage.getMeasuredWidth(); |
58 | | - const currentPageHeight = currentPage.getMeasuredHeight(); |
59 | | - const marginWidth = Math.round(topFrameWidth * 0.1); |
60 | | - const marginHeight = Math.round((topFrameHeight - statusBar) * 0.1); |
61 | | - |
62 | | - // expected page size |
63 | | - TKUnit.assertEqual(currentPageWidth, topFrameWidth - 2 * marginWidth, "Page measure width"); |
64 | | - TKUnit.assertEqual(currentPageHeight, topFrameHeight - 2 * marginHeight - statusBar, "Page measure height"); |
65 | | - |
66 | | - // expected page bounds |
67 | | - const bounds = currentPage._getCurrentLayoutBounds(); |
68 | | - TKUnit.assertEqual(bounds.left, Math.round(marginWidth), "Current page LEFT position incorrect"); |
69 | | - TKUnit.assertEqual(bounds.top, Math.round(marginHeight + statusBar), "Current page TOP position incorrect"); |
70 | | - TKUnit.assertEqual(bounds.right, Math.round(marginWidth + currentPageWidth), "Current page RIGHT position incorrect"); |
71 | | - TKUnit.assertEqual(bounds.bottom, Math.round(marginHeight + statusBar + currentPageHeight), "Current page BOTTOM position incorrect"); |
72 | | - |
73 | | - //reset values. |
74 | | - currentPage.margin = "0"; |
75 | | - TKUnit.waitUntilReady(() => { |
76 | | - return currentPage.isLayoutValid; |
77 | | - }, 1); |
78 | | - |
79 | | - TKUnit.assertTrue(PercentLength.equals(currentPage.marginLeft, 0)); |
80 | | - TKUnit.assertTrue(PercentLength.equals(currentPage.marginTop, 0)); |
81 | | - TKUnit.assertTrue(PercentLength.equals(currentPage.marginRight, 0)); |
82 | | - TKUnit.assertTrue(PercentLength.equals(currentPage.marginBottom, 0)); |
83 | | -} |
0 commit comments