# In Storybook

{% hint style="info" %}
TLDR:

```bash
npx keycloakify add-story
npm run storybook
```

{% endhint %}

[Storybook](https://storybook.js.org/) is a tool that enables to test UI component in isolation. For reference, the component showcase Keycloakify website is a website generated with Storybook.

{% embed url="<https://storybook.keycloakify.dev/?path=/story/introduction--page>" %}

The starter template does not initially contain any story files, instead there's a keycloakify CLI command that let's you import specifically the stories for the pages you want to test into your project.

So, just run this command in the root of your Keycloakify project and select the pages you want.

```bash
npx keycloakify add-story
```

It will enables you to select the pages you want to add stories for.

<figure><img src="https://723341942-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1pGOu8uVH5l8KqPEPmKi%2Fuploads%2FLG7qd8iWnXmw9f2S2NOE%2Fimage.png?alt=media&#x26;token=bf9ab6b9-dcc9-40d9-a5a5-c55f84b60504" alt=""><figcaption></figcaption></figure>

Selecting login -> register.ftl will result in this file to be created in your project:

<figure><img src="https://723341942-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1pGOu8uVH5l8KqPEPmKi%2Fuploads%2FccpS33zE8fk2os7bPP79%2Fimage.png?alt=media&#x26;token=44bb9ea4-56e6-4e39-89d4-55e90479b2ec" alt=""><figcaption></figcaption></figure>

You can run the above command multiple times to add stories for the different pages you want to develop.

Once your added a few stories you can start Storybook locally with:

```bash
npm run storybook
```

<figure><img src="https://723341942-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1pGOu8uVH5l8KqPEPmKi%2Fuploads%2FPQBVQ9FLALl6DwtdDsA0%2Fimage.png?alt=media&#x26;token=00d3d0be-ba3b-4923-845c-f4ffcc9948f0" alt=""><figcaption></figcaption></figure>

You can see the changes you make in you code in realtime in your Storybook.

The idea of Storybook is to easily let you see the pages in different configuration without having to reproduce the full login/register process in a real Keycloak.\
Keycloakify provide a default mock context for every pages, the stories let you partially override some specific part of this default mock to reflect pages in different configurations.\
\
For example, if you want to create a story that show the register page in chinese you would add this:

<pre class="language-tsx" data-title="src/login/pages/Register.stories.tsx"><code class="lang-tsx">import type { Meta, StoryObj } from "@storybook/react";
import { createKcPageStory } from "../KcPageStory";

const { KcPageStory } = createKcPageStory({ pageId: "register.ftl" });

const meta = {
    title: "login/register.ftl",
    component: KcPageStory
} satisfies Meta&#x3C;typeof KcPageStory>;

export default meta;

type Story = StoryObj&#x3C;typeof meta>;

export const Default: Story = {
    render: () => &#x3C;KcPageStory />
};

<strong>export const InChinese: Story = {
</strong><strong>    render: ()=> (
</strong><strong>        &#x3C;KcPageStory
</strong><strong>            kcContext={{
</strong><strong>                locale: {
</strong><strong>                    currentLanguageTag: "zh-CN"
</strong><strong>                }
</strong><strong>            }}
</strong><strong>        />
</strong><strong>    )
</strong><strong>};
</strong></code></pre>

<figure><img src="https://723341942-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1pGOu8uVH5l8KqPEPmKi%2Fuploads%2FLlOgCh9juEBckJ0uV8hG%2Fimage.png?alt=media&#x26;token=123e27a0-172a-46ed-b44f-dd0acec2eded" alt=""><figcaption></figcaption></figure>

That's really nice, however this approach has it's limits. At some point you'll want to test in a real Keycloak to make sure everything works. Also you don't necessary know the kcContext values to provides in order to replicate a desired configuration.

Don't worry! Keycloakify got you covered by letting you test in a local Keycloak Docker container.

{% content-ref url="in-a-keycloak-docker-container" %}
[in-a-keycloak-docker-container](https://doc-old.keycloakify.dev/documentation/v10/testing-your-theme/in-a-keycloak-docker-container)
{% endcontent-ref %}
