@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,197 @@
|
|
|
1
|
+
import { computeContentOverlayBehavior } from "./computeContentOverlayBehavior";
|
|
2
|
+
const arbitraryClosedPositionValue = 768;
|
|
3
|
+
const defaultConfig = {
|
|
4
|
+
fullScreen: false,
|
|
5
|
+
adjustToContentHeight: false,
|
|
6
|
+
isDraggable: true,
|
|
7
|
+
hasOnBeforeExit: false,
|
|
8
|
+
showDismiss: false,
|
|
9
|
+
};
|
|
10
|
+
const defaultState = {
|
|
11
|
+
isScreenReaderEnabled: false,
|
|
12
|
+
position: arbitraryClosedPositionValue,
|
|
13
|
+
};
|
|
14
|
+
function aConfig(overrides = {}) {
|
|
15
|
+
return Object.assign(Object.assign({}, defaultConfig), overrides);
|
|
16
|
+
}
|
|
17
|
+
function aState(overrides = {}) {
|
|
18
|
+
return Object.assign(Object.assign({}, defaultState), overrides);
|
|
19
|
+
}
|
|
20
|
+
describe("computeContentOverlayBehavior", () => {
|
|
21
|
+
describe("initialHeight", () => {
|
|
22
|
+
it("returns fullScreen when fullScreen=true", () => {
|
|
23
|
+
const config = aConfig({ fullScreen: true });
|
|
24
|
+
const state = aState();
|
|
25
|
+
const result = computeContentOverlayBehavior(config, state);
|
|
26
|
+
expect(result.initialHeight).toBe("fullScreen");
|
|
27
|
+
});
|
|
28
|
+
it("returns contentHeight when adjustToContentHeight=true", () => {
|
|
29
|
+
const config = aConfig({ adjustToContentHeight: true });
|
|
30
|
+
const state = aState();
|
|
31
|
+
const result = computeContentOverlayBehavior(config, state);
|
|
32
|
+
expect(result.initialHeight).toBe("contentHeight");
|
|
33
|
+
});
|
|
34
|
+
it("returns contentHeight for default props (legacy case)", () => {
|
|
35
|
+
const config = aConfig();
|
|
36
|
+
const state = aState();
|
|
37
|
+
const result = computeContentOverlayBehavior(config, state);
|
|
38
|
+
expect(result.initialHeight).toBe("contentHeight");
|
|
39
|
+
});
|
|
40
|
+
it("returns adjustToContentHeight when adjustToContentHeight=true even if fullScreen=true", () => {
|
|
41
|
+
const config = aConfig({ fullScreen: true, adjustToContentHeight: true });
|
|
42
|
+
const state = aState();
|
|
43
|
+
const result = computeContentOverlayBehavior(config, state);
|
|
44
|
+
expect(result.initialHeight).toBe("contentHeight");
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
describe("isDraggable", () => {
|
|
48
|
+
it("returns false when onBeforeExit is present regardless of isDraggable prop", () => {
|
|
49
|
+
const config = aConfig({ isDraggable: true, hasOnBeforeExit: true });
|
|
50
|
+
const state = aState();
|
|
51
|
+
const result = computeContentOverlayBehavior(config, state);
|
|
52
|
+
expect(result.isDraggable).toBe(false);
|
|
53
|
+
});
|
|
54
|
+
it("returns false when onBeforeExit is present and isDraggable is false", () => {
|
|
55
|
+
const config = aConfig({ isDraggable: false, hasOnBeforeExit: true });
|
|
56
|
+
const state = aState();
|
|
57
|
+
const result = computeContentOverlayBehavior(config, state);
|
|
58
|
+
expect(result.isDraggable).toBe(false);
|
|
59
|
+
});
|
|
60
|
+
it("respects isDraggable=true when no onBeforeExit", () => {
|
|
61
|
+
const config = aConfig({ isDraggable: true, hasOnBeforeExit: false });
|
|
62
|
+
const state = aState();
|
|
63
|
+
const result = computeContentOverlayBehavior(config, state);
|
|
64
|
+
expect(result.isDraggable).toBe(true);
|
|
65
|
+
});
|
|
66
|
+
it("respects isDraggable=false when no onBeforeExit", () => {
|
|
67
|
+
const config = aConfig({ isDraggable: false, hasOnBeforeExit: false });
|
|
68
|
+
const state = aState();
|
|
69
|
+
const result = computeContentOverlayBehavior(config, state);
|
|
70
|
+
expect(result.isDraggable).toBe(false);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
describe("showDismiss", () => {
|
|
74
|
+
it("returns true when showDismiss prop is true", () => {
|
|
75
|
+
const config = aConfig({ showDismiss: true });
|
|
76
|
+
const state = aState();
|
|
77
|
+
const result = computeContentOverlayBehavior(config, state);
|
|
78
|
+
expect(result.showDismiss).toBe(true);
|
|
79
|
+
});
|
|
80
|
+
it("returns true when screen reader is enabled", () => {
|
|
81
|
+
const config = aConfig({ showDismiss: false });
|
|
82
|
+
const state = aState({ isScreenReaderEnabled: true });
|
|
83
|
+
const result = computeContentOverlayBehavior(config, state);
|
|
84
|
+
expect(result.showDismiss).toBe(true);
|
|
85
|
+
});
|
|
86
|
+
it("returns true when fullScreen is true", () => {
|
|
87
|
+
const config = aConfig({ fullScreen: true, showDismiss: false });
|
|
88
|
+
const state = aState({ isScreenReaderEnabled: false });
|
|
89
|
+
const result = computeContentOverlayBehavior(config, state);
|
|
90
|
+
expect(result.showDismiss).toBe(true);
|
|
91
|
+
});
|
|
92
|
+
it("returns true when dragged to top and not adjustToContentHeight (legacy behavior)", () => {
|
|
93
|
+
const config = aConfig({
|
|
94
|
+
adjustToContentHeight: false,
|
|
95
|
+
showDismiss: false,
|
|
96
|
+
});
|
|
97
|
+
const state = aState({ position: 0, isScreenReaderEnabled: false });
|
|
98
|
+
const result = computeContentOverlayBehavior(config, state);
|
|
99
|
+
expect(result.showDismiss).toBe(true);
|
|
100
|
+
});
|
|
101
|
+
it("returns false when position is top but adjustToContentHeight is true", () => {
|
|
102
|
+
const config = aConfig({
|
|
103
|
+
adjustToContentHeight: true,
|
|
104
|
+
showDismiss: false,
|
|
105
|
+
});
|
|
106
|
+
const state = aState({ position: 0, isScreenReaderEnabled: false });
|
|
107
|
+
const result = computeContentOverlayBehavior(config, state);
|
|
108
|
+
expect(result.showDismiss).toBe(false);
|
|
109
|
+
});
|
|
110
|
+
it("returns false when position is initial and no other conditions met", () => {
|
|
111
|
+
const config = aConfig({
|
|
112
|
+
showDismiss: false,
|
|
113
|
+
fullScreen: false,
|
|
114
|
+
adjustToContentHeight: false,
|
|
115
|
+
});
|
|
116
|
+
const state = aState({
|
|
117
|
+
position: arbitraryClosedPositionValue,
|
|
118
|
+
isScreenReaderEnabled: false,
|
|
119
|
+
});
|
|
120
|
+
const result = computeContentOverlayBehavior(config, state);
|
|
121
|
+
expect(result.showDismiss).toBe(false);
|
|
122
|
+
});
|
|
123
|
+
it("returns false for default props with default state", () => {
|
|
124
|
+
const config = aConfig();
|
|
125
|
+
const state = aState();
|
|
126
|
+
const result = computeContentOverlayBehavior(config, state);
|
|
127
|
+
expect(result.showDismiss).toBe(false);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
describe("combined behaviors", () => {
|
|
131
|
+
it("returns expected behavior for fullScreen overlay", () => {
|
|
132
|
+
const config = aConfig({
|
|
133
|
+
fullScreen: true,
|
|
134
|
+
isDraggable: false,
|
|
135
|
+
showDismiss: true,
|
|
136
|
+
});
|
|
137
|
+
const state = aState();
|
|
138
|
+
const result = computeContentOverlayBehavior(config, state);
|
|
139
|
+
expect(result).toEqual({
|
|
140
|
+
initialHeight: "fullScreen",
|
|
141
|
+
isDraggable: false,
|
|
142
|
+
showDismiss: true,
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
it("returns expected behavior for content-height overlay with adjustToContentHeight", () => {
|
|
146
|
+
const config = aConfig({
|
|
147
|
+
adjustToContentHeight: true,
|
|
148
|
+
showDismiss: true,
|
|
149
|
+
});
|
|
150
|
+
const state = aState();
|
|
151
|
+
const result = computeContentOverlayBehavior(config, state);
|
|
152
|
+
expect(result).toEqual({
|
|
153
|
+
initialHeight: "contentHeight",
|
|
154
|
+
isDraggable: true,
|
|
155
|
+
showDismiss: true,
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
it("returns expected behavior for overlay with onBeforeExit (confirmation flow)", () => {
|
|
159
|
+
const config = aConfig({
|
|
160
|
+
adjustToContentHeight: true,
|
|
161
|
+
hasOnBeforeExit: true,
|
|
162
|
+
isDraggable: true,
|
|
163
|
+
showDismiss: true,
|
|
164
|
+
});
|
|
165
|
+
const state = aState();
|
|
166
|
+
const result = computeContentOverlayBehavior(config, state);
|
|
167
|
+
expect(result).toEqual({
|
|
168
|
+
initialHeight: "contentHeight",
|
|
169
|
+
isDraggable: false,
|
|
170
|
+
showDismiss: true,
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
it("returns expected behavior for default props (legacy behavior)", () => {
|
|
174
|
+
const config = aConfig();
|
|
175
|
+
const state = aState();
|
|
176
|
+
const result = computeContentOverlayBehavior(config, state);
|
|
177
|
+
expect(result).toEqual({
|
|
178
|
+
initialHeight: "contentHeight",
|
|
179
|
+
isDraggable: true,
|
|
180
|
+
showDismiss: false,
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
it("returns expected behavior for accessibility case where screen reader forces dismiss button", () => {
|
|
184
|
+
const config = aConfig({
|
|
185
|
+
adjustToContentHeight: true,
|
|
186
|
+
showDismiss: false,
|
|
187
|
+
});
|
|
188
|
+
const state = aState({ isScreenReaderEnabled: true });
|
|
189
|
+
const result = computeContentOverlayBehavior(config, state);
|
|
190
|
+
expect(result).toEqual({
|
|
191
|
+
initialHeight: "contentHeight",
|
|
192
|
+
isDraggable: true,
|
|
193
|
+
showDismiss: true,
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
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 { act, renderHook } from "@testing-library/react-native";
|
|
11
|
+
import { BackHandler } from "react-native";
|
|
12
|
+
import { useBottomSheetModalBackHandler } from "./useBottomSheetModalBackHandler";
|
|
13
|
+
describe("useBottomSheetModalBackHandler", () => {
|
|
14
|
+
let mockRemove;
|
|
15
|
+
let mockAddEventListener;
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
mockRemove = jest.fn();
|
|
18
|
+
mockAddEventListener = jest.spyOn(BackHandler, "addEventListener");
|
|
19
|
+
mockAddEventListener.mockReturnValue({ remove: mockRemove });
|
|
20
|
+
});
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
mockAddEventListener.mockRestore();
|
|
23
|
+
});
|
|
24
|
+
it("should register BackHandler listener when sheet becomes visible", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
+
const onCloseController = jest.fn();
|
|
26
|
+
const { result } = renderHook(() => useBottomSheetModalBackHandler(onCloseController));
|
|
27
|
+
yield act(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
+
result.current.handleSheetPositionChange(0);
|
|
29
|
+
}));
|
|
30
|
+
expect(mockAddEventListener).toHaveBeenCalledWith("hardwareBackPress", expect.any(Function));
|
|
31
|
+
}));
|
|
32
|
+
it("should call onCloseController when back button is pressed", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
+
const onCloseController = jest.fn();
|
|
34
|
+
const { result } = renderHook(() => useBottomSheetModalBackHandler(onCloseController));
|
|
35
|
+
yield act(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
+
result.current.handleSheetPositionChange(0);
|
|
37
|
+
}));
|
|
38
|
+
const registeredCallback = mockAddEventListener.mock.calls[0][1];
|
|
39
|
+
const returnValue = registeredCallback();
|
|
40
|
+
expect(onCloseController).toHaveBeenCalled();
|
|
41
|
+
expect(returnValue).toBe(true);
|
|
42
|
+
}));
|
|
43
|
+
it("should remove listener when sheet is dismissed", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
+
const onCloseController = jest.fn();
|
|
45
|
+
const { result } = renderHook(() => useBottomSheetModalBackHandler(onCloseController));
|
|
46
|
+
yield act(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
47
|
+
result.current.handleSheetPositionChange(0);
|
|
48
|
+
}));
|
|
49
|
+
yield act(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
50
|
+
result.current.handleSheetPositionChange(-1);
|
|
51
|
+
}));
|
|
52
|
+
expect(mockRemove).toHaveBeenCalled();
|
|
53
|
+
}));
|
|
54
|
+
it("should not register listener when index is negative", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
|
+
const onCloseController = jest.fn();
|
|
56
|
+
const { result } = renderHook(() => useBottomSheetModalBackHandler(onCloseController));
|
|
57
|
+
yield act(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
58
|
+
result.current.handleSheetPositionChange(-1);
|
|
59
|
+
}));
|
|
60
|
+
expect(mockAddEventListener).not.toHaveBeenCalled();
|
|
61
|
+
}));
|
|
62
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
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 { act, renderHook } from "@testing-library/react-native";
|
|
11
|
+
import { DeviceEventEmitter } from "react-native";
|
|
12
|
+
import { useKeyboardVisibility } from "./useKeyboardVisibility";
|
|
13
|
+
const keyboardEvent = {
|
|
14
|
+
endCoordinates: { height: 350, screenX: 120, screenY: 120, width: 200 },
|
|
15
|
+
};
|
|
16
|
+
describe("when the user is typing", () => {
|
|
17
|
+
it("sets the isKeyboardVisible to true", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
const { result } = renderHook(() => useKeyboardVisibility());
|
|
19
|
+
yield act(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
+
DeviceEventEmitter.emit("keyboardDidShow", keyboardEvent);
|
|
21
|
+
}));
|
|
22
|
+
expect(result.current.isKeyboardVisible).toBe(true);
|
|
23
|
+
}));
|
|
24
|
+
it("the keyboardDidShow event emits the keyboard height", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
+
var _a;
|
|
26
|
+
const { result } = renderHook(() => useKeyboardVisibility());
|
|
27
|
+
yield act(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
+
DeviceEventEmitter.emit("keyboardDidShow", keyboardEvent);
|
|
29
|
+
}));
|
|
30
|
+
expect(result.current.keyboardHeight).toBe((_a = keyboardEvent.endCoordinates) === null || _a === void 0 ? void 0 : _a.height);
|
|
31
|
+
}));
|
|
32
|
+
});
|
|
33
|
+
describe("when the user not typing", () => {
|
|
34
|
+
it("sets the isKeyboardVisible to false", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
|
+
const { result } = renderHook(() => useKeyboardVisibility());
|
|
36
|
+
yield act(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
DeviceEventEmitter.emit("keyboardDidHide");
|
|
38
|
+
}));
|
|
39
|
+
expect(result.current.isKeyboardVisible).toBe(false);
|
|
40
|
+
}));
|
|
41
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
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 { act, renderHook } from "@testing-library/react-native";
|
|
11
|
+
import { useViewLayoutHeight } from "./useViewLayoutHeight";
|
|
12
|
+
describe("useViewLayoutHeight", () => {
|
|
13
|
+
it("should return initial values", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
+
const { result } = renderHook(() => useViewLayoutHeight());
|
|
15
|
+
expect(result.current.height).toBe(0);
|
|
16
|
+
expect(result.current.heightKnown).toBe(false);
|
|
17
|
+
expect(typeof result.current.handleLayout).toBe("function");
|
|
18
|
+
}));
|
|
19
|
+
it("should handle layout change event", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
+
const expectedHeight = 100;
|
|
21
|
+
const layoutChangeEvent = {
|
|
22
|
+
nativeEvent: {
|
|
23
|
+
layout: {
|
|
24
|
+
height: expectedHeight,
|
|
25
|
+
width: 100,
|
|
26
|
+
x: 0,
|
|
27
|
+
y: 0,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
currentTarget: 0,
|
|
31
|
+
target: 0,
|
|
32
|
+
bubbles: false,
|
|
33
|
+
cancelable: false,
|
|
34
|
+
defaultPrevented: false,
|
|
35
|
+
eventPhase: 0,
|
|
36
|
+
isTrusted: false,
|
|
37
|
+
preventDefault: function () {
|
|
38
|
+
throw new Error("Function not implemented.");
|
|
39
|
+
},
|
|
40
|
+
isDefaultPrevented: function () {
|
|
41
|
+
throw new Error("Function not implemented.");
|
|
42
|
+
},
|
|
43
|
+
stopPropagation: function () {
|
|
44
|
+
throw new Error("Function not implemented.");
|
|
45
|
+
},
|
|
46
|
+
isPropagationStopped: function () {
|
|
47
|
+
throw new Error("Function not implemented.");
|
|
48
|
+
},
|
|
49
|
+
persist: function () {
|
|
50
|
+
throw new Error("Function not implemented.");
|
|
51
|
+
},
|
|
52
|
+
timeStamp: 0,
|
|
53
|
+
type: "",
|
|
54
|
+
};
|
|
55
|
+
const { result } = renderHook(() => useViewLayoutHeight());
|
|
56
|
+
yield act(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
|
+
result.current.handleLayout(layoutChangeEvent);
|
|
58
|
+
}));
|
|
59
|
+
expect(result.current.height).toBe(expectedHeight);
|
|
60
|
+
expect(result.current.heightKnown).toBe(true);
|
|
61
|
+
}));
|
|
62
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { fireEvent, render, screen } from "@testing-library/react-native";
|
|
3
|
+
import { Disclosure } from ".";
|
|
4
|
+
import { Text } from "../Text";
|
|
5
|
+
jest.mock("react-native-svg", () => {
|
|
6
|
+
return Object.assign(Object.assign({ __esModule: true }, jest.requireActual("react-native-svg")), { Path: "Path", default: "SVGMock" });
|
|
7
|
+
});
|
|
8
|
+
function fireLayoutEvent(disclosureContent) {
|
|
9
|
+
fireEvent(disclosureContent, "onLayout", {
|
|
10
|
+
nativeEvent: {
|
|
11
|
+
layout: {
|
|
12
|
+
height: 100,
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
describe("Disclosure", () => {
|
|
18
|
+
const defaultProps = {
|
|
19
|
+
header: React.createElement(Text, null, "This is the header"),
|
|
20
|
+
content: React.createElement(Text, null, "This is the content"),
|
|
21
|
+
onToggle: jest.fn(),
|
|
22
|
+
};
|
|
23
|
+
it("renders a Disclosure with a header and a content when open is true", () => {
|
|
24
|
+
render(React.createElement(Disclosure, { header: React.createElement(Text, null, "This is the header"), content: React.createElement(Text, null, "This is the content"), open: true, isEmpty: false, onToggle: () => {
|
|
25
|
+
return;
|
|
26
|
+
} }));
|
|
27
|
+
expect(screen.getByText("This is the header")).toBeTruthy();
|
|
28
|
+
const content = screen.getByTestId("content");
|
|
29
|
+
fireLayoutEvent(content);
|
|
30
|
+
expect(screen.getByText("This is the content")).toBeTruthy();
|
|
31
|
+
expect(screen.getByTestId("arrowUp")).toBeTruthy();
|
|
32
|
+
});
|
|
33
|
+
it("renders a Disclosure with a header and with a content of size 0 when open is false", () => {
|
|
34
|
+
render(React.createElement(Disclosure, { header: React.createElement(Text, null, "This is the header"), content: React.createElement(Text, null, "This is the content"), open: false, isEmpty: false, onToggle: () => {
|
|
35
|
+
return;
|
|
36
|
+
} }));
|
|
37
|
+
expect(screen.getByText("This is the header")).toBeTruthy();
|
|
38
|
+
const content = screen.getByTestId("content");
|
|
39
|
+
fireLayoutEvent(content);
|
|
40
|
+
expect(screen.getByText("This is the content")).toBeTruthy();
|
|
41
|
+
expect(screen.getByTestId("arrowUp")).toBeTruthy();
|
|
42
|
+
});
|
|
43
|
+
it("should not render the caret when the Disclosure is empty", () => {
|
|
44
|
+
render(React.createElement(Disclosure, { header: React.createElement(Text, null, "This is the header"), content: React.createElement(Text, null, "This is the content"), open: false, isEmpty: true, onToggle: () => {
|
|
45
|
+
return;
|
|
46
|
+
} }));
|
|
47
|
+
expect(screen.getByText("This is the header")).toBeTruthy();
|
|
48
|
+
expect(screen.queryByTestId("arrowUp")).toBeNull();
|
|
49
|
+
});
|
|
50
|
+
it("calls onToggle when header is pressed", () => {
|
|
51
|
+
const onToggleMock = jest.fn();
|
|
52
|
+
const { getByText } = render(React.createElement(Disclosure, Object.assign({}, defaultProps, { onToggle: onToggleMock, open: false, isEmpty: false })));
|
|
53
|
+
const headerText = getByText("This is the header");
|
|
54
|
+
fireEvent.press(headerText);
|
|
55
|
+
expect(onToggleMock).toHaveBeenCalledTimes(1);
|
|
56
|
+
});
|
|
57
|
+
it("does not call onToggle when header is pressed and isEmpty is true", () => {
|
|
58
|
+
const onToggleMock = jest.fn();
|
|
59
|
+
const { getByText } = render(React.createElement(Disclosure, Object.assign({}, defaultProps, { onToggle: onToggleMock, open: false, isEmpty: true })));
|
|
60
|
+
const headerText = getByText("This is the header");
|
|
61
|
+
fireEvent.press(headerText);
|
|
62
|
+
expect(onToggleMock).not.toHaveBeenCalled();
|
|
63
|
+
});
|
|
64
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render, renderHook } from "@testing-library/react-native";
|
|
3
|
+
import { Divider } from "./Divider";
|
|
4
|
+
import { useHorizontalStyles } from "./DividerHorizontal.style";
|
|
5
|
+
import { useVerticalStyles } from "./DividerVertical.style";
|
|
6
|
+
const dividerTestId = "Divider";
|
|
7
|
+
let horizontalStyles;
|
|
8
|
+
let verticalStyles;
|
|
9
|
+
beforeAll(() => {
|
|
10
|
+
horizontalStyles = renderHook(() => useHorizontalStyles()).result.current;
|
|
11
|
+
verticalStyles = renderHook(() => useVerticalStyles()).result.current;
|
|
12
|
+
});
|
|
13
|
+
describe("Divider", () => {
|
|
14
|
+
it("uses the given testID", () => {
|
|
15
|
+
const dividerTestID = "divider-test";
|
|
16
|
+
const { getByTestId } = render(React.createElement(Divider, { testID: dividerTestID }));
|
|
17
|
+
expect(getByTestId(dividerTestID)).toBeDefined();
|
|
18
|
+
});
|
|
19
|
+
describe("Horizontal", () => {
|
|
20
|
+
it("renders a default Divider", () => {
|
|
21
|
+
const { getByTestId } = render(React.createElement(Divider, null));
|
|
22
|
+
const dividerStyle = getByTestId(dividerTestId).props.style;
|
|
23
|
+
expect(dividerStyle).toContainEqual(horizontalStyles.base);
|
|
24
|
+
expect(dividerStyle).not.toContainEqual(horizontalStyles.large);
|
|
25
|
+
expect(dividerStyle).not.toContainEqual(horizontalStyles.largest);
|
|
26
|
+
});
|
|
27
|
+
it("renders a large Divider", () => {
|
|
28
|
+
const { getByTestId } = render(React.createElement(Divider, { size: "large" }));
|
|
29
|
+
const dividerStyle = getByTestId(dividerTestId).props.style;
|
|
30
|
+
expect(dividerStyle).toContainEqual(horizontalStyles.base);
|
|
31
|
+
expect(dividerStyle).toContainEqual(horizontalStyles.large);
|
|
32
|
+
expect(dividerStyle).not.toContainEqual(horizontalStyles.largest);
|
|
33
|
+
});
|
|
34
|
+
it("renders a largest Divider", () => {
|
|
35
|
+
const { getByTestId } = render(React.createElement(Divider, { size: "largest" }));
|
|
36
|
+
const dividerStyle = getByTestId(dividerTestId).props.style;
|
|
37
|
+
expect(dividerStyle).toContainEqual(horizontalStyles.base);
|
|
38
|
+
expect(dividerStyle).not.toContainEqual(horizontalStyles.large);
|
|
39
|
+
expect(dividerStyle).toContainEqual(horizontalStyles.largest);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
describe("Vertical", () => {
|
|
43
|
+
it("renders a default Divider", () => {
|
|
44
|
+
const { getByTestId } = render(React.createElement(Divider, { direction: "vertical" }));
|
|
45
|
+
const dividerStyle = getByTestId(dividerTestId).props.style;
|
|
46
|
+
expect(dividerStyle).toContainEqual(verticalStyles.base);
|
|
47
|
+
expect(dividerStyle).not.toContainEqual(verticalStyles.large);
|
|
48
|
+
expect(dividerStyle).not.toContainEqual(verticalStyles.largest);
|
|
49
|
+
});
|
|
50
|
+
it("renders a large Divider", () => {
|
|
51
|
+
const { getByTestId } = render(React.createElement(Divider, { direction: "vertical", size: "large" }));
|
|
52
|
+
const dividerStyle = getByTestId(dividerTestId).props.style;
|
|
53
|
+
expect(dividerStyle).toContainEqual(verticalStyles.base);
|
|
54
|
+
expect(dividerStyle).toContainEqual(verticalStyles.large);
|
|
55
|
+
expect(dividerStyle).not.toContainEqual(verticalStyles.largest);
|
|
56
|
+
});
|
|
57
|
+
it("renders a largest Divider", () => {
|
|
58
|
+
const { getByTestId } = render(React.createElement(Divider, { direction: "vertical", size: "largest" }));
|
|
59
|
+
const dividerStyle = getByTestId(dividerTestId).props.style;
|
|
60
|
+
expect(dividerStyle).toContainEqual(verticalStyles.base);
|
|
61
|
+
expect(dividerStyle).not.toContainEqual(verticalStyles.large);
|
|
62
|
+
expect(dividerStyle).toContainEqual(verticalStyles.largest);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
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, screen } from "@testing-library/react-native";
|
|
12
|
+
import { Path } from "react-native-svg";
|
|
13
|
+
import { EmptyState } from "./EmptyState";
|
|
14
|
+
const primaryOnPress = jest.fn();
|
|
15
|
+
const secondaryOnPress = jest.fn();
|
|
16
|
+
const defaultProps = {
|
|
17
|
+
icon: "home",
|
|
18
|
+
title: "Title",
|
|
19
|
+
description: "Description",
|
|
20
|
+
primaryAction: {
|
|
21
|
+
label: "Click Me",
|
|
22
|
+
onPress: primaryOnPress,
|
|
23
|
+
},
|
|
24
|
+
secondaryAction: {
|
|
25
|
+
label: "Don't Forget About Me",
|
|
26
|
+
onPress: secondaryOnPress,
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
const component = (overrideProps) => {
|
|
30
|
+
const props = Object.assign(Object.assign({}, defaultProps), overrideProps);
|
|
31
|
+
render(React.createElement(EmptyState, Object.assign({}, props)));
|
|
32
|
+
};
|
|
33
|
+
describe("EmptyState", () => {
|
|
34
|
+
it("renders the title", () => {
|
|
35
|
+
component();
|
|
36
|
+
expect(screen.getByText(defaultProps.title)).toBeDefined();
|
|
37
|
+
});
|
|
38
|
+
it("renders the description", () => {
|
|
39
|
+
component();
|
|
40
|
+
expect(screen.getByText(defaultProps.description)).toBeDefined();
|
|
41
|
+
});
|
|
42
|
+
it("renders the icon with default color and large size", () => {
|
|
43
|
+
component();
|
|
44
|
+
const icon = screen.getByTestId(defaultProps.icon);
|
|
45
|
+
const path = icon.findByType(Path);
|
|
46
|
+
expect(path.props.fill).toBe("hsl(197, 90%, 12%)");
|
|
47
|
+
expect(icon.props.style).toEqual(expect.arrayContaining([
|
|
48
|
+
expect.objectContaining({
|
|
49
|
+
width: 32,
|
|
50
|
+
height: 32,
|
|
51
|
+
}),
|
|
52
|
+
]));
|
|
53
|
+
});
|
|
54
|
+
it("renders the correct icon color when specified", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
|
+
component({ iconColor: "warning" });
|
|
56
|
+
const icon = screen.getByTestId(defaultProps.icon);
|
|
57
|
+
const pathElement = icon.findByType(Path);
|
|
58
|
+
expect(pathElement.props.fill).toBe("hsl(51, 64%, 49%)");
|
|
59
|
+
}));
|
|
60
|
+
it("renders the primary action and allows users to interact with it by clicking", () => {
|
|
61
|
+
component();
|
|
62
|
+
const button = screen.getByLabelText(defaultProps.primaryAction.label);
|
|
63
|
+
expect(button).toBeDefined();
|
|
64
|
+
fireEvent.press(button);
|
|
65
|
+
expect(primaryOnPress).toHaveBeenCalledTimes(1);
|
|
66
|
+
});
|
|
67
|
+
it("renders the secondary action and allows users to interact with it by clicking", () => {
|
|
68
|
+
component();
|
|
69
|
+
const button = screen.getByLabelText(defaultProps.secondaryAction.label);
|
|
70
|
+
expect(button).toBeDefined();
|
|
71
|
+
fireEvent.press(button);
|
|
72
|
+
expect(secondaryOnPress).toHaveBeenCalledTimes(1);
|
|
73
|
+
});
|
|
74
|
+
it("does render buttons if neither primary nor secondary action is passed in", () => {
|
|
75
|
+
component({
|
|
76
|
+
description: "No buttons",
|
|
77
|
+
primaryAction: undefined,
|
|
78
|
+
secondaryAction: undefined,
|
|
79
|
+
});
|
|
80
|
+
expect(screen.queryAllByRole("button")).toHaveLength(0);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render } from "@testing-library/react-native";
|
|
3
|
+
import { ErrorMessageWrapper } from "./ErrorMessageWrapper";
|
|
4
|
+
import { Text } from "../Text";
|
|
5
|
+
describe("ErrorMessageWrapper", () => {
|
|
6
|
+
it("should show the child, an error message, and an icon", () => {
|
|
7
|
+
const errorMessage = "This is an error message";
|
|
8
|
+
const childText = "Howdy";
|
|
9
|
+
const screen = render(React.createElement(ErrorMessageWrapper, { message: errorMessage },
|
|
10
|
+
React.createElement(Text, null, childText)));
|
|
11
|
+
expect(screen.getByText(childText)).toBeDefined();
|
|
12
|
+
expect(screen.getByText(errorMessage, { includeHiddenElements: true })).toBeDefined();
|
|
13
|
+
expect(screen.getByTestId("alert")).toBeDefined();
|
|
14
|
+
});
|
|
15
|
+
it("should show the child, but not an error message and an icon", () => {
|
|
16
|
+
const errorMessage = "This is an error message part 2";
|
|
17
|
+
const childText = "I'm still here";
|
|
18
|
+
const screen = render(React.createElement(ErrorMessageWrapper, { message: errorMessage },
|
|
19
|
+
React.createElement(Text, null, childText)));
|
|
20
|
+
expect(screen.getByText(childText)).toBeDefined();
|
|
21
|
+
expect(screen.getByText(errorMessage, { includeHiddenElements: true })).toBeDefined();
|
|
22
|
+
expect(screen.getByTestId("alert")).toBeDefined();
|
|
23
|
+
screen.rerender(React.createElement(ErrorMessageWrapper, null,
|
|
24
|
+
React.createElement(Text, null, childText)));
|
|
25
|
+
expect(screen.getByText(childText)).toBeDefined();
|
|
26
|
+
expect(screen.queryByText(errorMessage)).toBeNull();
|
|
27
|
+
expect(screen.queryByTestId("alert")).toBeNull();
|
|
28
|
+
});
|
|
29
|
+
});
|