keycloak_theme/stories/login/pages/LoginIdpLinkEmail.stories.tsx

108 lines
3.4 KiB
TypeScript
Raw Normal View History

2023-04-20 05:41:34 +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 05:41:34 +02:00
2024-10-19 17:24:29 -04:00
// Mock kcContext to avoid TS2304 error and to simulate the real environment
const mockKcContext = {
url: {
loginAction: "/login-action"
},
idpAlias: "mockIdpAlias",
brokerContext: {
username: "mockUser"
},
realm: {
displayName: "MockRealm"
}
};
2024-06-09 11:53:25 +02:00
const { KcPageStory } = createKcPageStory({ pageId: "login-idp-link-email.ftl" });
2023-04-20 05:41:34 +02:00
2024-06-03 00:11:19 +02:00
const meta = {
2024-06-06 07:28:34 +02:00
title: "login/login-idp-link-email.ftl",
2024-06-09 11:53:25 +02:00
component: KcPageStory
} satisfies Meta<typeof KcPageStory>;
2023-04-20 05:41:34 +02:00
export default meta;
2024-06-03 00:11:19 +02:00
type Story = StoryObj<typeof meta>;
2024-10-19 17:24:29 -04:00
/**
* Default:
* - Purpose: Tests the default behavior with mock data.
* - Scenario: The component renders with a mocked identity provider alias (`mockIdpAlias`), a default broker username (`mockUser`), and a default realm name (`MockRealm`).
* - Key Aspect: Ensures the default behavior of the component with typical kcContext values.
*/
2024-06-03 00:11:19 +02:00
export const Default: Story = {
2024-10-19 17:24:29 -04:00
render: () => <KcPageStory kcContext={mockKcContext} />
2024-06-03 00:11:19 +02:00
};
2024-10-19 17:24:29 -04:00
/**
* WithIdpAlias:
* - Purpose: Tests behavior when the idpAlias is set to "Google".
* - Scenario: Simulates the component being used with a Google identity provider, showing the username "john.doe" and realm "MyRealm".
* - Key Aspect: Ensures the correct identity provider alias ("Google") and broker context (user info) are displayed in the email linking instructions.
*/
export const WithIdpAlias: Story = {
render: () => (
<KcPageStory
kcContext={{
2024-10-19 17:24:29 -04:00
...mockKcContext,
idpAlias: "Google",
brokerContext: {
username: "john.doe"
},
realm: {
displayName: "MyRealm"
}
}}
/>
)
};
2024-10-19 17:24:29 -04:00
/**
* WithCustomRealmDisplayName:
* - Purpose: Tests behavior when the realm display name is customized.
* - Scenario: Simulates the component with a Facebook identity provider, a broker username "jane.doe", and a custom realm name "CustomRealm".
* - Key Aspect: Ensures that custom realm display names are rendered correctly alongside the idpAlias and broker context.
*/
export const WithCustomRealmDisplayName: Story = {
render: () => (
<KcPageStory
kcContext={{
2024-10-19 17:24:29 -04:00
...mockKcContext,
idpAlias: "Facebook",
brokerContext: {
2024-10-19 17:24:29 -04:00
username: "jane.doe"
},
realm: {
2024-10-19 17:24:29 -04:00
displayName: "CUSTOM REALM DISPLAY NAME"
}
}}
/>
)
};
2024-10-19 17:24:29 -04:00
/**
* WithFormSubmissionError:
* - Purpose: Tests how the component handles form submission errors.
* - Scenario: Simulates a form submission error by setting the login action URL to `/error` and displays an error message.
* - Key Aspect: Verifies that the component can display error messages during form submission failure, ensuring proper error handling.
*/
export const WithFormSubmissionError: Story = {
render: () => (
<KcPageStory
kcContext={{
2024-10-19 17:24:29 -04:00
...mockKcContext,
url: {
loginAction: "/error"
},
2024-10-19 17:24:29 -04:00
message: {
type: "error",
summary: "An error occurred during form submission."
}
}}
/>
)
};