-
Notifications
You must be signed in to change notification settings - Fork 885
chore(site): add storybook for terminal page #12441
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
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f76800c
Create terminal storybook
BrunoQuaresma 47a88f7
Refactor story to match connected
BrunoQuaresma 0374e11
Merge branch 'main' of https://github.com/coder/coder into bq/refacto…
BrunoQuaresma 7436c97
Fix fmt
BrunoQuaresma 2a2f35a
Support error
BrunoQuaresma 116b8d7
Stack multiple web socket events
BrunoQuaresma 0255669
Add terminal storybook for other states
BrunoQuaresma 3798d2a
Update site/src/testHelpers/storybook.tsx
BrunoQuaresma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { | ||
reactRouterOutlet, | ||
reactRouterParameters, | ||
} from "storybook-addon-react-router-v6"; | ||
import { getAuthorizationKey } from "api/queries/authCheck"; | ||
import { workspaceByOwnerAndNameKey } from "api/queries/workspaces"; | ||
import type { Workspace, WorkspaceAgentLifecycle } from "api/typesGenerated"; | ||
import { AuthProvider } from "contexts/auth/AuthProvider"; | ||
import { permissionsToCheck } from "contexts/auth/permissions"; | ||
import { RequireAuth } from "contexts/auth/RequireAuth"; | ||
import { | ||
MockAppearanceConfig, | ||
MockAuthMethodsAll, | ||
MockBuildInfo, | ||
MockEntitlements, | ||
MockExperiments, | ||
MockUser, | ||
MockWorkspace, | ||
MockWorkspaceAgent, | ||
} from "testHelpers/entities"; | ||
import { withWebSocket } from "testHelpers/storybook"; | ||
import TerminalPage from "./TerminalPage"; | ||
|
||
const createWorkspaceWithAgent = (lifecycle: WorkspaceAgentLifecycle) => { | ||
return { | ||
key: workspaceByOwnerAndNameKey( | ||
MockWorkspace.owner_name, | ||
MockWorkspace.name, | ||
), | ||
data: { | ||
...MockWorkspace, | ||
latest_build: { | ||
...MockWorkspace.latest_build, | ||
resources: [ | ||
{ | ||
...MockWorkspace.latest_build.resources[0], | ||
agents: [{ ...MockWorkspaceAgent, lifecycle_state: lifecycle }], | ||
}, | ||
], | ||
}, | ||
} satisfies Workspace, | ||
}; | ||
}; | ||
|
||
const meta = { | ||
title: "pages/Terminal", | ||
component: RequireAuth, | ||
parameters: { | ||
layout: "fullscreen", | ||
reactRouter: reactRouterParameters({ | ||
location: { | ||
pathParams: { | ||
username: `@${MockWorkspace.owner_name}`, | ||
workspace: MockWorkspace.name, | ||
}, | ||
}, | ||
routing: reactRouterOutlet( | ||
{ | ||
path: `/:username/:workspace/terminal`, | ||
}, | ||
<TerminalPage />, | ||
), | ||
}), | ||
queries: [ | ||
{ key: ["me"], data: MockUser }, | ||
{ key: ["authMethods"], data: MockAuthMethodsAll }, | ||
{ key: ["hasFirstUser"], data: true }, | ||
{ key: ["buildInfo"], data: MockBuildInfo }, | ||
{ key: ["entitlements"], data: MockEntitlements }, | ||
{ key: ["experiments"], data: MockExperiments }, | ||
{ key: ["appearance"], data: MockAppearanceConfig }, | ||
{ | ||
key: getAuthorizationKey({ checks: permissionsToCheck }), | ||
data: { editWorkspaceProxies: true }, | ||
}, | ||
], | ||
}, | ||
decorators: [ | ||
(Story) => ( | ||
<AuthProvider> | ||
<Story /> | ||
</AuthProvider> | ||
), | ||
], | ||
} satisfies Meta<typeof TerminalPage>; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof TerminalPage>; | ||
|
||
export const Starting: Story = { | ||
decorators: [withWebSocket], | ||
parameters: { | ||
...meta.parameters, | ||
webSocket: [ | ||
{ | ||
event: "message", | ||
// Copied and pasted this from browser | ||
data: `[H[2J[1m[32m➜ [36mcoder[C[34mgit:([31mbq/refactor-web-term-notifications[34m) [33m✗`, | ||
}, | ||
], | ||
queries: [...meta.parameters.queries, createWorkspaceWithAgent("starting")], | ||
}, | ||
}; | ||
|
||
export const Ready: Story = { | ||
decorators: [withWebSocket], | ||
parameters: { | ||
...meta.parameters, | ||
webSocket: [ | ||
{ | ||
event: "message", | ||
// Copied and pasted this from browser | ||
data: `[H[2J[1m[32m➜ [36mcoder[C[34mgit:([31mbq/refactor-web-term-notifications[34m) [33m✗`, | ||
}, | ||
], | ||
queries: [...meta.parameters.queries, createWorkspaceWithAgent("ready")], | ||
}, | ||
}; | ||
|
||
export const StartError: Story = { | ||
decorators: [withWebSocket], | ||
parameters: { | ||
...meta.parameters, | ||
webSocket: [], | ||
queries: [ | ||
...meta.parameters.queries, | ||
createWorkspaceWithAgent("start_error"), | ||
], | ||
}, | ||
}; | ||
|
||
export const ConnectionError: Story = { | ||
decorators: [withWebSocket], | ||
parameters: { | ||
...meta.parameters, | ||
webSocket: [ | ||
{ | ||
event: "error", | ||
}, | ||
], | ||
queries: [...meta.parameters.queries, createWorkspaceWithAgent("ready")], | ||
}, | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, why do we need the timeout? I think it makes sense since it allows us to make sure all the listeners are hooked up first but was there a bug with how it was before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the problem with the previous implementation is that it did not respect the order of the events so if the
error
listener was defined before it would call it first even if it was the third event in the list for example.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohhhhh I see! Makes sense.