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

QA Fast Follows #172

Merged
merged 9 commits into from
Feb 6, 2024
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
20 changes: 18 additions & 2 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { action } from "@storybook/addon-actions"
import { API, ManagerContext, State } from "@storybook/manager-api";
import type { Decorator, Loader, Preview } from "@storybook/react";
import { fn } from "@storybook/test"
import {
Global,
ThemeProvider,
Expand All @@ -10,10 +12,12 @@ import {
useTheme,
} from "@storybook/theming";
import { HttpResponse, graphql } from "msw";
import { initialize, mswLoader } from "msw-storybook-addon";
import React from "react";

import { baseModes } from "../src/modes";
import { initialize, mswLoader } from "msw-storybook-addon";
import { UninstallProvider } from "../src/screens/Uninstalled/UninstallContext"


// Initialize MSW
initialize({
Expand Down Expand Up @@ -124,6 +128,14 @@ const withManagerApi: Decorator = (Story, { argsByTarget }) => (
</ManagerContext.Provider>
);

const withUninstall: Decorator = (Story) => {
return (
<UninstallProvider>
<Story />
</UninstallProvider>
)
}

/**
* An experiment with targeted args for GraphQL. This loader will serve a graphql
* response for any arg nested under $graphql.
Expand Down Expand Up @@ -168,7 +180,7 @@ export const graphQLArgLoader: Loader = async ({ argTypes, argsByTarget, paramet
};

const preview: Preview = {
decorators: [withTheme, withManagerApi],
decorators: [withTheme, withUninstall, withManagerApi ],
loaders: [graphQLArgLoader],
parameters: {
actions: {
Expand All @@ -195,6 +207,10 @@ const preview: Preview = {
},
argTypes: {
$graphql: { target: "graphql" },
getChannel: { type: "function", target: "manager-api" },
},
args: {
getChannel: () => ({on: fn(), off: fn(), emit: action("channel.emit")}),
thafryer marked this conversation as resolved.
Show resolved Hide resolved
},
globalTypes: {
theme: {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
]
},
"dependencies": {
"chromatic": "^10.6.0",
"chromatic": "^10.7.0",
"filesize": "^10.0.12",
"jsonfile": "^6.1.0",
"react-confetti": "^6.1.0"
Expand Down
149 changes: 98 additions & 51 deletions src/Panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import { GitNotFound } from "./screens/GitNotFound/GitNotFound";
import { LinkedProject } from "./screens/LinkProject/LinkedProject";
import { LinkingProjectFailed } from "./screens/LinkProject/LinkingProjectFailed";
import { LinkProject } from "./screens/LinkProject/LinkProject";
import { UninstallProvider } from "./screens/Uninstalled/UninstallContext";
import { Uninstalled } from "./screens/Uninstalled/Uninstalled";
import { ControlsProvider } from "./screens/VisualTests/ControlsContext";
import { VisualTests } from "./screens/VisualTests/VisualTests";
import { GitInfoPayload, LocalBuildProgress, UpdateStatusFunction } from "./types";
Expand Down Expand Up @@ -60,15 +62,36 @@ export const Panel = ({ active, api }: PanelProps) => {

// If the user creates a project in a dialog (either during login or later, it get set here)
const [createdProjectId, setCreatedProjectId] = useState<Project["id"]>();
const [addonUninstalled, setAddonUninstalled] = useSharedState<boolean>(REMOVE_ADDON);

if (addonUninstalled) {
return (
<Provider key={PANEL_ID} value={client}>
<UninstallProvider
addonUninstalled={addonUninstalled}
setAddonUninstalled={setAddonUninstalled}
>
<Sections hidden={!active}>
<Uninstalled />
</Sections>
</UninstallProvider>
</Provider>
);
}

if (gitInfoError) {
// eslint-disable-next-line no-console
console.error(gitInfoError);
return (
<Provider key={PANEL_ID} value={client}>
<Sections hidden={!active}>
<GitNotFound gitInfoError={gitInfoError} setAccessToken={setAccessToken} />
</Sections>
<UninstallProvider
addonUninstalled={addonUninstalled}
setAddonUninstalled={setAddonUninstalled}
>
<Sections hidden={!active}>
<GitNotFound gitInfoError={gitInfoError} setAccessToken={setAccessToken} />
</Sections>
</UninstallProvider>
</Provider>
);
}
Expand All @@ -77,15 +100,19 @@ export const Panel = ({ active, api }: PanelProps) => {
if (!accessToken) {
return (
<Provider key={PANEL_ID} value={client}>
<Sections hidden={!active}>
<Authentication
key={PANEL_ID}
setAccessToken={setAccessToken}
setCreatedProjectId={setCreatedProjectId}
hasProjectId={!!projectId}
onUninstall={() => emit(REMOVE_ADDON)}
/>
</Sections>
<UninstallProvider
addonUninstalled={addonUninstalled}
setAddonUninstalled={setAddonUninstalled}
>
<Sections hidden={!active}>
<Authentication
key={PANEL_ID}
setAccessToken={setAccessToken}
setCreatedProjectId={setCreatedProjectId}
hasProjectId={!!projectId}
/>
</Sections>
</UninstallProvider>
</Provider>
);
}
Expand All @@ -98,14 +125,19 @@ export const Panel = ({ active, api }: PanelProps) => {
if (!projectId)
return (
<Provider key={PANEL_ID} value={client}>
<Sections hidden={!active}>
<LinkProject
createdProjectId={createdProjectId}
setCreatedProjectId={setCreatedProjectId}
onUpdateProject={updateProject}
setAccessToken={setAccessToken}
/>
</Sections>
<UninstallProvider
addonUninstalled={addonUninstalled}
setAddonUninstalled={setAddonUninstalled}
>
<Sections hidden={!active}>
<LinkProject
createdProjectId={createdProjectId}
setCreatedProjectId={setCreatedProjectId}
onUpdateProject={updateProject}
setAccessToken={setAccessToken}
/>
</Sections>
</UninstallProvider>
</Provider>
);

Expand All @@ -116,13 +148,18 @@ export const Panel = ({ active, api }: PanelProps) => {
}

return (
<Sections hidden={!active}>
<LinkingProjectFailed
projectId={projectId}
configFile={configFile}
setAccessToken={setAccessToken}
/>
</Sections>
<UninstallProvider
addonUninstalled={addonUninstalled}
setAddonUninstalled={setAddonUninstalled}
>
<Sections hidden={!active}>
<LinkingProjectFailed
projectId={projectId}
configFile={configFile}
setAccessToken={setAccessToken}
/>
</Sections>
</UninstallProvider>
);
}

Expand All @@ -132,37 +169,47 @@ export const Panel = ({ active, api }: PanelProps) => {

return (
<Provider key={PANEL_ID} value={client}>
<Sections hidden={!active}>
<LinkedProject
projectId={projectId}
configFile={configFile}
goToNext={clearProjectIdUpdated}
setAccessToken={setAccessToken}
/>
</Sections>
<UninstallProvider
addonUninstalled={addonUninstalled}
setAddonUninstalled={setAddonUninstalled}
>
<Sections hidden={!active}>
<LinkedProject
projectId={projectId}
configFile={configFile}
goToNext={clearProjectIdUpdated}
setAccessToken={setAccessToken}
/>
</Sections>
</UninstallProvider>
</Provider>
);
}

const localBuildIsRightBranch = gitInfo.branch === localBuildProgress?.branch;
return (
<Provider key={PANEL_ID} value={client}>
<Sections hidden={!active}>
<ControlsProvider>
<VisualTests
dismissBuildError={() => setLocalBuildProgress(undefined)}
isOutdated={!!isOutdated}
localBuildProgress={localBuildIsRightBranch ? localBuildProgress : undefined}
startDevBuild={() => emit(START_BUILD, { accessToken })}
setAccessToken={setAccessToken}
setOutdated={setOutdated}
updateBuildStatus={updateBuildStatus}
projectId={projectId}
gitInfo={gitInfo}
storyId={storyId}
/>
</ControlsProvider>
</Sections>
<UninstallProvider
addonUninstalled={addonUninstalled}
setAddonUninstalled={setAddonUninstalled}
>
<Sections hidden={!active}>
<ControlsProvider>
<VisualTests
dismissBuildError={() => setLocalBuildProgress(undefined)}
isOutdated={!!isOutdated}
localBuildProgress={localBuildIsRightBranch ? localBuildProgress : undefined}
startDevBuild={() => emit(START_BUILD, { accessToken })}
setAccessToken={setAccessToken}
setOutdated={setOutdated}
updateBuildStatus={updateBuildStatus}
projectId={projectId}
gitInfo={gitInfo}
storyId={storyId}
/>
</ControlsProvider>
</Sections>
</UninstallProvider>
</Provider>
);
};
61 changes: 43 additions & 18 deletions src/components/FooterMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,56 @@
import { EllipsisIcon, QuestionIcon, UserIcon } from "@storybook/icons";
import { ChangedIcon, EllipsisIcon, QuestionIcon, ShareAltIcon, UserIcon } from "@storybook/icons";
import React from "react";

import { PROJECT_INFO } from "../constants";
import { useUninstallAddon } from "../screens/Uninstalled/UninstallContext";
import { ProjectInfoPayload } from "../types";
import { useSharedState } from "../utils/useSharedState";
import { TooltipMenu } from "./TooltipMenu";

interface FooterMenuProps {
setAccessToken: (value: string | null) => void;
}

export const FooterMenu = ({ setAccessToken }: FooterMenuProps) => {
const { uninstallAddon } = useUninstallAddon();
const [projectInfo] = useSharedState<ProjectInfoPayload>(PROJECT_INFO);
const { projectId } = projectInfo || {};
const links = [
{
id: "remove",
title: "Remove addon",
icon: <ChangedIcon aria-hidden />,
onClick: () => uninstallAddon(),
},
{
id: "logout",
title: "Log out",
icon: <UserIcon aria-hidden />,
onClick: () => setAccessToken(null),
},
{
id: "learn",
title: "Learn about this addon",
icon: <QuestionIcon aria-hidden />,
href: "https://www.chromatic.com/docs/visual-testing-addon",
target: "_blank",
},
...(projectId
? [
{
id: "visit",
title: "Visit Project on Chromatic",
icon: <ShareAltIcon aria-hidden />,
href: projectId
? `https://www.chromatic.com/builds?appId=${projectId?.split(":")[1]}`
: "https://www.chromatic.com/start",
target: "_blank",
},
]
: []),
];
return (
<TooltipMenu
placement="top"
links={[
{
id: "logout",
title: "Log out",
icon: <UserIcon />,
onClick: () => setAccessToken(null),
},
{
id: "learn",
title: "Learn about this addon",
icon: <QuestionIcon />,
href: "https://www.chromatic.com/docs/visual-testing-addon",
},
]}
>
<TooltipMenu placement="top" links={links}>
<EllipsisIcon />
</TooltipMenu>
);
Expand Down
5 changes: 5 additions & 0 deletions src/runChromaticBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ export const runChromaticBuild = async (
process.env.SB_TESTBUILD = "true";

await run({
flags: {
interactive: false,
},
options: {
...options,

Expand All @@ -198,6 +201,8 @@ export const runChromaticBuild = async (
isLocalBuild: true,
// Never skip local builds
skip: false,
// No prompts from the Build proces
interactive: false,

experimental_onTaskStart: onStartOrProgress(localBuildProgress, timeout),
experimental_onTaskProgress: onStartOrProgress(localBuildProgress, timeout),
Expand Down
Loading
Loading