Skip to content
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
9 changes: 9 additions & 0 deletions packages/app/src/web/actions-projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,19 @@ export const connectProjectById = (
})
}

const applyProjectConfirmMessage = (label: string): string =>
`Apply docker-git config to ${label}? This restarts the container and ends active SSH sessions and in-container browsers.`

export const applyProjectById = (
projectId: string,
context: BrowserActionContext
) => {
const label = context.selectedProjectId === projectId
? projectActionLabel(context)
: projectId
if (!confirmAction(applyProjectConfirmMessage(label))) {
return
}
context.setSelectedProjectId(projectId)
withBusy({
context,
Expand Down
31 changes: 30 additions & 1 deletion packages/app/tests/docker-git/actions-projects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,21 +240,50 @@ describe("web project actions", () => {

it.effect("applies a selected project through the project apply endpoint", () =>
Effect.gen(function*(_) {
const confirmMock = vi.fn(() => true)
vi.stubGlobal("confirm", confirmMock)
applyProjectMock.mockImplementation(() => Effect.succeed(project))
const { context, reloadDashboard, setMessage } = makeBrowserActionContext()
const { context, reloadDashboard, setMessage } = makeBrowserActionContext({
selectedProjectId: "project-1",
selectedProjectName: "octocat/hello-world"
})

applyProjectById("project-1", context)

yield* _(waitForAssertion(() => {
expect(applyProjectMock).toHaveBeenCalledWith("project-1")
}))

expect(confirmMock).toHaveBeenCalledWith(
"Apply docker-git config to octocat/hello-world? "
+ "This restarts the container and ends active SSH sessions and in-container browsers."
)
expect(context.setSelectedProjectId).toHaveBeenCalledWith("project-1")
expect(context.setSelectedProject).toHaveBeenCalledWith(project)
expect(reloadDashboard).toHaveBeenCalledTimes(1)
expect(setMessage).toHaveBeenLastCalledWith("Applied octocat/hello-world.")
}))

it("does not apply a project when the user declines confirmation", () => {
const confirmMock = vi.fn(() => false)
vi.stubGlobal("confirm", confirmMock)
applyProjectMock.mockImplementation(() => Effect.succeed(project))
const { context, reloadDashboard } = makeBrowserActionContext({
selectedProjectId: "project-1",
selectedProjectName: "octocat/hello-world"
})

applyProjectById("project-1", context)

expect(confirmMock).toHaveBeenCalledWith(
"Apply docker-git config to octocat/hello-world? "
+ "This restarts the container and ends active SSH sessions and in-container browsers."
)
expect(applyProjectMock).not.toHaveBeenCalled()
expect(context.setSelectedProjectId).not.toHaveBeenCalled()
expect(reloadDashboard).not.toHaveBeenCalled()
})

it.effect("confirms and applies all projects", () =>
Effect.gen(function*(_) {
const confirmMock = vi.fn(() => true)
Expand Down