react-native-web-internals
Version:
React Native for Web
67 lines (66 loc) • 3.74 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(".."));
const createStyledNode = (name = "div", style = {}) => {
const root = document.createElement(name);
return Object.keys(style).forEach((prop) => {
root.style[prop] = style[prop];
}), root;
}, componentStub = {
_reactInternalInstance: {
_currentElement: { _owner: {} },
_debugID: 1
}
};
describe("apis/UIManager", () => {
describe("focus", () => {
test('sets tabIndex="-1" on elements not programmatically focusable by default', () => {
const node = createStyledNode();
import__.default.focus(node), expect(node.getAttribute("tabIndex")).toEqual("-1");
}), test(`doesn't set tabIndex="-1" on elements with an existing tabIndex`, () => {
const 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`, () => {
["a", "input", "select", "textarea"].forEach((name) => {
const node = createStyledNode(name);
import__.default.focus(node), expect(node.getAttribute("tabIndex")).toBeNull();
});
});
}), describe("updateView", () => {
test("supports className alias for class", () => {
const 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", () => {
const 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", () => {
const node = createStyledNode("textarea");
node.value = "initial";
const 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", () => {
const 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