Skip to content

Commit 49a99bb

Browse files
committed
photocontainer story, check loading
1 parent f3fa558 commit 49a99bb

File tree

1 file changed

+167
-0
lines changed

1 file changed

+167
-0
lines changed
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
import { PhotoContainer } from "@/components/OPhotoContainer/OPhotoContainer";
2+
import { IUserAction, IUserData } from "@/context/UserContext";
3+
import { Meta, StoryObj } from "@storybook/react";
4+
import * as ImagePicker from "expo-image-picker";
5+
import { PermissionStatus } from "expo-image-picker";
6+
import React from "react";
7+
import { View } from "react-native";
8+
9+
// Mock initial state matching the actual structure
10+
const mockState: IUserData = {
11+
wantsEmailUpdates: false,
12+
email: "",
13+
firstName: "",
14+
clearPassword: "",
15+
birthDay: new Date(2000, 1, 1),
16+
imageURIs: {
17+
"0": undefined,
18+
"1": undefined,
19+
"2": undefined,
20+
"3": undefined,
21+
"4": undefined,
22+
"5": undefined,
23+
},
24+
verificationStatus: "pending",
25+
approachChoice: "both",
26+
blacklistedRegions: [],
27+
approachFromTime: new Date(),
28+
approachToTime: new Date(),
29+
bio: "",
30+
dateMode: "ghost",
31+
markedForDeletion: false,
32+
};
33+
34+
// Mock dispatch function
35+
const mockDispatch: React.Dispatch<IUserAction> = (action) => {
36+
console.log("Dispatched action:", action);
37+
};
38+
39+
// Mock media permission response
40+
const mockMediaStatus: ImagePicker.MediaLibraryPermissionResponse = {
41+
status: PermissionStatus.GRANTED,
42+
granted: true,
43+
expires: "never",
44+
canAskAgain: true,
45+
};
46+
47+
// Mock permission request function
48+
const mockRequestMediaLibPermission = async () => mockMediaStatus;
49+
50+
const meta: Meta<typeof PhotoContainer> = {
51+
title: "Components/PhotoContainer",
52+
component: PhotoContainer,
53+
parameters: {
54+
notes: `
55+
PhotoContainer is used for managing user profile photos.
56+
- Supports image selection from media library
57+
- Handles image preview and removal
58+
- Integrates with the UserContext for state management
59+
`,
60+
},
61+
decorators: [
62+
(Story) => (
63+
<View style={{ padding: 20, backgroundColor: "#f5f5f5" }}>
64+
<Story />
65+
</View>
66+
),
67+
],
68+
argTypes: {
69+
size: {
70+
control: { type: "number" },
71+
description: "Size of the photo container in pixels",
72+
},
73+
imageIdx: {
74+
control: { type: "select" },
75+
options: ["0", "1", "2", "3", "4", "5"],
76+
description: "Index of the image slot (0-5)",
77+
},
78+
},
79+
};
80+
81+
export default meta;
82+
83+
type Story = StoryObj<typeof PhotoContainer>;
84+
85+
export const Empty: Story = {
86+
args: {
87+
imageIdx: "0",
88+
dispatch: mockDispatch,
89+
state: mockState,
90+
size: 200,
91+
mediaStatus: mockMediaStatus,
92+
requestMediaLibPermission: mockRequestMediaLibPermission,
93+
},
94+
};
95+
96+
export const WithImage: Story = {
97+
args: {
98+
...Empty.args,
99+
state: {
100+
...mockState,
101+
imageURIs: {
102+
...mockState.imageURIs,
103+
"0": {
104+
uri: "https://placekitten.com/200/200",
105+
fileName: "0",
106+
width: 200,
107+
height: 200,
108+
type: "image",
109+
fileSize: 1024,
110+
},
111+
},
112+
},
113+
},
114+
};
115+
116+
export const MultipleImages: Story = {
117+
args: {
118+
...Empty.args,
119+
imageIdx: "1",
120+
state: {
121+
...mockState,
122+
imageURIs: {
123+
"0": {
124+
uri: "https://placekitten.com/200/200",
125+
fileName: "0",
126+
width: 200,
127+
height: 200,
128+
type: "image",
129+
fileSize: 1024,
130+
},
131+
"1": {
132+
uri: "https://placekitten.com/201/201",
133+
fileName: "1",
134+
width: 201,
135+
height: 201,
136+
type: "image",
137+
fileSize: 1024,
138+
},
139+
},
140+
},
141+
},
142+
};
143+
144+
export const SmallSize: Story = {
145+
args: {
146+
...Empty.args,
147+
size: 100,
148+
},
149+
};
150+
151+
export const LargeSize: Story = {
152+
args: {
153+
...Empty.args,
154+
size: 300,
155+
},
156+
};
157+
158+
export const WithPermissionDenied: Story = {
159+
args: {
160+
...Empty.args,
161+
mediaStatus: {
162+
...mockMediaStatus,
163+
status: "denied",
164+
granted: false,
165+
},
166+
},
167+
};

0 commit comments

Comments
 (0)