mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 19:26:42 +08:00

Split type.class from CssTypeSelector to CssCompositeSelector, probably support type#id.class selectors Apply review comments, refactor css-selectors internally Applied refactoring, all tests pass, button does not notify changes Add tests for the css selectors parser. Added tests for css-selectors Added basic implementation of mayMatch and changeMap for css match state Implemented TKUnit.assertDeepEqual to check key and key/values in Map and Set Watch for property and pseudoClass changes Add one child group test Add typings for animations Added mechanism to enable/disable listeners for pseudo classes Count listeners instead of checking handlers, reverse subscription and unsubscription
95 lines
3.9 KiB
TypeScript
95 lines
3.9 KiB
TypeScript
import TKUnit = require("../../TKUnit");
|
|
import view = require("ui/core/view");
|
|
import page = require("ui/page");
|
|
import types = require("utils/types");
|
|
import helper = require("../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);
|
|
}
|