UNPKG

react-native-web-internals

Version:

React Native for Web

107 lines (106 loc) 5.25 kB
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 createProps = (props) => (0, import__.default)(null, props); describe("modules/createDOMProps", () => { describe("focus-related accessibility attributes", () => { test("with no accessibility props", () => { expect(createProps({})).toEqual({}); }), describe('"accessibilityRole" of "link"', () => { const accessibilityRole = "link"; test("default case", () => { expect(createProps({ accessibilityRole })).toEqual( expect.not.objectContaining({ tabIndex: "-1" }) ); }), test('when "focusable" is true', () => { expect(createProps({ accessibilityRole, focusable: !0 })).toEqual( expect.not.objectContaining({ tabIndex: "-1" }) ); }), test('when "focusable" is false', () => { expect(createProps({ accessibilityRole, focusable: !1 })).toEqual( expect.objectContaining({ tabIndex: "-1" }) ); }), test('when "accessibilityDisabled" is true', () => { expect(createProps({ accessibilityRole, accessibilityDisabled: !0 })).toEqual( expect.objectContaining({ "aria-disabled": !0 }) ); }), test('when "disabled" is false', () => { expect(createProps({ accessibilityRole, accessibilityDisabled: !1 })).toEqual( expect.not.objectContaining({ tabIndex: "-1" }) ); }); }); const testFocusableRole = (accessibilityRole) => { test("default case", () => { expect(createProps({ accessibilityRole })).toEqual( expect.objectContaining({ tabIndex: "0" }) ); }), test('when "focusable" is true', () => { expect(createProps({ accessibilityRole, focusable: !0 })).toEqual( expect.objectContaining({ tabIndex: "0" }) ); }), test('when "focusable" is false', () => { expect(createProps({ accessibilityRole, focusable: !1 })).toEqual( expect.objectContaining({ tabIndex: "-1" }) ); }), test('when "accessibilityDisabled" is true', () => { expect(createProps({ accessibilityRole, accessibilityDisabled: !0 })).toEqual( expect.objectContaining({ "aria-disabled": !0 }) ); }), test('when "accessibilityDisabled" is false', () => { expect(createProps({ accessibilityRole, accessibilityDisabled: !1 })).toEqual( expect.objectContaining({ tabIndex: "0" }) ); }); }; describe('"accessibilityRole" of "button"', () => { testFocusableRole("button"); }), describe("with unfocusable accessibilityRole", () => { test('when "focusable" is true', () => { expect(createProps({ focusable: !0 })).toEqual( expect.objectContaining({ tabIndex: "0" }) ); }), test('when "focusable" is false', () => { expect(createProps({ focusable: !1 })).toEqual( expect.objectContaining({ tabIndex: "-1" }) ); }); }); }), test('prop "accessibilityLabel" becomes "aria-label"', () => { const accessibilityLabel = "accessibilityLabel", props = createProps({ accessibilityLabel }); expect(props["aria-label"]).toEqual(accessibilityLabel); }), test('prop "accessibilityLiveRegion" becomes "aria-live"', () => { const props = createProps({ accessibilityLiveRegion: "none" }); expect(props["aria-live"]).toEqual("off"); }), test('prop "accessibilityRole" becomes "role"', () => { const props = createProps({ accessibilityRole: "button" }); expect(props.role).toEqual("button"); }), test('prop "className" is preserved', () => { const className = "external-class-name", props = createProps({ className }); expect(props.className).toEqual(className); }), test('prop "nativeID" becomes "id"', () => { const nativeID = "Example.nativeID", props = createProps({ nativeID }); expect(props.id).toEqual(nativeID); }), test('prop "testID" becomes "data-testid"', () => { const testID = "Example.testID", props = createProps({ testID }); expect(props["data-testid"]).toEqual(testID); }); }); //# sourceMappingURL=index-test.js.map