|
| 1 | +import { screen } from "@testing-library/react" |
| 2 | +import * as Mocks from "../../testHelpers/entities" |
| 3 | +import { render } from "../../testHelpers/renderHelpers" |
| 4 | +import { Language } from "./ActionCtas" |
| 5 | +import { WorkspaceStateEnum } from "./constants" |
| 6 | +import { WorkspaceActions, WorkspaceActionsProps } from "./WorkspaceActions" |
| 7 | + |
| 8 | +const renderAndClick = async (props: Partial<WorkspaceActionsProps> = {}) => { |
| 9 | + render( |
| 10 | + <WorkspaceActions |
| 11 | + workspace={props.workspace ?? Mocks.MockWorkspace} |
| 12 | + handleStart={jest.fn()} |
| 13 | + handleStop={jest.fn()} |
| 14 | + handleDelete={jest.fn()} |
| 15 | + handleUpdate={jest.fn()} |
| 16 | + handleCancel={jest.fn()} |
| 17 | + />, |
| 18 | + ) |
| 19 | + const trigger = await screen.findByTestId("workspace-actions-button") |
| 20 | + trigger.click() |
| 21 | +} |
| 22 | + |
| 23 | +describe("WorkspaceActions", () => { |
| 24 | + describe("when the workspace is starting", () => { |
| 25 | + it("primary is cancel; no secondary", async () => { |
| 26 | + await renderAndClick({ workspace: Mocks.MockStartingWorkspace }) |
| 27 | + expect(screen.getByTestId("primary-cta")).toHaveTextContent(Language.cancel) |
| 28 | + expect(screen.queryByTestId("secondary-ctas")).toBeNull() |
| 29 | + }) |
| 30 | + }) |
| 31 | + describe("when the workspace is started", () => { |
| 32 | + it("primary is stop; secondary is delete", async () => { |
| 33 | + await renderAndClick({ workspace: Mocks.MockWorkspace }) |
| 34 | + expect(screen.getByTestId("primary-cta")).toHaveTextContent(Language.stop) |
| 35 | + expect(screen.getByTestId("secondary-ctas")).toHaveTextContent(Language.delete) |
| 36 | + }) |
| 37 | + }) |
| 38 | + describe("when the workspace is stopping", () => { |
| 39 | + it("primary is cancel; no secondary", async () => { |
| 40 | + await renderAndClick({ workspace: Mocks.MockStoppingWorkspace }) |
| 41 | + expect(screen.getByTestId("primary-cta")).toHaveTextContent(Language.cancel) |
| 42 | + expect(screen.queryByTestId("secondary-ctas")).toBeNull() |
| 43 | + }) |
| 44 | + }) |
| 45 | + describe("when the workspace is canceling", () => { |
| 46 | + it("primary is canceling; no secondary", async () => { |
| 47 | + await renderAndClick({ workspace: Mocks.MockCancelingWorkspace }) |
| 48 | + expect(screen.getByTestId("primary-cta")).toHaveTextContent(WorkspaceStateEnum.canceling) |
| 49 | + expect(screen.queryByTestId("secondary-ctas")).toBeNull() |
| 50 | + }) |
| 51 | + }) |
| 52 | + describe("when the workspace is canceled", () => { |
| 53 | + it("primary is start; secondary are stop, delete", async () => { |
| 54 | + await renderAndClick({ workspace: Mocks.MockCanceledWorkspace }) |
| 55 | + expect(screen.getByTestId("primary-cta")).toHaveTextContent(Language.start) |
| 56 | + expect(screen.getByTestId("secondary-ctas")).toHaveTextContent(Language.stop) |
| 57 | + expect(screen.getByTestId("secondary-ctas")).toHaveTextContent(Language.delete) |
| 58 | + }) |
| 59 | + }) |
| 60 | + describe("when the workspace is errored", () => { |
| 61 | + it("primary is start; secondary is delete", async () => { |
| 62 | + await renderAndClick({ workspace: Mocks.MockFailedWorkspace }) |
| 63 | + expect(screen.getByTestId("primary-cta")).toHaveTextContent(Language.start) |
| 64 | + expect(screen.getByTestId("secondary-ctas")).toHaveTextContent(Language.delete) |
| 65 | + }) |
| 66 | + }) |
| 67 | + describe("when the workspace is deleting", () => { |
| 68 | + it("primary is cancel; no secondary", async () => { |
| 69 | + await renderAndClick({ workspace: Mocks.MockDeletingWorkspace }) |
| 70 | + expect(screen.getByTestId("primary-cta")).toHaveTextContent(Language.cancel) |
| 71 | + expect(screen.queryByTestId("secondary-ctas")).toBeNull() |
| 72 | + }) |
| 73 | + }) |
| 74 | + describe("when the workspace is deleted", () => { |
| 75 | + it("primary is deleted; no secondary", async () => { |
| 76 | + await renderAndClick({ workspace: Mocks.MockDeletedWorkspace }) |
| 77 | + expect(screen.getByTestId("primary-cta")).toHaveTextContent(WorkspaceStateEnum.deleted) |
| 78 | + expect(screen.queryByTestId("secondary-ctas")).toBeNull() |
| 79 | + }) |
| 80 | + }) |
| 81 | + describe("when the workspace is outdated", () => { |
| 82 | + it("primary is start; secondary are delete, update", async () => { |
| 83 | + await renderAndClick({ workspace: Mocks.MockOutdatedWorkspace }) |
| 84 | + expect(screen.getByTestId("primary-cta")).toHaveTextContent(Language.start) |
| 85 | + expect(screen.getByTestId("secondary-ctas")).toHaveTextContent(Language.delete) |
| 86 | + expect(screen.getByTestId("secondary-ctas")).toHaveTextContent(Language.update) |
| 87 | + }) |
| 88 | + }) |
| 89 | +}) |
0 commit comments