|
| 1 | +import React from "react"; |
| 2 | +import { View } from "react-native"; |
| 3 | +import { render, screen } from "@testing-library/react-native"; |
| 4 | +import { SectionList, SectionHeader } from "../components/SectionList"; |
| 5 | +import { TabView, TabViewItem } from "../components/TabView"; |
| 6 | +import { |
| 7 | + SwipeableItem, |
| 8 | + SwipeableItemButton, |
| 9 | +} from "../components/SwipeableItem"; |
| 10 | +import { flattenReactFragments } from "../utilities"; |
| 11 | + |
| 12 | +describe("Type checked components wrapped in a fragment tests", () => { |
| 13 | + describe("Type checked components render when wrapped in a fragment tests", () => { |
| 14 | + test("should SectionHeader render when wrapped in fragment", () => { |
| 15 | + render( |
| 16 | + <SectionList |
| 17 | + data={[{ test: "data" }]} |
| 18 | + renderItem={() => ( |
| 19 | + <> |
| 20 | + <SectionHeader> |
| 21 | + <View testID="header" /> |
| 22 | + </SectionHeader> |
| 23 | + </> |
| 24 | + )} |
| 25 | + sectionKey="test" |
| 26 | + /> |
| 27 | + ); |
| 28 | + |
| 29 | + const headerView = screen.queryByTestId("header"); |
| 30 | + expect(headerView).toBeTruthy(); |
| 31 | + }); |
| 32 | + |
| 33 | + test("should TabViewItem render when wrapped in fragment", () => { |
| 34 | + render( |
| 35 | + <TabView Icon={() => <View />}> |
| 36 | + <> |
| 37 | + <TabViewItem title="Test"> |
| 38 | + <View testID="tab-item" /> |
| 39 | + </TabViewItem> |
| 40 | + </> |
| 41 | + </TabView> |
| 42 | + ); |
| 43 | + |
| 44 | + const tabItem = screen.queryByTestId("tab-item"); |
| 45 | + expect(tabItem).toBeTruthy(); |
| 46 | + }); |
| 47 | + |
| 48 | + test("should SwipeableItemButton render when wrapped in fragment", () => { |
| 49 | + render( |
| 50 | + <SwipeableItem Icon={() => <View />}> |
| 51 | + <> |
| 52 | + <SwipeableItemButton revealSwipeDirection="left" title="test" /> |
| 53 | + </> |
| 54 | + </SwipeableItem> |
| 55 | + ); |
| 56 | + |
| 57 | + const swipeableButton = screen.queryByTestId("swipeable-behind-item"); |
| 58 | + expect(swipeableButton).toBeTruthy(); |
| 59 | + }); |
| 60 | + }); |
| 61 | + |
| 62 | + describe("flattenReactFragments tests", () => { |
| 63 | + test("should extract components from react fragments", () => { |
| 64 | + const components = [ |
| 65 | + <React.Fragment> |
| 66 | + <View testID="1" /> |
| 67 | + <View testID="2" /> |
| 68 | + <View testID="3" /> |
| 69 | + </React.Fragment>, |
| 70 | + <> |
| 71 | + <View testID="4" /> |
| 72 | + </>, |
| 73 | + <> |
| 74 | + <View testID="5" /> |
| 75 | + <View testID="6" /> |
| 76 | + </>, |
| 77 | + ]; |
| 78 | + |
| 79 | + const result = flattenReactFragments(components); |
| 80 | + expect(result).toMatchInlineSnapshot(` |
| 81 | + [ |
| 82 | + <View |
| 83 | + testID="1" |
| 84 | + />, |
| 85 | + <View |
| 86 | + testID="2" |
| 87 | + />, |
| 88 | + <View |
| 89 | + testID="3" |
| 90 | + />, |
| 91 | + <View |
| 92 | + testID="4" |
| 93 | + />, |
| 94 | + <View |
| 95 | + testID="5" |
| 96 | + />, |
| 97 | + <View |
| 98 | + testID="6" |
| 99 | + />, |
| 100 | + ] |
| 101 | + `); |
| 102 | + }); |
| 103 | + }); |
| 104 | +}); |
0 commit comments