Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/src/app/features/user/apis/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const makeRequest = (overrides: Partial<CreateUserRequest> = {}): CreateUserRequ
last_name: "Yamada",
email: "taro@example.com",
password: "password123",
age_range: "teens",
...overrides,
});

Expand Down
1 change: 1 addition & 0 deletions client/src/app/features/user/apis/user-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type CreateUserRequest = {
last_name: string;
email: string;
password: string;
age_range: AgeRange;
};

export type UpdateUserRequest = {
Expand Down
17 changes: 17 additions & 0 deletions client/src/app/features/user/components/UserCreateForm.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import type { FormEvent } from "react";
import MenuItem from "@mui/material/MenuItem";
import TextField from "@shared/uis/TextField.tsx";
import { Button } from "@shared/uis/Button.tsx";
import { ErrorPanel } from "@shared/uis/ErrorPanel.tsx";
import { useText } from "@shared/locale/ui-text.ts";
import { AGE_RANGES } from "../types";
import type { CreateUserFormValues } from "../types";
import type { ApiUserDto } from "../apis/user-api";

Expand Down Expand Up @@ -75,6 +77,21 @@ export function UserCreateForm({
onChange={(e) => handleField("password", e.target.value)}
required
/>
<TextField
select
label={text.userAgeRange}
value={value.ageRange}
onChange={(e) =>
handleField("ageRange", e.target.value as CreateUserFormValues["ageRange"])
}
required
>
{AGE_RANGES.map((ageRange) => (
<MenuItem key={ageRange} value={ageRange}>
{ageRange}
</MenuItem>
))}
</TextField>

<Button type="submit" variant="primary" isLoading={isLoading}>
{text.userCreateSubmit}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const renderForm = (props: Partial<React.ComponentProps<typeof UserCreateForm>>
lastName: "",
email: "",
password: "",
ageRange: "teens",
};

const defaultProps: React.ComponentProps<typeof UserCreateForm> = {
Expand All @@ -35,15 +36,15 @@ const renderForm = (props: Partial<React.ComponentProps<typeof UserCreateForm>>
};

describe("UserCreateForm", () => {
it("renders only first name, last name, email, and password fields", () => {
it("renders first name, last name, email, password, and age range fields, but not subscription", () => {
renderForm();

expect(screen.getByLabelText(/^First Name/)).toBeInTheDocument();
expect(screen.getByLabelText(/^Last Name/)).toBeInTheDocument();
expect(screen.getByLabelText(/^Email/)).toBeInTheDocument();
expect(screen.getByLabelText(/^Password/)).toBeInTheDocument();
expect(screen.getByLabelText(/age range/i)).toBeInTheDocument();

expect(screen.queryByLabelText(/age range/i)).not.toBeInTheDocument();
expect(screen.queryByLabelText(/subscription/i)).not.toBeInTheDocument();
});

Expand All @@ -54,7 +55,13 @@ describe("UserCreateForm", () => {
fireEvent.change(screen.getByLabelText(/^First Name/), { target: { value: "Taro" } });

expect(onChange).toHaveBeenCalledWith(
expect.objectContaining({ firstName: "Taro", lastName: "", email: "", password: "" }),
expect.objectContaining({
firstName: "Taro",
lastName: "",
email: "",
password: "",
ageRange: "teens",
}),
);
});

Expand All @@ -65,6 +72,7 @@ describe("UserCreateForm", () => {
lastName: "Yamada",
email: "taro@example.com",
password: "password123",
ageRange: "20s",
};
renderForm({ onSubmit, value });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ const formValues: CreateUserFormValues = {
lastName: "Yamada",
email: "taro@example.com",
password: "password123",
ageRange: "teens",
};

const request: CreateUserRequest = {
first_name: "Taro",
last_name: "Yamada",
email: "taro@example.com",
password: "password123",
age_range: "teens",
};

const user: ApiUserDto = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const makeFormValues = (overrides: Partial<CreateUserFormValues> = {}): CreateUs
lastName: "Yamada",
email: "taro@example.com",
password: "password123",
ageRange: "20s",
...overrides,
});

Expand All @@ -19,6 +20,7 @@ describe("toCreateUserRequest", () => {
last_name: "Yamada",
email: "taro@example.com",
password: "password123",
age_range: "20s",
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export const toCreateUserRequest = (values: CreateUserFormValues): CreateUserReq
last_name: values.lastName.trim(),
email: values.email.trim(),
password: values.password,
age_range: values.ageRange,
});
1 change: 1 addition & 0 deletions client/src/app/features/user/mapper/user.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export const DEFAULT_CREATE_USER_FORM_VALUES: CreateUserFormValues = {
lastName: "",
email: "",
password: "",
ageRange: "teens",
};
1 change: 1 addition & 0 deletions client/src/app/features/user/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type CreateUserFormValues = {
lastName: string;
email: string;
password: string;
ageRange: AgeRange;
};

export type UserProfile = {
Expand Down
Loading