Skip to content

Commit

Permalink
TEST: Fix screenshot fuzz params
Browse files Browse the repository at this point in the history
  • Loading branch information
thoughtspile committed Dec 10, 2020
1 parent e165330 commit 50c3f5c
Show file tree
Hide file tree
Showing 18 changed files with 39 additions and 45 deletions.
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.

This file was deleted.

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.

This file was deleted.

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.

This file was deleted.

19 changes: 11 additions & 8 deletions src/testing/e2e/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Platform } from '../../lib/platform';
import { Scheme } from '../../components/ConfigProvider/ConfigProviderContext';
import AdaptivityProvider, { AdaptivityProviderProps } from '../../components/AdaptivityProvider/AdaptivityProvider';
import { SizeType } from '../../components/AdaptivityProvider/AdaptivityContext';
import { AdaptivityProps } from 'index';

type AdaptivityFlag = boolean | 'x' | 'y';
type PropDesc<Props> = { [K in keyof Props]?: Array<Props[K]> } & { $adaptivity?: AdaptivityFlag };
Expand Down Expand Up @@ -64,10 +65,9 @@ type ScreenshotOptions = {
matchScreenshot?: MatchImageSnapshotOptions;
platforms?: Platform[];
schemes?: Scheme[];
adaptivity?: AdaptivityProps;
};
const CompactProvider: React.ComponentType = ({ children }) => (
<AdaptivityProvider sizeX={SizeType.COMPACT} sizeY={SizeType.COMPACT}>{children}</AdaptivityProvider>
);

export function describeScreenshotFuzz<Props>(
Component: ComponentType<Props>,
propSets: Array<PropDesc<Props>> = [],
Expand All @@ -77,18 +77,21 @@ export function describeScreenshotFuzz<Props>(
matchScreenshot,
platforms = Object.values(Platform),
schemes = [Scheme.BRIGHT_LIGHT, Scheme.SPACE_GRAY],
adaptivity = {},
} = options;
platforms.forEach((platform) => {
describe(platform, () => {
const isVkCom = platform === 'vkcom';
const width = isVkCom ? 'auto' : 320;
const ForceAdaptivity = isVkCom ? CompactProvider : Fragment;
schemes.forEach((scheme) => {
const width = adaptivity.viewWidth || (isVkCom ? 'auto' : 320);
const adaptivityProps = Object.assign(
isVkCom ? { sizeX: SizeType.COMPACT, sizeY: SizeType.COMPACT } : {},
adaptivity);
(isVkCom ? [Scheme.BRIGHT_LIGHT] : schemes).forEach((scheme) => {
it(scheme, async () => {
expect(await screenshot((
<ConfigProvider scheme={scheme} platform={platform}>
<div style={{ width, position: 'absolute' }}>
<ForceAdaptivity>
<AdaptivityProvider {...adaptivityProps}>
<Panel id="panel">
{multiCartesian(propSets, { adaptive: !isVkCom }).map((props, i) => (
<Fragment key={i}>
Expand All @@ -97,7 +100,7 @@ export function describeScreenshotFuzz<Props>(
</Fragment>
))}
</Panel>
</ForceAdaptivity>
</AdaptivityProvider>
</div>
</ConfigProvider>
))).toMatchImageSnapshot(matchScreenshot);
Expand Down

0 comments on commit 50c3f5c

Please sign in to comment.