react-native-web-internals
Version:
React Native for Web
89 lines (88 loc) • 4.09 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from == "object" || typeof from == "function")
for (let key of __getOwnPropNames(from))
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
mod
));
var import__ = __toESM(require("..")), createStyledNode = function() {
var name = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "div", style = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, root = document.createElement(name);
return Object.keys(style).forEach(function(prop) {
root.style[prop] = style[prop];
}), root;
}, componentStub = {
_reactInternalInstance: {
_currentElement: {
_owner: {}
},
_debugID: 1
}
};
describe("apis/UIManager", function() {
describe("focus", function() {
test('sets tabIndex="-1" on elements not programmatically focusable by default', function() {
var node = createStyledNode();
import__.default.focus(node), expect(node.getAttribute("tabIndex")).toEqual("-1");
}), test(`doesn't set tabIndex="-1" on elements with an existing tabIndex`, function() {
var node = createStyledNode();
node.tabIndex = 0, import__.default.focus(node), expect(node.getAttribute("tabIndex")).toEqual("0");
}), test(`doesn't set tabIndex="-1" on elements focusable by default`, function() {
[
"a",
"input",
"select",
"textarea"
].forEach(function(name) {
var node = createStyledNode(name);
import__.default.focus(node), expect(node.getAttribute("tabIndex")).toBeNull();
});
});
}), describe("updateView", function() {
test("supports className alias for class", function() {
var node = createStyledNode(), props = {
className: "extra"
};
import__.default.updateView(node, props, componentStub), expect(node.getAttribute("class")).toEqual("extra");
}), test("adds correct DOM styles to existing style", function() {
var node = createStyledNode("div", {
color: "red"
}), props = {
style: {
marginTop: 0,
marginBottom: 0,
opacity: 0
}
};
import__.default.updateView(node, props, componentStub), expect(node.getAttribute("style")).toEqual("color: red; margin-top: 0px; margin-bottom: 0px; opacity: 0;");
}), test("replaces input and textarea text", function() {
var node = createStyledNode("textarea");
node.value = "initial";
var textProp = {
text: "expected-text"
}, valueProp = {
value: "expected-value"
};
import__.default.updateView(node, textProp), expect(node.value).toEqual("expected-text"), import__.default.updateView(node, valueProp), expect(node.value).toEqual("expected-value");
}), test("sets other attribute values", function() {
var node = createStyledNode(), props = {
"aria-level": "4",
"data-of-type": "string"
};
import__.default.updateView(node, props), expect(node.getAttribute("aria-level")).toEqual("4"), expect(node.getAttribute("data-of-type")).toEqual("string");
});
});
});
//# sourceMappingURL=index-test.js.map