mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
refactor: tests to parce templates
This commit is contained in:
@@ -2,11 +2,9 @@ import * as app from "tns-core-modules/application/application";
|
|||||||
import * as frame from "tns-core-modules/ui/frame";
|
import * as frame from "tns-core-modules/ui/frame";
|
||||||
import * as helper from "../ui/helper";
|
import * as helper from "../ui/helper";
|
||||||
import * as TKUnit from "../TKUnit";
|
import * as TKUnit from "../TKUnit";
|
||||||
import { Button } from "tns-core-modules/ui/button/button";
|
|
||||||
import { Color } from "tns-core-modules/color";
|
import { Color } from "tns-core-modules/color";
|
||||||
|
import { parse } from "tns-core-modules/ui/builder";
|
||||||
import { Page } from "tns-core-modules/ui/page";
|
import { Page } from "tns-core-modules/ui/page";
|
||||||
import { Label } from "tns-core-modules/ui/label/label";
|
|
||||||
import { StackLayout } from "tns-core-modules/ui/layouts/stack-layout";
|
|
||||||
|
|
||||||
const appCssFileName = "./app/application.css";
|
const appCssFileName = "./app/application.css";
|
||||||
const appNewCssFileName = "./app/app-new.css";
|
const appNewCssFileName = "./app/app-new.css";
|
||||||
@@ -19,27 +17,19 @@ const mainPageXmlFileName = "./app/main-page.xml";
|
|||||||
|
|
||||||
const green = new Color("green");
|
const green = new Color("green");
|
||||||
|
|
||||||
const mainPageFactory = function (): Page {
|
const mainPageTemplate = `
|
||||||
const page = new Page();
|
<Page>
|
||||||
const stack = new StackLayout();
|
<StackLayout>
|
||||||
const label = new Label();
|
<Label id="label" text="label"></Label>
|
||||||
label.id = "label";
|
</StackLayout>
|
||||||
label.text = "label";
|
</Page>`;
|
||||||
stack.addChild(label);
|
|
||||||
page.content = stack;
|
|
||||||
return page;
|
|
||||||
}
|
|
||||||
|
|
||||||
const pageFactory = function (): Page {
|
const pageTemplate = `
|
||||||
const page = new Page();
|
<Page>
|
||||||
const stack = new StackLayout();
|
<StackLayout>
|
||||||
const button = new Button();
|
<Button id="button" text="button"></Button>
|
||||||
button.id = "button";
|
</StackLayout>
|
||||||
button.text = "button";
|
</Page>`;
|
||||||
stack.addChild(button);
|
|
||||||
page.content = stack;
|
|
||||||
return page;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function test_onLiveSync_HmrContext_AppStyle_AppNewCss() {
|
export function test_onLiveSync_HmrContext_AppStyle_AppNewCss() {
|
||||||
_test_onLiveSync_HmrContext_AppStyle(appNewCssFileName);
|
_test_onLiveSync_HmrContext_AppStyle(appNewCssFileName);
|
||||||
@@ -78,7 +68,8 @@ export function test_onLiveSync_HmrContext_Markup_MainPageXml() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function setUpModule() {
|
export function setUpModule() {
|
||||||
helper.navigate(mainPageFactory);
|
const mainPage = <Page>parse(mainPageTemplate);
|
||||||
|
helper.navigate(() => mainPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function tearDown() {
|
export function tearDown() {
|
||||||
@@ -88,7 +79,8 @@ export function tearDown() {
|
|||||||
function _test_onLiveSync_HmrContext_AppStyle(styleFileName: string) {
|
function _test_onLiveSync_HmrContext_AppStyle(styleFileName: string) {
|
||||||
const pageBeforeNavigation = helper.getCurrentPage();
|
const pageBeforeNavigation = helper.getCurrentPage();
|
||||||
|
|
||||||
helper.navigateWithHistory(pageFactory);
|
const page = <Page>parse(pageTemplate);
|
||||||
|
helper.navigateWithHistory(() => page);
|
||||||
app.setCssFileName(styleFileName);
|
app.setCssFileName(styleFileName);
|
||||||
|
|
||||||
const pageBeforeLiveSync = helper.getCurrentPage();
|
const pageBeforeLiveSync = helper.getCurrentPage();
|
||||||
@@ -110,7 +102,8 @@ function _test_onLiveSync_HmrContext_AppStyle(styleFileName: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function _test_onLiveSync_HmrContext(context: { type, module }) {
|
function _test_onLiveSync_HmrContext(context: { type, module }) {
|
||||||
helper.navigateWithHistory(pageFactory);
|
const page = <Page>parse(pageTemplate);
|
||||||
|
helper.navigateWithHistory(() => page);
|
||||||
global.__onLiveSync({ type: context.type, module: context.module });
|
global.__onLiveSync({ type: context.type, module: context.module });
|
||||||
|
|
||||||
TKUnit.waitUntilReady(() => !!frame.topmost());
|
TKUnit.waitUntilReady(() => !!frame.topmost());
|
||||||
|
|||||||
Reference in New Issue
Block a user