react-native-web-internals
Version:
React Native for Web
88 lines (87 loc) • 4.1 kB
JavaScript
import createDOMProps from "..";
const createProps = (props) => createDOMProps(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