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

Don't show the SnapshotComparison for skipped stories #33

Merged
merged 7 commits into from
Aug 22, 2023
Merged
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
12 changes: 10 additions & 2 deletions src/components/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { Button as BaseButton } from "@storybook/components";
import { css, styled } from "@storybook/theming";

export const Button = styled(BaseButton)<{ link?: boolean; tertiary?: boolean }>(
export const Button = styled(BaseButton)<{
link?: boolean;
tertiary?: boolean;
belowText?: boolean;
}>(
{
"&&": {
display: "inline-flex",
Expand Down Expand Up @@ -35,5 +39,9 @@ export const Button = styled(BaseButton)<{ link?: boolean; tertiary?: boolean }>
tertiary &&
css({
"&&:hover": { boxShadow: "none" },
})
}),
({ belowText }) =>
belowText && {
"margin-top": "7px",
}
);
20 changes: 20 additions & 0 deletions src/screens/VisualTests/VisualTests.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ const tests = [
viewport: 1200,
storyId: "button--secondary",
}),
makeTest({
id: "31",
status: TestStatus.Passed,
result: TestResult.Skipped,
browsers,
viewport: 1200,
storyId: "button--tertiary",
}),
];

const paginated = (nodes: TestFieldsFragment[]) => ({
Expand Down Expand Up @@ -290,6 +298,18 @@ export const Accepted: Story = {
},
};

export const Skipped: Story = {
args: {
storyId: "button--tertiary",
},
parameters: {
...withBuild(pendingBuild),
...withFigmaDesign(
"https://www.figma.com/file/GFEbCgCVDtbZhngULbw2gP/Visual-testing-in-Storybook?type=design&node-id=2255-42087&t=a8NRPgQk3kXMyxqZ-0"
),
},
};

export const CaptureError: Story = {
parameters: {
...withBuild(brokenBuild),
Expand Down
32 changes: 32 additions & 0 deletions src/screens/VisualTests/VisualTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
ReviewTestBatch,
ReviewTestInputStatus,
TestFieldsFragment,
TestResult,
} from "../../gql/graphql";
import { StatusUpdate, testsToStatusUpdate } from "../../utils/testsToStatusUpdate";
import { RenderSettings } from "./RenderSettings";
Expand Down Expand Up @@ -303,6 +304,37 @@ export const VisualTests = ({
const startedAt = "startedAt" in build && build.startedAt;
const isBuildFailed = build.status === BuildStatus.Failed;

// It shouldn't be possible for one test to be skipped but not all of them
const isSkipped = !!tests?.find((t) => t.result === TestResult.Skipped);
if (isSkipped) {
return (
<Sections>
<Section grow>
<Container>
<Heading>This story was skipped</Heading>
<CenterText>
If you would like to resume testing it, comment out or remove
`parameters.chromatic.disableSnapshot = true` from the CSF file.
</CenterText>
<Button
belowText
small
tertiary
containsIcon
// @ts-expect-error Button component is not quite typed properly
target="_new"
isLink
href="https://www.chromatic.com/docs/ignoring-elements#ignore-stories"
>
<Icons icon="document" />
View Docs
</Button>
</Container>
</Section>
</Sections>
);
}

return (
<Sections>
<Section grow hidden={settingsVisible || warningsVisible}>
Expand Down
4 changes: 4 additions & 0 deletions src/utils/storyData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ export function makeTest(options: {
const viewportWidth = options.viewport || 1200;

function generateComparisons() {
if (result === TestResult.Skipped) {
return [];
}

const browsers = options.browsers || [Browser.Chrome];

if (options.comparisonResults && options.comparisonResults.length !== browsers.length) {
Expand Down
Loading