@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,153 @@
|
|
|
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 from "react";
|
|
11
|
+
import { fireEvent, render, waitFor } from "@testing-library/react-native";
|
|
12
|
+
import { Alert } from "react-native";
|
|
13
|
+
import { ButtonGroup } from "./ButtonGroup";
|
|
14
|
+
import { Button } from "../Button";
|
|
15
|
+
import * as atlantisContext from "../AtlantisContext/AtlantisContext";
|
|
16
|
+
import { atlantisContextDefaultValues } from "../AtlantisContext";
|
|
17
|
+
const mockOnOpen = jest.fn();
|
|
18
|
+
function ButtonGroupForTest(props) {
|
|
19
|
+
return (React.createElement(ButtonGroup, { bottomSheetHeading: props.bottomSheetHeading, showCancelInBottomSheet: props.showCancelInBottomSheet, onOpenBottomSheet: mockOnOpen }, props.children));
|
|
20
|
+
}
|
|
21
|
+
it("renders a single primary action", () => {
|
|
22
|
+
const createAction = jest.fn();
|
|
23
|
+
const { getByText, queryByLabelText } = render(React.createElement(ButtonGroupForTest, null,
|
|
24
|
+
React.createElement(ButtonGroup.PrimaryAction, { label: "Create", icon: "plus", onPress: createAction })));
|
|
25
|
+
expect(getByText("Create")).not.toBeNull();
|
|
26
|
+
expect(queryByLabelText("More")).toBeNull();
|
|
27
|
+
});
|
|
28
|
+
it("renders 2 primary actions", () => {
|
|
29
|
+
const createAction = jest.fn();
|
|
30
|
+
const editAction = jest.fn();
|
|
31
|
+
const { getByText, queryByLabelText } = render(React.createElement(ButtonGroupForTest, null,
|
|
32
|
+
React.createElement(ButtonGroup.PrimaryAction, { label: "Create", icon: "plus", onPress: createAction }),
|
|
33
|
+
React.createElement(ButtonGroup.PrimaryAction, { label: "Edit", icon: "edit", onPress: editAction })));
|
|
34
|
+
expect(getByText("Create")).not.toBeNull();
|
|
35
|
+
expect(getByText("Edit")).not.toBeNull();
|
|
36
|
+
expect(queryByLabelText("More")).toBeNull();
|
|
37
|
+
});
|
|
38
|
+
it("does not render more than 2 primary actions but adds a More button", () => {
|
|
39
|
+
const createAction = jest.fn();
|
|
40
|
+
const editAction = jest.fn();
|
|
41
|
+
const mysteryAction = jest.fn();
|
|
42
|
+
const { getByText, queryByText, getByLabelText } = render(React.createElement(ButtonGroupForTest, null,
|
|
43
|
+
React.createElement(ButtonGroup.PrimaryAction, { label: "Create", icon: "plus", onPress: createAction }),
|
|
44
|
+
React.createElement(ButtonGroup.PrimaryAction, { label: "Edit", icon: "edit", onPress: editAction }),
|
|
45
|
+
React.createElement(ButtonGroup.PrimaryAction, { label: "Mystery", icon: "edit", onPress: mysteryAction })));
|
|
46
|
+
expect(getByText("Create")).not.toBeNull();
|
|
47
|
+
expect(getByText("Edit")).not.toBeNull();
|
|
48
|
+
expect(queryByText("Mystery")).toBeNull();
|
|
49
|
+
expect(getByLabelText("More")).toBeDefined();
|
|
50
|
+
});
|
|
51
|
+
it("does not render secondary actions", () => {
|
|
52
|
+
const createAction = jest.fn();
|
|
53
|
+
const editAction = jest.fn();
|
|
54
|
+
const deleteAction = jest.fn();
|
|
55
|
+
const { getByText, queryByText, getByLabelText } = render(React.createElement(ButtonGroupForTest, null,
|
|
56
|
+
React.createElement(ButtonGroup.PrimaryAction, { label: "Create", icon: "plus", onPress: createAction }),
|
|
57
|
+
React.createElement(ButtonGroup.SecondaryAction, { label: "Edit", icon: "edit", onPress: editAction }),
|
|
58
|
+
React.createElement(ButtonGroup.SecondaryAction, { label: "Delete", icon: "trash", onPress: deleteAction })));
|
|
59
|
+
expect(getByText("Create")).not.toBeNull();
|
|
60
|
+
expect(queryByText("Edit")).toBeNull();
|
|
61
|
+
expect(queryByText("Delete")).toBeNull();
|
|
62
|
+
expect(getByLabelText("More")).toBeDefined();
|
|
63
|
+
});
|
|
64
|
+
it("renders first secondary action as a primary action button if no primary action specified", () => {
|
|
65
|
+
const editAction = jest.fn();
|
|
66
|
+
const deleteAction = jest.fn();
|
|
67
|
+
const { queryByText, getByText, getByLabelText } = render(React.createElement(ButtonGroupForTest, null,
|
|
68
|
+
React.createElement(ButtonGroup.SecondaryAction, { label: "Edit", icon: "edit", onPress: editAction }),
|
|
69
|
+
React.createElement(ButtonGroup.SecondaryAction, { label: "Delete", icon: "trash", onPress: deleteAction })));
|
|
70
|
+
expect(getByText("Edit")).not.toBeNull();
|
|
71
|
+
expect(queryByText("Delete")).toBeNull();
|
|
72
|
+
expect(getByLabelText("More")).toBeDefined();
|
|
73
|
+
});
|
|
74
|
+
it("fires the press handlers when the primary action buttons are pressed", () => {
|
|
75
|
+
const createAction = jest.fn();
|
|
76
|
+
const editAction = jest.fn();
|
|
77
|
+
const { getByText } = render(React.createElement(ButtonGroupForTest, null,
|
|
78
|
+
React.createElement(ButtonGroup.PrimaryAction, { label: "Create", icon: "plus", onPress: createAction }),
|
|
79
|
+
React.createElement(ButtonGroup.PrimaryAction, { label: "Edit", icon: "edit", onPress: editAction })));
|
|
80
|
+
fireEvent.press(getByText("Create"));
|
|
81
|
+
expect(createAction).toHaveBeenCalled();
|
|
82
|
+
fireEvent.press(getByText("Edit"));
|
|
83
|
+
expect(editAction).toHaveBeenCalled();
|
|
84
|
+
});
|
|
85
|
+
it("opens the secondary action menu when the More button is pressed", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
86
|
+
const createAction = jest.fn();
|
|
87
|
+
const editAction = jest.fn();
|
|
88
|
+
const deleteAction = jest.fn();
|
|
89
|
+
const { findByText, queryByText, getByLabelText } = render(React.createElement(ButtonGroupForTest, null,
|
|
90
|
+
React.createElement(ButtonGroup.PrimaryAction, { label: "Create", icon: "plus", onPress: createAction }),
|
|
91
|
+
React.createElement(ButtonGroup.SecondaryAction, { label: "Edit", icon: "edit", onPress: editAction }),
|
|
92
|
+
React.createElement(ButtonGroup.SecondaryAction, { label: "Delete", icon: "trash", onPress: deleteAction })));
|
|
93
|
+
expect(queryByText("Edit")).toBeNull();
|
|
94
|
+
fireEvent.press(getByLabelText("More"));
|
|
95
|
+
expect(yield findByText("Edit")).not.toBeNull();
|
|
96
|
+
expect(yield findByText("Delete")).not.toBeNull();
|
|
97
|
+
}));
|
|
98
|
+
it("renders heading and cancel options if passed in", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
99
|
+
const createAction = jest.fn();
|
|
100
|
+
const editAction = jest.fn();
|
|
101
|
+
const { findByText, getByLabelText } = render(React.createElement(ButtonGroupForTest, { bottomSheetHeading: "Heading", showCancelInBottomSheet: true },
|
|
102
|
+
React.createElement(ButtonGroup.PrimaryAction, { label: "Create", icon: "plus", onPress: createAction }),
|
|
103
|
+
React.createElement(ButtonGroup.SecondaryAction, { label: "Edit", icon: "edit", onPress: editAction })));
|
|
104
|
+
fireEvent.press(getByLabelText("More"));
|
|
105
|
+
expect(yield findByText("Heading")).not.toBeNull();
|
|
106
|
+
expect(yield findByText("Cancel")).not.toBeNull();
|
|
107
|
+
}));
|
|
108
|
+
it("renders custom button for primary action if passed in", () => {
|
|
109
|
+
const createAction = jest.fn();
|
|
110
|
+
const customCreateButton = (React.createElement(Button, { label: "CustomCreate", onPress: createAction }));
|
|
111
|
+
const { queryByText, getByText } = render(React.createElement(ButtonGroupForTest, null,
|
|
112
|
+
React.createElement(ButtonGroup.PrimaryAction, { label: "Create", icon: "plus", onPress: createAction, customButton: customCreateButton })));
|
|
113
|
+
expect(getByText("CustomCreate")).not.toBeNull();
|
|
114
|
+
expect(queryByText("Create")).toBeNull();
|
|
115
|
+
});
|
|
116
|
+
it("calls onOpenBottomSheet when the secondary actions are opened", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
117
|
+
const createAction = jest.fn();
|
|
118
|
+
const editAction = jest.fn();
|
|
119
|
+
const deleteAction = jest.fn();
|
|
120
|
+
const { getByLabelText } = render(React.createElement(ButtonGroupForTest, null,
|
|
121
|
+
React.createElement(ButtonGroup.PrimaryAction, { label: "Create", icon: "plus", onPress: createAction }),
|
|
122
|
+
React.createElement(ButtonGroup.SecondaryAction, { label: "Edit", icon: "edit", onPress: editAction }),
|
|
123
|
+
React.createElement(ButtonGroup.SecondaryAction, { label: "Delete", icon: "trash", onPress: deleteAction })));
|
|
124
|
+
fireEvent.press(getByLabelText("More"));
|
|
125
|
+
yield waitFor(() => {
|
|
126
|
+
expect(mockOnOpen).toHaveBeenCalledTimes(1);
|
|
127
|
+
});
|
|
128
|
+
}));
|
|
129
|
+
describe("ButtonGroup Offline/Online", () => {
|
|
130
|
+
const atlantisContextSpy = jest.spyOn(atlantisContext, "useAtlantisContext");
|
|
131
|
+
afterEach(() => {
|
|
132
|
+
jest.restoreAllMocks();
|
|
133
|
+
});
|
|
134
|
+
const handlePress = jest.fn();
|
|
135
|
+
const label = "Click me";
|
|
136
|
+
const setup = () => render(React.createElement(ButtonGroupForTest, null,
|
|
137
|
+
React.createElement(ButtonGroup.PrimaryAction, { label: label, icon: "plus", onPress: handlePress })));
|
|
138
|
+
it("should show an alert and not fire the onPress", () => {
|
|
139
|
+
const alertSpy = jest.spyOn(Alert, "alert");
|
|
140
|
+
atlantisContextSpy.mockReturnValue(Object.assign(Object.assign({}, atlantisContextDefaultValues), { isOnline: false }));
|
|
141
|
+
const { getByText } = setup();
|
|
142
|
+
fireEvent.press(getByText(label));
|
|
143
|
+
expect(alertSpy).toHaveBeenCalled();
|
|
144
|
+
expect(handlePress).not.toHaveBeenCalled();
|
|
145
|
+
});
|
|
146
|
+
it("should fire the onPress and not show an alert", () => {
|
|
147
|
+
const alertSpy = jest.spyOn(Alert, "alert");
|
|
148
|
+
const { getByText } = setup();
|
|
149
|
+
fireEvent.press(getByText(label));
|
|
150
|
+
expect(handlePress).toHaveBeenCalled();
|
|
151
|
+
expect(alertSpy).not.toHaveBeenCalled();
|
|
152
|
+
});
|
|
153
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { fireEvent, render } from "@testing-library/react-native";
|
|
3
|
+
import { Card } from "./Card";
|
|
4
|
+
import { Text } from "../Text";
|
|
5
|
+
const cardHeaderTestID = "cardHeader";
|
|
6
|
+
const cardFooterTestID = "cardFooter";
|
|
7
|
+
it("renders with only a header title", () => {
|
|
8
|
+
const title = "Foobar";
|
|
9
|
+
const { getByTestId, getByText, queryAllByRole } = render(React.createElement(Card, { header: { title } }));
|
|
10
|
+
expect(getByText(title)).toBeDefined();
|
|
11
|
+
expect(getByTestId(cardHeaderTestID)).toBeDefined();
|
|
12
|
+
expect(queryAllByRole("button")).toEqual([]);
|
|
13
|
+
});
|
|
14
|
+
it("renders with an icon action", () => {
|
|
15
|
+
const iconName = "plus2";
|
|
16
|
+
const { getByTestId } = render(React.createElement(Card, { header: {
|
|
17
|
+
title: "Foobar",
|
|
18
|
+
actionItem: { iconName },
|
|
19
|
+
onPress: jest.fn(),
|
|
20
|
+
} }));
|
|
21
|
+
expect(getByTestId(iconName)).toBeDefined();
|
|
22
|
+
});
|
|
23
|
+
it("renders with a button action", () => {
|
|
24
|
+
const label = "Edit";
|
|
25
|
+
const { getByText } = render(React.createElement(Card, { header: {
|
|
26
|
+
title: "Foobar",
|
|
27
|
+
actionItem: { label },
|
|
28
|
+
onPress: jest.fn(),
|
|
29
|
+
} }));
|
|
30
|
+
expect(getByText(label)).toBeDefined();
|
|
31
|
+
});
|
|
32
|
+
it("renders without a header and footer", () => {
|
|
33
|
+
const content = "I am the content";
|
|
34
|
+
const { getByText, queryByTestId } = render(React.createElement(Card, null,
|
|
35
|
+
React.createElement(Text, null, content)));
|
|
36
|
+
expect(getByText(content)).toBeDefined();
|
|
37
|
+
expect(queryByTestId(cardHeaderTestID)).toBeNull();
|
|
38
|
+
expect(queryByTestId(cardFooterTestID)).toBeNull();
|
|
39
|
+
});
|
|
40
|
+
it("should call the onPress when pressing the header", () => {
|
|
41
|
+
const pressHandler = jest.fn();
|
|
42
|
+
const { getByText } = render(React.createElement(Card, { header: {
|
|
43
|
+
title: "Header",
|
|
44
|
+
actionItem: { iconName: "plus2" },
|
|
45
|
+
onPress: pressHandler,
|
|
46
|
+
} }));
|
|
47
|
+
fireEvent.press(getByText("Header"));
|
|
48
|
+
expect(pressHandler).toHaveBeenCalled();
|
|
49
|
+
});
|
|
50
|
+
it("should call the onPress when pressing the action button", () => {
|
|
51
|
+
const pressHandler = jest.fn();
|
|
52
|
+
const { getByText } = render(React.createElement(Card, { header: {
|
|
53
|
+
title: "Header",
|
|
54
|
+
actionItem: { label: "Edit" },
|
|
55
|
+
onPress: pressHandler,
|
|
56
|
+
} }));
|
|
57
|
+
fireEvent.press(getByText("Edit"));
|
|
58
|
+
expect(pressHandler).toHaveBeenCalled();
|
|
59
|
+
});
|
|
60
|
+
it("renders with a footer", () => {
|
|
61
|
+
const title = "View All";
|
|
62
|
+
const { getByText, getByTestId, queryByTestId } = render(React.createElement(Card, { footer: { title: title, onPress: jest.fn() } }));
|
|
63
|
+
expect(getByText(title)).toBeDefined();
|
|
64
|
+
expect(getByTestId(cardFooterTestID)).toBeDefined();
|
|
65
|
+
expect(queryByTestId(cardHeaderTestID)).toBeNull();
|
|
66
|
+
});
|
|
67
|
+
it("should call the onPress when pressing the footer", () => {
|
|
68
|
+
const headerPressHandler = jest.fn();
|
|
69
|
+
const footerPressHandler = jest.fn();
|
|
70
|
+
const { getByText } = render(React.createElement(Card, { header: {
|
|
71
|
+
title: "Header",
|
|
72
|
+
actionItem: { iconName: "plus2" },
|
|
73
|
+
onPress: headerPressHandler,
|
|
74
|
+
}, footer: {
|
|
75
|
+
title: "View All",
|
|
76
|
+
onPress: footerPressHandler,
|
|
77
|
+
} }));
|
|
78
|
+
fireEvent.press(getByText("View All"));
|
|
79
|
+
expect(footerPressHandler).toHaveBeenCalled();
|
|
80
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { fireEvent, render } from "@testing-library/react-native";
|
|
3
|
+
import { InternalCardHeader } from "./InternalCardHeader";
|
|
4
|
+
it("should render a pressable header", () => {
|
|
5
|
+
const handlePress = jest.fn();
|
|
6
|
+
const screen = render(React.createElement(InternalCardHeader, { collapsable: true, onPress: handlePress, testID: "cardHeader" }, "\uD83C\uDF69"));
|
|
7
|
+
const header = screen.getByTestId("cardHeader");
|
|
8
|
+
expect(header).toBeDefined();
|
|
9
|
+
expect(header.props.accessibilityRole).toBe("button");
|
|
10
|
+
fireEvent.press(header);
|
|
11
|
+
expect(handlePress).toHaveBeenCalled();
|
|
12
|
+
});
|
|
13
|
+
it("should render an un-pressable header", () => {
|
|
14
|
+
const screen = render(React.createElement(InternalCardHeader, { collapsable: true, testID: "cardHeader" }, "\uD83C\uDF1E"));
|
|
15
|
+
const header = screen.getByTestId("cardHeader");
|
|
16
|
+
expect(header).toBeDefined();
|
|
17
|
+
expect(header.props.onPress).toBeUndefined();
|
|
18
|
+
});
|
|
@@ -0,0 +1,135 @@
|
|
|
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 from "react";
|
|
11
|
+
import { fireEvent, render, waitFor } from "@testing-library/react-native";
|
|
12
|
+
import { FormProvider, useForm } from "react-hook-form";
|
|
13
|
+
import { Button } from "react-native";
|
|
14
|
+
import { Checkbox } from "./Checkbox";
|
|
15
|
+
const accessibilityLabel = "testA11y";
|
|
16
|
+
const onChange = jest.fn();
|
|
17
|
+
afterEach(() => jest.resetAllMocks());
|
|
18
|
+
describe("Checkbox", () => {
|
|
19
|
+
it("renders checkbox label", () => {
|
|
20
|
+
const label = "TestLabel";
|
|
21
|
+
const { getByLabelText } = render(React.createElement(Checkbox, { name: "testCheckbox", label: label }));
|
|
22
|
+
expect(getByLabelText(label)).toBeTruthy();
|
|
23
|
+
});
|
|
24
|
+
it("renders checkbox with defaultChecked set to true", () => {
|
|
25
|
+
const { getByTestId, getByRole } = render(React.createElement(Checkbox, { name: "testCheckbox", defaultChecked: true }));
|
|
26
|
+
expect(getByRole("checkbox").props.accessibilityState).toHaveProperty("checked", true);
|
|
27
|
+
expect(getByTestId("checkmark")).toBeDefined();
|
|
28
|
+
});
|
|
29
|
+
it("renders checkbox label with assistive text", () => {
|
|
30
|
+
const label = "TestLabel";
|
|
31
|
+
const assistive = "TestAssistive";
|
|
32
|
+
const { getByLabelText, getByText } = render(React.createElement(Checkbox, { name: "testCheckbox", label: label, assistiveText: assistive }));
|
|
33
|
+
expect(getByLabelText(label)).toBeTruthy();
|
|
34
|
+
expect(getByText(assistive)).toBeTruthy();
|
|
35
|
+
});
|
|
36
|
+
it("will call onChange with true when pressed without default checked state set", () => {
|
|
37
|
+
const { getByLabelText } = render(React.createElement(Checkbox, { name: "testCheckbox", onChange: onChange, accessibilityLabel: accessibilityLabel }));
|
|
38
|
+
const checkbox = getByLabelText(accessibilityLabel);
|
|
39
|
+
fireEvent.press(checkbox);
|
|
40
|
+
expect(onChange).toHaveBeenCalledWith(true);
|
|
41
|
+
});
|
|
42
|
+
it("will call onChange with false when checked checkbox is pressed", () => {
|
|
43
|
+
const { getByLabelText } = render(React.createElement(Checkbox, { name: "onChangeTest", checked: true, onChange: onChange, accessibilityLabel: accessibilityLabel }));
|
|
44
|
+
const checkbox = getByLabelText(accessibilityLabel);
|
|
45
|
+
fireEvent.press(checkbox);
|
|
46
|
+
expect(onChange).toHaveBeenCalledWith(false);
|
|
47
|
+
});
|
|
48
|
+
it("will call onChange with true when unchecked checkbox is pressed", () => {
|
|
49
|
+
const { getByLabelText } = render(React.createElement(Checkbox, { name: "onChangeTest", checked: false, onChange: onChange, accessibilityLabel: accessibilityLabel }));
|
|
50
|
+
const checkbox = getByLabelText(accessibilityLabel);
|
|
51
|
+
fireEvent.press(checkbox);
|
|
52
|
+
expect(onChange).toHaveBeenCalledWith(true);
|
|
53
|
+
});
|
|
54
|
+
it("will not call onChange when disabled", () => {
|
|
55
|
+
const { getByLabelText } = render(React.createElement(Checkbox, { name: "testCheckbox", onChange: onChange, disabled: true, accessibilityLabel: accessibilityLabel }));
|
|
56
|
+
const checkbox = getByLabelText(accessibilityLabel);
|
|
57
|
+
fireEvent.press(checkbox);
|
|
58
|
+
expect(onChange).not.toHaveBeenCalled();
|
|
59
|
+
});
|
|
60
|
+
it("can be set as indeterminate", () => {
|
|
61
|
+
const { getByTestId } = render(React.createElement(Checkbox, { name: "testCheckbox", onChange: onChange, indeterminate: true, accessibilityLabel: accessibilityLabel }));
|
|
62
|
+
expect(getByTestId("minus2")).toBeDefined();
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
describe("Checkbox with FormProvider", () => {
|
|
66
|
+
const mockOnSubmit = jest.fn();
|
|
67
|
+
const checkboxName = "testCheckbox";
|
|
68
|
+
const checkboxLabel = "Test Checkbox";
|
|
69
|
+
const saveButtonText = "Save";
|
|
70
|
+
function FormWithProvider({ defaultChecked, }) {
|
|
71
|
+
const formMethods = useForm();
|
|
72
|
+
return (React.createElement(FormProvider, Object.assign({}, formMethods),
|
|
73
|
+
React.createElement(Checkbox, { name: checkboxName, label: checkboxLabel, defaultChecked: defaultChecked, accessibilityLabel: accessibilityLabel }),
|
|
74
|
+
React.createElement(Button, { onPress: formMethods.handleSubmit(values => mockOnSubmit(values)), title: saveButtonText, accessibilityLabel: saveButtonText })));
|
|
75
|
+
}
|
|
76
|
+
beforeEach(() => {
|
|
77
|
+
mockOnSubmit.mockClear();
|
|
78
|
+
});
|
|
79
|
+
describe("defaultChecked prop sets form value", () => {
|
|
80
|
+
it("sets form value to true when defaultChecked is true", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
81
|
+
const { getByLabelText } = render(React.createElement(FormWithProvider, { defaultChecked: true }));
|
|
82
|
+
const saveButton = getByLabelText(saveButtonText);
|
|
83
|
+
yield waitFor(() => {
|
|
84
|
+
fireEvent.press(saveButton);
|
|
85
|
+
});
|
|
86
|
+
expect(mockOnSubmit).toHaveBeenCalledWith({
|
|
87
|
+
[checkboxName]: true,
|
|
88
|
+
});
|
|
89
|
+
}));
|
|
90
|
+
it("sets form value to false when defaultChecked is false", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
91
|
+
const { getByLabelText } = render(React.createElement(FormWithProvider, { defaultChecked: false }));
|
|
92
|
+
const saveButton = getByLabelText(saveButtonText);
|
|
93
|
+
yield waitFor(() => {
|
|
94
|
+
fireEvent.press(saveButton);
|
|
95
|
+
});
|
|
96
|
+
expect(mockOnSubmit).toHaveBeenCalledWith({
|
|
97
|
+
[checkboxName]: false,
|
|
98
|
+
});
|
|
99
|
+
}));
|
|
100
|
+
it("sets form value to undefined when defaultChecked is undefined", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
101
|
+
const { getByLabelText } = render(React.createElement(FormWithProvider, null));
|
|
102
|
+
const saveButton = getByLabelText(saveButtonText);
|
|
103
|
+
yield waitFor(() => {
|
|
104
|
+
fireEvent.press(saveButton);
|
|
105
|
+
});
|
|
106
|
+
expect(mockOnSubmit).toHaveBeenCalledWith({
|
|
107
|
+
[checkboxName]: undefined,
|
|
108
|
+
});
|
|
109
|
+
}));
|
|
110
|
+
});
|
|
111
|
+
describe("checkbox value updates form value", () => {
|
|
112
|
+
it("updates form value when checkbox is toggled", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
113
|
+
const { getByLabelText } = render(React.createElement(FormWithProvider, { defaultChecked: false }));
|
|
114
|
+
const checkbox = getByLabelText(accessibilityLabel);
|
|
115
|
+
fireEvent.press(checkbox);
|
|
116
|
+
const saveButton = getByLabelText(saveButtonText);
|
|
117
|
+
yield waitFor(() => {
|
|
118
|
+
fireEvent.press(saveButton);
|
|
119
|
+
});
|
|
120
|
+
expect(mockOnSubmit).toHaveBeenCalledWith({
|
|
121
|
+
[checkboxName]: true,
|
|
122
|
+
});
|
|
123
|
+
}));
|
|
124
|
+
it("preserves defaultChecked value when checkbox is not interacted with", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
125
|
+
const { getByLabelText } = render(React.createElement(FormWithProvider, { defaultChecked: true }));
|
|
126
|
+
const saveButton = getByLabelText(saveButtonText);
|
|
127
|
+
yield waitFor(() => {
|
|
128
|
+
fireEvent.press(saveButton);
|
|
129
|
+
});
|
|
130
|
+
expect(mockOnSubmit).toHaveBeenCalledWith({
|
|
131
|
+
[checkboxName]: true,
|
|
132
|
+
});
|
|
133
|
+
}));
|
|
134
|
+
});
|
|
135
|
+
});
|
|
@@ -0,0 +1,197 @@
|
|
|
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 from "react";
|
|
11
|
+
import { fireEvent, render, waitFor } from "@testing-library/react-native";
|
|
12
|
+
import { FormProvider, useForm } from "react-hook-form";
|
|
13
|
+
import { CheckboxGroup } from "./CheckboxGroup";
|
|
14
|
+
import { Checkbox } from "./Checkbox";
|
|
15
|
+
import { Button } from "../Button";
|
|
16
|
+
const onSubmitMock = jest.fn();
|
|
17
|
+
const parentCheckboxLabel = "all condiments";
|
|
18
|
+
const firstCheckboxLabel = "relish";
|
|
19
|
+
const secondCheckboxLabel = "ketchup";
|
|
20
|
+
const thirdCheckboxLabel = "mustard";
|
|
21
|
+
const saveButtonText = "Save";
|
|
22
|
+
function setup(label, disabled, childDisabled) {
|
|
23
|
+
const checkboxGroup = render(React.createElement(CheckboxGroup, { name: "condimentsGroupCheckbox", label: label, accessibilityLabel: parentCheckboxLabel, disabled: disabled },
|
|
24
|
+
React.createElement(Checkbox, { label: "Relish", name: "relish", accessibilityLabel: firstCheckboxLabel }),
|
|
25
|
+
React.createElement(Checkbox, { label: "Ketchup", name: "ketchup", accessibilityLabel: secondCheckboxLabel, disabled: childDisabled }),
|
|
26
|
+
React.createElement(Checkbox, { label: "Mustard", name: "mustard", accessibilityLabel: thirdCheckboxLabel })));
|
|
27
|
+
return { checkboxGroup };
|
|
28
|
+
}
|
|
29
|
+
function SetupWithForm({ initialValues, onChangeHandlers, }) {
|
|
30
|
+
const formMethods = useForm({ defaultValues: initialValues });
|
|
31
|
+
return (React.createElement(FormProvider, Object.assign({}, formMethods),
|
|
32
|
+
React.createElement(CheckboxGroup, { name: "condiments", label: "All Condiments", accessibilityLabel: parentCheckboxLabel, onChange: onChangeHandlers === null || onChangeHandlers === void 0 ? void 0 : onChangeHandlers.all },
|
|
33
|
+
React.createElement(Checkbox, { label: "Relish", name: "relish", accessibilityLabel: firstCheckboxLabel, onChange: onChangeHandlers === null || onChangeHandlers === void 0 ? void 0 : onChangeHandlers.relish }),
|
|
34
|
+
React.createElement(Checkbox, { label: "Ketchup", name: "ketchup", accessibilityLabel: secondCheckboxLabel, onChange: onChangeHandlers === null || onChangeHandlers === void 0 ? void 0 : onChangeHandlers.ketchup }),
|
|
35
|
+
React.createElement(Checkbox, { label: "Mustard", name: "mustard", accessibilityLabel: thirdCheckboxLabel, onChange: onChangeHandlers === null || onChangeHandlers === void 0 ? void 0 : onChangeHandlers.mustard })),
|
|
36
|
+
React.createElement(Button, { onPress: formMethods.handleSubmit(values => onSubmitMock(values)), label: saveButtonText, accessibilityLabel: saveButtonText })));
|
|
37
|
+
}
|
|
38
|
+
describe("when none of the checkboxes in a group are checked", () => {
|
|
39
|
+
it("the parent checkbox should be in the unchecked state", () => {
|
|
40
|
+
const { checkboxGroup } = setup("All Condiments");
|
|
41
|
+
const parentCheckbox = checkboxGroup.getByLabelText(parentCheckboxLabel);
|
|
42
|
+
expect(parentCheckbox.props.accessibilityState.checked).toEqual(false);
|
|
43
|
+
});
|
|
44
|
+
describe("when the parent checkbox is pressed", () => {
|
|
45
|
+
it("should check all the checkboxes within the group", () => {
|
|
46
|
+
const { checkboxGroup } = setup("All Condiments");
|
|
47
|
+
fireEvent.press(checkboxGroup.getByLabelText(parentCheckboxLabel));
|
|
48
|
+
[firstCheckboxLabel, secondCheckboxLabel, thirdCheckboxLabel].forEach(checkboxLabel => {
|
|
49
|
+
const checkboxElement = checkboxGroup.getByLabelText(checkboxLabel);
|
|
50
|
+
expect(checkboxElement.props.accessibilityState.checked).toEqual(true);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
describe("when one of the checkboxes in a group are checked", () => {
|
|
56
|
+
it("the parent checkbox should be in the indeterminate state", () => {
|
|
57
|
+
const { checkboxGroup } = setup("All Condiments");
|
|
58
|
+
fireEvent.press(checkboxGroup.getByLabelText(secondCheckboxLabel));
|
|
59
|
+
const parentCheckbox = checkboxGroup.getByLabelText(parentCheckboxLabel);
|
|
60
|
+
expect(parentCheckbox.props.accessibilityState.checked).toEqual("mixed");
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
describe("when all of the checkboxes in a group are checked", () => {
|
|
64
|
+
function pressAllCheckboxes(checkboxGroup) {
|
|
65
|
+
fireEvent.press(checkboxGroup.getByLabelText(firstCheckboxLabel));
|
|
66
|
+
fireEvent.press(checkboxGroup.getByLabelText(secondCheckboxLabel));
|
|
67
|
+
fireEvent.press(checkboxGroup.getByLabelText(thirdCheckboxLabel));
|
|
68
|
+
}
|
|
69
|
+
it("the parent checkbox should be in the checked state", () => {
|
|
70
|
+
const { checkboxGroup } = setup("All Condiments");
|
|
71
|
+
pressAllCheckboxes(checkboxGroup);
|
|
72
|
+
const parentCheckbox = checkboxGroup.getByLabelText(parentCheckboxLabel);
|
|
73
|
+
expect(parentCheckbox.props.accessibilityState.checked).toEqual(true);
|
|
74
|
+
});
|
|
75
|
+
describe("when the parent checkbox is pressed", () => {
|
|
76
|
+
it("should uncheck all the checkboxes within the group", () => {
|
|
77
|
+
const { checkboxGroup } = setup("All Condiments");
|
|
78
|
+
pressAllCheckboxes(checkboxGroup);
|
|
79
|
+
fireEvent.press(checkboxGroup.getByLabelText(parentCheckboxLabel));
|
|
80
|
+
[firstCheckboxLabel, secondCheckboxLabel, thirdCheckboxLabel].forEach(checkboxLabel => {
|
|
81
|
+
const checkboxElement = checkboxGroup.getByLabelText(checkboxLabel);
|
|
82
|
+
expect(checkboxElement.props.accessibilityState.checked).toEqual(false);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
describe("when the parent checkbox does not have a label", () => {
|
|
88
|
+
it("does not render the parent checkbox", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
89
|
+
const { checkboxGroup } = setup(undefined);
|
|
90
|
+
const parentCheckbox = checkboxGroup.queryByLabelText(parentCheckboxLabel);
|
|
91
|
+
expect(parentCheckbox).toBeNull();
|
|
92
|
+
}));
|
|
93
|
+
});
|
|
94
|
+
describe("when the parent checkbox is disabled", () => {
|
|
95
|
+
it("disabled all the children checkboxes", () => {
|
|
96
|
+
const { checkboxGroup } = setup("All Condiments", true);
|
|
97
|
+
fireEvent.press(checkboxGroup.getByLabelText(parentCheckboxLabel));
|
|
98
|
+
[firstCheckboxLabel, secondCheckboxLabel, thirdCheckboxLabel].forEach(checkboxLabel => {
|
|
99
|
+
const checkboxElement = checkboxGroup.getByLabelText(checkboxLabel);
|
|
100
|
+
expect(checkboxElement.props.accessibilityState.disabled).toEqual(true);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
describe("when one of the checkboxes in a group are disabled", () => {
|
|
105
|
+
it("the parent shouldn't modify the disabled checkbox's state", () => {
|
|
106
|
+
const parentDisabled = false;
|
|
107
|
+
const childDisabled = true;
|
|
108
|
+
const { checkboxGroup } = setup("All Condiments", parentDisabled, childDisabled);
|
|
109
|
+
fireEvent.press(checkboxGroup.getByLabelText(parentCheckboxLabel));
|
|
110
|
+
[firstCheckboxLabel, thirdCheckboxLabel].forEach(checkboxLabel => {
|
|
111
|
+
const checkboxElement = checkboxGroup.getByLabelText(checkboxLabel);
|
|
112
|
+
expect(checkboxElement.props.accessibilityState.checked).toEqual(true);
|
|
113
|
+
});
|
|
114
|
+
const parentCheckbox = checkboxGroup.getByLabelText(parentCheckboxLabel);
|
|
115
|
+
expect(parentCheckbox.props.accessibilityState.checked).toEqual("mixed");
|
|
116
|
+
});
|
|
117
|
+
it("the parent should update the non disabled checkboxes", () => {
|
|
118
|
+
const parentDisabled = false;
|
|
119
|
+
const childDisabled = true;
|
|
120
|
+
const { checkboxGroup } = setup("All Condiments", parentDisabled, childDisabled);
|
|
121
|
+
fireEvent.press(checkboxGroup.getByLabelText(parentCheckboxLabel));
|
|
122
|
+
const secondCheckbox = checkboxGroup.getByLabelText(secondCheckboxLabel);
|
|
123
|
+
const parentCheckbox = checkboxGroup.getByLabelText(parentCheckboxLabel);
|
|
124
|
+
expect(secondCheckbox.props.accessibilityState.checked).toEqual(false);
|
|
125
|
+
expect(parentCheckbox.props.accessibilityState.checked).toEqual("mixed");
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
describe("when one of the checkbox has no name", () => {
|
|
129
|
+
it("should throw an error", () => {
|
|
130
|
+
expect(() => render(React.createElement(CheckboxGroup, { name: "condimentsGroupCheckbox", label: "test", accessibilityLabel: parentCheckboxLabel },
|
|
131
|
+
React.createElement(Checkbox, { label: "Relish", name: "relish", accessibilityLabel: firstCheckboxLabel }),
|
|
132
|
+
React.createElement(Checkbox, { label: "Ketchup", name: "ketchup", accessibilityLabel: secondCheckboxLabel }),
|
|
133
|
+
React.createElement(Checkbox, { onChange: jest.fn, checked: false })))).toThrow("You must provide a name to checkboxes in a checkbox group");
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
describe("when controlled by a form", () => {
|
|
137
|
+
describe("when a checkbox is pressed", () => {
|
|
138
|
+
it("should update the form values", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
139
|
+
const initialValues = {
|
|
140
|
+
condiments: {
|
|
141
|
+
parentChecked: false,
|
|
142
|
+
childrenChecked: { relish: false, ketchup: false, mustard: false },
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
const expectedValues = {
|
|
146
|
+
condiments: {
|
|
147
|
+
parentChecked: false,
|
|
148
|
+
childrenChecked: { relish: false, ketchup: true, mustard: false },
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
const { getByLabelText } = render(React.createElement(SetupWithForm, { initialValues: initialValues }));
|
|
152
|
+
fireEvent.press(getByLabelText(secondCheckboxLabel));
|
|
153
|
+
const saveButton = getByLabelText(saveButtonText);
|
|
154
|
+
yield waitFor(() => {
|
|
155
|
+
fireEvent.press(saveButton);
|
|
156
|
+
});
|
|
157
|
+
expect(onSubmitMock).toHaveBeenCalledWith(expectedValues);
|
|
158
|
+
}));
|
|
159
|
+
it("should call the onChange handler for child checkbox", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
160
|
+
const initialValues = {
|
|
161
|
+
condiments: {
|
|
162
|
+
parentChecked: false,
|
|
163
|
+
childrenChecked: { relish: false, ketchup: false, mustard: false },
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
const relishHandler = jest.fn();
|
|
167
|
+
const onChangeHandlers = {
|
|
168
|
+
relish: relishHandler,
|
|
169
|
+
};
|
|
170
|
+
const { getByLabelText } = render(React.createElement(SetupWithForm, { initialValues: initialValues, onChangeHandlers: onChangeHandlers }));
|
|
171
|
+
fireEvent.press(getByLabelText(firstCheckboxLabel));
|
|
172
|
+
expect(relishHandler).toHaveBeenCalledWith(true);
|
|
173
|
+
}));
|
|
174
|
+
it("should call the onChange handler for parent checkbox", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
175
|
+
const initialValues = {
|
|
176
|
+
condiments: {
|
|
177
|
+
parentChecked: false,
|
|
178
|
+
childrenChecked: { relish: false, ketchup: false, mustard: false },
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
const allHandler = jest.fn();
|
|
182
|
+
const onChangeHandlers = {
|
|
183
|
+
all: allHandler,
|
|
184
|
+
};
|
|
185
|
+
const { getByLabelText } = render(React.createElement(SetupWithForm, { initialValues: initialValues, onChangeHandlers: onChangeHandlers }));
|
|
186
|
+
fireEvent.press(getByLabelText(parentCheckboxLabel));
|
|
187
|
+
expect(allHandler).toHaveBeenCalledWith({
|
|
188
|
+
parentChecked: true,
|
|
189
|
+
childrenChecked: {
|
|
190
|
+
relish: true,
|
|
191
|
+
ketchup: true,
|
|
192
|
+
mustard: true,
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
}));
|
|
196
|
+
});
|
|
197
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { checkboxGroupReducer, initCheckboxGroupState, } from "./CheckboxGroupReducer";
|
|
2
|
+
let state;
|
|
3
|
+
const checkbox1 = "checkbox1";
|
|
4
|
+
const checkbox2 = "checkbox2";
|
|
5
|
+
const checkbox3 = "checkbox3";
|
|
6
|
+
const childrenNames = [checkbox1, checkbox2, checkbox3];
|
|
7
|
+
describe("update", () => {
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
state = initCheckboxGroupState(childrenNames);
|
|
10
|
+
});
|
|
11
|
+
it("should update childrenChecked", () => {
|
|
12
|
+
const result = checkboxGroupReducer(state, {
|
|
13
|
+
type: "Update",
|
|
14
|
+
data: { childrenChecked: { [checkbox1]: true } },
|
|
15
|
+
});
|
|
16
|
+
expect(result).toEqual(Object.assign(Object.assign({}, state), { childrenChecked: Object.assign(Object.assign({}, state.childrenChecked), { [checkbox1]: true }) }));
|
|
17
|
+
});
|
|
18
|
+
it("should update parentChecked", () => {
|
|
19
|
+
const result = checkboxGroupReducer(state, {
|
|
20
|
+
type: "Update",
|
|
21
|
+
data: { parentChecked: true },
|
|
22
|
+
});
|
|
23
|
+
expect(result).toEqual(Object.assign(Object.assign({}, state), { parentChecked: true }));
|
|
24
|
+
});
|
|
25
|
+
});
|