-
Notifications
You must be signed in to change notification settings - Fork 3
feat: 어드민 대학 이미지 업로드 연동 #568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0586e31
feat: 어드민 대학 이미지 업로드 연동
whqtker f80eca0
feat: enhance image upload functionality with previews and loading st…
whqtker 9d578f5
feat: integrate CDN normalization for logo and background image uploads
whqtker b2fb02d
test: 대학 이미지 미리보기 CDN 경로 검증
whqtker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
apps/admin/src/components/features/univ-apply-infos/tabs/HostUniversityTab.test.tsx
This file contains hidden or 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,92 @@ | ||
| import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; | ||
| import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react"; | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; | ||
| import { adminApi } from "@/lib/api/admin"; | ||
| import { HostUniversityTab } from "./HostUniversityTab"; | ||
|
|
||
| const { toastError, toastSuccess } = vi.hoisted(() => ({ | ||
| toastError: vi.fn(), | ||
| toastSuccess: vi.fn(), | ||
| })); | ||
|
|
||
| vi.mock("sonner", () => ({ toast: { error: toastError, success: toastSuccess } })); | ||
| vi.mock("@tanstack/react-query", async (importOriginal) => { | ||
| const actual = await importOriginal<typeof import("@tanstack/react-query")>(); | ||
| return { ...actual, useQueries: () => [] }; | ||
| }); | ||
|
|
||
| function renderTab() { | ||
| const client = new QueryClient({ | ||
| defaultOptions: { queries: { retry: false }, mutations: { retry: false } }, | ||
| }); | ||
| return render( | ||
| <QueryClientProvider client={client}> | ||
| <HostUniversityTab /> | ||
| </QueryClientProvider>, | ||
| ); | ||
| } | ||
|
|
||
| async function openCreateModal() { | ||
| renderTab(); | ||
| fireEvent.click(await screen.findByRole("button", { name: "호스트 대학교 생성" })); | ||
| } | ||
|
|
||
| describe("HostUniversityTab image uploads", () => { | ||
| beforeEach(() => { | ||
| vi.spyOn(adminApi, "getHostUniversities").mockResolvedValue({ | ||
| content: [], | ||
| page: 0, | ||
| size: 20, | ||
| totalElements: 0, | ||
| totalPages: 0, | ||
| }); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| cleanup(); | ||
| vi.restoreAllMocks(); | ||
| toastError.mockReset(); | ||
| toastSuccess.mockReset(); | ||
| }); | ||
|
|
||
| it("uploads a selected logo with formatName and writes the returned URL", async () => { | ||
| const upload = vi | ||
| .spyOn(adminApi, "uploadAdminUniversityLogo") | ||
| .mockResolvedValue({ fileUrl: "admin/logo/test.webp" }); | ||
| await openCreateModal(); | ||
| fireEvent.change(screen.getByLabelText("표시명 *"), { target: { value: "university_of_test" } }); | ||
| const file = new File(["logo"], "logo.png", { type: "image/png" }); | ||
| fireEvent.change(screen.getByLabelText("로고 이미지 파일"), { target: { files: [file] } }); | ||
|
|
||
| await waitFor(() => expect(upload).toHaveBeenCalledWith(file, "university_of_test")); | ||
| await waitFor(() => | ||
| expect((screen.getByLabelText("로고 이미지 URL *") as HTMLInputElement).value).toBe("admin/logo/test.webp"), | ||
| ); | ||
| expect(screen.getByRole("img", { name: "로고 미리보기" }).getAttribute("src")).toBe( | ||
| "https://cdn.upload.solid-connection.com/admin/logo/test.webp", | ||
| ); | ||
| }); | ||
|
|
||
| it("does not upload when formatName is blank", async () => { | ||
| const upload = vi.spyOn(adminApi, "uploadAdminUniversityLogo"); | ||
| await openCreateModal(); | ||
| const file = new File(["logo"], "logo.png", { type: "image/png" }); | ||
| fireEvent.change(screen.getByLabelText("로고 이미지 파일"), { target: { files: [file] } }); | ||
|
|
||
| expect(upload).not.toHaveBeenCalled(); | ||
| expect(toastError).toHaveBeenCalledWith("표시명을 먼저 입력해 주세요."); | ||
| }); | ||
|
|
||
| it("preserves the current background URL when upload fails", async () => { | ||
| vi.spyOn(adminApi, "uploadAdminUniversityBackground").mockRejectedValue(new Error("업로드 실패")); | ||
| await openCreateModal(); | ||
| fireEvent.change(screen.getByLabelText("표시명 *"), { target: { value: "university_of_test" } }); | ||
| const urlInput = screen.getByLabelText("배경 이미지 URL *") as HTMLInputElement; | ||
| fireEvent.change(urlInput, { target: { value: "existing/background.webp" } }); | ||
| const file = new File(["background"], "background.png", { type: "image/png" }); | ||
| fireEvent.change(screen.getByLabelText("배경 이미지 파일"), { target: { files: [file] } }); | ||
|
|
||
| await waitFor(() => expect(toastError).toHaveBeenCalledWith("업로드 실패")); | ||
| expect(urlInput.value).toBe("existing/background.webp"); | ||
| }); | ||
| }); | ||
This file contains hidden or 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 hidden or 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,42 @@ | ||
| import { beforeEach, describe, expect, it, vi } from "vitest"; | ||
|
|
||
| const { post } = vi.hoisted(() => ({ post: vi.fn() })); | ||
|
|
||
| vi.mock("@/lib/api/client", () => ({ | ||
| axiosInstance: { | ||
| get: vi.fn(), | ||
| post, | ||
| put: vi.fn(), | ||
| patch: vi.fn(), | ||
| delete: vi.fn(), | ||
| }, | ||
| })); | ||
|
|
||
| import { adminApi } from "./admin"; | ||
|
|
||
| describe("admin university image uploads", () => { | ||
| beforeEach(() => { | ||
| post.mockReset(); | ||
| }); | ||
|
|
||
| it.each([ | ||
| ["logo", "/file/admin/university/logo"], | ||
| ["background", "/file/admin/university/background"], | ||
| ] as const)("uploads the %s with formatName under the existing englishName wire key", async (kind, endpoint) => { | ||
| post.mockResolvedValue({ data: { fileUrl: `admin/${kind}/image.webp` } }); | ||
| const file = new File(["image"], `${kind}.png`, { type: "image/png" }); | ||
|
|
||
| const result = | ||
| kind === "logo" | ||
| ? await adminApi.uploadAdminUniversityLogo(file, "university_of_test") | ||
| : await adminApi.uploadAdminUniversityBackground(file, "university_of_test"); | ||
|
|
||
| expect(post).toHaveBeenCalledWith(endpoint, expect.any(FormData), { | ||
| headers: { "Content-Type": "multipart/form-data" }, | ||
| }); | ||
| const formData = post.mock.calls[0]?.[1] as FormData; | ||
| expect(formData.get("file")).toBe(file); | ||
| expect(formData.get("englishName")).toBe("university_of_test"); | ||
| expect(result).toEqual({ fileUrl: `admin/${kind}/image.webp` }); | ||
| }); | ||
| }); |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.