Skip to content

Commit 1d12136

Browse files
authored
feat: apply styles when adding them to the application scope (#7652)
1 parent 1f8dca9 commit 1d12136

13 files changed

Lines changed: 103 additions & 17 deletions

File tree

‎e2e/ui-tests-app/app/app.css‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#app {
2-
background-color: lightblue;
2+
background-color: lightyellow;
33
}
44

55
.ui-tests-app-issue-1639-red {
@@ -20,4 +20,4 @@
2020
.ui-tests-app-issue-1639-yellow {
2121
color: yellow;
2222
margin-left: 30;
23-
}
23+
}

‎e2e/ui-tests-app/app/button/main-page.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export function loadExamples() {
1313
const examples = new Map<string, string>();
1414
examples.set("btn-wrap-text-alignment-4266", "button/btn-wrap-text-alignment-4266-page");
1515
examples.set("button-border", "button/button-border-page");
16-
examples.set("styles", "button/styles-page");
1716
examples.set("background", "button/background-page");
1817
examples.set("border-playground", "button/border-playground-page");
1918
examples.set("issue-4287", "button/issue-4287-page");

‎e2e/ui-tests-app/app/button/styles-page.ts‎

Lines changed: 0 additions & 4 deletions
This file was deleted.

‎e2e/ui-tests-app/app/css/main-page.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export function loadExamples() {
4545
examples.set("background-shorthand", "css/background-shorthand-page");
4646
examples.set("background-image-linear-gradient", "css/background-image-linear-gradient-page");
4747
examples.set("background-image", "css/background-image-page");
48+
examples.set("styles", "css/styles-page");
4849

4950
return examples;
5051
}
File renamed without changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { addCss } from "tns-core-modules/application";
2+
3+
export function onLoaded(args) {
4+
var page = args.object;
5+
page.addCss("#property { background-color: lightsalmon; }");
6+
}
7+
8+
export function onTap() {
9+
addCss("#app { background-color: lightblue; }");
10+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<Page loaded="onLoaded">
22
<WrapLayout>
3-
<Button id="app" automationText="app" text="app" />
3+
<Button id="app" automationText="app" text="app" tap="onTap" />
44
<Button id="inline" automationText="inline" text="inline" style="background-color: lightgreen;" />
55
<Button id="page" automationText="page" text="page" />
66
<Button id="property" automationText="property" text="property" />
77
<Button id="import" automationText="import" text="import" />
88
</WrapLayout>
9-
</Page>
9+
</Page>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { AppiumDriver, logInfo } from "nativescript-dev-appium";
2+
3+
import { PageObjectBaseModel } from "../../../page-object-base-model";
4+
5+
export class StylesPage extends PageObjectBaseModel {
6+
7+
private readonly app = "app";
8+
9+
constructor(_driver: AppiumDriver) {
10+
super(_driver, ["css", "styles"]);
11+
}
12+
13+
async btnApp() {
14+
return this._driver.waitForElement(this.app);
15+
}
16+
17+
async tapAppBtn() {
18+
await (await this.btnApp()).tap();
19+
logInfo(`Tap on '${this.app}' button.`);
20+
}
21+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { assert } from "chai";
2+
import { AppiumDriver, createDriver, nsCapabilities } from "nativescript-dev-appium";
3+
4+
import { setImageName } from "../../../helpers/image-helper";
5+
import { StylesPage } from "./styles-page";
6+
7+
const suite = "css";
8+
const spec = "styles";
9+
10+
describe(`${suite}-${spec}-suite`, () => {
11+
let driver: AppiumDriver;
12+
let stylesPage: StylesPage;
13+
14+
before(async function () {
15+
nsCapabilities.testReporter.context = this;
16+
driver = await createDriver();
17+
await driver.restartApp();
18+
stylesPage = new StylesPage(driver);
19+
await stylesPage.initSuite();
20+
});
21+
22+
after(async function () {
23+
await stylesPage.endSuite();
24+
});
25+
26+
beforeEach(async function () {
27+
driver.imageHelper.testName = setImageName(suite, spec, this.currentTest.title);
28+
});
29+
30+
afterEach(async function () {
31+
if (this.currentTest.state === "failed") {
32+
await driver.logTestArtifacts(this.currentTest.title);
33+
}
34+
});
35+
36+
it(`${suite}-${spec}-apply`, async function () {
37+
await stylesPage.tapAppBtn();
38+
await driver.imageHelper.compareScreen();
39+
assert.isTrue(driver.imageHelper.hasImageComparisonPassed());
40+
});
41+
});

‎tns-core-modules/application/application-common.ts‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,6 @@ export function loadAppCss(): void {
117117
}
118118
}
119119

120-
export function addCss(cssText: string): void {
121-
events.notify(<CssChangedEventData>{ eventName: "cssChanged", object: app, cssText: cssText });
122-
}
123-
124120
global.__onUncaughtError = function (error: NativeScriptError) {
125121
events.notify(<UnhandledErrorEventData>{ eventName: uncaughtErrorEvent, object: app, android: error, ios: error, error: error });
126122
};

0 commit comments

Comments
 (0)