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

test(FilePreview): Add smoke tests/file preview #2026

Open
wants to merge 6 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.
Copy link
Contributor

Choose a reason for hiding this comment

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

It's worth waiting for me to fix the icons(

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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import {expect} from '@playwright/experimental-ct-react';

import {smokeTest, test} from '~playwright/core';

import {FilePreviewWithAllActions} from './helpers';
import {FilePreviewStories} from './helpersPlaywright';

test.describe('FilePreview', {tag: '@FilePreview'}, () => {
test(`render story: <Default>`, async ({mount, expectScreenshot}) => {
await mount(<FilePreviewStories.Default />);

await expectScreenshot({});
});

test(`render story: <Collage>`, async ({mount, page, expectScreenshot}) => {
await mount(<FilePreviewStories.Collage />);

// wait download image
await page.waitForLoadState('networkidle');

await expectScreenshot({});
});

smokeTest('actions', async ({mount, page, expectScreenshot}) => {
await mount(
<div style={{padding: 50}}>
<FilePreviewWithAllActions />
</div>,
);

await page.getByTestId('file-preview').hover();

await expectScreenshot({
themes: ['light'],
nameSuffix: 'show actions',
});

await page.locator('button[aria-label="Close"]').hover();
await expect(page.getByTestId('action-1-tooltip')).toBeVisible({
timeout: 3000,
});

await expectScreenshot({
themes: ['light'],
nameSuffix: 'show action tooltip',
});
});
});
54 changes: 54 additions & 0 deletions src/components/FilePreview/__tests__/helpers.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import {Link, Xmark} from '@gravity-ui/icons';

import {FilePreview} from '../FilePreview';
import type {FilePreviewProps} from '../FilePreview';

export const FilePreviewWithAllActions = (
props: Partial<Omit<FilePreviewProps, 'actions' | 'onClose'>>,
) => {
return (
<FilePreview
qa="file-preview"
file={{name: 'File', type: 'text/docs'} as File}
onClick={() => {
// nothing
}}
actions={[
{
icon: null,
title: 'Without icon action',
onClick: () => {
// nothing
},
},
{
icon: <Link width={14} height={14} />,
disabled: true,
title: 'Disabled action',
onClick: () => {
// nothing
},
},
{
icon: <Link width={14} height={14} />,
href: '#',
title: 'Link action',
onClick: () => {
// nothing
},
},
{
icon: <Xmark width={14} height={14} />,
title: 'Close',
onClick: () => {
// nothing
},
tooltipExtraProps: {
qa: 'action-1-tooltip',
},
},
]}
{...props}
/>
);
};
5 changes: 5 additions & 0 deletions src/components/FilePreview/__tests__/helpersPlaywright.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {composeStories} from '@storybook/react';

import * as DefaultFilePreviewStories from '../__stories__/FilePreview.stories';

export const FilePreviewStories = composeStories(DefaultFilePreviewStories);
Loading