- add a RevealableCodeBlock ui component that renders its code only after the user clicks Reveal, with a storybook story - use it for the data section of the credential page - bump version to 1.21.1
34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
import { expect, userEvent, within } from 'storybook/test';
|
|
import { RevealableCodeBlock } from '../../src/ui/RevealableCodeBlock/RevealableCodeBlock';
|
|
|
|
const meta: Meta<typeof RevealableCodeBlock> = {
|
|
title: 'UI/RevealableCodeBlock',
|
|
component: RevealableCodeBlock,
|
|
parameters: { layout: 'padded' },
|
|
tags: ['autodocs'],
|
|
};
|
|
export default meta;
|
|
type Story = StoryObj<typeof RevealableCodeBlock>;
|
|
|
|
export const Default: Story = {
|
|
args: {
|
|
language: 'json',
|
|
code: JSON.stringify({ username: 'admin', password: 's3cr3t-p4ss' }, null, 2),
|
|
},
|
|
play: async ({ canvasElement }) => {
|
|
// The code is not rendered until revealed, and hidden again on the second click
|
|
const canvas = within(canvasElement);
|
|
const toggle = canvas.getByRole('button');
|
|
await expect(canvasElement).not.toHaveTextContent('s3cr3t-p4ss');
|
|
await expect(toggle).toHaveAttribute('aria-expanded', 'false');
|
|
|
|
await userEvent.click(toggle);
|
|
await expect(canvasElement.querySelector('code')).toHaveTextContent('s3cr3t-p4ss');
|
|
await expect(toggle).toHaveAttribute('aria-expanded', 'true');
|
|
|
|
await userEvent.click(toggle);
|
|
await expect(canvasElement).not.toHaveTextContent('s3cr3t-p4ss');
|
|
},
|
|
};
|