@jobber/components-native 0.101.3 → 0.101.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json +19 -11
- package/dist/src/ActionItem/ActionItem.test.js +81 -0
- package/dist/src/ActionItem/ActionItemGroup.test.js +25 -0
- package/dist/src/ActionItem/components/ActionItemContainer.test.js +24 -0
- package/dist/src/ActionLabel/ActionLabel.test.js +81 -0
- package/dist/src/ActivityIndicator/ActivityIndicator.test.js +23 -0
- package/dist/src/AtlantisContext/AtlantisContext.test.js +35 -0
- package/dist/src/AtlantisThemeContext/AtlantisThemeContext.test.js +65 -0
- package/dist/src/AtlantisThemeContext/buildThemedStyles.test.js +43 -0
- package/dist/src/AutoLink/AutoLink.test.js +133 -0
- package/dist/src/AutoLink/components/Link/Link.test.js +18 -0
- package/dist/src/Banner/Banner.test.js +98 -0
- package/dist/src/BottomSheet/BottomSheet.test.js +105 -0
- package/dist/src/BottomSheet/components/BottomSheetOption/BottomSheetOption.test.js +19 -0
- package/dist/src/BottomSheet/hooks/useBottomSheetBackHandler.test.js +68 -0
- package/dist/src/Button/Button.test.js +228 -0
- package/dist/src/Button/components/InternalButtonLoading/InternalButtonLoading.test.js +25 -0
- package/dist/src/ButtonGroup/ButtonGroup.test.js +153 -0
- package/dist/src/Card/Card.test.js +80 -0
- package/dist/src/Card/components/InternalCardHeader.test.js +18 -0
- package/dist/src/Checkbox/Checkbox.test.js +135 -0
- package/dist/src/Checkbox/CheckboxGroup.test.js +197 -0
- package/dist/src/Checkbox/CheckboxGroupReducer.test.js +25 -0
- package/dist/src/Chip/Chip.test.js +69 -0
- package/dist/src/Content/Content.test.js +250 -0
- package/dist/src/ContentOverlay/ContentOverlay.test.js +297 -0
- package/dist/src/ContentOverlay/computeContentOverlayBehavior.test.js +197 -0
- package/dist/src/ContentOverlay/hooks/useBottomSheetModalBackHandler.test.js +62 -0
- package/dist/src/ContentOverlay/hooks/useKeyboardVisibility.test.js +41 -0
- package/dist/src/ContentOverlay/hooks/useViewLayoutHeight.test.js +62 -0
- package/dist/src/Disclosure/Disclosure.test.js +64 -0
- package/dist/src/Divider/Divider.test.js +65 -0
- package/dist/src/EmptyState/EmptyState.test.js +82 -0
- package/dist/src/ErrorMessageWrapper/ErrorMessageWrapper.test.js +29 -0
- package/dist/src/Flex/Flex.test.js +104 -0
- package/dist/src/Form/Form.test.js +393 -0
- package/dist/src/Form/components/FormErrorBanner/FormErrorBanner.test.js +41 -0
- package/dist/src/Form/components/FormMessage/FormMessage.test.js +73 -0
- package/dist/src/Form/components/FormMessageBanner/FormMessageBanner.test.js +30 -0
- package/dist/src/Form/components/FormSaveButton/FormSaveButton.test.js +82 -0
- package/dist/src/Form/context/AtlantisFormContext.test.js +28 -0
- package/dist/src/Form/hooks/useScrollToError/useScrollToError.test.js +89 -0
- package/dist/src/FormField/FormField.test.js +81 -0
- package/dist/src/FormatFile/FormatFile.test.js +212 -0
- package/dist/src/FormatFile/FormatFileThumbnail.test.js +192 -0
- package/dist/src/FormatFile/components/FormatFileBottomSheet/FormatFileBottomSheet.test.js +74 -0
- package/dist/src/FormatFile/components/MediaView/MediaView.test.js +202 -0
- package/dist/src/FormatFile/utils/parseFile.test.js +188 -0
- package/dist/src/Glimmer/Glimmer.test.js +61 -0
- package/dist/src/Heading/Heading.test.js +61 -0
- package/dist/src/Icon/Icon.test.js +40 -0
- package/dist/src/IconButton/IconButton.test.js +38 -0
- package/dist/src/InputCurrency/InputCurrency.test.js +106 -0
- package/dist/src/InputDate/InputDate.test.js +184 -0
- package/dist/src/InputEmail/InputEmail.test.js +27 -0
- package/dist/src/InputFieldWrapper/InputFieldWrapper.test.js +279 -0
- package/dist/src/InputFieldWrapper/components/ClearAction/ClearAction.test.js +9 -0
- package/dist/src/InputFieldWrapper/components/Prefix/Prefix.test.js +130 -0
- package/dist/src/InputFieldWrapper/components/Suffix/Suffix.test.js +51 -0
- package/dist/src/InputNumber/InputNumber.test.js +220 -0
- package/dist/src/InputPassword/InputPassword.test.js +63 -0
- package/dist/src/InputPressable/InputPressable.test.js +138 -0
- package/dist/src/InputSearch/InputSearch.test.js +54 -0
- package/dist/src/InputText/InputText.test.js +652 -0
- package/dist/src/InputText/context/InputAccessoriesProvider.test.js +71 -0
- package/dist/src/InputTime/InputTime.test.js +199 -0
- package/dist/src/InputTime/utils/utils.test.js +32 -0
- package/dist/src/ProgressBar/ProgressBar.test.js +89 -0
- package/dist/src/Select/Select.test.js +183 -0
- package/dist/src/Select/components/SelectDefaultPicker/SelectDefaultPicker.test.js +51 -0
- package/dist/src/Select/components/SelectInternalPicker/SelectInternalPicker.test.js +72 -0
- package/dist/src/StatusLabel/StatusLabel.test.js +51 -0
- package/dist/src/Switch/Switch.test.js +60 -0
- package/dist/src/Switch/components/BaseSwitch/BaseSwitch.test.js +61 -0
- package/dist/src/Text/Text.test.js +161 -0
- package/dist/src/TextList/TextList.test.js +16 -0
- package/dist/src/ThumbnailList/ThumbnailList.test.js +72 -0
- package/dist/src/Toast/Toast.test.js +51 -0
- package/dist/src/Typography/Typography.test.js +225 -0
- package/dist/src/hooks/useAtlantisI18n/useAtlantisI18n.test.js +103 -0
- package/dist/src/utils/meta/meta.test.js +83 -0
- package/dist/tsconfig.build.json +5 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/tsconfig.eslint.json +14 -0
- package/dist/tsconfig.json +3 -4
- package/dist/types/src/ActionItem/ActionItem.test.d.ts +1 -0
- package/dist/types/src/ActionItem/ActionItemGroup.test.d.ts +1 -0
- package/dist/types/src/ActionItem/components/ActionItemContainer.test.d.ts +1 -0
- package/dist/types/src/ActionLabel/ActionLabel.test.d.ts +1 -0
- package/dist/types/src/ActivityIndicator/ActivityIndicator.test.d.ts +1 -0
- package/dist/types/src/AtlantisContext/AtlantisContext.test.d.ts +1 -0
- package/dist/types/src/AtlantisThemeContext/AtlantisThemeContext.test.d.ts +1 -0
- package/dist/types/src/AtlantisThemeContext/buildThemedStyles.test.d.ts +1 -0
- package/dist/types/src/AutoLink/AutoLink.test.d.ts +1 -0
- package/dist/types/src/AutoLink/components/Link/Link.test.d.ts +1 -0
- package/dist/types/src/Banner/Banner.test.d.ts +1 -0
- package/dist/types/src/BottomSheet/BottomSheet.test.d.ts +1 -0
- package/dist/types/src/BottomSheet/components/BottomSheetOption/BottomSheetOption.test.d.ts +1 -0
- package/dist/types/src/BottomSheet/hooks/useBottomSheetBackHandler.test.d.ts +1 -0
- package/dist/types/src/Button/Button.test.d.ts +1 -0
- package/dist/types/src/Button/components/InternalButtonLoading/InternalButtonLoading.test.d.ts +1 -0
- package/dist/types/src/ButtonGroup/ButtonGroup.test.d.ts +1 -0
- package/dist/types/src/Card/Card.test.d.ts +1 -0
- package/dist/types/src/Card/components/InternalCardHeader.test.d.ts +1 -0
- package/dist/types/src/Checkbox/Checkbox.test.d.ts +1 -0
- package/dist/types/src/Checkbox/CheckboxGroup.test.d.ts +1 -0
- package/dist/types/src/Checkbox/CheckboxGroupReducer.test.d.ts +1 -0
- package/dist/types/src/Chip/Chip.test.d.ts +1 -0
- package/dist/types/src/Content/Content.test.d.ts +1 -0
- package/dist/types/src/ContentOverlay/BottomSheetKeyboardAwareScrollView.d.ts +2 -1
- package/dist/types/src/ContentOverlay/ContentOverlay.test.d.ts +1 -0
- package/dist/types/src/ContentOverlay/computeContentOverlayBehavior.test.d.ts +1 -0
- package/dist/types/src/ContentOverlay/hooks/useBottomSheetModalBackHandler.test.d.ts +1 -0
- package/dist/types/src/ContentOverlay/hooks/useKeyboardVisibility.test.d.ts +1 -0
- package/dist/types/src/ContentOverlay/hooks/useViewLayoutHeight.test.d.ts +1 -0
- package/dist/types/src/Disclosure/Disclosure.test.d.ts +1 -0
- package/dist/types/src/Divider/Divider.test.d.ts +1 -0
- package/dist/types/src/EmptyState/EmptyState.test.d.ts +1 -0
- package/dist/types/src/ErrorMessageWrapper/ErrorMessageWrapper.test.d.ts +1 -0
- package/dist/types/src/Flex/Flex.test.d.ts +1 -0
- package/dist/types/src/Form/Form.test.d.ts +1 -0
- package/dist/types/src/Form/components/FormErrorBanner/FormErrorBanner.test.d.ts +1 -0
- package/dist/types/src/Form/components/FormMessage/FormMessage.test.d.ts +1 -0
- package/dist/types/src/Form/components/FormMessageBanner/FormMessageBanner.test.d.ts +1 -0
- package/dist/types/src/Form/components/FormSaveButton/FormSaveButton.test.d.ts +1 -0
- package/dist/types/src/Form/context/AtlantisFormContext.test.d.ts +1 -0
- package/dist/types/src/Form/hooks/useScrollToError/useScrollToError.test.d.ts +1 -0
- package/dist/types/src/FormField/FormField.test.d.ts +1 -0
- package/dist/types/src/FormatFile/FormatFile.test.d.ts +1 -0
- package/dist/types/src/FormatFile/FormatFileThumbnail.test.d.ts +1 -0
- package/dist/types/src/FormatFile/components/FormatFileBottomSheet/FormatFileBottomSheet.test.d.ts +1 -0
- package/dist/types/src/FormatFile/components/MediaView/MediaView.test.d.ts +1 -0
- package/dist/types/src/FormatFile/utils/parseFile.test.d.ts +1 -0
- package/dist/types/src/Glimmer/Glimmer.test.d.ts +1 -0
- package/dist/types/src/Heading/Heading.test.d.ts +1 -0
- package/dist/types/src/Icon/Icon.test.d.ts +1 -0
- package/dist/types/src/IconButton/IconButton.test.d.ts +1 -0
- package/dist/types/src/InputCurrency/InputCurrency.test.d.ts +1 -0
- package/dist/types/src/InputDate/InputDate.test.d.ts +1 -0
- package/dist/types/src/InputEmail/InputEmail.test.d.ts +1 -0
- package/dist/types/src/InputFieldWrapper/InputFieldWrapper.test.d.ts +1 -0
- package/dist/types/src/InputFieldWrapper/components/ClearAction/ClearAction.test.d.ts +1 -0
- package/dist/types/src/InputFieldWrapper/components/Prefix/Prefix.test.d.ts +1 -0
- package/dist/types/src/InputFieldWrapper/components/Suffix/Suffix.test.d.ts +1 -0
- package/dist/types/src/InputNumber/InputNumber.test.d.ts +1 -0
- package/dist/types/src/InputPassword/InputPassword.test.d.ts +1 -0
- package/dist/types/src/InputPressable/InputPressable.test.d.ts +1 -0
- package/dist/types/src/InputSearch/InputSearch.test.d.ts +1 -0
- package/dist/types/src/InputText/InputText.test.d.ts +1 -0
- package/dist/types/src/InputText/context/InputAccessoriesProvider.test.d.ts +1 -0
- package/dist/types/src/InputTime/InputTime.test.d.ts +1 -0
- package/dist/types/src/InputTime/utils/utils.test.d.ts +1 -0
- package/dist/types/src/ProgressBar/ProgressBar.test.d.ts +1 -0
- package/dist/types/src/Select/Select.test.d.ts +1 -0
- package/dist/types/src/Select/components/SelectDefaultPicker/SelectDefaultPicker.test.d.ts +1 -0
- package/dist/types/src/Select/components/SelectInternalPicker/SelectInternalPicker.test.d.ts +1 -0
- package/dist/types/src/StatusLabel/StatusLabel.test.d.ts +1 -0
- package/dist/types/src/Switch/Switch.test.d.ts +1 -0
- package/dist/types/src/Switch/components/BaseSwitch/BaseSwitch.test.d.ts +1 -0
- package/dist/types/src/Text/Text.test.d.ts +1 -0
- package/dist/types/src/TextList/TextList.test.d.ts +1 -0
- package/dist/types/src/ThumbnailList/ThumbnailList.test.d.ts +1 -0
- package/dist/types/src/Toast/Toast.test.d.ts +1 -0
- package/dist/types/src/Typography/Typography.test.d.ts +1 -0
- package/dist/types/src/hooks/useAtlantisI18n/useAtlantisI18n.test.d.ts +1 -0
- package/dist/types/src/utils/meta/meta.test.d.ts +1 -0
- package/package.json +19 -11
- package/src/Button/Button.test.tsx +6 -2
- package/src/ContentOverlay/hooks/useViewLayoutHeight.test.ts +3 -3
- package/src/Divider/Divider.stories.tsx +1 -1
- package/src/Flex/Flex.test.tsx +1 -1
- package/src/Form/Form.test.tsx +3 -1
- package/src/FormField/FormField.test.tsx +5 -1
- package/src/Heading/__snapshots__/Heading.test.tsx.snap +1 -1
- package/src/InputDate/InputDate.test.tsx +7 -1
- package/src/InputText/InputText.test.tsx +2 -1
- package/src/InputTime/InputTime.test.tsx +7 -1
- package/src/Select/Select.test.tsx +1 -1
- package/src/StatusLabel/__snapshots__/StatusLabel.test.tsx.snap +8 -8
- package/src/Text/__snapshots__/Text.test.tsx.snap +2 -2
- package/src/ThumbnailList/__snapshots__/ThumbnailList.test.tsx.snap +1 -1
- package/src/Typography/__snapshots__/Typography.test.tsx.snap +4 -4
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { fireEvent, render } from "@testing-library/react-native";
|
|
3
|
+
import { Chip } from "./Chip";
|
|
4
|
+
import { tokens } from "../utils/design";
|
|
5
|
+
it("renders an active Chip", () => {
|
|
6
|
+
const { getByText, getByLabelText } = render(React.createElement(Chip, { label: "Foo", onPress: jest.fn(), accessibilityLabel: "Foo chip", isActive: true }));
|
|
7
|
+
expect(getByText("Foo")).toBeDefined();
|
|
8
|
+
expect(getByLabelText("Foo chip").props.style).toContainEqual({
|
|
9
|
+
backgroundColor: tokens["color-surface--reverse"],
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
it("renders an active Chip without onPress as disabled", () => {
|
|
13
|
+
const { getByTestId } = render(React.createElement(Chip, { label: "Foo", accessibilityLabel: "Foo chip", isActive: true }));
|
|
14
|
+
expect(getByTestId("chipTest").props.accessibilityState.disabled).toBeTruthy();
|
|
15
|
+
});
|
|
16
|
+
it("renders an inactive Chip with a default backgroundColor", () => {
|
|
17
|
+
const { getByTestId } = render(React.createElement(Chip, { label: "Foo", onPress: jest.fn(), isActive: false }));
|
|
18
|
+
expect(getByTestId("chipTest").props.style).not.toContainEqual({
|
|
19
|
+
backgroundColor: tokens["color-surface--reverse"],
|
|
20
|
+
});
|
|
21
|
+
expect(getByTestId("chipTest").props.style).toContainEqual({
|
|
22
|
+
backgroundColor: tokens["color-interactive--background"],
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
it("renders an inactive Chip with a surface backgroundColor", () => {
|
|
26
|
+
const { getByTestId } = render(React.createElement(Chip, { label: "Foo", onPress: jest.fn(), isActive: false, inactiveBackgroundColor: "surface" }));
|
|
27
|
+
expect(getByTestId("chipTest").props.style).toContainEqual({
|
|
28
|
+
backgroundColor: tokens["color-surface"],
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
it("renders an active Chip with icon", () => {
|
|
32
|
+
const { getByTestId } = render(React.createElement(Chip, { onPress: jest.fn(), icon: "invoice", isActive: true }));
|
|
33
|
+
expect(getByTestId("invoice")).toBeDefined();
|
|
34
|
+
});
|
|
35
|
+
it("renders an inactive Chip with icon", () => {
|
|
36
|
+
const { getByTestId } = render(React.createElement(Chip, { onPress: jest.fn(), icon: "invoice", isActive: false }));
|
|
37
|
+
expect(getByTestId("invoice")).toBeDefined();
|
|
38
|
+
});
|
|
39
|
+
it("renders a Chip with the dismiss icon", () => {
|
|
40
|
+
const { getByTestId } = render(React.createElement(Chip, { label: "Foo", onPress: jest.fn(), isActive: true, isDismissible: true }));
|
|
41
|
+
expect(getByTestId("remove")).toBeDefined();
|
|
42
|
+
});
|
|
43
|
+
it("should call the handler with the new value", () => {
|
|
44
|
+
const pressHandler = jest.fn();
|
|
45
|
+
const accessibilityLabel = "test chip";
|
|
46
|
+
const { getByLabelText } = render(React.createElement(Chip, { onPress: pressHandler, label: "foo", accessibilityLabel: accessibilityLabel, isActive: true }));
|
|
47
|
+
fireEvent.press(getByLabelText(accessibilityLabel));
|
|
48
|
+
expect(pressHandler).toHaveBeenCalled();
|
|
49
|
+
});
|
|
50
|
+
describe("accessibilityLabel", () => {
|
|
51
|
+
it("uses accessibilityLabel if specified", () => {
|
|
52
|
+
const pressHandler = jest.fn();
|
|
53
|
+
const { getByLabelText } = render(React.createElement(Chip, { onPress: pressHandler, label: "label", accessibilityLabel: "accessibilityLabel", isActive: true }));
|
|
54
|
+
expect(getByLabelText("accessibilityLabel")).toBeTruthy();
|
|
55
|
+
});
|
|
56
|
+
it("uses label if unspecified", () => {
|
|
57
|
+
const pressHandler = jest.fn();
|
|
58
|
+
const { getByLabelText } = render(React.createElement(Chip, { onPress: pressHandler, label: "label", isActive: true }));
|
|
59
|
+
expect(getByLabelText("label")).toBeTruthy();
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
describe("accent", () => {
|
|
63
|
+
it("uses accent color when present and chip is Active", () => {
|
|
64
|
+
const { getByTestId } = render(React.createElement(Chip, { label: "Foo", onPress: jest.fn(), accessibilityLabel: "Foo chip", isActive: true, accent: "client" }));
|
|
65
|
+
expect(getByTestId("chipTest").props.style).toContainEqual({
|
|
66
|
+
backgroundColor: tokens["color-client"],
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render, renderHook } from "@testing-library/react-native";
|
|
3
|
+
import { View } from "react-native";
|
|
4
|
+
import { Content } from "./Content";
|
|
5
|
+
import { useSpaceAroundStyles } from "./ContentSpaceAround.style";
|
|
6
|
+
import { useVerticalStyles } from "./ContentVertical.style";
|
|
7
|
+
import { useHorizontalStyles } from "./ContentHorizontal.style";
|
|
8
|
+
import { Text } from "../Text";
|
|
9
|
+
function getContentComponent(parentView) {
|
|
10
|
+
var _a;
|
|
11
|
+
return (_a = parentView === null || parentView === void 0 ? void 0 : parentView.children[0]) === null || _a === void 0 ? void 0 : _a.children[0];
|
|
12
|
+
}
|
|
13
|
+
function getContentChildren(contentView) {
|
|
14
|
+
var _a;
|
|
15
|
+
return (_a = contentView.children[0]) === null || _a === void 0 ? void 0 : _a.children;
|
|
16
|
+
}
|
|
17
|
+
const text = "🌚 I am the text 🌞";
|
|
18
|
+
function setupContent(props) {
|
|
19
|
+
const container = render(React.createElement(View, { accessibilityLabel: "contentView" },
|
|
20
|
+
React.createElement(Content, { spacing: props === null || props === void 0 ? void 0 : props.spacing, childSpacing: props === null || props === void 0 ? void 0 : props.childSpacing, direction: props === null || props === void 0 ? void 0 : props.direction, UNSAFE_style: props === null || props === void 0 ? void 0 : props.UNSAFE_style },
|
|
21
|
+
React.createElement(Text, null, text),
|
|
22
|
+
React.createElement(Text, null, text))));
|
|
23
|
+
const parentView = container.getByLabelText("contentView");
|
|
24
|
+
const contentView = getContentComponent(parentView);
|
|
25
|
+
const contentChildren = getContentChildren(contentView);
|
|
26
|
+
return Object.assign(Object.assign({}, container), { parentView, contentView, contentChildren });
|
|
27
|
+
}
|
|
28
|
+
let spaceStyles;
|
|
29
|
+
let verticalStyles;
|
|
30
|
+
let horizontalStyles;
|
|
31
|
+
beforeAll(() => {
|
|
32
|
+
spaceStyles = renderHook(() => useSpaceAroundStyles()).result.current;
|
|
33
|
+
verticalStyles = renderHook(() => useVerticalStyles()).result.current;
|
|
34
|
+
horizontalStyles = renderHook(() => useHorizontalStyles()).result.current;
|
|
35
|
+
});
|
|
36
|
+
describe("Space around", () => {
|
|
37
|
+
it("should have a base padding around the component", () => {
|
|
38
|
+
const { contentView } = setupContent();
|
|
39
|
+
expect(contentView.props.style).toContainEqual(spaceStyles.baseSpace);
|
|
40
|
+
});
|
|
41
|
+
it("should have a small padding around the component", () => {
|
|
42
|
+
const { contentView } = setupContent({ spacing: "small" });
|
|
43
|
+
expect(contentView.props.style).toContainEqual(spaceStyles.smallSpace);
|
|
44
|
+
});
|
|
45
|
+
it("should have a large padding around the component", () => {
|
|
46
|
+
const { contentView } = setupContent({ spacing: "large" });
|
|
47
|
+
expect(contentView.props.style).toContainEqual(spaceStyles.largeSpace);
|
|
48
|
+
});
|
|
49
|
+
it("should have a no padding around the component", () => {
|
|
50
|
+
const { contentView } = setupContent({ spacing: "none" });
|
|
51
|
+
expect(contentView.props.style).toContainEqual(spaceStyles.noneSpace);
|
|
52
|
+
});
|
|
53
|
+
it("should have a smaller padding around the component", () => {
|
|
54
|
+
const { contentView } = setupContent({ spacing: "smaller" });
|
|
55
|
+
expect(contentView.props.style).toContainEqual(spaceStyles.smallerSpace);
|
|
56
|
+
});
|
|
57
|
+
it("should have the smallest padding around the component", () => {
|
|
58
|
+
const { contentView } = setupContent({ spacing: "smallest" });
|
|
59
|
+
expect(contentView.props.style).toContainEqual(spaceStyles.smallestSpace);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
describe("Vertical", () => {
|
|
63
|
+
it("should have the vertical wrapper style", () => {
|
|
64
|
+
const { contentView } = setupContent();
|
|
65
|
+
expect(contentView.props.style).toContainEqual(verticalStyles.wrapper);
|
|
66
|
+
});
|
|
67
|
+
describe("Child space between", () => {
|
|
68
|
+
it("should have a base top padding on every child but the first", () => {
|
|
69
|
+
const { contentChildren } = setupContent({
|
|
70
|
+
direction: "vertical",
|
|
71
|
+
childSpacing: "base",
|
|
72
|
+
});
|
|
73
|
+
expect(contentChildren[0].props.style).toEqual([
|
|
74
|
+
verticalStyles.childWrapper,
|
|
75
|
+
]);
|
|
76
|
+
expect(contentChildren[1].props.style).toContainEqual(verticalStyles.baseChildSpace);
|
|
77
|
+
});
|
|
78
|
+
it("should have a small top padding on every child but the first", () => {
|
|
79
|
+
const { contentChildren } = setupContent({
|
|
80
|
+
direction: "vertical",
|
|
81
|
+
childSpacing: "small",
|
|
82
|
+
});
|
|
83
|
+
expect(contentChildren[0].props.style).toEqual([
|
|
84
|
+
verticalStyles.childWrapper,
|
|
85
|
+
]);
|
|
86
|
+
expect(contentChildren[1].props.style).toContainEqual(verticalStyles.smallChildSpace);
|
|
87
|
+
});
|
|
88
|
+
it("should have a large top padding on every child but the first", () => {
|
|
89
|
+
const { contentChildren } = setupContent({
|
|
90
|
+
direction: "vertical",
|
|
91
|
+
childSpacing: "large",
|
|
92
|
+
});
|
|
93
|
+
expect(contentChildren[0].props.style).toEqual([
|
|
94
|
+
verticalStyles.childWrapper,
|
|
95
|
+
]);
|
|
96
|
+
expect(contentChildren[1].props.style).toContainEqual(verticalStyles.largeChildSpace);
|
|
97
|
+
});
|
|
98
|
+
it("should have no top padding on every child but the first", () => {
|
|
99
|
+
const { contentChildren } = setupContent({
|
|
100
|
+
direction: "vertical",
|
|
101
|
+
childSpacing: "none",
|
|
102
|
+
});
|
|
103
|
+
expect(contentChildren[0].props.style).toEqual([
|
|
104
|
+
verticalStyles.childWrapper,
|
|
105
|
+
]);
|
|
106
|
+
expect(contentChildren[1].props.style).toContainEqual(verticalStyles.noneChildSpace);
|
|
107
|
+
});
|
|
108
|
+
it("should have a smaller top padding on every child but the first", () => {
|
|
109
|
+
const { contentChildren } = setupContent({
|
|
110
|
+
direction: "vertical",
|
|
111
|
+
childSpacing: "smaller",
|
|
112
|
+
});
|
|
113
|
+
expect(contentChildren[0].props.style).toEqual([
|
|
114
|
+
verticalStyles.childWrapper,
|
|
115
|
+
]);
|
|
116
|
+
expect(contentChildren[1].props.style).toContainEqual(verticalStyles.smallerChildSpace);
|
|
117
|
+
});
|
|
118
|
+
it("should have the smallest top padding on every child but the first", () => {
|
|
119
|
+
const { contentChildren } = setupContent({
|
|
120
|
+
direction: "vertical",
|
|
121
|
+
childSpacing: "smallest",
|
|
122
|
+
});
|
|
123
|
+
expect(contentChildren[0].props.style).toEqual([
|
|
124
|
+
verticalStyles.childWrapper,
|
|
125
|
+
]);
|
|
126
|
+
expect(contentChildren[1].props.style).toContainEqual(verticalStyles.smallestChildSpace);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
describe("Horizontal", () => {
|
|
131
|
+
it("should have the horizontal wrapper style", () => {
|
|
132
|
+
const { contentView } = setupContent({ direction: "horizontal" });
|
|
133
|
+
expect(contentView.props.style).toContainEqual(horizontalStyles.wrapper);
|
|
134
|
+
});
|
|
135
|
+
describe("Child space between", () => {
|
|
136
|
+
it("should have a base left padding on every child but the first", () => {
|
|
137
|
+
const { contentChildren } = setupContent({
|
|
138
|
+
direction: "horizontal",
|
|
139
|
+
childSpacing: "base",
|
|
140
|
+
});
|
|
141
|
+
expect(contentChildren[0].props.style).toEqual([
|
|
142
|
+
horizontalStyles.childWrapper,
|
|
143
|
+
]);
|
|
144
|
+
expect(contentChildren[1].props.style).toContainEqual(horizontalStyles.baseChildSpace);
|
|
145
|
+
});
|
|
146
|
+
it("should have a small left padding on every child but the first", () => {
|
|
147
|
+
const { contentChildren } = setupContent({
|
|
148
|
+
direction: "horizontal",
|
|
149
|
+
childSpacing: "small",
|
|
150
|
+
});
|
|
151
|
+
expect(contentChildren[0].props.style).toEqual([
|
|
152
|
+
horizontalStyles.childWrapper,
|
|
153
|
+
]);
|
|
154
|
+
expect(contentChildren[1].props.style).toContainEqual(horizontalStyles.smallChildSpace);
|
|
155
|
+
});
|
|
156
|
+
it("should have a large left padding on every child but the first", () => {
|
|
157
|
+
const { contentChildren } = setupContent({
|
|
158
|
+
direction: "horizontal",
|
|
159
|
+
childSpacing: "large",
|
|
160
|
+
});
|
|
161
|
+
expect(contentChildren[0].props.style).toEqual([
|
|
162
|
+
horizontalStyles.childWrapper,
|
|
163
|
+
]);
|
|
164
|
+
expect(contentChildren[1].props.style).toContainEqual(horizontalStyles.largeChildSpace);
|
|
165
|
+
});
|
|
166
|
+
it("should have no left padding on every child but the first", () => {
|
|
167
|
+
const { contentChildren } = setupContent({
|
|
168
|
+
direction: "horizontal",
|
|
169
|
+
childSpacing: "none",
|
|
170
|
+
});
|
|
171
|
+
expect(contentChildren[0].props.style).toEqual([
|
|
172
|
+
horizontalStyles.childWrapper,
|
|
173
|
+
]);
|
|
174
|
+
expect(contentChildren[1].props.style).toContainEqual(horizontalStyles.noneChildSpace);
|
|
175
|
+
});
|
|
176
|
+
it("should have a smaller left padding on every child but the first", () => {
|
|
177
|
+
const { contentChildren } = setupContent({
|
|
178
|
+
direction: "horizontal",
|
|
179
|
+
childSpacing: "smaller",
|
|
180
|
+
});
|
|
181
|
+
expect(contentChildren[0].props.style).toEqual([
|
|
182
|
+
horizontalStyles.childWrapper,
|
|
183
|
+
]);
|
|
184
|
+
expect(contentChildren[1].props.style).toContainEqual(horizontalStyles.smallerChildSpace);
|
|
185
|
+
});
|
|
186
|
+
it("should have the smallest left padding on every child but the first", () => {
|
|
187
|
+
const { contentChildren } = setupContent({
|
|
188
|
+
direction: "horizontal",
|
|
189
|
+
childSpacing: "smallest",
|
|
190
|
+
});
|
|
191
|
+
expect(contentChildren[0].props.style).toEqual([
|
|
192
|
+
horizontalStyles.childWrapper,
|
|
193
|
+
]);
|
|
194
|
+
expect(contentChildren[1].props.style).toContainEqual(horizontalStyles.smallestChildSpace);
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
describe("UNSAFE_style", () => {
|
|
199
|
+
it("applies custom styles to container", () => {
|
|
200
|
+
const customStyle = {
|
|
201
|
+
backgroundColor: "red",
|
|
202
|
+
padding: 16,
|
|
203
|
+
};
|
|
204
|
+
const { parentView } = setupContent({
|
|
205
|
+
UNSAFE_style: {
|
|
206
|
+
container: customStyle,
|
|
207
|
+
},
|
|
208
|
+
});
|
|
209
|
+
const contentView = getContentComponent(parentView);
|
|
210
|
+
expect(contentView.props.style).toEqual(expect.arrayContaining([expect.objectContaining(customStyle)]));
|
|
211
|
+
});
|
|
212
|
+
it("applies custom styles to child wrapper", () => {
|
|
213
|
+
const customStyle = {
|
|
214
|
+
backgroundColor: "blue",
|
|
215
|
+
marginLeft: 8,
|
|
216
|
+
};
|
|
217
|
+
const { parentView } = setupContent({
|
|
218
|
+
UNSAFE_style: {
|
|
219
|
+
childWrapper: customStyle,
|
|
220
|
+
},
|
|
221
|
+
});
|
|
222
|
+
const contentView = getContentComponent(parentView);
|
|
223
|
+
const contentChildren = getContentChildren(contentView);
|
|
224
|
+
contentChildren.forEach(child => {
|
|
225
|
+
expect(child.props.style).toEqual(expect.arrayContaining([expect.objectContaining(customStyle)]));
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
it("applies custom styles to both container and child wrapper", () => {
|
|
229
|
+
const containerStyle = {
|
|
230
|
+
backgroundColor: "red",
|
|
231
|
+
padding: 16,
|
|
232
|
+
};
|
|
233
|
+
const childWrapperStyle = {
|
|
234
|
+
backgroundColor: "blue",
|
|
235
|
+
marginLeft: 8,
|
|
236
|
+
};
|
|
237
|
+
const { parentView } = setupContent({
|
|
238
|
+
UNSAFE_style: {
|
|
239
|
+
container: containerStyle,
|
|
240
|
+
childWrapper: childWrapperStyle,
|
|
241
|
+
},
|
|
242
|
+
});
|
|
243
|
+
const contentView = getContentComponent(parentView);
|
|
244
|
+
const contentChildren = getContentChildren(contentView);
|
|
245
|
+
expect(contentView.props.style).toEqual(expect.arrayContaining([expect.objectContaining(containerStyle)]));
|
|
246
|
+
contentChildren.forEach(child => {
|
|
247
|
+
expect(child.props.style).toEqual(expect.arrayContaining([expect.objectContaining(childWrapperStyle)]));
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
});
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import React, { createRef } from "react";
|
|
11
|
+
import { act, render, screen, userEvent, waitFor, } from "@testing-library/react-native";
|
|
12
|
+
import { AccessibilityInfo, View } from "react-native";
|
|
13
|
+
import { ContentOverlay } from "./ContentOverlay";
|
|
14
|
+
import { AtlantisOverlayProvider } from "../AtlantisOverlayProvider";
|
|
15
|
+
import { tokens } from "../utils/design";
|
|
16
|
+
import { Button } from "../Button";
|
|
17
|
+
import { Content } from "../Content";
|
|
18
|
+
import { Text } from "../Text";
|
|
19
|
+
jest.unmock("../hooks/useIsScreenReaderEnabled");
|
|
20
|
+
jest.unmock("react-native-reanimated");
|
|
21
|
+
jest.unmock("@gorhom/bottom-sheet");
|
|
22
|
+
jest.mock("@gorhom/bottom-sheet/lib/commonjs/hooks/useAnimatedLayout", () => ({
|
|
23
|
+
// Fix for reanimated not actually running in the test environment.
|
|
24
|
+
useAnimatedLayout: () => {
|
|
25
|
+
const value = {
|
|
26
|
+
containerHeight: 600,
|
|
27
|
+
rawContainerHeight: 600,
|
|
28
|
+
handleHeight: 24,
|
|
29
|
+
footerHeight: 0,
|
|
30
|
+
contentHeight: 400,
|
|
31
|
+
containerOffset: { top: 0, bottom: 0, left: 0, right: 0 },
|
|
32
|
+
};
|
|
33
|
+
return { value, get: () => value };
|
|
34
|
+
},
|
|
35
|
+
}));
|
|
36
|
+
const user = userEvent.setup();
|
|
37
|
+
function getDefaultOptions() {
|
|
38
|
+
return {
|
|
39
|
+
text: "I am the contentOverlay text",
|
|
40
|
+
title: "Title",
|
|
41
|
+
buttonLabel: "Open Content Overlay",
|
|
42
|
+
fullScreen: false,
|
|
43
|
+
showDismiss: false,
|
|
44
|
+
modalBackgroundColor: "surface",
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function renderContentOverlay({ text, title, buttonLabel, a11yLabel, fullScreen, showDismiss, modalBackgroundColor, onCloseCallback, onOpenCallback, onBeforeExitCallback, } = getDefaultOptions()) {
|
|
48
|
+
const contentOverlayRef = createRef();
|
|
49
|
+
render(React.createElement(AtlantisOverlayProvider, null,
|
|
50
|
+
React.createElement(View, null,
|
|
51
|
+
React.createElement(Text, null, "I am a bunch of text"),
|
|
52
|
+
React.createElement(Button, { label: buttonLabel || "Open Content Overlay", onPress: () => {
|
|
53
|
+
var _a, _b;
|
|
54
|
+
(_b = (_a = contentOverlayRef === null || contentOverlayRef === void 0 ? void 0 : contentOverlayRef.current) === null || _a === void 0 ? void 0 : _a.open) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
55
|
+
} }),
|
|
56
|
+
React.createElement(ContentOverlay, { ref: contentOverlayRef, title: title, onClose: onCloseCallback, onOpen: onOpenCallback, accessibilityLabel: a11yLabel, fullScreen: fullScreen, showDismiss: showDismiss, modalBackgroundColor: modalBackgroundColor, onBeforeExit: onBeforeExitCallback },
|
|
57
|
+
React.createElement(Content, null,
|
|
58
|
+
React.createElement(Text, null, text))))));
|
|
59
|
+
}
|
|
60
|
+
function renderAndOpenContentOverlay() {
|
|
61
|
+
return __awaiter(this, arguments, void 0, function* (defaultOptions = getDefaultOptions()) {
|
|
62
|
+
jest.useFakeTimers();
|
|
63
|
+
const props = Object.assign({ onOpenCallback: jest.fn(), onCloseCallback: jest.fn() }, defaultOptions);
|
|
64
|
+
renderContentOverlay(props);
|
|
65
|
+
yield user.press(screen.getByLabelText(defaultOptions.buttonLabel));
|
|
66
|
+
yield act(() => __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
jest.runAllTimers();
|
|
68
|
+
}));
|
|
69
|
+
yield waitFor(() => {
|
|
70
|
+
// expect(screen.getByTestId("ATL-Overlay-Header")).toBeDefined();
|
|
71
|
+
expect(props.onOpenCallback).toHaveBeenCalledTimes(1);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
describe("when open is called on the content overlay ref", () => {
|
|
76
|
+
it("should open the content overlay, exposing the content to the user", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
77
|
+
const options = Object.assign(Object.assign({}, getDefaultOptions()), { text: "I am text within the content overlay" });
|
|
78
|
+
yield renderAndOpenContentOverlay(options);
|
|
79
|
+
expect(screen.getByText(options.text)).toBeDefined();
|
|
80
|
+
}));
|
|
81
|
+
});
|
|
82
|
+
describe("when the close button is clicked on an open content overlay", () => {
|
|
83
|
+
it("should close the content overlay", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
84
|
+
const options = Object.assign(Object.assign({}, getDefaultOptions()), { text: "I am text within the content overlay", showDismiss: true });
|
|
85
|
+
yield renderAndOpenContentOverlay(options);
|
|
86
|
+
const closeButton = yield screen.findByTestId("ATL-Overlay-CloseButton");
|
|
87
|
+
yield user.press(closeButton);
|
|
88
|
+
yield act(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
89
|
+
jest.runAllTimers();
|
|
90
|
+
}));
|
|
91
|
+
yield waitFor(() => {
|
|
92
|
+
expect(screen.queryByText(options.text)).toBeNull();
|
|
93
|
+
});
|
|
94
|
+
}));
|
|
95
|
+
});
|
|
96
|
+
describe("when the close button is clicked on an open content overlay with a defined onClose prop", () => {
|
|
97
|
+
it("should call the passed in onClose prop", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
98
|
+
const options = Object.assign(Object.assign({}, getDefaultOptions()), { onCloseCallback: jest.fn(), showDismiss: true });
|
|
99
|
+
yield renderAndOpenContentOverlay(options);
|
|
100
|
+
const closeButton = yield screen.findByTestId("ATL-Overlay-CloseButton");
|
|
101
|
+
yield user.press(closeButton);
|
|
102
|
+
yield act(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
103
|
+
jest.runAllTimers();
|
|
104
|
+
}));
|
|
105
|
+
yield waitFor(() => {
|
|
106
|
+
expect(options.onCloseCallback).toHaveBeenCalled();
|
|
107
|
+
});
|
|
108
|
+
}));
|
|
109
|
+
});
|
|
110
|
+
describe("when the content overlay is created with a defined onOpen prop", () => {
|
|
111
|
+
describe("when the content overlay is not opened", () => {
|
|
112
|
+
it("should not call the passed in onOpen prop", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
113
|
+
const options = Object.assign(Object.assign({}, getDefaultOptions()), { onOpenCallback: jest.fn() });
|
|
114
|
+
renderContentOverlay(options);
|
|
115
|
+
yield waitFor(() => {
|
|
116
|
+
expect(options.onOpenCallback).not.toHaveBeenCalled();
|
|
117
|
+
});
|
|
118
|
+
}));
|
|
119
|
+
});
|
|
120
|
+
describe("when the content overlay is opened", () => {
|
|
121
|
+
it("should call the passed in onOpen prop", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
122
|
+
const options = Object.assign(Object.assign({}, getDefaultOptions()), { onOpenCallback: jest.fn() });
|
|
123
|
+
yield renderAndOpenContentOverlay(options);
|
|
124
|
+
yield waitFor(() => {
|
|
125
|
+
expect(options.onOpenCallback).toHaveBeenCalled();
|
|
126
|
+
});
|
|
127
|
+
}));
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
describe("when title prop passed to content overlay", () => {
|
|
131
|
+
it("should set the header title", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
132
|
+
const options = Object.assign(Object.assign({}, getDefaultOptions()), { title: "Awesome Title" });
|
|
133
|
+
yield renderAndOpenContentOverlay(options);
|
|
134
|
+
expect(screen.getByText(options.title)).toBeDefined();
|
|
135
|
+
}));
|
|
136
|
+
});
|
|
137
|
+
describe("when accessibilityLabel prop passed to content overlay", () => {
|
|
138
|
+
it("should set the header accessibilityLabel", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
139
|
+
const options = Object.assign(Object.assign({}, getDefaultOptions()), { a11yLabel: "Awesome a11y Label", showDismiss: true });
|
|
140
|
+
yield renderAndOpenContentOverlay(options);
|
|
141
|
+
expect(screen.getByLabelText(options.a11yLabel || "ohno")).toBeDefined();
|
|
142
|
+
}));
|
|
143
|
+
});
|
|
144
|
+
describe("when accessibilityLabel prop NOT passed to content overlay", () => {
|
|
145
|
+
it("should use default accessibilityLabel", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
146
|
+
const options = Object.assign(Object.assign({}, getDefaultOptions()), { title: "Awesome Title", showDismiss: true });
|
|
147
|
+
yield renderAndOpenContentOverlay(options);
|
|
148
|
+
expect(screen.getAllByLabelText(`Close ${options.title} modal`)).toHaveLength(2);
|
|
149
|
+
}));
|
|
150
|
+
});
|
|
151
|
+
describe("when there is a screen reader enabled", () => {
|
|
152
|
+
jest
|
|
153
|
+
.spyOn(AccessibilityInfo, "isScreenReaderEnabled")
|
|
154
|
+
.mockImplementation(() => Promise.resolve(true));
|
|
155
|
+
it("should show the dismiss button", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
156
|
+
const options = Object.assign({}, getDefaultOptions());
|
|
157
|
+
yield renderAndOpenContentOverlay(options);
|
|
158
|
+
expect(yield screen.findByTestId("ATL-Overlay-CloseButton")).toBeDefined();
|
|
159
|
+
}));
|
|
160
|
+
});
|
|
161
|
+
describe("when fullScreen is set to true", () => {
|
|
162
|
+
it("should show the dismiss button", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
163
|
+
const options = Object.assign(Object.assign({}, getDefaultOptions()), { fullScreen: true });
|
|
164
|
+
yield renderAndOpenContentOverlay(options);
|
|
165
|
+
expect(screen.getByTestId("ATL-Overlay-CloseButton")).toBeDefined();
|
|
166
|
+
}));
|
|
167
|
+
});
|
|
168
|
+
describe("when showDismiss is set to true", () => {
|
|
169
|
+
it("should show the dismiss button", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
170
|
+
const options = Object.assign(Object.assign({}, getDefaultOptions()), { showDismiss: true });
|
|
171
|
+
yield renderAndOpenContentOverlay(options);
|
|
172
|
+
expect(screen.getByTestId("ATL-Overlay-CloseButton")).toBeDefined();
|
|
173
|
+
}));
|
|
174
|
+
});
|
|
175
|
+
describe("when the close button is clicked on an open content overlay with a defined onBeforeExit", () => {
|
|
176
|
+
it("should call the callback method on exit", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
177
|
+
const options = Object.assign(Object.assign({}, getDefaultOptions()), { onBeforeExitCallback: jest.fn(), showDismiss: true });
|
|
178
|
+
yield renderAndOpenContentOverlay(options);
|
|
179
|
+
yield user.press(screen.getByTestId("ATL-Overlay-CloseButton"));
|
|
180
|
+
yield waitFor(() => {
|
|
181
|
+
expect(options.onBeforeExitCallback).toHaveBeenCalled();
|
|
182
|
+
});
|
|
183
|
+
}));
|
|
184
|
+
});
|
|
185
|
+
describe("modalBackgroundColor prop", () => {
|
|
186
|
+
describe("when using the default surface value", () => {
|
|
187
|
+
it("renders the component with the color-surface color", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
188
|
+
const options = Object.assign({}, getDefaultOptions());
|
|
189
|
+
yield renderAndOpenContentOverlay(options);
|
|
190
|
+
const OverlayHeader = screen.getByTestId("ATL-Overlay-Header")
|
|
191
|
+
.children[0];
|
|
192
|
+
const OverlayHeaderStyles = OverlayHeader.props.style;
|
|
193
|
+
expect(OverlayHeaderStyles).toEqual(expect.arrayContaining([
|
|
194
|
+
expect.objectContaining({
|
|
195
|
+
backgroundColor: tokens["color-surface"],
|
|
196
|
+
}),
|
|
197
|
+
]));
|
|
198
|
+
expect(OverlayHeaderStyles).not.toEqual(expect.arrayContaining([
|
|
199
|
+
expect.objectContaining({
|
|
200
|
+
backgroundColor: tokens["color-surface--background"],
|
|
201
|
+
}),
|
|
202
|
+
]));
|
|
203
|
+
}));
|
|
204
|
+
});
|
|
205
|
+
describe("when set to background", () => {
|
|
206
|
+
it("changes the backround color of the modal to color-surface--background", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
207
|
+
const options = Object.assign(Object.assign({}, getDefaultOptions()), { modalBackgroundColor: "background" });
|
|
208
|
+
yield renderAndOpenContentOverlay(options);
|
|
209
|
+
const OverlayHeader = screen.getByTestId("ATL-Overlay-Header")
|
|
210
|
+
.children[0];
|
|
211
|
+
const OverlayHeaderStyles = OverlayHeader.props.style;
|
|
212
|
+
expect(OverlayHeaderStyles).toEqual(expect.arrayContaining([
|
|
213
|
+
expect.objectContaining({
|
|
214
|
+
backgroundColor: tokens["color-surface--background"],
|
|
215
|
+
}),
|
|
216
|
+
]));
|
|
217
|
+
}));
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
describe("scrollEnabled prop", () => {
|
|
221
|
+
describe("when scrollEnabled is false (default)", () => {
|
|
222
|
+
it("should render content in BottomSheetView", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
223
|
+
const options = Object.assign({}, getDefaultOptions());
|
|
224
|
+
yield renderAndOpenContentOverlay(options);
|
|
225
|
+
expect(screen.getByText(options.text)).toBeDefined();
|
|
226
|
+
expect(screen.getByTestId("ATL-Overlay-Children")).toBeDefined();
|
|
227
|
+
}));
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
describe("loading prop", () => {
|
|
231
|
+
describe("when loading is true", () => {
|
|
232
|
+
it("should show subdued heading text", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
233
|
+
const overlayRef = createRef();
|
|
234
|
+
render(React.createElement(AtlantisOverlayProvider, null,
|
|
235
|
+
React.createElement(View, null,
|
|
236
|
+
React.createElement(ContentOverlay, { ref: overlayRef, title: "Loading Overlay", loading: true, showDismiss: true },
|
|
237
|
+
React.createElement(Text, null, "Loading content")))));
|
|
238
|
+
yield act(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
239
|
+
var _a, _b;
|
|
240
|
+
(_b = (_a = overlayRef.current) === null || _a === void 0 ? void 0 : _a.open) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
241
|
+
}));
|
|
242
|
+
yield waitFor(() => {
|
|
243
|
+
expect(screen.getByText("Loading Overlay")).toBeDefined();
|
|
244
|
+
});
|
|
245
|
+
}));
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
describe("onBeforeExit callback", () => {
|
|
249
|
+
describe("when close button is pressed with onBeforeExit defined", () => {
|
|
250
|
+
it("should call onBeforeExit instead of immediately closing", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
251
|
+
const overlayRef = createRef();
|
|
252
|
+
const onBeforeExitCallback = jest.fn();
|
|
253
|
+
render(React.createElement(AtlantisOverlayProvider, null,
|
|
254
|
+
React.createElement(View, null,
|
|
255
|
+
React.createElement(ContentOverlay, { ref: overlayRef, title: "Confirmation Required", onBeforeExit: onBeforeExitCallback, showDismiss: true },
|
|
256
|
+
React.createElement(Text, null, "Must confirm to close")))));
|
|
257
|
+
yield act(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
258
|
+
var _a, _b;
|
|
259
|
+
(_b = (_a = overlayRef.current) === null || _a === void 0 ? void 0 : _a.open) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
260
|
+
}));
|
|
261
|
+
yield waitFor(() => {
|
|
262
|
+
expect(screen.getByText("Must confirm to close")).toBeDefined();
|
|
263
|
+
});
|
|
264
|
+
const closeButton = screen.getByTestId("ATL-Overlay-CloseButton");
|
|
265
|
+
yield user.press(closeButton);
|
|
266
|
+
yield waitFor(() => {
|
|
267
|
+
expect(onBeforeExitCallback).toHaveBeenCalled();
|
|
268
|
+
expect(screen.getByText("Must confirm to close")).toBeDefined();
|
|
269
|
+
});
|
|
270
|
+
}));
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
describe("title prop", () => {
|
|
274
|
+
it("should render the title", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
275
|
+
const options = Object.assign(Object.assign({}, getDefaultOptions()), { title: "Awesome Title" });
|
|
276
|
+
yield renderAndOpenContentOverlay(options);
|
|
277
|
+
expect(screen.getByText(options.title)).toBeDefined();
|
|
278
|
+
}));
|
|
279
|
+
describe("when title is not passed but showDismiss is true", () => {
|
|
280
|
+
it("should should render dismiss button", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
281
|
+
const options = Object.assign(Object.assign({}, getDefaultOptions()), { showDismiss: true });
|
|
282
|
+
yield renderAndOpenContentOverlay(options);
|
|
283
|
+
expect(screen.getByTestId("ATL-Overlay-CloseButton")).toBeDefined();
|
|
284
|
+
}));
|
|
285
|
+
});
|
|
286
|
+
describe("when title is not passed but showDismiss is false", () => {
|
|
287
|
+
it("should not render the header", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
288
|
+
jest
|
|
289
|
+
.spyOn(AccessibilityInfo, "isScreenReaderEnabled")
|
|
290
|
+
.mockImplementation(() => Promise.resolve(false));
|
|
291
|
+
const options = Object.assign(Object.assign({}, getDefaultOptions()), { showDismiss: false, title: "", fullScreen: false });
|
|
292
|
+
yield renderAndOpenContentOverlay(options);
|
|
293
|
+
console.log(options);
|
|
294
|
+
expect(screen.queryByTestId("ATL-Overlay-Header")).toBeNull();
|
|
295
|
+
}));
|
|
296
|
+
});
|
|
297
|
+
});
|