@wordpress/components 35.0.0 → 35.0.1
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/CHANGELOG.md +20 -1
- package/build/alignment-matrix-control/cell.cjs +1 -1
- package/build/alignment-matrix-control/cell.cjs.map +2 -2
- package/build/alignment-matrix-control/index.cjs +1 -1
- package/build/alignment-matrix-control/index.cjs.map +2 -2
- package/build/color-palette/index.cjs +3 -0
- package/build/color-palette/index.cjs.map +2 -2
- package/build/custom-gradient-picker/gradient-bar/index.cjs.map +2 -2
- package/build/draggable/index.cjs +1 -1
- package/build/draggable/index.cjs.map +2 -2
- package/build/navigable-container/container.cjs +15 -21
- package/build/navigable-container/container.cjs.map +2 -2
- package/build/unit-control/utils.cjs +33 -35
- package/build/unit-control/utils.cjs.map +2 -2
- package/build-module/alignment-matrix-control/cell.mjs +1 -1
- package/build-module/alignment-matrix-control/cell.mjs.map +2 -2
- package/build-module/alignment-matrix-control/index.mjs +1 -1
- package/build-module/alignment-matrix-control/index.mjs.map +2 -2
- package/build-module/color-palette/index.mjs +3 -0
- package/build-module/color-palette/index.mjs.map +2 -2
- package/build-module/custom-gradient-picker/gradient-bar/index.mjs.map +2 -2
- package/build-module/draggable/index.mjs +1 -1
- package/build-module/draggable/index.mjs.map +2 -2
- package/build-module/navigable-container/container.mjs +16 -22
- package/build-module/navigable-container/container.mjs.map +2 -2
- package/build-module/unit-control/utils.mjs +33 -35
- package/build-module/unit-control/utils.mjs.map +2 -2
- package/build-style/style-rtl.css +41 -10
- package/build-style/style.css +41 -10
- package/build-types/card/context.d.ts +3 -0
- package/build-types/card/context.d.ts.map +1 -0
- package/build-types/color-palette/index.d.ts.map +1 -1
- package/build-types/custom-gradient-picker/gradient-bar/index.d.ts.map +1 -1
- package/build-types/date-time/date/index.d.ts +23 -0
- package/build-types/date-time/date/index.d.ts.map +1 -0
- package/build-types/date-time/date/styles.d.ts +45 -0
- package/build-types/date-time/date/styles.d.ts.map +1 -0
- package/build-types/date-time/date/test/index.d.ts +2 -0
- package/build-types/date-time/date/test/index.d.ts.map +1 -0
- package/build-types/date-time/date/test/use-lilius.d.ts +2 -0
- package/build-types/date-time/date/test/use-lilius.d.ts.map +1 -0
- package/build-types/date-time/date/use-lilius/index.d.ts +169 -0
- package/build-types/date-time/date/use-lilius/index.d.ts.map +1 -0
- package/build-types/date-time/time/index.d.ts +27 -0
- package/build-types/date-time/time/index.d.ts.map +1 -0
- package/build-types/date-time/time/styles.d.ts +93 -0
- package/build-types/date-time/time/styles.d.ts.map +1 -0
- package/build-types/date-time/time/test/index.d.ts +2 -0
- package/build-types/date-time/time/test/index.d.ts.map +1 -0
- package/build-types/date-time/time/time-input/index.d.ts +4 -0
- package/build-types/date-time/time/time-input/index.d.ts.map +1 -0
- package/build-types/date-time/time/time-input/test/index.d.ts +2 -0
- package/build-types/date-time/time/time-input/test/index.d.ts.map +1 -0
- package/build-types/date-time/time/timezone.d.ts +7 -0
- package/build-types/date-time/time/timezone.d.ts.map +1 -0
- package/build-types/navigable-container/container.d.ts.map +1 -1
- package/build-types/navigation/back-button/index.d.ts +7 -0
- package/build-types/navigation/back-button/index.d.ts.map +1 -0
- package/build-types/navigation/constants.d.ts +3 -0
- package/build-types/navigation/constants.d.ts.map +1 -0
- package/build-types/navigation/context.d.ts +4 -0
- package/build-types/navigation/context.d.ts.map +1 -0
- package/build-types/navigation/group/context.d.ts +7 -0
- package/build-types/navigation/group/context.d.ts.map +1 -0
- package/build-types/navigation/group/index.d.ts +7 -0
- package/build-types/navigation/group/index.d.ts.map +1 -0
- package/build-types/navigation/index.d.ts +46 -0
- package/build-types/navigation/index.d.ts.map +1 -0
- package/build-types/navigation/item/base-content.d.ts +3 -0
- package/build-types/navigation/item/base-content.d.ts.map +1 -0
- package/build-types/navigation/item/base.d.ts +3 -0
- package/build-types/navigation/item/base.d.ts.map +1 -0
- package/build-types/navigation/item/index.d.ts +7 -0
- package/build-types/navigation/item/index.d.ts.map +1 -0
- package/build-types/navigation/item/use-navigation-tree-item.d.ts +3 -0
- package/build-types/navigation/item/use-navigation-tree-item.d.ts.map +1 -0
- package/build-types/navigation/menu/context.d.ts +7 -0
- package/build-types/navigation/menu/context.d.ts.map +1 -0
- package/build-types/navigation/menu/index.d.ts +7 -0
- package/build-types/navigation/menu/index.d.ts.map +1 -0
- package/build-types/navigation/menu/menu-title-search.d.ts +3 -0
- package/build-types/navigation/menu/menu-title-search.d.ts.map +1 -0
- package/build-types/navigation/menu/menu-title.d.ts +3 -0
- package/build-types/navigation/menu/menu-title.d.ts.map +1 -0
- package/build-types/navigation/menu/search-no-results-found.d.ts +3 -0
- package/build-types/navigation/menu/search-no-results-found.d.ts.map +1 -0
- package/build-types/navigation/menu/use-navigation-tree-menu.d.ts +3 -0
- package/build-types/navigation/menu/use-navigation-tree-menu.d.ts.map +1 -0
- package/build-types/navigation/stories/index.story.d.ts +23 -0
- package/build-types/navigation/stories/index.story.d.ts.map +1 -0
- package/build-types/navigation/stories/utils/controlled-state.d.ts +7 -0
- package/build-types/navigation/stories/utils/controlled-state.d.ts.map +1 -0
- package/build-types/navigation/stories/utils/default.d.ts +10 -0
- package/build-types/navigation/stories/utils/default.d.ts.map +1 -0
- package/build-types/navigation/stories/utils/group.d.ts +10 -0
- package/build-types/navigation/stories/utils/group.d.ts.map +1 -0
- package/build-types/navigation/stories/utils/hide-if-empty.d.ts +10 -0
- package/build-types/navigation/stories/utils/hide-if-empty.d.ts.map +1 -0
- package/build-types/navigation/stories/utils/more-examples.d.ts +10 -0
- package/build-types/navigation/stories/utils/more-examples.d.ts.map +1 -0
- package/build-types/navigation/stories/utils/search.d.ts +10 -0
- package/build-types/navigation/stories/utils/search.d.ts.map +1 -0
- package/build-types/navigation/styles/navigation-styles.d.ts +55 -0
- package/build-types/navigation/styles/navigation-styles.d.ts.map +1 -0
- package/build-types/navigation/test/index.d.ts +2 -0
- package/build-types/navigation/test/index.d.ts.map +1 -0
- package/build-types/navigation/types.d.ts +266 -0
- package/build-types/navigation/types.d.ts.map +1 -0
- package/build-types/navigation/use-create-navigation-tree.d.ts +15 -0
- package/build-types/navigation/use-create-navigation-tree.d.ts.map +1 -0
- package/build-types/navigation/use-navigation-tree-nodes.d.ts +10 -0
- package/build-types/navigation/use-navigation-tree-nodes.d.ts.map +1 -0
- package/build-types/navigation/utils.d.ts +3 -0
- package/build-types/navigation/utils.d.ts.map +1 -0
- package/build-types/unit-control/utils.d.ts.map +1 -1
- package/build-types/validated-form-controls/components/combobox-control.d.ts +2 -2
- package/build-types/visually-hidden/test/index.d.ts +2 -0
- package/build-types/visually-hidden/test/index.d.ts.map +1 -0
- package/package.json +34 -32
- package/src/card/card/README.md +4 -4
- package/src/checkbox-control/README.md +1 -1
- package/src/clipboard-button/README.md +4 -4
- package/src/color-palette/index.tsx +5 -0
- package/src/color-palette/test/index.tsx +30 -0
- package/src/combobox-control/README.md +1 -1
- package/src/confirm-dialog/README.md +1 -1
- package/src/custom-gradient-picker/gradient-bar/index.tsx +1 -1
- package/src/flex/flex/README.md +1 -1
- package/src/navigable-container/container.tsx +22 -30
- package/src/popover/README.md +1 -1
- package/src/scrollable/README.md +1 -1
- package/src/tooltip/style.scss +1 -1
- package/src/unit-control/utils.ts +33 -52
- package/build/mobile/image/constants.cjs +0 -34
- package/build/mobile/image/constants.cjs.map +0 -7
- package/build-module/mobile/image/constants.mjs +0 -9
- package/build-module/mobile/image/constants.mjs.map +0 -7
- package/src/autocomplete/autocompleter-ui.native.js +0 -211
- package/src/autocomplete/background-view.android.js +0 -25
- package/src/autocomplete/background-view.ios.js +0 -23
- package/src/autocomplete/style.android.scss +0 -7
- package/src/autocomplete/style.native.scss +0 -74
- package/src/base-control/index.native.js +0 -14
- package/src/button/index.native.js +0 -236
- package/src/button/style.native.scss +0 -9
- package/src/color-control/index.native.js +0 -24
- package/src/color-indicator/index.native.js +0 -80
- package/src/color-indicator/style.native.scss +0 -51
- package/src/color-palette/index.native.js +0 -360
- package/src/color-palette/style.native.scss +0 -49
- package/src/color-picker/hsv-color-picker.native.js +0 -88
- package/src/color-picker/hue-picker.native.js +0 -198
- package/src/color-picker/index.native.js +0 -215
- package/src/color-picker/saturation-picker.native.js +0 -167
- package/src/color-picker/style.native.scss +0 -87
- package/src/custom-gradient-picker/index.native.js +0 -110
- package/src/custom-gradient-picker/style.native.scss +0 -3
- package/src/dashicon/index.native.js +0 -18
- package/src/disabled/index.native.js +0 -10
- package/src/draggable/index.native.js +0 -234
- package/src/draggable/style.native.scss +0 -3
- package/src/draggable/test/index.native.js +0 -138
- package/src/dropdown/index.native.js +0 -59
- package/src/dropdown-menu/index.native.js +0 -152
- package/src/external-link/index.native.js +0 -25
- package/src/focal-point-picker/focal-point.native.js +0 -30
- package/src/focal-point-picker/index.native.js +0 -281
- package/src/focal-point-picker/tooltip/index.native.js +0 -144
- package/src/focal-point-picker/tooltip/style.native.scss +0 -42
- package/src/font-size-picker/index.native.js +0 -190
- package/src/font-size-picker/style.native.scss +0 -6
- package/src/footer-message-control/index.native.js +0 -14
- package/src/higher-order/with-focus-outside/index.native.js +0 -38
- package/src/index.native.js +0 -134
- package/src/keyboard-shortcuts/index.native.js +0 -2
- package/src/mobile/README.md +0 -3
- package/src/mobile/autocompletion-items.native.js +0 -11
- package/src/mobile/badge/README.md +0 -31
- package/src/mobile/badge/index.native.js +0 -27
- package/src/mobile/badge/style.scss +0 -18
- package/src/mobile/bottom-sheet/borderStyles.android.scss +0 -8
- package/src/mobile/bottom-sheet/borderStyles.ios.scss +0 -9
- package/src/mobile/bottom-sheet/bottom-sheet-context.native.js +0 -40
- package/src/mobile/bottom-sheet/bottom-sheet-navigation/README.md +0 -101
- package/src/mobile/bottom-sheet/bottom-sheet-navigation/bottom-sheet-navigation-context.native.js +0 -16
- package/src/mobile/bottom-sheet/bottom-sheet-navigation/navigation-container.native.js +0 -193
- package/src/mobile/bottom-sheet/bottom-sheet-navigation/navigation-screen.native.js +0 -146
- package/src/mobile/bottom-sheet/bottom-sheet-navigation/styles.native.scss +0 -11
- package/src/mobile/bottom-sheet/bottom-sheet-navigation/test/navigation-container.native.js +0 -197
- package/src/mobile/bottom-sheet/button.native.js +0 -19
- package/src/mobile/bottom-sheet/cell.native.js +0 -464
- package/src/mobile/bottom-sheet/cellStyles.android.scss +0 -15
- package/src/mobile/bottom-sheet/cellStyles.ios.scss +0 -19
- package/src/mobile/bottom-sheet/chevron-back.native.js +0 -18
- package/src/mobile/bottom-sheet/color-cell.native.js +0 -35
- package/src/mobile/bottom-sheet/cycle-picker-cell.native.js +0 -31
- package/src/mobile/bottom-sheet/footer-message-cell.native.js +0 -23
- package/src/mobile/bottom-sheet/footer-message-link/README.md +0 -37
- package/src/mobile/bottom-sheet/footer-message-link/footer-message-link.native.js +0 -26
- package/src/mobile/bottom-sheet/footer-message-link/styles.native.scss +0 -7
- package/src/mobile/bottom-sheet/index.native.js +0 -646
- package/src/mobile/bottom-sheet/keyboard-avoiding-view.native.js +0 -125
- package/src/mobile/bottom-sheet/link-cell.native.js +0 -35
- package/src/mobile/bottom-sheet/link-suggestion-item-cell.native.js +0 -92
- package/src/mobile/bottom-sheet/link-suggestion-styles.native.scss +0 -27
- package/src/mobile/bottom-sheet/lock-icon/index.native.js +0 -19
- package/src/mobile/bottom-sheet/lock-icon/styles.native.scss +0 -8
- package/src/mobile/bottom-sheet/nav-bar/README.md +0 -63
- package/src/mobile/bottom-sheet/nav-bar/action-button.native.js +0 -30
- package/src/mobile/bottom-sheet/nav-bar/apply-button.native.js +0 -53
- package/src/mobile/bottom-sheet/nav-bar/back-button.native.js +0 -94
- package/src/mobile/bottom-sheet/nav-bar/heading.native.js +0 -33
- package/src/mobile/bottom-sheet/nav-bar/index.native.js +0 -23
- package/src/mobile/bottom-sheet/nav-bar/styles.native.scss +0 -69
- package/src/mobile/bottom-sheet/picker-cell.native.js +0 -40
- package/src/mobile/bottom-sheet/radio-cell.native.js +0 -39
- package/src/mobile/bottom-sheet/range-cell.native.js +0 -274
- package/src/mobile/bottom-sheet/range-cell.native.scss +0 -40
- package/src/mobile/bottom-sheet/range-text-input.native.js +0 -248
- package/src/mobile/bottom-sheet/ripple.native.js +0 -83
- package/src/mobile/bottom-sheet/ripple.native.scss +0 -11
- package/src/mobile/bottom-sheet/stepper-cell/index.native.js +0 -264
- package/src/mobile/bottom-sheet/stepper-cell/stepper.android.js +0 -78
- package/src/mobile/bottom-sheet/stepper-cell/stepper.ios.js +0 -64
- package/src/mobile/bottom-sheet/stepper-cell/style.native.scss +0 -89
- package/src/mobile/bottom-sheet/styles.native.scss +0 -333
- package/src/mobile/bottom-sheet/sub-sheet/README.md +0 -90
- package/src/mobile/bottom-sheet/sub-sheet/index.native.js +0 -49
- package/src/mobile/bottom-sheet/switch-cell.native.js +0 -75
- package/src/mobile/bottom-sheet/test/index.native.js +0 -24
- package/src/mobile/bottom-sheet/test/range-cell.native.js +0 -73
- package/src/mobile/bottom-sheet-select-control/README.md +0 -97
- package/src/mobile/bottom-sheet-select-control/index.native.js +0 -124
- package/src/mobile/bottom-sheet-select-control/style.native.scss +0 -3
- package/src/mobile/bottom-sheet-text-control/README.md +0 -98
- package/src/mobile/bottom-sheet-text-control/index.native.js +0 -104
- package/src/mobile/bottom-sheet-text-control/styles.scss +0 -25
- package/src/mobile/clipboard/index.native.js +0 -18
- package/src/mobile/color-settings/gradient-picker-screen.native.js +0 -37
- package/src/mobile/color-settings/index.native.js +0 -88
- package/src/mobile/color-settings/palette.screen.native.js +0 -232
- package/src/mobile/color-settings/picker-screen.native.js +0 -60
- package/src/mobile/color-settings/style.native.scss +0 -62
- package/src/mobile/color-settings/utils.native.js +0 -36
- package/src/mobile/cycle-select-control/README.md +0 -3
- package/src/mobile/cycle-select-control/index.native.js +0 -39
- package/src/mobile/dashicons/index.native.js +0 -22
- package/src/mobile/focal-point-settings-panel/index.native.js +0 -84
- package/src/mobile/focal-point-settings-panel/styles.native.scss +0 -3
- package/src/mobile/gradient/index.native.js +0 -188
- package/src/mobile/gradient/style.native.scss +0 -8
- package/src/mobile/gradient/test/index.native.js +0 -114
- package/src/mobile/gridicons/index.native.js +0 -39
- package/src/mobile/html-text-input/index.native.js +0 -169
- package/src/mobile/html-text-input/style.android.scss +0 -8
- package/src/mobile/html-text-input/style.ios.scss +0 -10
- package/src/mobile/html-text-input/style.scss +0 -45
- package/src/mobile/html-text-input/test/__snapshots__/index.native.js.snap +0 -48
- package/src/mobile/html-text-input/test/index.native.js +0 -118
- package/src/mobile/image/constants.js +0 -1
- package/src/mobile/image/icon-customize.native.js +0 -10
- package/src/mobile/image/icon-retry.native.js +0 -11
- package/src/mobile/image/image-editing-button.native.js +0 -63
- package/src/mobile/image/index.native.js +0 -401
- package/src/mobile/image/style.native.scss +0 -179
- package/src/mobile/image/utils/index.native.js +0 -58
- package/src/mobile/keyboard-avoiding-view/index.android.js +0 -8
- package/src/mobile/keyboard-avoiding-view/index.ios.js +0 -143
- package/src/mobile/keyboard-avoiding-view/styles.native.scss +0 -9
- package/src/mobile/keyboard-aware-flat-list/index.android.js +0 -81
- package/src/mobile/keyboard-aware-flat-list/index.ios.js +0 -147
- package/src/mobile/keyboard-aware-flat-list/shared.native.js +0 -26
- package/src/mobile/keyboard-aware-flat-list/styles.native.scss +0 -8
- package/src/mobile/keyboard-aware-flat-list/test/use-keyboard-offset.native.js +0 -203
- package/src/mobile/keyboard-aware-flat-list/test/use-scroll-to-section.native.js +0 -142
- package/src/mobile/keyboard-aware-flat-list/test/use-scroll.native.js +0 -71
- package/src/mobile/keyboard-aware-flat-list/test/use-text-input-caret-position.native.js +0 -82
- package/src/mobile/keyboard-aware-flat-list/test/use-text-input-offset.native.js +0 -147
- package/src/mobile/keyboard-aware-flat-list/use-keyboard-offset.native.js +0 -87
- package/src/mobile/keyboard-aware-flat-list/use-scroll-to-element.native.js +0 -41
- package/src/mobile/keyboard-aware-flat-list/use-scroll-to-section.native.js +0 -100
- package/src/mobile/keyboard-aware-flat-list/use-scroll.native.js +0 -100
- package/src/mobile/keyboard-aware-flat-list/use-text-input-caret-position.native.js +0 -36
- package/src/mobile/keyboard-aware-flat-list/use-text-input-offset.native.js +0 -54
- package/src/mobile/layout-animation/index.native.js +0 -16
- package/src/mobile/link-picker/index.native.js +0 -160
- package/src/mobile/link-picker/link-picker-results.native.js +0 -129
- package/src/mobile/link-picker/link-picker-screen.native.js +0 -60
- package/src/mobile/link-picker/styles.native.scss +0 -45
- package/src/mobile/link-picker/test/performance/index.native.js +0 -35
- package/src/mobile/link-settings/index.native.js +0 -332
- package/src/mobile/link-settings/link-rel.native.js +0 -10
- package/src/mobile/link-settings/link-settings-navigation.native.js +0 -50
- package/src/mobile/link-settings/link-settings-screen.native.js +0 -44
- package/src/mobile/link-settings/style.native.scss +0 -4
- package/src/mobile/link-settings/test/edit.native.js +0 -325
- package/src/mobile/link-settings/test/link-settings-navigation.native.js +0 -94
- package/src/mobile/media-edit/index.native.js +0 -125
- package/src/mobile/picker/index.android.js +0 -104
- package/src/mobile/picker/index.ios.js +0 -96
- package/src/mobile/picker/styles.native.scss +0 -29
- package/src/mobile/segmented-control/index.native.js +0 -186
- package/src/mobile/segmented-control/style.native.scss +0 -99
- package/src/mobile/utils/alignments.native.js +0 -78
- package/src/mobile/utils/get-px-from-css-unit.native.js +0 -329
- package/src/mobile/utils/index.native.js +0 -12
- package/src/mobile/utils/test/get-px-from-css-unit.native.js +0 -172
- package/src/mobile/utils/test/index.native.js +0 -134
- package/src/mobile/utils/use-is-floating-keyboard.native.js +0 -31
- package/src/mobile/utils/use-unit-converter-to-mobile.native.js +0 -90
- package/src/notice/index.native.js +0 -123
- package/src/notice/list.native.js +0 -55
- package/src/notice/style.native.scss +0 -60
- package/src/panel/actions.native.js +0 -46
- package/src/panel/actions.native.scss +0 -12
- package/src/panel/body.native.js +0 -29
- package/src/panel/body.native.scss +0 -11
- package/src/panel/bottom-separator-cover.native.js +0 -27
- package/src/panel/bottom-separator-cover.native.scss +0 -9
- package/src/private-apis.native.js +0 -13
- package/src/query-controls/index.native.js +0 -103
- package/src/radio-control/index.native.js +0 -24
- package/src/range-control/index.native.js +0 -73
- package/src/resizable-box/index.native.js +0 -32
- package/src/resizable-box/style.native.scss +0 -14
- package/src/sandbox/index.native.js +0 -392
- package/src/sandbox/style.native.scss +0 -7
- package/src/search-control/index.native.js +0 -274
- package/src/search-control/platform-style.android.scss +0 -57
- package/src/search-control/platform-style.ios.scss +0 -43
- package/src/search-control/style.native.scss +0 -63
- package/src/select-control/index.native.js +0 -41
- package/src/slot-fill/index.native.js +0 -25
- package/src/spinner/index.native.js +0 -22
- package/src/spinner/style.native.scss +0 -4
- package/src/style-provider/index.native.js +0 -3
- package/src/text/index.native.js +0 -13
- package/src/text/styles/emotion-css.native.js +0 -6
- package/src/text/styles/font-family.native.js +0 -1
- package/src/text/styles/text-mixins.native.js +0 -163
- package/src/text-control/index.native.js +0 -41
- package/src/textarea-control/index.native.js +0 -26
- package/src/toggle-control/index.native.js +0 -31
- package/src/toolbar/toolbar/style.native.scss +0 -11
- package/src/toolbar/toolbar/toolbar-container.native.js +0 -8
- package/src/toolbar/toolbar-button/toolbar-button-container.native.js +0 -8
- package/src/toolbar/toolbar-group/style.native.scss +0 -10
- package/src/toolbar/toolbar-group/toolbar-group-collapsed.native.js +0 -36
- package/src/toolbar/toolbar-group/toolbar-group-container.native.js +0 -26
- package/src/toolbar/toolbar-item/index.native.js +0 -17
- package/src/tooltip/index.native.js +0 -292
- package/src/tooltip/style.native.scss +0 -39
- package/src/tooltip/test/index.native.js +0 -98
- package/src/unit-control/index.native.js +0 -202
- package/src/unit-control/style.native.scss +0 -19
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { act, renderHook } from '@testing-library/react-native';
|
|
5
|
-
import { Keyboard } from 'react-native';
|
|
6
|
-
import RCTDeviceEventEmitter from 'react-native/Libraries/EventEmitter/RCTDeviceEventEmitter';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Internal dependencies
|
|
10
|
-
*/
|
|
11
|
-
import useKeyboardOffset from '../use-keyboard-offset';
|
|
12
|
-
|
|
13
|
-
jest.useFakeTimers();
|
|
14
|
-
|
|
15
|
-
describe( 'useKeyboardOffset', () => {
|
|
16
|
-
beforeEach( () => {
|
|
17
|
-
Keyboard.removeAllListeners( 'keyboardDidShow' );
|
|
18
|
-
Keyboard.removeAllListeners( 'keyboardDidHide' );
|
|
19
|
-
Keyboard.removeAllListeners( 'keyboardWillShow' );
|
|
20
|
-
} );
|
|
21
|
-
|
|
22
|
-
it( 'returns the initial state', () => {
|
|
23
|
-
// Arrange
|
|
24
|
-
const { result } = renderHook( () => useKeyboardOffset( true ) );
|
|
25
|
-
const [ keyboardOffset ] = result.current;
|
|
26
|
-
|
|
27
|
-
// Assert
|
|
28
|
-
expect( keyboardOffset ).toBe( 0 );
|
|
29
|
-
} );
|
|
30
|
-
|
|
31
|
-
it( 'updates keyboard visibility and offset when the keyboard is shown', () => {
|
|
32
|
-
// Arrange
|
|
33
|
-
const { result } = renderHook( () => useKeyboardOffset( true ) );
|
|
34
|
-
|
|
35
|
-
// Act
|
|
36
|
-
act( () => {
|
|
37
|
-
RCTDeviceEventEmitter.emit( 'keyboardDidShow', {
|
|
38
|
-
endCoordinates: { height: 250 },
|
|
39
|
-
} );
|
|
40
|
-
} );
|
|
41
|
-
|
|
42
|
-
// Assert
|
|
43
|
-
const [ keyboardOffset ] = result.current;
|
|
44
|
-
expect( keyboardOffset ).toBe( 250 );
|
|
45
|
-
} );
|
|
46
|
-
|
|
47
|
-
it( 'updates keyboard visibility and offset when the keyboard is hidden', () => {
|
|
48
|
-
// Arrange
|
|
49
|
-
const shouldPreventAutomaticScroll = jest.fn().mockReturnValue( false );
|
|
50
|
-
const { result } = renderHook( () =>
|
|
51
|
-
useKeyboardOffset( true, shouldPreventAutomaticScroll )
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
// Act
|
|
55
|
-
act( () => {
|
|
56
|
-
RCTDeviceEventEmitter.emit( 'keyboardDidShow', {
|
|
57
|
-
endCoordinates: { height: 250 },
|
|
58
|
-
} );
|
|
59
|
-
} );
|
|
60
|
-
|
|
61
|
-
act( () => {
|
|
62
|
-
RCTDeviceEventEmitter.emit( 'keyboardDidHide' );
|
|
63
|
-
jest.runAllTimers();
|
|
64
|
-
} );
|
|
65
|
-
|
|
66
|
-
// Assert
|
|
67
|
-
const [ keyboardOffset ] = result.current;
|
|
68
|
-
expect( keyboardOffset ).toBe( 0 );
|
|
69
|
-
} );
|
|
70
|
-
|
|
71
|
-
it( 'removes all keyboard listeners when scrollEnabled changes to false', () => {
|
|
72
|
-
// Arrange
|
|
73
|
-
const { result, rerender } = renderHook(
|
|
74
|
-
( { scrollEnabled } ) => useKeyboardOffset( scrollEnabled ),
|
|
75
|
-
{
|
|
76
|
-
initialProps: { scrollEnabled: true },
|
|
77
|
-
}
|
|
78
|
-
);
|
|
79
|
-
const [ keyboardOffset ] = result.current;
|
|
80
|
-
|
|
81
|
-
// Act
|
|
82
|
-
rerender( { scrollEnabled: false } );
|
|
83
|
-
|
|
84
|
-
// Assert
|
|
85
|
-
expect( keyboardOffset ).toBe( 0 );
|
|
86
|
-
expect( RCTDeviceEventEmitter.listenerCount( 'keyboardDidHide' ) ).toBe(
|
|
87
|
-
0
|
|
88
|
-
);
|
|
89
|
-
expect( RCTDeviceEventEmitter.listenerCount( 'keyboardDidShow' ) ).toBe(
|
|
90
|
-
0
|
|
91
|
-
);
|
|
92
|
-
} );
|
|
93
|
-
|
|
94
|
-
it( 'adds all keyboard listeners when scrollEnabled changes to true', () => {
|
|
95
|
-
// Arrange
|
|
96
|
-
const { result, rerender } = renderHook(
|
|
97
|
-
( { scrollEnabled } ) => useKeyboardOffset( scrollEnabled ),
|
|
98
|
-
{
|
|
99
|
-
initialProps: { scrollEnabled: false },
|
|
100
|
-
}
|
|
101
|
-
);
|
|
102
|
-
// Act
|
|
103
|
-
act( () => {
|
|
104
|
-
rerender( { scrollEnabled: true } );
|
|
105
|
-
} );
|
|
106
|
-
|
|
107
|
-
act( () => {
|
|
108
|
-
RCTDeviceEventEmitter.emit( 'keyboardDidShow', {
|
|
109
|
-
endCoordinates: { height: 250 },
|
|
110
|
-
} );
|
|
111
|
-
} );
|
|
112
|
-
|
|
113
|
-
const [ keyboardOffset ] = result.current;
|
|
114
|
-
|
|
115
|
-
// Assert
|
|
116
|
-
expect( keyboardOffset ).toBe( 250 );
|
|
117
|
-
expect( RCTDeviceEventEmitter.listenerCount( 'keyboardDidShow' ) ).toBe(
|
|
118
|
-
1
|
|
119
|
-
);
|
|
120
|
-
expect( RCTDeviceEventEmitter.listenerCount( 'keyboardDidHide' ) ).toBe(
|
|
121
|
-
1
|
|
122
|
-
);
|
|
123
|
-
} );
|
|
124
|
-
|
|
125
|
-
it( 'does not set keyboard offset to 0 when keyboard is hidden and shouldPreventAutomaticScroll is true', () => {
|
|
126
|
-
// Arrange
|
|
127
|
-
const shouldPreventAutomaticScroll = jest.fn().mockReturnValue( true );
|
|
128
|
-
const { result } = renderHook( () =>
|
|
129
|
-
useKeyboardOffset( true, shouldPreventAutomaticScroll )
|
|
130
|
-
);
|
|
131
|
-
|
|
132
|
-
// Act
|
|
133
|
-
act( () => {
|
|
134
|
-
RCTDeviceEventEmitter.emit( 'keyboardDidShow', {
|
|
135
|
-
endCoordinates: { height: 250 },
|
|
136
|
-
} );
|
|
137
|
-
} );
|
|
138
|
-
act( () => {
|
|
139
|
-
RCTDeviceEventEmitter.emit( 'keyboardDidHide' );
|
|
140
|
-
jest.runAllTimers();
|
|
141
|
-
} );
|
|
142
|
-
|
|
143
|
-
// Assert
|
|
144
|
-
expect( result.current[ 0 ] ).toBe( 250 );
|
|
145
|
-
} );
|
|
146
|
-
|
|
147
|
-
it( 'handles updates to shouldPreventAutomaticScroll', () => {
|
|
148
|
-
// Arrange
|
|
149
|
-
const preventScrollTrue = jest.fn( () => true );
|
|
150
|
-
const preventScrollFalse = jest.fn( () => false );
|
|
151
|
-
|
|
152
|
-
// Act
|
|
153
|
-
const { result, rerender } = renderHook(
|
|
154
|
-
( { shouldPreventAutomaticScroll } ) =>
|
|
155
|
-
useKeyboardOffset( true, shouldPreventAutomaticScroll ),
|
|
156
|
-
{
|
|
157
|
-
initialProps: {
|
|
158
|
-
shouldPreventAutomaticScroll: preventScrollFalse,
|
|
159
|
-
},
|
|
160
|
-
}
|
|
161
|
-
);
|
|
162
|
-
|
|
163
|
-
// Assert
|
|
164
|
-
expect( result.current[ 0 ] ).toBe( 0 );
|
|
165
|
-
|
|
166
|
-
// Act
|
|
167
|
-
act( () => {
|
|
168
|
-
RCTDeviceEventEmitter.emit( 'keyboardDidShow', {
|
|
169
|
-
endCoordinates: { height: 150 },
|
|
170
|
-
} );
|
|
171
|
-
} );
|
|
172
|
-
|
|
173
|
-
// Assert
|
|
174
|
-
expect( result.current[ 0 ] ).toBe( 150 );
|
|
175
|
-
|
|
176
|
-
// Act
|
|
177
|
-
act( () => {
|
|
178
|
-
rerender( { shouldPreventAutomaticScroll: preventScrollTrue } );
|
|
179
|
-
} );
|
|
180
|
-
|
|
181
|
-
act( () => {
|
|
182
|
-
RCTDeviceEventEmitter.emit( 'keyboardDidHide' );
|
|
183
|
-
jest.runAllTimers();
|
|
184
|
-
} );
|
|
185
|
-
|
|
186
|
-
// Assert
|
|
187
|
-
expect( result.current[ 0 ] ).toBe( 150 );
|
|
188
|
-
|
|
189
|
-
// Act
|
|
190
|
-
act( () => {
|
|
191
|
-
rerender( { shouldPreventAutomaticScroll: preventScrollFalse } );
|
|
192
|
-
} );
|
|
193
|
-
|
|
194
|
-
act( () => {
|
|
195
|
-
RCTDeviceEventEmitter.emit( 'keyboardDidShow', {
|
|
196
|
-
endCoordinates: { height: 250 },
|
|
197
|
-
} );
|
|
198
|
-
} );
|
|
199
|
-
|
|
200
|
-
// Assert
|
|
201
|
-
expect( result.current[ 0 ] ).toBe( 250 );
|
|
202
|
-
} );
|
|
203
|
-
} );
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { renderHook } from '@testing-library/react-native';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Internal dependencies
|
|
9
|
-
*/
|
|
10
|
-
import useScrollToSection from '../use-scroll-to-section';
|
|
11
|
-
|
|
12
|
-
describe( 'useScrollToSection', () => {
|
|
13
|
-
it( 'scrolls up to the section', () => {
|
|
14
|
-
// Arrange
|
|
15
|
-
const sectionY = 50;
|
|
16
|
-
const sectionHeight = 10;
|
|
17
|
-
|
|
18
|
-
const extraScrollHeight = 50;
|
|
19
|
-
const keyboardOffset = 100;
|
|
20
|
-
const scrollEnabled = true;
|
|
21
|
-
const scrollViewRef = { current: { scrollTo: jest.fn() } };
|
|
22
|
-
const scrollViewMeasurements = { current: { height: 600 } };
|
|
23
|
-
const scrollViewYOffset = { value: 150 };
|
|
24
|
-
|
|
25
|
-
const { result } = renderHook( () =>
|
|
26
|
-
useScrollToSection(
|
|
27
|
-
extraScrollHeight,
|
|
28
|
-
keyboardOffset,
|
|
29
|
-
scrollEnabled,
|
|
30
|
-
scrollViewMeasurements,
|
|
31
|
-
scrollViewRef,
|
|
32
|
-
scrollViewYOffset
|
|
33
|
-
)
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
// Act
|
|
37
|
-
result.current[ 0 ]( sectionY, sectionHeight );
|
|
38
|
-
|
|
39
|
-
// Assert
|
|
40
|
-
expect( scrollViewRef.current.scrollTo ).toHaveBeenCalledWith( {
|
|
41
|
-
y: sectionY,
|
|
42
|
-
animated: true,
|
|
43
|
-
} );
|
|
44
|
-
} );
|
|
45
|
-
|
|
46
|
-
it( 'scrolls down to the section', () => {
|
|
47
|
-
// Arrange
|
|
48
|
-
const sectionY = 750;
|
|
49
|
-
const sectionHeight = 10;
|
|
50
|
-
|
|
51
|
-
const extraScrollHeight = 50;
|
|
52
|
-
const keyboardOffset = 100;
|
|
53
|
-
const scrollEnabled = true;
|
|
54
|
-
const scrollViewRef = { current: { scrollTo: jest.fn() } };
|
|
55
|
-
const scrollViewMeasurements = { current: { height: 600 } };
|
|
56
|
-
const scrollViewYOffset = { value: 250 };
|
|
57
|
-
|
|
58
|
-
const { result } = renderHook( () =>
|
|
59
|
-
useScrollToSection(
|
|
60
|
-
extraScrollHeight,
|
|
61
|
-
keyboardOffset,
|
|
62
|
-
scrollEnabled,
|
|
63
|
-
scrollViewMeasurements,
|
|
64
|
-
scrollViewRef,
|
|
65
|
-
scrollViewYOffset
|
|
66
|
-
)
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
// Act
|
|
70
|
-
result.current[ 0 ]( sectionY, sectionHeight );
|
|
71
|
-
|
|
72
|
-
// Assert
|
|
73
|
-
const expectedYOffset =
|
|
74
|
-
sectionY -
|
|
75
|
-
( scrollViewMeasurements.current.height -
|
|
76
|
-
( keyboardOffset + extraScrollHeight + sectionHeight ) );
|
|
77
|
-
expect( scrollViewRef.current.scrollTo ).toHaveBeenCalledWith( {
|
|
78
|
-
y: expectedYOffset,
|
|
79
|
-
animated: true,
|
|
80
|
-
} );
|
|
81
|
-
} );
|
|
82
|
-
|
|
83
|
-
it( 'does not scroll when the ScrollView ref is not available', () => {
|
|
84
|
-
// Arrange
|
|
85
|
-
const sectionY = 50;
|
|
86
|
-
const sectionHeight = 10;
|
|
87
|
-
|
|
88
|
-
const extraScrollHeight = 50;
|
|
89
|
-
const keyboardOffset = 100;
|
|
90
|
-
const scrollEnabled = true;
|
|
91
|
-
const scrollViewRef = { current: null };
|
|
92
|
-
const scrollViewMeasurements = { current: { height: 600 } };
|
|
93
|
-
const scrollViewYOffset = { value: 0 };
|
|
94
|
-
|
|
95
|
-
const { result } = renderHook( () =>
|
|
96
|
-
useScrollToSection(
|
|
97
|
-
extraScrollHeight,
|
|
98
|
-
keyboardOffset,
|
|
99
|
-
scrollEnabled,
|
|
100
|
-
scrollViewMeasurements,
|
|
101
|
-
scrollViewRef,
|
|
102
|
-
scrollViewYOffset
|
|
103
|
-
)
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
// Act
|
|
107
|
-
result.current[ 0 ]( sectionY, sectionHeight );
|
|
108
|
-
|
|
109
|
-
// Assert
|
|
110
|
-
expect( scrollViewRef.current ).toBeNull();
|
|
111
|
-
} );
|
|
112
|
-
|
|
113
|
-
it( 'does not scroll when the scroll is not enabled', () => {
|
|
114
|
-
// Arrange
|
|
115
|
-
const sectionY = 50;
|
|
116
|
-
const sectionHeight = 10;
|
|
117
|
-
|
|
118
|
-
const extraScrollHeight = 50;
|
|
119
|
-
const keyboardOffset = 100;
|
|
120
|
-
const scrollEnabled = false;
|
|
121
|
-
const scrollViewRef = { current: { scrollTo: jest.fn() } };
|
|
122
|
-
const scrollViewMeasurements = { current: { height: 600 } };
|
|
123
|
-
const scrollViewYOffset = { value: 0 };
|
|
124
|
-
|
|
125
|
-
const { result } = renderHook( () =>
|
|
126
|
-
useScrollToSection(
|
|
127
|
-
extraScrollHeight,
|
|
128
|
-
keyboardOffset,
|
|
129
|
-
scrollEnabled,
|
|
130
|
-
scrollViewMeasurements,
|
|
131
|
-
scrollViewRef,
|
|
132
|
-
scrollViewYOffset
|
|
133
|
-
)
|
|
134
|
-
);
|
|
135
|
-
|
|
136
|
-
// Act
|
|
137
|
-
result.current[ 0 ]( sectionY, sectionHeight );
|
|
138
|
-
|
|
139
|
-
// Assert
|
|
140
|
-
expect( scrollViewRef.current.scrollTo ).not.toHaveBeenCalled();
|
|
141
|
-
} );
|
|
142
|
-
} );
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { renderHook } from 'test/helpers';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Internal dependencies
|
|
9
|
-
*/
|
|
10
|
-
import useScroll from '../use-scroll';
|
|
11
|
-
|
|
12
|
-
// Mock Reanimated with default mock
|
|
13
|
-
jest.mock( 'react-native-reanimated', () => ( {
|
|
14
|
-
...require( 'react-native-reanimated/mock' ),
|
|
15
|
-
useAnimatedScrollHandler: jest.fn( ( args ) => args ),
|
|
16
|
-
} ) );
|
|
17
|
-
|
|
18
|
-
describe( 'useScroll', () => {
|
|
19
|
-
it( 'scrolls using current scroll position', () => {
|
|
20
|
-
const sectionY = 50;
|
|
21
|
-
const sectionHeight = 10;
|
|
22
|
-
const scrollViewMeasurements = { x: 0, y: 0, width: 0, height: 600 };
|
|
23
|
-
const extraScrollHeight = 50;
|
|
24
|
-
const scrollEnabled = true;
|
|
25
|
-
const shouldPreventAutomaticScroll = false;
|
|
26
|
-
|
|
27
|
-
const scrollTo = jest.fn();
|
|
28
|
-
const measureInWindow = jest.fn( ( callback ) =>
|
|
29
|
-
callback( ...Object.values( scrollViewMeasurements ) )
|
|
30
|
-
);
|
|
31
|
-
const scrollRef = { scrollTo, measureInWindow };
|
|
32
|
-
const onScroll = jest.fn();
|
|
33
|
-
const onSizeChange = jest.fn();
|
|
34
|
-
|
|
35
|
-
const { result } = renderHook( () =>
|
|
36
|
-
useScroll( {
|
|
37
|
-
scrollEnabled,
|
|
38
|
-
shouldPreventAutomaticScroll,
|
|
39
|
-
onScroll,
|
|
40
|
-
onSizeChange,
|
|
41
|
-
extraScrollHeight,
|
|
42
|
-
} )
|
|
43
|
-
);
|
|
44
|
-
const {
|
|
45
|
-
scrollViewRef,
|
|
46
|
-
onContentSizeChange,
|
|
47
|
-
scrollHandler,
|
|
48
|
-
scrollToSection,
|
|
49
|
-
} = result.current;
|
|
50
|
-
|
|
51
|
-
// Assign ref
|
|
52
|
-
scrollViewRef.current = scrollRef;
|
|
53
|
-
|
|
54
|
-
// Check content size changes
|
|
55
|
-
onContentSizeChange();
|
|
56
|
-
expect( measureInWindow ).toHaveBeenCalled();
|
|
57
|
-
expect( onSizeChange ).toHaveBeenCalled();
|
|
58
|
-
|
|
59
|
-
// Set up initial scroll offset
|
|
60
|
-
scrollHandler.onScroll( { contentOffset: { y: 150 } } );
|
|
61
|
-
|
|
62
|
-
// Scroll to section
|
|
63
|
-
scrollToSection( sectionY, sectionHeight );
|
|
64
|
-
|
|
65
|
-
// Assert
|
|
66
|
-
expect( scrollTo ).toHaveBeenCalledWith( {
|
|
67
|
-
y: sectionY,
|
|
68
|
-
animated: true,
|
|
69
|
-
} );
|
|
70
|
-
} );
|
|
71
|
-
} );
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { renderHook } from '@testing-library/react-native';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* WordPress dependencies
|
|
8
|
-
*/
|
|
9
|
-
import RCTAztecView from '@wordpress/react-native-aztec';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Internal dependencies
|
|
13
|
-
*/
|
|
14
|
-
import useTextInputCaretPosition from '../use-text-input-caret-position';
|
|
15
|
-
|
|
16
|
-
describe( 'useTextInputCaretPosition', () => {
|
|
17
|
-
let addCaretChangeListenerSpy;
|
|
18
|
-
let removeCaretChangeListenerSpy;
|
|
19
|
-
|
|
20
|
-
beforeAll( () => {
|
|
21
|
-
addCaretChangeListenerSpy = jest.spyOn(
|
|
22
|
-
RCTAztecView.InputState,
|
|
23
|
-
'addCaretChangeListener'
|
|
24
|
-
);
|
|
25
|
-
removeCaretChangeListenerSpy = jest.spyOn(
|
|
26
|
-
RCTAztecView.InputState,
|
|
27
|
-
'removeCaretChangeListener'
|
|
28
|
-
);
|
|
29
|
-
} );
|
|
30
|
-
|
|
31
|
-
beforeEach( () => {
|
|
32
|
-
addCaretChangeListenerSpy.mockClear();
|
|
33
|
-
removeCaretChangeListenerSpy.mockClear();
|
|
34
|
-
} );
|
|
35
|
-
|
|
36
|
-
it( 'should add and remove caret change listener correctly', () => {
|
|
37
|
-
// Arrange
|
|
38
|
-
const scrollEnabled = true;
|
|
39
|
-
|
|
40
|
-
// Act
|
|
41
|
-
const { unmount } = renderHook( () =>
|
|
42
|
-
useTextInputCaretPosition( scrollEnabled )
|
|
43
|
-
);
|
|
44
|
-
unmount();
|
|
45
|
-
|
|
46
|
-
// Assert
|
|
47
|
-
expect( addCaretChangeListenerSpy ).toHaveBeenCalledTimes( 1 );
|
|
48
|
-
expect( removeCaretChangeListenerSpy ).toHaveBeenCalledTimes( 1 );
|
|
49
|
-
} );
|
|
50
|
-
|
|
51
|
-
it( 'should add caret change listener when scroll is enabled', () => {
|
|
52
|
-
// Arrange
|
|
53
|
-
const scrollEnabled = true;
|
|
54
|
-
|
|
55
|
-
// Act
|
|
56
|
-
renderHook( () => useTextInputCaretPosition( scrollEnabled ) );
|
|
57
|
-
|
|
58
|
-
// Assert
|
|
59
|
-
expect( addCaretChangeListenerSpy ).toHaveBeenCalledTimes( 1 );
|
|
60
|
-
expect( removeCaretChangeListenerSpy ).not.toHaveBeenCalled();
|
|
61
|
-
} );
|
|
62
|
-
|
|
63
|
-
it( 'should remove caret change listener when scroll is enabled and then changed to disabled', () => {
|
|
64
|
-
// Arrange
|
|
65
|
-
const { rerender } = renderHook(
|
|
66
|
-
( props ) => useTextInputCaretPosition( props.scrollEnabled ),
|
|
67
|
-
{
|
|
68
|
-
initialProps: { scrollEnabled: true },
|
|
69
|
-
}
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
// Assert
|
|
73
|
-
expect( addCaretChangeListenerSpy ).toHaveBeenCalled();
|
|
74
|
-
|
|
75
|
-
// Act
|
|
76
|
-
rerender( { scrollEnabled: false } );
|
|
77
|
-
|
|
78
|
-
// Assert
|
|
79
|
-
expect( removeCaretChangeListenerSpy ).toHaveBeenCalled();
|
|
80
|
-
expect( addCaretChangeListenerSpy ).toHaveBeenCalledTimes( 1 );
|
|
81
|
-
} );
|
|
82
|
-
} );
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { renderHook } from '@testing-library/react-native';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* WordPress dependencies
|
|
8
|
-
*/
|
|
9
|
-
import RCTAztecView from '@wordpress/react-native-aztec';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Internal dependencies
|
|
13
|
-
*/
|
|
14
|
-
import useTextInputOffset from '../use-text-input-offset';
|
|
15
|
-
|
|
16
|
-
jest.mock( '@wordpress/react-native-aztec', () => ( {
|
|
17
|
-
InputState: {
|
|
18
|
-
getCurrentFocusedElement: jest.fn(),
|
|
19
|
-
},
|
|
20
|
-
} ) );
|
|
21
|
-
|
|
22
|
-
describe( 'useTextInputOffset', () => {
|
|
23
|
-
afterEach( () => {
|
|
24
|
-
jest.clearAllMocks();
|
|
25
|
-
} );
|
|
26
|
-
|
|
27
|
-
it( 'should return a function', () => {
|
|
28
|
-
// Arrange
|
|
29
|
-
const scrollViewRef = { current: {} };
|
|
30
|
-
const scrollEnabled = true;
|
|
31
|
-
|
|
32
|
-
// Act
|
|
33
|
-
const { result } = renderHook( () =>
|
|
34
|
-
useTextInputOffset( scrollEnabled, scrollViewRef )
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
// Assert
|
|
38
|
-
expect( result.current[ 0 ] ).toBeInstanceOf( Function );
|
|
39
|
-
} );
|
|
40
|
-
|
|
41
|
-
it( 'should return null when scrollViewRef.current is null', async () => {
|
|
42
|
-
// Arrange
|
|
43
|
-
const scrollViewRef = { current: null };
|
|
44
|
-
const scrollEnabled = true;
|
|
45
|
-
|
|
46
|
-
// Act
|
|
47
|
-
const { result } = renderHook( () =>
|
|
48
|
-
useTextInputOffset( scrollEnabled, scrollViewRef )
|
|
49
|
-
);
|
|
50
|
-
const getTextInputOffset = result.current[ 0 ];
|
|
51
|
-
|
|
52
|
-
// Assert
|
|
53
|
-
const offset = await getTextInputOffset();
|
|
54
|
-
expect( offset ).toBeNull();
|
|
55
|
-
} );
|
|
56
|
-
|
|
57
|
-
it( 'should return null when textInput is null', async () => {
|
|
58
|
-
// Arrange
|
|
59
|
-
const scrollViewRef = { current: {} };
|
|
60
|
-
const scrollEnabled = true;
|
|
61
|
-
RCTAztecView.InputState.getCurrentFocusedElement.mockReturnValue(
|
|
62
|
-
null
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
// Act
|
|
66
|
-
const { result } = renderHook( () =>
|
|
67
|
-
useTextInputOffset( scrollEnabled, scrollViewRef )
|
|
68
|
-
);
|
|
69
|
-
const getTextInputOffset = result.current[ 0 ];
|
|
70
|
-
|
|
71
|
-
// Assert
|
|
72
|
-
const offset = await getTextInputOffset();
|
|
73
|
-
expect( offset ).toBeNull();
|
|
74
|
-
} );
|
|
75
|
-
|
|
76
|
-
it( 'should return null when scroll is not enabled', async () => {
|
|
77
|
-
// Arrange
|
|
78
|
-
const scrollViewRef = { current: {} };
|
|
79
|
-
const scrollEnabled = false;
|
|
80
|
-
|
|
81
|
-
// Act
|
|
82
|
-
const { result } = renderHook( () =>
|
|
83
|
-
useTextInputOffset( scrollEnabled, scrollViewRef )
|
|
84
|
-
);
|
|
85
|
-
const getTextInputOffset = result.current[ 0 ];
|
|
86
|
-
|
|
87
|
-
// Assert
|
|
88
|
-
const offset = await getTextInputOffset();
|
|
89
|
-
expect( offset ).toBeNull();
|
|
90
|
-
} );
|
|
91
|
-
|
|
92
|
-
it( 'should return correct offset value when caretY is not null', async () => {
|
|
93
|
-
// Arrange
|
|
94
|
-
const scrollViewRef = { current: {} };
|
|
95
|
-
const scrollEnabled = true;
|
|
96
|
-
const x = 0;
|
|
97
|
-
const y = 10;
|
|
98
|
-
const width = 0;
|
|
99
|
-
const height = 100;
|
|
100
|
-
const textInput = {
|
|
101
|
-
measureLayout: jest.fn( ( _, callback ) => {
|
|
102
|
-
callback( x, y, width, height );
|
|
103
|
-
} ),
|
|
104
|
-
};
|
|
105
|
-
RCTAztecView.InputState.getCurrentFocusedElement.mockReturnValue(
|
|
106
|
-
textInput
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
// Act
|
|
110
|
-
const { result } = renderHook( () =>
|
|
111
|
-
useTextInputOffset( scrollEnabled, scrollViewRef )
|
|
112
|
-
);
|
|
113
|
-
const getTextInputOffset = result.current[ 0 ];
|
|
114
|
-
|
|
115
|
-
// Assert
|
|
116
|
-
const offset = await getTextInputOffset( { caretY: 10 } );
|
|
117
|
-
expect( offset ).toBe( 20 );
|
|
118
|
-
} );
|
|
119
|
-
|
|
120
|
-
it( 'should return correct offset value when caretY is -1', async () => {
|
|
121
|
-
// Arrange
|
|
122
|
-
const scrollViewRef = { current: {} };
|
|
123
|
-
const scrollEnabled = true;
|
|
124
|
-
const x = 0;
|
|
125
|
-
const y = 10;
|
|
126
|
-
const width = 0;
|
|
127
|
-
const height = 100;
|
|
128
|
-
const textInput = {
|
|
129
|
-
measureLayout: jest.fn( ( _, callback ) => {
|
|
130
|
-
callback( x, y, width, height );
|
|
131
|
-
} ),
|
|
132
|
-
};
|
|
133
|
-
RCTAztecView.InputState.getCurrentFocusedElement.mockReturnValue(
|
|
134
|
-
textInput
|
|
135
|
-
);
|
|
136
|
-
|
|
137
|
-
// Act
|
|
138
|
-
const { result } = renderHook( () =>
|
|
139
|
-
useTextInputOffset( scrollEnabled, scrollViewRef )
|
|
140
|
-
);
|
|
141
|
-
const getTextInputOffset = result.current[ 0 ];
|
|
142
|
-
|
|
143
|
-
// Assert
|
|
144
|
-
const offset = await getTextInputOffset( { caretY: -1 } );
|
|
145
|
-
expect( offset ).toBe( 110 );
|
|
146
|
-
} );
|
|
147
|
-
} );
|