mirror of
https://github.com/andwati/zitadel.git
synced 2026-10-30 11:02:16 +00:00
# Which Problems Are Solved This PR introduces a comprehensive theme customization system for the login application with responsive behavior and enhanced visual options. <img width="1122" height="578" alt="Screenshot 2025-08-19 at 09 55 24" src="https://github.com/user-attachments/assets/cdcc8948-533d-4e13-bf45-fdcc24acfb2b" /> # How the Problems Are Solved ## ✨ Features Added - **🔄 Responsive Layout System**: Automatic switching between side-by-side and top-to-bottom layouts based on screen size - **🖼️ Background Image Support**: Custom background images configurable via environment variables - **⚙️ Theme Configuration**: Complete theme system with roundness, spacing, appearance, and layout options - **📱 Mobile-First Design**: Intelligent layout adaptation for different screen sizes - **🎯 Enhanced Typography**: Improved visual hierarchy with larger titles in side-by-side mode ## 🏗️ Architecture - **Server-Safe Theme Functions**: Theme configuration accessible on both server and client - **SSR-Safe Hooks**: Proper hydration handling for responsive layouts - **Component Separation**: Clear boundaries between server and client components - **Two-Section Layout**: Consistent content structure across all login pages ## 🔧 Configuration Options All theme options are configurable via environment variables: - `NEXT_PUBLIC_THEME_ROUNDNESS`: `edgy` | `mid` | `full` - `NEXT_PUBLIC_THEME_LAYOUT`: `side-by-side` | `top-to-bottom` - `NEXT_PUBLIC_THEME_APPEARANCE`: `flat` | `material` - `NEXT_PUBLIC_THEME_SPACING`: `regular` | `compact` - `NEXT_PUBLIC_THEME_BACKGROUND_IMAGE`: Custom background image URL ## 📄 Pages Updated Updated all major login pages to use the new two-section responsive layout: - Login name entry - Password verification - MFA verification - User registration - Account selection - Device authorization - Logout confirmation ## 📚 Documentation - **THEME_ARCHITECTURE.md**: Complete technical documentation of the theme system - **THEME_CUSTOMIZATION.md**: User-friendly guide with examples and troubleshooting ## 🚀 Benefits - **Better UX**: Responsive design that works seamlessly across all devices - **Brand Flexibility**: Easy customization to match any brand identity - **Maintainable Code**: Clean separation of concerns and well-documented architecture - **Future-Proof**: Extensible system for additional theme options <img width="580" height="680" alt="Screenshot 2025-08-19 at 09 22 23" src="https://github.com/user-attachments/assets/9de8da37-6d56-4fe9-b337-5d8ad2a3ba59" /> <img width="599" height="689" alt="Screenshot 2025-08-19 at 09 23 45" src="https://github.com/user-attachments/assets/26a30cc7-4017-4f4b-8b87-a49466c42b94" /> <img width="595" height="681" alt="Screenshot 2025-08-19 at 09 23 17" src="https://github.com/user-attachments/assets/a3d31088-4545-4f36-aafe-1aae1253d677" />
189 lines
6.9 KiB
TypeScript
189 lines
6.9 KiB
TypeScript
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
import { render, screen } from "@testing-library/react";
|
|
import { TextInput } from "./input";
|
|
|
|
describe("TextInput Component", () => {
|
|
const originalEnv = process.env;
|
|
|
|
beforeEach(() => {
|
|
process.env = { ...originalEnv };
|
|
});
|
|
|
|
afterEach(() => {
|
|
process.env = originalEnv;
|
|
});
|
|
|
|
describe("Component Rendering", () => {
|
|
it("should render input with label", () => {
|
|
render(<TextInput label="Email" />);
|
|
expect(screen.getByText("Email")).toBeTruthy();
|
|
});
|
|
|
|
it("should render input with placeholder", () => {
|
|
const { container } = render(<TextInput label="Username" placeholder="Enter username" />);
|
|
const input = container.querySelector("input");
|
|
expect(input?.placeholder).toBe("Enter username");
|
|
});
|
|
|
|
it("should render input with default value", () => {
|
|
const { container } = render(<TextInput label="Name" defaultValue="John Doe" />);
|
|
const input = container.querySelector("input");
|
|
expect(input?.defaultValue).toBe("John Doe");
|
|
});
|
|
|
|
it("should show required indicator when required", () => {
|
|
render(<TextInput label="Required Field" required />);
|
|
expect(screen.getByText(/\*/)).toBeTruthy();
|
|
});
|
|
});
|
|
|
|
describe("Input States", () => {
|
|
it("should render disabled state", () => {
|
|
const { container } = render(<TextInput label="Disabled" disabled />);
|
|
const input = container.querySelector("input");
|
|
expect(input?.disabled).toBe(true);
|
|
// Should have disabled/pointer-events styles
|
|
expect(input?.className).toMatch(/pointer-events/);
|
|
});
|
|
|
|
it("should render error state with message", () => {
|
|
render(<TextInput label="Email" error="Invalid email" />);
|
|
expect(screen.getByText("Invalid email")).toBeTruthy();
|
|
});
|
|
|
|
it("should apply error styling when error is present", () => {
|
|
const { container } = render(<TextInput label="Email" error="Invalid" />);
|
|
const input = container.querySelector("input");
|
|
expect(input).toBeTruthy();
|
|
// Should have border-warn or warn-related styles
|
|
expect(input?.className).toMatch(/border-warn/);
|
|
});
|
|
|
|
it("should render success state with message", () => {
|
|
render(<TextInput label="Email" success="Valid email" />);
|
|
expect(screen.getByText("Valid email")).toBeTruthy();
|
|
});
|
|
});
|
|
|
|
describe("Theme Integration", () => {
|
|
it("should apply theme-based roundness", () => {
|
|
const { container } = render(<TextInput label="Themed" />);
|
|
const input = container.querySelector("input");
|
|
// Should have some roundness class applied
|
|
expect(input?.className).toBeTruthy();
|
|
expect(input?.className).toMatch(/rounded/);
|
|
});
|
|
|
|
it("should completely override theme roundness with custom roundness prop", () => {
|
|
// Set theme to have full roundness
|
|
process.env.NEXT_PUBLIC_THEME_ROUNDNESS = "full";
|
|
const customRoundness = "custom-input-round";
|
|
|
|
const { container } = render(<TextInput label="Custom" roundness={customRoundness} />);
|
|
const input = container.querySelector("input");
|
|
|
|
// Should contain the custom roundness
|
|
expect(input?.className).toContain(customRoundness);
|
|
|
|
// The custom prop completely replaces theme roundness
|
|
expect(input).toBeTruthy();
|
|
});
|
|
|
|
it("should respect theme roundness changes", () => {
|
|
// Default theme
|
|
const { container: container1 } = render(<TextInput label="Default" />);
|
|
const input1 = container1.querySelector("input");
|
|
const defaultClasses = input1?.className;
|
|
|
|
// Change theme
|
|
process.env.NEXT_PUBLIC_THEME_ROUNDNESS = "full";
|
|
const { container: container2 } = render(<TextInput label="Full" />);
|
|
const input2 = container2.querySelector("input");
|
|
|
|
// Classes should be present
|
|
expect(defaultClasses).toBeTruthy();
|
|
expect(input2?.className).toBeTruthy();
|
|
});
|
|
});
|
|
|
|
describe("Input Behavior", () => {
|
|
it("should have autocomplete off by default", () => {
|
|
const { container } = render(<TextInput label="Test" />);
|
|
const input = container.querySelector("input");
|
|
expect(input?.autocomplete).toBe("off");
|
|
});
|
|
|
|
it("should allow custom autocomplete", () => {
|
|
const { container } = render(<TextInput label="Email" autoComplete="email" />);
|
|
const input = container.querySelector("input");
|
|
expect(input?.autocomplete).toBe("email");
|
|
});
|
|
|
|
it("should pass through native input props", () => {
|
|
const { container } = render(<TextInput label="Test" maxLength={10} type="email" />);
|
|
const input = container.querySelector("input");
|
|
expect(input?.maxLength).toBe(10);
|
|
expect(input?.type).toBe("email");
|
|
});
|
|
});
|
|
|
|
describe("Styling", () => {
|
|
it("should have consistent base styling", () => {
|
|
const { container } = render(<TextInput label="Test" />);
|
|
const input = container.querySelector("input");
|
|
expect(input).toBeTruthy();
|
|
expect(input?.className).toBeTruthy();
|
|
expect(input?.className.length).toBeGreaterThan(0);
|
|
// Should have transition styles
|
|
expect(input?.className).toMatch(/transition/);
|
|
});
|
|
|
|
it("should apply border styles", () => {
|
|
const { container } = render(<TextInput label="Test" />);
|
|
const input = container.querySelector("input");
|
|
expect(input).toBeTruthy();
|
|
// Should have border-related classes
|
|
expect(input?.className).toMatch(/border/);
|
|
});
|
|
|
|
it("should have focus styles", () => {
|
|
const { container } = render(<TextInput label="Test" />);
|
|
const input = container.querySelector("input");
|
|
expect(input).toBeTruthy();
|
|
// Should have focus-related classes
|
|
expect(input?.className).toMatch(/focus:/);
|
|
});
|
|
});
|
|
|
|
describe("Label Styling", () => {
|
|
it("should apply error color to label when error exists", () => {
|
|
const { container } = render(<TextInput label="Error Field" error="Error message" />);
|
|
const label = container.querySelector("label");
|
|
expect(label).toBeTruthy();
|
|
});
|
|
|
|
it("should have default label styling", () => {
|
|
const { container } = render(<TextInput label="Normal Field" />);
|
|
const label = container.querySelector("label");
|
|
expect(label).toBeTruthy();
|
|
expect(label?.className).toBeTruthy();
|
|
});
|
|
});
|
|
|
|
describe("Accessibility", () => {
|
|
it("should connect label to input", () => {
|
|
const { container } = render(<TextInput label="Accessible Input" />);
|
|
const label = container.querySelector("label");
|
|
const input = container.querySelector("input");
|
|
expect(label).toBeTruthy();
|
|
expect(input).toBeTruthy();
|
|
});
|
|
|
|
it("should show required indicator", () => {
|
|
const { container } = render(<TextInput label="UniqueRequiredField" required />);
|
|
const label = container.querySelector("label");
|
|
expect(label?.textContent).toContain("*");
|
|
});
|
|
});
|
|
});
|