Files
NativeScript/tests/app/ui/styling/visual-state-tests.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

95 lines
3.9 KiB
TypeScript

import * as TKUnit from "../../tk-unit";
import * as view from "@nativescript/core/ui/core/view";
import * as page from "@nativescript/core/ui/page";
import * as types from "@nativescript/core/utils/types";
import * as helper from "../../ui-helper";
function assertInState(view: view.View, state: string, knownStates: string[]): void {
let pseudo = view.cssPseudoClasses;
if (state) {
TKUnit.assert(pseudo.has(state), "Expected view " + view + " to have pseudo class " + state);
}
knownStates.filter(s => s !== state).forEach(s => {
TKUnit.assert(!pseudo.has(s), "Expected view " + view + " not to have pseudo class " + s + (state ? " expected just " + state + "." : ""));
});
}
export var test_goToVisualState = function () {
var test = function (views: Array<view.View>) {
(<page.Page>views[0]).css = "button:hovered { color: red; background-color: orange } button:pressed { color: white; background-color: black }";
var btn = views[1];
assertInState(btn, null, ["hovered", "pressed"]);
btn._goToVisualState("hovered");
assertInState(btn, "hovered", ["hovered", "pressed"]);
TKUnit.assert(types.isDefined(btn.style.color) && btn.style.color.name === "red");
TKUnit.assert(types.isDefined(btn.style.backgroundColor) && btn.style.backgroundColor.name === "orange");
btn._goToVisualState("pressed");
assertInState(btn, "pressed", ["hovered", "pressed"]);
TKUnit.assert(types.isDefined(btn.style.color) && btn.style.color.name === "white");
TKUnit.assert(types.isDefined(btn.style.backgroundColor) && btn.style.backgroundColor.name === "black");
};
helper.do_PageTest_WithButton(test);
};
export var test_goToVisualState_NoState_ShouldResetStyledProperties = function () {
var test = function (views: Array<view.View>) {
(<page.Page>views[0]).css = "button:hovered { color: red; background-color: orange }";
var btn = views[1];
assertInState(btn, null, ["hovered", "pressed"]);
btn._goToVisualState("hovered");
assertInState(btn, "hovered", ["hovered", "pressed"]);
TKUnit.assert(types.isDefined(btn.style.color) && btn.style.color.name === "red");
TKUnit.assert(types.isDefined(btn.style.backgroundColor) && btn.style.backgroundColor.name === "orange");
btn._goToVisualState("pressed");
// since there are no modifiers for the "Pressed" state, the "Normal" state is returned.
assertInState(btn, "pressed", ["hovered", "pressed"]);
// properties are reset (set to undefined)
TKUnit.assert(types.isUndefined(btn.style.color));
TKUnit.assert(types.isUndefined(btn.style.backgroundColor));
};
helper.do_PageTest_WithButton(test);
};
export var test_goToVisualState_NoState_ShouldGoToNormal = function () {
var test = function (views: Array<view.View>) {
(<page.Page>views[0]).css = "button { color: orange; background-color: black } button:hovered { color: red; background-color: orange }";
var btn = views[1];
assertInState(btn, null, ["hovered", "pressed"]);
btn._goToVisualState("hovered");
assertInState(btn, "hovered", ["hovered", "pressed"]);
TKUnit.assert(types.isDefined(btn.style.color) && btn.style.color.name === "red");
TKUnit.assert(types.isDefined(btn.style.backgroundColor) && btn.style.backgroundColor.name === "orange");
btn._goToVisualState("pressed");
// since there are no modifiers for the "Pressed" state, the "Normal" state is returned.
assertInState(btn, "pressed", ["hovered", "pressed"]);
// the actual state is "normal" and properties are reverted to these settings (if any)
TKUnit.assert(types.isDefined(btn.style.color) && btn.style.color.name === "orange");
TKUnit.assert(types.isDefined(btn.style.backgroundColor) && btn.style.backgroundColor.name === "black");
};
helper.do_PageTest_WithButton(test);
};