-
Notifications
You must be signed in to change notification settings - Fork 875
chore: refactor frontend to use workspace status directly #4361
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 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
330f2af
Add/update copy
presleyp c38352d
Update mocks
presleyp 7dc2ef2
Handle disabled button labels separately
presleyp 56f927e
Use workspace status directly, use i18n
presleyp a363534
Update stories and tests
presleyp 1992e08
Fix optimistic update in xservice to use status, pending
presleyp 5072691
Merge branch 'main' into ws-status/presleyp
presleyp d06c432
Rename started to running in story
presleyp b9829b5
Fix deletion banner conditional
presleyp 23c607e
Send label to disabled button
presleyp 5e10ddf
Refactor workspace actions
presleyp 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
Update stories and tests
- Loading branch information
commit a3635349d8a242bc85161db63cba95cc5d304615
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
import { fireEvent, screen } from "@testing-library/react" | ||
import { WorkspaceStateEnum } from "util/workspace" | ||
import i18next from "i18next" | ||
import * as Mocks from "../../testHelpers/entities" | ||
import { render } from "../../testHelpers/renderHelpers" | ||
import { Language } from "../DropdownButton/ActionCtas" | ||
import { WorkspaceActions, WorkspaceActionsProps } from "./WorkspaceActions" | ||
|
||
const { t } = i18next | ||
|
||
const renderComponent = async (props: Partial<WorkspaceActionsProps> = {}) => { | ||
render( | ||
<WorkspaceActions | ||
|
@@ -39,7 +40,9 @@ describe("WorkspaceActions", () => { | |
describe("when the workspace is starting", () => { | ||
it("primary is starting; cancel is available; no secondary", async () => { | ||
await renderComponent({ workspace: Mocks.MockStartingWorkspace }) | ||
expect(screen.getByTestId("primary-cta")).toHaveTextContent(Language.starting) | ||
expect(screen.getByTestId("primary-cta")).toHaveTextContent( | ||
t("actionButton.starting", { ns: "workspacePage" }), | ||
) | ||
expect( | ||
screen.getByRole("button", { | ||
name: "cancel action", | ||
|
@@ -51,14 +54,20 @@ describe("WorkspaceActions", () => { | |
describe("when the workspace is started", () => { | ||
it("primary is stop; secondary is delete", async () => { | ||
await renderAndClick({ workspace: Mocks.MockWorkspace }) | ||
expect(screen.getByTestId("primary-cta")).toHaveTextContent(Language.stop) | ||
expect(screen.getByTestId("secondary-ctas")).toHaveTextContent(Language.delete) | ||
expect(screen.getByTestId("primary-cta")).toHaveTextContent( | ||
t("actionButton.stop", { ns: "workspacePage" }), | ||
) | ||
expect(screen.getByTestId("secondary-ctas")).toHaveTextContent( | ||
t("actionButton.delete", { ns: "workspacePage" }), | ||
) | ||
}) | ||
}) | ||
describe("when the workspace is stopping", () => { | ||
it("primary is stopping; cancel is available; no secondary", async () => { | ||
await renderComponent({ workspace: Mocks.MockStoppingWorkspace }) | ||
expect(screen.getByTestId("primary-cta")).toHaveTextContent(Language.stopping) | ||
expect(screen.getByTestId("primary-cta")).toHaveTextContent( | ||
t("actionButton.stopping", { ns: "workspacePage" }), | ||
) | ||
expect( | ||
screen.getByRole("button", { | ||
name: "cancel action", | ||
|
@@ -70,29 +79,43 @@ describe("WorkspaceActions", () => { | |
describe("when the workspace is canceling", () => { | ||
it("primary is canceling; no secondary", async () => { | ||
await renderAndClick({ workspace: Mocks.MockCancelingWorkspace }) | ||
expect(screen.getByTestId("primary-cta")).toHaveTextContent(WorkspaceStateEnum.canceling) | ||
expect(screen.getByTestId("primary-cta")).toHaveTextContent( | ||
t("disabledButton.canceling", { ns: "workspacePage" }), | ||
) | ||
expect(screen.queryByTestId("secondary-ctas")).toBeNull() | ||
}) | ||
}) | ||
describe("when the workspace is canceled", () => { | ||
it("primary is start; secondary are stop, delete", async () => { | ||
await renderAndClick({ workspace: Mocks.MockCanceledWorkspace }) | ||
expect(screen.getByTestId("primary-cta")).toHaveTextContent(Language.start) | ||
expect(screen.getByTestId("secondary-ctas")).toHaveTextContent(Language.stop) | ||
expect(screen.getByTestId("secondary-ctas")).toHaveTextContent(Language.delete) | ||
expect(screen.getByTestId("primary-cta")).toHaveTextContent( | ||
t("actionButton.start", { ns: "workspacePage" }), | ||
) | ||
expect(screen.getByTestId("secondary-ctas")).toHaveTextContent( | ||
t("actionButton.stop", { ns: "workspacePage" }), | ||
) | ||
expect(screen.getByTestId("secondary-ctas")).toHaveTextContent( | ||
t("actionButton.delete", { ns: "workspacePage" }), | ||
) | ||
}) | ||
}) | ||
describe("when the workspace is errored", () => { | ||
it("primary is start; secondary is delete", async () => { | ||
await renderAndClick({ workspace: Mocks.MockFailedWorkspace }) | ||
expect(screen.getByTestId("primary-cta")).toHaveTextContent(Language.start) | ||
expect(screen.getByTestId("secondary-ctas")).toHaveTextContent(Language.delete) | ||
expect(screen.getByTestId("primary-cta")).toHaveTextContent( | ||
t("actionButton.start", { ns: "workspacePage" }), | ||
) | ||
expect(screen.getByTestId("secondary-ctas")).toHaveTextContent( | ||
t("actionButton.delete", { ns: "workspacePage" }), | ||
) | ||
}) | ||
}) | ||
describe("when the workspace is deleting", () => { | ||
it("primary is deleting; cancel is available; no secondary", async () => { | ||
await renderComponent({ workspace: Mocks.MockDeletingWorkspace }) | ||
expect(screen.getByTestId("primary-cta")).toHaveTextContent(Language.deleting) | ||
expect(screen.getByTestId("primary-cta")).toHaveTextContent( | ||
t("actionButton.deleting", { ns: "workspacePage" }), | ||
) | ||
expect( | ||
screen.getByRole("button", { | ||
name: "cancel action", | ||
|
@@ -104,16 +127,24 @@ describe("WorkspaceActions", () => { | |
describe("when the workspace is deleted", () => { | ||
it("primary is deleted; no secondary", async () => { | ||
await renderAndClick({ workspace: Mocks.MockDeletedWorkspace }) | ||
expect(screen.getByTestId("primary-cta")).toHaveTextContent(WorkspaceStateEnum.deleted) | ||
expect(screen.getByTestId("primary-cta")).toHaveTextContent( | ||
t("disabledButton.deleted", { ns: "workspacePage" }), | ||
) | ||
expect(screen.queryByTestId("secondary-ctas")).toBeNull() | ||
}) | ||
}) | ||
describe("when the workspace is outdated", () => { | ||
it("primary is update; secondary are start, delete", async () => { | ||
await renderAndClick({ workspace: Mocks.MockOutdatedWorkspace }) | ||
expect(screen.getByTestId("primary-cta")).toHaveTextContent(Language.update) | ||
expect(screen.getByTestId("secondary-ctas")).toHaveTextContent(Language.start) | ||
expect(screen.getByTestId("secondary-ctas")).toHaveTextContent(Language.delete) | ||
expect(screen.getByTestId("primary-cta")).toHaveTextContent( | ||
t("actionButton.update", { ns: "workspacePage" }), | ||
) | ||
expect(screen.getByTestId("secondary-ctas")).toHaveTextContent( | ||
t("actionButton.start", { ns: "workspacePage" }), | ||
) | ||
expect(screen.getByTestId("secondary-ctas")).toHaveTextContent( | ||
t("actionButton.delete", { ns: "workspacePage" }), | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for doing all these translations!!! |
||
}) | ||
}) | ||
}) |
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
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.
Curious why we're no longer using the enum here?
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.
The WorkspaceStatus type is defined by the backend now