-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from su-its/feat/user-card/update-data
UserCardでAPIから取得したデータを使用
- Loading branch information
Showing
3 changed files
with
63 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { UserCardPresenter } from "@/components/molecules/UserCard"; | ||
import { describe, expect, it } from "@jest/globals"; | ||
import { render, screen } from "@testing-library/react"; | ||
import type { User } from "@/types/user"; | ||
|
||
describe("UserCard", () => { | ||
const mockUser: User = { | ||
handleName: "しずっぴー", | ||
studentNumber: "B1234567", | ||
id: "1", | ||
}; | ||
|
||
it("renders UserCard", () => { | ||
const userCard = render(<UserCardPresenter user={mockUser} />); | ||
|
||
const avatar = screen.getByRole("img"); | ||
expect(avatar).toBeInTheDocument(); | ||
}); | ||
|
||
it("renders UserCard with user data", () => { | ||
const userCard = render(<UserCardPresenter user={mockUser} />); | ||
|
||
const name = screen.getByText(/名前:/); | ||
const studentNumber = screen.getByText(/学籍番号:/); | ||
expect(name).toHaveTextContent(mockUser.handleName); | ||
expect(studentNumber).toHaveTextContent(mockUser.studentNumber); | ||
}); | ||
|
||
it("renders UserCard with default data", () => { | ||
const userCard = render(<UserCardPresenter user={null as any} />); | ||
|
||
const name = screen.getByText(/名前:/); | ||
const studentNumber = screen.getByText(/学籍番号:/); | ||
expect(name).toHaveTextContent("ログインしていません"); | ||
expect(studentNumber).toHaveTextContent("未ログイン"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,33 @@ | ||
import React from "react"; | ||
import { Avatar, Box, Text, HStack, VStack } from "@chakra-ui/react"; | ||
import { getCurrentUser } from "@/app/actions"; | ||
import type { User } from "@/types/user"; | ||
|
||
const UserCard: React.FC = () => { | ||
// モックのユーザー情報 | ||
const user = { | ||
name: "テストユーザー", | ||
studentId: "24AB1234", | ||
avatarUrl: "https://avatars.githubusercontent.com/u/12345678?v=4", | ||
}; | ||
interface UserCardPresenterProps { | ||
user?: User; | ||
} | ||
|
||
export const UserCardPresenter = ({ user }: UserCardPresenterProps) => { | ||
return ( | ||
user && ( | ||
<Box bg={"blue.600"} p={5}> | ||
<HStack spacing={4}> | ||
<Avatar src={user.avatarUrl} maxW="100px" borderRadius="9" /> | ||
<VStack align="start"> | ||
<Text fontSize="lg" fontWeight="bold" color={"white"}> | ||
名前: {user.name} | ||
</Text> | ||
<Text color={"white"}>学籍番号: {user.studentId}</Text> | ||
</VStack> | ||
</HStack> | ||
</Box> | ||
) | ||
<HStack spacing={4} bg="blue.600"> | ||
<Avatar | ||
src={"https://www.shizuoka.ac.jp/cms/files/shizudai/MASTER/0100/uISrbYCb_VL033_r03.png"} | ||
boxSize="100px" | ||
borderRadius="0" | ||
/> | ||
<VStack align="start" paddingRight="8px"> | ||
<Text fontSize="lg" fontWeight="bold" color="white"> | ||
名前: {user ? user.handleName : "ログインしていません"} | ||
</Text> | ||
<Text color="white">学籍番号: {user ? user.studentNumber : "未ログイン"}</Text> | ||
</VStack> | ||
</HStack> | ||
); | ||
}; | ||
|
||
const UserCard = async () => { | ||
const user = await getCurrentUser(); | ||
return <UserCardPresenter user={user} />; | ||
}; | ||
|
||
export default UserCard; |