-
Notifications
You must be signed in to change notification settings - Fork 894
feat(site): Ask for version name and if it is active when publishing a new version on editor #6756
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
8 commits
Select commit
Hold shift + click to select a range
d1e93c8
Add basic publish new version flow
BrunoQuaresma f222b1b
Merge branch 'main' into bq/ask-template-version-name
BrunoQuaresma 3513404
Fix patch
BrunoQuaresma a2eec18
Add tests
BrunoQuaresma 5195c83
Merge branch 'main' into bq/ask-template-version-name
BrunoQuaresma 0461806
Merge branch 'main' into bq/ask-template-version-name
BrunoQuaresma 90dc55f
Fix duplicated name
BrunoQuaresma 05d3944
Merge branch 'main' into bq/ask-template-version-name
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
Add tests
- Loading branch information
commit a2eec188e8a78d2ad0836dbcf6ff5ac25b1c8003
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
183 changes: 183 additions & 0 deletions
183
...rc/pages/TemplateVersionPage/TemplateVersionEditorPage/TemplateVersionEditorPage.test.tsx
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,183 @@ | ||
import { | ||
MockTemplateVersion, | ||
MockWorkspaceBuildLogs, | ||
renderWithAuth, | ||
} from "testHelpers/renderHelpers" | ||
import TemplateVersionEditorPage from "./TemplateVersionEditorPage" | ||
import { screen, waitFor, within } from "@testing-library/react" | ||
import userEvent from "@testing-library/user-event" | ||
import * as api from "api/api" | ||
|
||
// For some reason this component in Jest is throwing a MUI style warning so, | ||
// since we don't need it for this test, we can mock it out | ||
jest.mock("components/TemplateResourcesTable/TemplateResourcesTable", () => { | ||
return { | ||
TemplateResourcesTable: () => <div />, | ||
} | ||
}) | ||
|
||
test("Use custom name and set it as active when publishing", async () => { | ||
const user = userEvent.setup() | ||
renderWithAuth(<TemplateVersionEditorPage />, { | ||
extraRoutes: [ | ||
{ | ||
path: "/templates/:templateId", | ||
element: <div />, | ||
}, | ||
], | ||
}) | ||
const topbar = await screen.findByTestId("topbar") | ||
|
||
// Build Template | ||
jest.spyOn(api, "uploadTemplateFile").mockResolvedValueOnce({ hash: "hash" }) | ||
jest | ||
.spyOn(api, "createTemplateVersion") | ||
.mockResolvedValueOnce(MockTemplateVersion) | ||
jest | ||
.spyOn(api, "getTemplateVersion") | ||
.mockResolvedValue({ ...MockTemplateVersion, id: "new-version-id" }) | ||
jest.spyOn(api, "watchBuildLogs").mockImplementation((_, onMessage) => { | ||
onMessage(MockWorkspaceBuildLogs[0]) | ||
return Promise.resolve() | ||
}) | ||
const buildButton = within(topbar).getByRole("button", { | ||
name: "Build template", | ||
}) | ||
await user.click(buildButton) | ||
|
||
// Publish | ||
const patchTemplateVersion = jest | ||
.spyOn(api, "patchTemplateVersion") | ||
.mockResolvedValue(MockTemplateVersion) | ||
const updateActiveTemplateVersion = jest | ||
.spyOn(api, "updateActiveTemplateVersion") | ||
.mockResolvedValue({ message: "" }) | ||
await within(topbar).findByText("Success") | ||
const publishButton = within(topbar).getByRole("button", { | ||
name: "Publish version", | ||
}) | ||
await user.click(publishButton) | ||
const publishDialog = await screen.findByTestId("dialog") | ||
const nameField = within(publishDialog).getByLabelText("Version name") | ||
await user.clear(nameField) | ||
await user.type(nameField, "v1.0") | ||
await user.click( | ||
within(publishDialog).getByLabelText("Promote to default version"), | ||
) | ||
await user.click( | ||
within(publishDialog).getByRole("button", { name: "Publish" }), | ||
) | ||
await waitFor(() => { | ||
expect(patchTemplateVersion).toBeCalledWith("new-version-id", { | ||
name: "v1.0", | ||
}) | ||
expect(updateActiveTemplateVersion).toBeCalledWith("test-template", { | ||
id: "new-version-id", | ||
}) | ||
}) | ||
}) | ||
|
||
test("Do not mark as active if promote is not checked", async () => { | ||
const user = userEvent.setup() | ||
renderWithAuth(<TemplateVersionEditorPage />, { | ||
extraRoutes: [ | ||
{ | ||
path: "/templates/:templateId", | ||
element: <div />, | ||
}, | ||
], | ||
}) | ||
const topbar = await screen.findByTestId("topbar") | ||
|
||
// Build Template | ||
jest.spyOn(api, "uploadTemplateFile").mockResolvedValueOnce({ hash: "hash" }) | ||
jest | ||
.spyOn(api, "createTemplateVersion") | ||
.mockResolvedValueOnce(MockTemplateVersion) | ||
jest | ||
.spyOn(api, "getTemplateVersion") | ||
.mockResolvedValue({ ...MockTemplateVersion, id: "new-version-id" }) | ||
jest.spyOn(api, "watchBuildLogs").mockImplementation((_, onMessage) => { | ||
onMessage(MockWorkspaceBuildLogs[0]) | ||
return Promise.resolve() | ||
}) | ||
const buildButton = within(topbar).getByRole("button", { | ||
name: "Build template", | ||
}) | ||
await user.click(buildButton) | ||
|
||
// Publish | ||
const patchTemplateVersion = jest | ||
.spyOn(api, "patchTemplateVersion") | ||
.mockResolvedValue(MockTemplateVersion) | ||
const updateActiveTemplateVersion = jest | ||
.spyOn(api, "updateActiveTemplateVersion") | ||
.mockResolvedValue({ message: "" }) | ||
await within(topbar).findByText("Success") | ||
const publishButton = within(topbar).getByRole("button", { | ||
name: "Publish version", | ||
}) | ||
await user.click(publishButton) | ||
const publishDialog = await screen.findByTestId("dialog") | ||
const nameField = within(publishDialog).getByLabelText("Version name") | ||
await user.clear(nameField) | ||
await user.type(nameField, "v1.0") | ||
await user.click( | ||
within(publishDialog).getByRole("button", { name: "Publish" }), | ||
) | ||
await waitFor(() => { | ||
expect(patchTemplateVersion).toBeCalledWith("new-version-id", { | ||
name: "v1.0", | ||
}) | ||
}) | ||
expect(updateActiveTemplateVersion).toBeCalledTimes(0) | ||
}) | ||
|
||
test("The default version name is used when a new one is not used", async () => { | ||
const user = userEvent.setup() | ||
renderWithAuth(<TemplateVersionEditorPage />, { | ||
extraRoutes: [ | ||
{ | ||
path: "/templates/:templateId", | ||
element: <div />, | ||
}, | ||
], | ||
}) | ||
const topbar = await screen.findByTestId("topbar") | ||
|
||
// Build Template | ||
jest.spyOn(api, "uploadTemplateFile").mockResolvedValueOnce({ hash: "hash" }) | ||
jest | ||
.spyOn(api, "createTemplateVersion") | ||
.mockResolvedValueOnce(MockTemplateVersion) | ||
jest | ||
.spyOn(api, "getTemplateVersion") | ||
.mockResolvedValue({ ...MockTemplateVersion, id: "new-version-id" }) | ||
jest.spyOn(api, "watchBuildLogs").mockImplementation((_, onMessage) => { | ||
onMessage(MockWorkspaceBuildLogs[0]) | ||
return Promise.resolve() | ||
}) | ||
const buildButton = within(topbar).getByRole("button", { | ||
name: "Build template", | ||
}) | ||
await user.click(buildButton) | ||
|
||
// Publish | ||
const patchTemplateVersion = jest | ||
.spyOn(api, "patchTemplateVersion") | ||
.mockResolvedValue(MockTemplateVersion) | ||
await within(topbar).findByText("Success") | ||
const publishButton = within(topbar).getByRole("button", { | ||
name: "Publish version", | ||
}) | ||
await user.click(publishButton) | ||
const publishDialog = await screen.findByTestId("dialog") | ||
await user.click( | ||
within(publishDialog).getByRole("button", { name: "Publish" }), | ||
) | ||
await waitFor(() => { | ||
expect(patchTemplateVersion).toBeCalledWith("new-version-id", { | ||
name: MockTemplateVersion.name, | ||
}) | ||
}) | ||
}) |
2 changes: 1 addition & 1 deletion
2
site/src/pages/TemplateVersionPage/TemplateVersionEditorPage/types.ts
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,4 +1,4 @@ | ||
export type PublishVersionData = { | ||
name?: string | ||
name: string | ||
isActiveVersion: boolean | ||
} |
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
Binary file not shown.
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.
Uh oh!
There was an error while loading. Please reload this page.