-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add a cypress test for project basic operations: create, edit, …
…delete (#3881)
- Loading branch information
1 parent
cbe29dc
commit b0a62ab
Showing
8 changed files
with
178 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -150,6 +150,7 @@ jobs: | |
checkWorkflows, | ||
rstudioSession, | ||
v2/dashboardV2, | ||
v2/projectBasics, | ||
] | ||
|
||
steps: | ||
|
This file contains 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 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,117 @@ | ||
import { | ||
getRandomString, | ||
getUserData, | ||
validateLoginV2, | ||
} from "../../support/commands/general"; | ||
import { ProjectIdentifierV2 } from "../../support/types/project.types"; | ||
import { User } from "../../support/types/user.types"; | ||
import { | ||
deleteProjectFromAPIV2, | ||
getProjectByNamespaceAPIV2, | ||
} from "../../support/utils/projectsV2.utils"; | ||
|
||
const sessionId = ["projectBasics", getRandomString()]; | ||
|
||
beforeEach(() => { | ||
// Restore the session (login) | ||
cy.session( | ||
sessionId, | ||
() => { | ||
cy.robustLogin(); | ||
}, | ||
validateLoginV2 | ||
); | ||
}); | ||
|
||
describe("Project - create, edit and delete", () => { | ||
// Define some project details | ||
const projectNameRandomPart = getRandomString(); | ||
const projectName = `project/$test-${projectNameRandomPart}`; | ||
const projectPath = `project-test-${projectNameRandomPart}`; | ||
const projectDescription = "This is a test project from Cypress"; | ||
const projectIdentifier: ProjectIdentifierV2 = { | ||
slug: projectPath, | ||
id: null, | ||
namespace: null, | ||
}; | ||
|
||
// Cleanup the project after the test -- useful on failure | ||
after(() => { | ||
getProjectByNamespaceAPIV2(projectIdentifier).then((response) => { | ||
if (response.status === 200) { | ||
projectIdentifier.id = response.body.id; | ||
projectIdentifier.namespace = response.body.namespace; | ||
deleteProjectFromAPIV2(projectIdentifier); | ||
} | ||
}); | ||
}); | ||
|
||
it("Project - create, edit and delete", () => { | ||
// Create a new project | ||
cy.visit("/v2"); | ||
getUserData().then((user: User) => { | ||
const username = user.username; | ||
cy.getDataCy("navbar-new-entity").click(); | ||
cy.getDataCy("navbar-project-new").click(); | ||
cy.getDataCy("project-creation-form").should("exist"); | ||
cy.getDataCy("project-name-input").type(projectName); | ||
cy.getDataCy("project-slug-toggle").click(); | ||
cy.getDataCy("project-slug-input").should("have.value", projectPath); | ||
cy.getDataCy("project-visibility-public").click(); | ||
cy.getDataCy("project-description-input").type(projectDescription); | ||
cy.getDataCy("project-url-preview").contains( | ||
`/${username}/${projectPath}` | ||
); | ||
cy.intercept("POST", /(?:\/ui-server)?\/api\/data\/projects/).as("createProject"); | ||
cy.getDataCy("project-create-button").click(); | ||
cy.wait("@createProject"); | ||
cy.getDataCy("project-name").should("contain", projectName); | ||
|
||
// Change settings | ||
const modifiedProjectName = `${projectName} - modified`; | ||
const modifiedProjectDescription = `${projectDescription} - modified`; | ||
cy.getDataCy("project-settings-link").click(); | ||
cy.getDataCy("project-name-input").should("have.value", projectName); | ||
cy.getDataCy("project-name-input").clear().type(modifiedProjectName); | ||
|
||
cy.getDataCy("project-description-input").should( | ||
"have.value", | ||
projectDescription | ||
); | ||
cy.getDataCy("project-description-input") | ||
.clear() | ||
.type(modifiedProjectDescription); | ||
|
||
cy.get("#project-visibility-public").should("be.checked"); | ||
cy.getDataCy("project-visibility-private").click(); | ||
|
||
cy.intercept("PATCH", /(?:\/ui-server)?\/api\/data\/projects\/[^/]+/).as( | ||
"updateProject" | ||
); | ||
cy.getDataCy("project-update-button").click(); | ||
cy.wait("@updateProject"); | ||
cy.getDataCy("project-settings-general") | ||
.get(".alert-success") | ||
.contains("The project has been successfully updated."); | ||
cy.getDataCy("project-name").should("contain", modifiedProjectName); | ||
cy.getDataCy("project-description").should( | ||
"contain", | ||
modifiedProjectDescription | ||
); | ||
|
||
// Delete project | ||
cy.getDataCy("project-settings-link").click(); | ||
cy.getDataCy("project-delete"); | ||
cy.getDataCy("project-delete-button").should("not.be.enabled"); | ||
cy.getDataCy("delete-confirmation-input").type(projectPath); | ||
cy.intercept("DELETE", /(?:\/ui-server)?\/api\/data\/projects\/[^/]+/).as( | ||
"deleteProject" | ||
); | ||
cy.getDataCy("project-delete-button").should("be.enabled").click(); | ||
cy.wait("@deleteProject"); | ||
getProjectByNamespaceAPIV2(projectIdentifier).then((response) => { | ||
expect(response.status).to.equal(404); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains 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 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 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,10 @@ | ||
export type ProjectIdentifierV2 = { | ||
id?: string; | ||
namespace?: string; | ||
slug: string; | ||
}; | ||
|
||
export interface NewProjectV2Body extends ProjectIdentifierV2 { | ||
name: string; | ||
visibility?: "public" | "private"; | ||
} |
This file contains 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,8 @@ | ||
export interface User { | ||
id: string; | ||
username: string; | ||
email: string; | ||
first_name: string; | ||
last_name: string; | ||
is_admin: boolean; | ||
} |
This file contains 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