2023-04-20 02:52:49 +02:00
|
|
|
import React from "react";
|
2024-06-03 00:11:19 +02:00
|
|
|
import type { Meta, StoryObj } from "@storybook/react";
|
2024-06-09 11:53:25 +02:00
|
|
|
import { createKcPageStory } from "../KcPageStory";
|
2023-04-20 02:52:49 +02:00
|
|
|
|
2024-06-09 11:53:25 +02:00
|
|
|
const { KcPageStory } = createKcPageStory({ pageId: "account.ftl" });
|
2023-04-20 02:52:49 +02:00
|
|
|
|
2024-05-17 12:17:17 +03:00
|
|
|
const meta = {
|
2024-06-06 07:28:34 +02:00
|
|
|
title: "account/account.ftl",
|
2024-06-09 11:53:25 +02:00
|
|
|
component: KcPageStory
|
|
|
|
} satisfies Meta<typeof KcPageStory>;
|
2024-06-03 00:11:19 +02:00
|
|
|
|
2023-04-20 02:52:49 +02:00
|
|
|
export default meta;
|
|
|
|
|
2024-05-17 12:17:17 +03:00
|
|
|
type Story = StoryObj<typeof meta>;
|
|
|
|
|
|
|
|
export const Default: Story = {
|
2024-06-09 11:53:25 +02:00
|
|
|
render: () => <KcPageStory />
|
2024-05-17 12:17:17 +03:00
|
|
|
};
|
2024-10-19 19:10:32 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* UsernameNotEditable:
|
|
|
|
* - Purpose: Test the scenario where the username field is not editable.
|
|
|
|
* - Scenario: The component renders, but the username field is disabled.
|
|
|
|
* - Key Aspect: Ensures that the `editUsernameAllowed` condition is respected and the username field is read-only.
|
|
|
|
*/
|
|
|
|
export const UsernameNotEditable: Story = {
|
|
|
|
render: () => (
|
|
|
|
<KcPageStory
|
|
|
|
kcContext={{
|
|
|
|
account: {
|
|
|
|
username: "john_doe",
|
|
|
|
email: "john.doe@gmail.com",
|
|
|
|
firstName: "John",
|
|
|
|
lastName: "Doe"
|
|
|
|
},
|
|
|
|
realm: {
|
|
|
|
registrationEmailAsUsername: false,
|
|
|
|
editUsernameAllowed: false
|
|
|
|
},
|
|
|
|
referrer: {
|
|
|
|
url: "/home"
|
|
|
|
},
|
|
|
|
url: {
|
|
|
|
accountUrl: "/account"
|
|
|
|
},
|
|
|
|
messagesPerField: {
|
|
|
|
printIfExists: () => ""
|
|
|
|
},
|
|
|
|
stateChecker: "state-checker"
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WithValidationErrors:
|
|
|
|
* - Purpose: Test the form when there are validation errors.
|
|
|
|
* - Scenario: The component renders with error messages for invalid input in the fields.
|
|
|
|
* - Key Aspect: Ensures that error messages are properly displayed and the user can correct their inputs.
|
|
|
|
*/
|
|
|
|
export const WithValidationErrors: Story = {
|
|
|
|
render: () => (
|
|
|
|
<KcPageStory
|
|
|
|
kcContext={{
|
|
|
|
account: {
|
|
|
|
username: "john_doe",
|
|
|
|
email: "",
|
|
|
|
firstName: "",
|
|
|
|
lastName: "Doe"
|
|
|
|
},
|
|
|
|
realm: {
|
|
|
|
registrationEmailAsUsername: false,
|
|
|
|
editUsernameAllowed: true
|
|
|
|
},
|
|
|
|
referrer: {
|
|
|
|
url: "/home"
|
|
|
|
},
|
|
|
|
url: {
|
|
|
|
accountUrl: "/account"
|
|
|
|
},
|
|
|
|
messagesPerField: {
|
|
|
|
printIfExists: field => (field === "email" || field === "firstName" ? "has-error" : "")
|
|
|
|
},
|
|
|
|
stateChecker: "state-checker"
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* EmailAsUsername:
|
|
|
|
* - Purpose: Test the form where email is used as the username.
|
|
|
|
* - Scenario: The component renders without a separate username field, and the email field is treated as the username.
|
|
|
|
* - Key Aspect: Ensures the form functions correctly when `registrationEmailAsUsername` is enabled.
|
|
|
|
*/
|
|
|
|
export const EmailAsUsername: Story = {
|
|
|
|
render: () => (
|
|
|
|
<KcPageStory
|
|
|
|
kcContext={{
|
|
|
|
account: {
|
|
|
|
email: "john.doe@gmail.com",
|
|
|
|
firstName: "John",
|
|
|
|
lastName: "Doe"
|
|
|
|
},
|
|
|
|
realm: {
|
|
|
|
registrationEmailAsUsername: true
|
|
|
|
},
|
|
|
|
referrer: {
|
|
|
|
url: "/home"
|
|
|
|
},
|
|
|
|
url: {
|
|
|
|
accountUrl: "/account"
|
|
|
|
},
|
|
|
|
messagesPerField: {
|
|
|
|
printIfExists: () => ""
|
|
|
|
},
|
|
|
|
stateChecker: "state-checker"
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
};
|