Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(code_block): remove all snapshot tests and redundant describe blocks #8185

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Large diffs are not rendered by default.

71 changes: 67 additions & 4 deletions packages/eui/src/components/code/code_block.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
* Side Public License, v 1.
*/

import type { Meta, StoryObj } from '@storybook/react';
import type { Meta, StoryObj, ReactRenderer } from '@storybook/react';
import type { PlayFunctionContext } from '@storybook/csf';

import { within } from '../../../.storybook/test';
import { LOKI_SELECTORS } from '../../../.storybook/loki';

import { EuiCodeBlock, EuiCodeBlockProps } from './code_block';
import { expect, userEvent } from '@storybook/test';

const meta: Meta<EuiCodeBlockProps> = {
title: 'Editors & Syntax/EuiCodeBlock',
Expand All @@ -32,10 +37,68 @@ const meta: Meta<EuiCodeBlockProps> = {
export default meta;
type Story = StoryObj<EuiCodeBlockProps>;

const htmlCode = `<p>
<!-- Hello world -->
</p>`;

export const Playground: Story = {
args: {
children: `<p>
<!-- Hello world -->
</p>`,
children: htmlCode,
},
};

export const StartValue: Story = {
args: {
children: htmlCode,
language: 'html',
lineNumbers: {
start: 10,
},
},
argTypes: {
lineNumbers: { table: { disable: true } },
},
};

export const HighlightedLines: Story = {
args: {
children: htmlCode,
language: 'html',
lineNumbers: {
highlight: '1,3',
},
},
argTypes: {
lineNumbers: { table: { disable: true } },
},
};

export const Annotations: Story = {
args: {
children: htmlCode,
language: 'html',
lineNumbers: {
annotations: {
2: 'Hello world',
},
},
},
argTypes: {
lineNumbers: { table: { disable: true } },
},
parameters: {
loki: { chromeSelector: LOKI_SELECTORS.portal },
},
play: async ({ canvasElement }: PlayFunctionContext<ReactRenderer>) => {
const canvas = within(canvasElement);
const annotationButton = await canvas.findByRole('button', {
name: 'Click to view a code annotation for line 2',
});

userEvent.click(annotationButton);

const dialog = await canvas.findByRole('dialog');

expect(dialog).toHaveTextContent('Hello world');
},
};
7 changes: 0 additions & 7 deletions packages/eui/src/components/code/code_block.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦 Thank you so much for catching this!


import { css } from '@emotion/react';
import {
Expand Down
Loading