Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into tom/ap-3633-show-snap…
Browse files Browse the repository at this point in the history
…shot-outdated-header-as-soon-as-we-have-a-new
  • Loading branch information
tmeasday committed Sep 12, 2023
2 parents 8eb9e69 + fe0146e commit ea70fc7
Show file tree
Hide file tree
Showing 18 changed files with 542 additions and 174 deletions.
50 changes: 50 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,53 @@
# v0.0.65 (Mon Sep 11 2023)

#### 🐛 Bug Fix

- Show a notification when there is trouble accepting [#84](https://github.com/chromaui/addon-visual-tests/pull/84) ([@tmeasday](https://github.com/tmeasday))

#### Authors: 1

- Tom Coleman ([@tmeasday](https://github.com/tmeasday))

---

# v0.0.64 (Fri Sep 08 2023)

#### 🐛 Bug Fix

- Notify users when a build is completed or when a build fails [#66](https://github.com/chromaui/addon-visual-tests/pull/66) ([@weeksling](https://github.com/weeksling) [@tmeasday](https://github.com/tmeasday) [@ghengeveld](https://github.com/ghengeveld))

#### Authors: 3

- Gert Hengeveld ([@ghengeveld](https://github.com/ghengeveld))
- Matthew Weeks ([@weeksling](https://github.com/weeksling))
- Tom Coleman ([@tmeasday](https://github.com/tmeasday))

---

# v0.0.63 (Thu Sep 07 2023)

#### 🐛 Bug Fix

- Reviewing: Rerun query when accepting & un-accepting changes [#86](https://github.com/chromaui/addon-visual-tests/pull/86) ([@ndelangen](https://github.com/ndelangen))

#### Authors: 1

- Norbert de Langen ([@ndelangen](https://github.com/ndelangen))

---

# v0.0.62 (Thu Sep 07 2023)

#### 🐛 Bug Fix

- Add a bunch of `VisualTests` stories [#85](https://github.com/chromaui/addon-visual-tests/pull/85) ([@tmeasday](https://github.com/tmeasday))

#### Authors: 1

- Tom Coleman ([@tmeasday](https://github.com/tmeasday))

---

# v0.0.61 (Thu Sep 07 2023)

#### 🐛 Bug Fix
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@chromaui/addon-visual-tests",
"version": "0.0.61",
"version": "0.0.65",
"description": "Visual Testing addon with Chromatic",
"engines": {
"node": ">=16.0.0",
Expand All @@ -18,7 +18,7 @@
"url": "https://github.com/chromaui/addon-visual-tests"
},
"license": "MIT",
"author": "Chromatic <tom@chromatic.com>",
"author": "Chromatic <support@chromatic.com>",
"exports": {
".": {
"require": "./dist/index.js",
Expand Down Expand Up @@ -72,6 +72,7 @@
"@graphql-codegen/client-preset": "^4.0.1",
"@graphql-typed-document-node/core": "^3.2.0",
"@storybook/addon-actions": "7.5.0-alpha.1",
"@storybook/addon-designs": "^7.0.5",
"@storybook/addon-essentials": "7.5.0-alpha.1",
"@storybook/addon-interactions": "7.5.0-alpha.1",
"@storybook/addon-mdx-gfm": "7.5.0-alpha.1",
Expand Down Expand Up @@ -110,7 +111,6 @@
"react-dom": "^16.14.0",
"rimraf": "^3.0.2",
"storybook": "7.5.0-alpha.1",
"@storybook/addon-designs": "^7.0.5",
"ts-jest": "^29.1.1",
"tsup": "^6.6.3",
"typescript": "^4.9.5",
Expand Down
6 changes: 3 additions & 3 deletions src/Panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import React, { useCallback } from "react";
import { Sections } from "./components/layout";
import {
ADDON_ID,
DEV_BUILD_ID_KEY,
GIT_INFO,
GitInfoPayload,
IS_OUTDATED,
PANEL_ID,
RUNNING_BUILD,
RunningBuildPayload,
Expand All @@ -29,14 +29,13 @@ interface PanelProps {
api: API;
}

const storedBuildId = localStorage.getItem(DEV_BUILD_ID_KEY);

export const Panel = ({ active, api }: PanelProps) => {
const [accessToken, setAccessToken] = useAccessToken();
const { storyId } = useStorybookState();

const [gitInfo] = useAddonState<GitInfoPayload>(GIT_INFO);
const [runningBuild] = useAddonState<RunningBuildPayload>(RUNNING_BUILD);
const [, setOutdated] = useAddonState<boolean>(IS_OUTDATED);
const emit = useChannel({});

const updateBuildStatus = useCallback<UpdateStatusFunction>(
Expand Down Expand Up @@ -109,6 +108,7 @@ export const Panel = ({ active, api }: PanelProps) => {
runningBuild={runningBuild}
startDevBuild={() => emit(START_BUILD)}
setAccessToken={setAccessToken}
setOutdated={setOutdated}
updateBuildStatus={updateBuildStatus}
storyId={storyId}
/>
Expand Down
112 changes: 112 additions & 0 deletions src/SidebarTop.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { type API, useChannel } from "@storybook/manager-api";
import { color } from "@storybook/theming";
import pluralize from "pluralize";
import React, { useEffect, useRef } from "react";

import { SidebarTopButton } from "./components/SidebarTopButton";
import {
ADDON_ID,
IS_OUTDATED,
RUNNING_BUILD,
RunningBuildPayload,
START_BUILD,
} from "./constants";
import { useAddonState } from "./useAddonState/manager";
import { useAccessToken } from "./utils/graphQLClient";
import { useProjectId } from "./utils/useProjectId";

interface SidebarTopProps {
api: API;
}

export const SidebarTop = ({ api }: SidebarTopProps) => {
const { addNotification, clearNotification } = api;

const { projectId } = useProjectId();
const [accessToken] = useAccessToken();
const isLoggedIn = !!accessToken;

const [isOutdated] = useAddonState<boolean>(IS_OUTDATED);
const [runningBuild] = useAddonState<RunningBuildPayload>(RUNNING_BUILD);
const isRunning = !!runningBuild && runningBuild.step !== "complete";

const lastStep = useRef(runningBuild?.step);
useEffect(() => {
if (runningBuild?.step === lastStep.current) return;
lastStep.current = runningBuild?.step;

if (runningBuild?.step === "initialize") {
addNotification({
id: `${ADDON_ID}/build-initialize`,
content: {
headline: "Build started",
subHeadline: "Check the Storybook process on the command line for more details.",
},
icon: {
name: "passed",
color: color.positive,
},
link: undefined,
});
setTimeout(() => clearNotification(`${ADDON_ID}/build-initialize`), 10_000);
}

if (runningBuild?.step === "complete") {
addNotification({
id: `${ADDON_ID}/build-complete`,
content: {
headline: "Build complete",
// eslint-disable-next-line no-nested-ternary
subHeadline: runningBuild.errorCount
? `Encountered ${pluralize("component error", runningBuild.errorCount, true)}`
: runningBuild.changeCount
? `Found ${pluralize("change", runningBuild.changeCount, true)}`
: "No visual changes detected",
},
icon: {
name: "passed",
color: color.positive,
},
link: undefined,
});
setTimeout(() => clearNotification(`${ADDON_ID}/build-complete`), 10_000);
}

if (runningBuild?.step === "error") {
addNotification({
id: `${ADDON_ID}/build-error`,
content: {
headline: "Build error",
subHeadline: "Check the Storybook process on the command line for more details.",
},
icon: {
name: "failed",
color: color.negative,
},
link: undefined,
});
}
}, [
addNotification,
clearNotification,
runningBuild?.step,
runningBuild?.errorCount,
runningBuild?.changeCount,
]);

const emit = useChannel({});
const startBuild = () => emit(START_BUILD);

if (!projectId || isLoggedIn === false) {
return null;
}

return (
<SidebarTopButton
isOutdated={isOutdated}
isRunning={isRunning}
runningBuild={runningBuild}
startBuild={startBuild}
/>
);
};
26 changes: 0 additions & 26 deletions src/Tool.stories.ts

This file was deleted.

60 changes: 0 additions & 60 deletions src/Tool.tsx

This file was deleted.

21 changes: 21 additions & 0 deletions src/components/BuildProgressLabel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from "react";

import { RunningBuildPayload } from "../constants";

const messageMap: Record<RunningBuildPayload["step"], (payload: RunningBuildPayload) => string> = {
initialize: () => `📦 Validating Storybook files...`,
build: () => `📦 Validating Storybook files...`,
upload: () => `📡 Uploading to Chromatic...`, // TODO represent progress in bytes
verify: () => `🛠️ Initiating build...`, // TODO build number
snapshot: () => `👀 Running visual tests...`, // TODO count
complete: () => `🎉 Visual tests completed!`,
error: () => `❌ Build failed`, // TODO error
};

interface BuildProgressLabelProps {
runningBuild: RunningBuildPayload;
}

export const BuildProgressLabel = ({ runningBuild }: BuildProgressLabelProps) => (
<>{messageMap[runningBuild.step](runningBuild)}</>
);
45 changes: 45 additions & 0 deletions src/components/SidebarTopButton.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { action } from "@storybook/addon-actions";
import type { Meta, StoryObj } from "@storybook/react";
import { userEvent, within } from "@storybook/testing-library";

import { playAll } from "../utils/playAll";
import { SidebarTopButton } from "./SidebarTopButton";

const meta = {
component: SidebarTopButton,
args: {
startBuild: action("startBuild"),
},
} satisfies Meta<typeof SidebarTopButton>;

export default meta;
type Story = StoryObj<typeof meta>;

export const Default: Story = {
play: playAll(async ({ canvasElement }) => {
const canvas = within(canvasElement);
const button = await canvas.findByRole("button", { name: "Run tests" });
await userEvent.click(button);
}),
};

export const Outdated: Story = {
args: {
isOutdated: true,
},
};

export const IsRunning: Story = {
args: {
isRunning: true,
runningBuild: {
step: "build",
buildProgressPercentage: 40,
},
},
play: playAll(async ({ canvasElement }) => {
const canvas = within(canvasElement);
const button = await canvas.findByRole("button", { name: "Run tests" });
await userEvent.hover(button);
}),
};
Loading

0 comments on commit ea70fc7

Please sign in to comment.