Skip to content

chore(site): refactor stories and test from page components #9603

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

Merged
merged 31 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
52fae61
Refactor AuditPage
BrunoQuaresma Sep 7, 2023
cc2a549
Refactor CliAuthPageView stories
BrunoQuaresma Sep 7, 2023
4f7bb53
Refactor CreateTemplateForm stories
BrunoQuaresma Sep 7, 2023
cd5b40f
Refactor CreateUserPage test
BrunoQuaresma Sep 7, 2023
c5b4eb5
Refactor CreateWorkspacePage tests
BrunoQuaresma Sep 7, 2023
6121f0d
Fix stories name
BrunoQuaresma Sep 7, 2023
a5440cb
Refactor AppereancePageView stories
BrunoQuaresma Sep 7, 2023
4b3d9f8
Refactor GitAuthSettingsPageView stories
BrunoQuaresma Sep 7, 2023
8f654b6
Refactor NetworkSettingsPageView stories
BrunoQuaresma Sep 7, 2023
1618d36
Refactor SecuritySettingsPageView stories
BrunoQuaresma Sep 7, 2023
64ee732
Refactor UserAuthSettingsPageView stories
BrunoQuaresma Sep 7, 2023
1e40624
Refactor GroupsPage stories
BrunoQuaresma Sep 7, 2023
974bb3f
Refactor LoginPage tests
BrunoQuaresma Sep 7, 2023
30a783a
Refactor SetupPage stories
BrunoQuaresma Sep 7, 2023
5e5e35c
Refactor StarterTemplatePageView stories
BrunoQuaresma Sep 7, 2023
429b823
Refactor StarterTemplatesPage tests
BrunoQuaresma Sep 8, 2023
5dd69e9
Refactor TemplatePage tests
BrunoQuaresma Sep 8, 2023
d5532f0
RefactorTemplateSettingsPage tests
BrunoQuaresma Sep 8, 2023
d6444c9
Refactor TemplatesPage tests
BrunoQuaresma Sep 8, 2023
08adf24
Flat TemplateVersionEditorPage
BrunoQuaresma Sep 8, 2023
d40214a
Refactor TemplateVersionPage stories
BrunoQuaresma Sep 8, 2023
5a8b649
Refactor UserSettingsPage stories
BrunoQuaresma Sep 8, 2023
2d1e6bf
Refactor UsersPage stories
BrunoQuaresma Sep 8, 2023
30ad92b
Simplify IndexPage
BrunoQuaresma Sep 8, 2023
5c64496
Refactor WorkspaceSettingsPage stories
BrunoQuaresma Sep 8, 2023
5d8bcde
Refactor WorkspacePage stories
BrunoQuaresma Sep 8, 2023
7f0e89e
Refactor Conditionals stories
BrunoQuaresma Sep 8, 2023
b5d365b
Fix typo
BrunoQuaresma Sep 8, 2023
2f55e6b
Fix imports
BrunoQuaresma Sep 8, 2023
b3114d6
Fix ChooseOne story
BrunoQuaresma Sep 8, 2023
397370c
Fix UserAuthSettingsPageView stories
BrunoQuaresma Sep 8, 2023
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
10 changes: 7 additions & 3 deletions site/src/AppRouter.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { FullScreenLoader } from "components/Loader/FullScreenLoader";
import { TemplateLayout } from "components/TemplateLayout/TemplateLayout";
import { UsersLayout } from "components/UsersLayout/UsersLayout";
import IndexPage from "pages";
import AuditPage from "pages/AuditPage/AuditPage";
import GroupsPage from "pages/GroupsPage/GroupsPage";
import LoginPage from "pages/LoginPage/LoginPage";
Expand All @@ -11,7 +10,12 @@ import TemplatesPage from "pages/TemplatesPage/TemplatesPage";
import UsersPage from "pages/UsersPage/UsersPage";
import WorkspacesPage from "pages/WorkspacesPage/WorkspacesPage";
import { FC, lazy, Suspense } from "react";
import { Route, Routes, BrowserRouter as Router } from "react-router-dom";
import {
Route,
Routes,
BrowserRouter as Router,
Navigate,
} from "react-router-dom";
import { DashboardLayout } from "./components/Dashboard/DashboardLayout";
import { RequireAuth } from "./components/RequireAuth/RequireAuth";
import { SettingsLayout } from "./components/SettingsLayout/SettingsLayout";
Expand Down Expand Up @@ -195,7 +199,7 @@ export const AppRouter: FC = () => {
{/* Dashboard routes */}
<Route element={<RequireAuth />}>
<Route element={<DashboardLayout />}>
<Route index element={<IndexPage />} />
<Route index element={<Navigate to="/workspaces" replace />} />

<Route path="health" element={<HealthPage />} />

Expand Down
97 changes: 61 additions & 36 deletions site/src/components/Conditionals/ChooseOne.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,71 @@
import { Story } from "@storybook/react";
import { Meta, StoryObj } from "@storybook/react";
import { ChooseOne, Cond } from "./ChooseOne";

export default {
const meta: Meta<typeof ChooseOne> = {
title: "components/Conditionals/ChooseOne",
component: ChooseOne,
subcomponents: { Cond },
};

export const FirstIsTrue: Story = () => (
<ChooseOne>
<Cond condition>The first one shows.</Cond>
<Cond condition={false}>The second one does not show.</Cond>
<Cond>The default does not show.</Cond>
</ChooseOne>
);
export default meta;
type Story = StoryObj<typeof ChooseOne>;

export const SecondIsTrue: Story = () => (
<ChooseOne>
<Cond condition={false}>The first one does not show.</Cond>
<Cond condition>The second one shows.</Cond>
<Cond>The default does not show.</Cond>
</ChooseOne>
);
export const FirstIsTrue: Story = {
args: {
children: [
<Cond key="1" condition>
The first one shows.
</Cond>,
<Cond key="2" condition={false}>
The second one does not show.
</Cond>,
<Cond key="3">The default does not show.</Cond>,
],
Comment on lines +14 to +22
Copy link
Member

Choose a reason for hiding this comment

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

I liked the earlier commit where these were fragments: React will perform better with those. Does it break the ChooseOne component or something?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nops, it is just for the storybook. I didnt find a similar API to keep it as a fragment in the new Storybook v7 API

},
};

export const AllAreTrue: Story = () => (
<ChooseOne>
<Cond condition>Only the first one shows.</Cond>
<Cond condition>The second one does not show.</Cond>
<Cond>The default does not show.</Cond>
</ChooseOne>
);
export const SecondIsTrue: Story = {
args: {
children: [
<Cond key="1" condition={false}>
The first one does not show.
</Cond>,
<Cond key="2" condition>
The second one shows.
</Cond>,
<Cond key="3">The default does not show.</Cond>,
],
},
};
export const AllAreTrue: Story = {
args: {
children: [
<Cond key="1" condition>
Only the first one shows.
</Cond>,
<Cond key="2" condition>
The second one does not show.
</Cond>,
<Cond key="3">The default does not show.</Cond>,
],
},
};

export const NoneAreTrue: Story = () => (
<ChooseOne>
<Cond condition={false}>The first one does not show.</Cond>
<Cond condition={false}>The second one does not show.</Cond>
<Cond>The default shows.</Cond>
</ChooseOne>
);
export const NoneAreTrue: Story = {
args: {
children: [
<Cond key="1" condition={false}>
The first one does not show.
</Cond>,
<Cond key="2" condition={false}>
The second one does not show.
</Cond>,
<Cond key="3">The default shows.</Cond>,
],
},
};

export const OneCond: Story = () => (
<ChooseOne>
<Cond>An only child renders.</Cond>
</ChooseOne>
);
export const OneCond: Story = {
args: {
children: <Cond>An only child renders.</Cond>,
},
};
28 changes: 16 additions & 12 deletions site/src/components/Conditionals/Maybe.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import { Story } from "@storybook/react";
import { Maybe, MaybeProps } from "./Maybe";
import { StoryObj, Meta } from "@storybook/react";
import { Maybe } from "./Maybe";

export default {
const meta: Meta<typeof Maybe> = {
title: "components/Conditionals/Maybe",
component: Maybe,
args: {
children: "Now you see me",
},
};

const Template: Story<MaybeProps> = (args: MaybeProps) => (
<Maybe {...args}>Now you see me</Maybe>
);
export default meta;
type Story = StoryObj<typeof Maybe>;

export const ConditionIsTrue = Template.bind({});
ConditionIsTrue.args = {
condition: true,
export const ConditionIsTrue: Story = {
args: {
condition: true,
},
};

export const ConditionIsFalse = Template.bind({});
ConditionIsFalse.args = {
condition: false,
export const ConditionIsFalse: Story = {
args: {
condition: false,
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import type { Meta, StoryObj } from "@storybook/react";
import { AuditLogDescription } from "./AuditLogDescription";
import {
MockAuditLog,
MockAuditLogSuccessfulLogin,
MockAuditLogUnsuccessfulLoginKnownUser,
MockAuditLogWithWorkspaceBuild,
MockWorkspaceCreateAuditLogForDifferentOwner,
} from "testHelpers/entities";

const meta: Meta<typeof AuditLogDescription> = {
title: "components/AuditLogDescription",
component: AuditLogDescription,
};

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

export const WorkspaceCreate: Story = {
args: {
auditLog: MockAuditLog,
},
};

export const WorkspaceBuildStop: Story = {
args: {
auditLog: MockAuditLogWithWorkspaceBuild,
},
};

export const WorkspaceBuildDuplicatedWord: Story = {
args: {
auditLog: {
...MockAuditLogWithWorkspaceBuild,
additional_fields: {
workspace_name: "workspace",
},
},
},
};

export const CreateWorkspaceWithDiffOwner: Story = {
args: {
auditLog: MockWorkspaceCreateAuditLogForDifferentOwner,
},
};

export const SuccessLogin: Story = {
args: {
auditLog: MockAuditLogSuccessfulLogin,
},
};

export const UnsuccessfulLoginForUnknownUser: Story = {
args: {
auditLog: MockAuditLogUnsuccessfulLoginKnownUser,
},
};

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions site/src/pages/AuditPage/AuditLogRow/AuditLogDiff/index.ts

This file was deleted.

Loading