Skip to content

Commit

Permalink
Added SectionList and SectionHeader components + Tests (48.1.0) (#684)
Browse files Browse the repository at this point in the history
* Added section list and section header components

* Updated how section header child is identified to use .type

* Updated extraction of props to be null safe

* Fixed null checks when rendering section list

* Setup for tests

* Added tests for sectionlist

* Added test step to ci

* Removed tests from ts build

* v48.1.0
  • Loading branch information
YoussefHenna authored May 25, 2023
1 parent c5259bd commit 0d9c143
Show file tree
Hide file tree
Showing 23 changed files with 1,038 additions and 861 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ jobs:
- name: Lint
run: yarn lint

- name: Test
run: yarn test

- name: Build
run: yarn build

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,5 @@ components.json

js.map
.eslintcache

**/coverage/**
7 changes: 4 additions & 3 deletions example/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@draftbit/example",
"description": "Example app for @draftbit/ui",
"version": "48.0.2",
"version": "48.1.0",
"private": true,
"main": "__generated__/AppEntry.js",
"scripts": {
Expand All @@ -10,13 +10,14 @@
"web": "expo start --web",
"start": "expo start",
"test": "jest",
"test:coverage": "jest --coverage",
"postinstall": "expo-yarn-workspaces postinstall",
"example": "yarn --cwd example",
"clean:modules": "rimraf node_modules"
},
"dependencies": {
"@draftbit/maps": "48.0.2",
"@draftbit/ui": "48.0.2",
"@draftbit/maps": "48.1.0",
"@draftbit/ui": "48.1.0",
"@expo/dev-server": "0.1.123",
"@expo/webpack-config": "^18.0.1",
"@react-navigation/drawer": "^5.12.9",
Expand Down
2 changes: 2 additions & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import BottomSheetExample from "./BottomSheetExample";
import YoutubeExample from "./YoutubeExample";
import TableExample from "./TableExample";
import SwipeableItemExample from "./SwipeableItemExample";
import SectionListExample from "./SectionListExample";

const ROUTES = {
AudioPlayer: AudioPlayerExample,
Expand Down Expand Up @@ -93,6 +94,7 @@ const ROUTES = {
Youtube: YoutubeExample,
Table: TableExample,
SwipeableView: SwipeableItemExample,
SectionList: SectionListExample,
};

let customFonts = {
Expand Down
112 changes: 112 additions & 0 deletions example/src/SectionListExample.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { SectionList, SectionHeader } from "@draftbit/ui";
import React from "react";
import Section, { Container } from "./Section";
import { Text, View } from "react-native";

type Food = { id: number; name: string; category: string };

const sampleData: Food[] = [
{
id: 5,
name: "Onion Rings",
category: "Side",
},
{
id: 1,
name: "Pizza",
category: "Main Dish",
},
{
id: 3,
name: "Risotto",
category: "Main Dish",
},
{
id: 6,
name: "Ice Cream",
category: "Dessert",
},
{
id: 4,
name: "Fries",
category: "Side",
},
{
id: 7,
name: "Churros",
category: "Dessert",
},
{
id: 2,
name: "Burger",
category: "Main Dish",
},
];

const SwipeableViewExample: React.FC = () => {
return (
<Container style={{ flex: 1 }}>
<Section style={{}} title="Section List (FlatList)">
<View style={{ height: 150 }}>
<SectionList
listComponent="FlatList"
data={sampleData}
sectionKey="category"
renderItem={({ item }) => (
<View>
<Text>{item?.id}</Text>
<Text>{item?.name}</Text>
</View>
)}
/>
</View>
</Section>
<Section style={{}} title="Section List (FlashList)">
<View style={{ height: 150 }}>
<SectionList
listComponent="FlashList"
data={sampleData}
sectionKey="category"
estimatedItemSize={40}
renderItem={({ item }) => (
<View>
<Text>{item?.id}</Text>
<Text>{item?.name}</Text>
</View>
)}
/>
</View>
</Section>
<Section style={{}} title="Section List Custom Header">
<View style={{ height: 150 }}>
<SectionList
data={sampleData}
sectionKey="category"
renderItem={({ item, section }) => (
<>
<SectionHeader>
<Text
style={{
padding: 10,
color: "green",
borderWidth: 2,
borderColor: "green",
}}
>
Custom Section: {section}
</Text>
</SectionHeader>
<View>
<Text>{item?.id}</Text>
<Text>{item?.name}</Text>
</View>
</>
)}
/>
</View>
</Section>
</Container>
);
};

export default SwipeableViewExample;
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "48.0.2",
"version": "48.1.0",
"npmClient": "yarn",
"useWorkspaces": true,
"packages": ["packages/*", "example"],
Expand Down
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"format": "prettier --write .",
"lint": "eslint \"**/*.{ts,tsx}\"",
"build": "lerna run build",
"test": "lerna run test --stream -- --passWithNoTests",
"release": "lerna publish",
"example:snack": "ts-node --transpile-only scripts/upload-to-snack.ts",
"clean": "lerna run clean",
Expand All @@ -35,14 +36,17 @@
],
"devDependencies": {
"@react-native-community/eslint-config": "^3.2.0",
"@types/jest": "^26.0.23",
"babel-jest": "^26.6.3",
"@testing-library/jest-native": "^5.4.2",
"@testing-library/react-native": "^12.1.2",
"@types/jest": "^29.5.0",
"babel-jest": "^29.5.0",
"dotenv": "^9.0.2",
"eslint": "^8.18.0",
"eslint-plugin-prettier": "^4.2.0",
"expo-yarn-workspaces": "^2.0.0",
"husky": ">=6",
"jest": "^26.6.3",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"json-server": "^0.16.3",
"lerna": "^5.6.2",
"lint-staged": ">=13",
Expand Down
1 change: 1 addition & 0 deletions packages/core/jest-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require("@shopify/flash-list/jestSetup");
23 changes: 19 additions & 4 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@draftbit/core",
"version": "48.0.2",
"version": "48.1.0",
"description": "Core (non-native) Components",
"main": "lib/src/index.js",
"types": "lib/src/index.d.ts",
Expand All @@ -15,7 +15,9 @@
"scripts": {
"clean": "rimraf lib",
"clean:modules": "rimraf node_modules",
"build": "yarn clean && yarn tsc"
"build": "yarn clean && yarn tsc",
"test": "jest",
"test:coverage": "jest --coverage"
},
"keywords": [
"react-native",
Expand All @@ -39,7 +41,7 @@
"dependencies": {
"@date-io/date-fns": "^1.3.13",
"@draftbit/react-theme-provider": "^2.1.1",
"@draftbit/types": "48.0.2",
"@draftbit/types": "48.1.0",
"@expo/vector-icons": "^13.0.0",
"@material-ui/core": "^4.11.0",
"@material-ui/pickers": "^3.2.10",
Expand Down Expand Up @@ -78,5 +80,18 @@
"eslintIgnore": [
"node_modules/",
"lib/"
]
],
"jest": {
"preset": "react-native",
"setupFiles": [
"./jest-setup.js"
],
"setupFilesAfterEnv": [
"@testing-library/jest-native/extend-expect"
],
"testPathIgnorePatterns": [
"lib",
"__mocks__"
]
}
}
44 changes: 44 additions & 0 deletions packages/core/src/__tests__/__mocks__/mock_food_data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
export type Food = {
id: number;
name: string;
category: string;
priceRange: string;
};
export const mockFoodData: Food[] = [
{
id: 554,
name: "Onion Rings",
category: "Side",
priceRange: "low",
},
{
id: 145,
name: "Pizza",
category: "Main Dish",
priceRange: "high",
},
{
id: 423,
name: "Risotto",
category: "Main Dish",
priceRange: "high",
},
{
id: 642,
name: "Ice Cream",
category: "Dessert",
priceRange: "medium",
},
{
id: 463,
name: "Fries",
category: "Side",
priceRange: "low",
},
{
id: 724,
name: "Churros",
category: "Dessert",
priceRange: "medium",
},
];
Loading

0 comments on commit 0d9c143

Please sign in to comment.