-
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.
- Loading branch information
1 parent
4169bd2
commit 251ba36
Showing
5 changed files
with
157 additions
and
0 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 |
---|---|---|
|
@@ -147,6 +147,7 @@ jobs: | |
useSession, | ||
checkWorkflows, | ||
rstudioSession, | ||
dashboardV2, | ||
] | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { getRandomString, validateLogin } from "../support/commands/general"; | ||
import { generatorProjectName } from "../support/commands/projects"; | ||
import { ProjectIdentifierV2 } from "../support/commands/projectsV2"; | ||
|
||
const projectTestConfig = { | ||
projectAlreadyExists: false, | ||
projectName: generatorProjectName("dashboardV2"), | ||
}; | ||
|
||
const prefixProjectTitle = "My Renku Project"; | ||
const sessionId = ["dashboardV2", getRandomString()]; | ||
|
||
describe("Dashboard v2, Authenticated Users", () => { | ||
const projectIdentifier: ProjectIdentifierV2 = { | ||
slug: projectTestConfig.projectName, | ||
id: null, | ||
namespace: null, | ||
}; | ||
|
||
after(() => { | ||
if (!projectTestConfig.projectAlreadyExists && projectIdentifier.id != null){ | ||
cy.deleteProjectFromAPIV2(projectIdentifier); | ||
cy.getProjectByNamespaceAPIV2(projectIdentifier).then((response) => { | ||
expect(response.status).to.equal(404); | ||
}); | ||
} | ||
|
||
}); | ||
|
||
beforeEach(() => { | ||
// Restore the session | ||
cy.session( | ||
sessionId, | ||
() => { | ||
cy.robustLogin(); | ||
}, | ||
validateLogin | ||
); | ||
cy.getUserNamespaceAPIV2().then((namespace) => { | ||
if (namespace) { | ||
projectIdentifier.namespace = namespace; | ||
cy.createProjectIfMissingAPIV2({ | ||
visibility: "private", | ||
name: `${prefixProjectTitle} ${projectIdentifier.slug}`, | ||
namespace, | ||
slug: projectIdentifier.slug, | ||
}).then((project) => projectIdentifier.id=project.id) | ||
} else { | ||
cy.log('No user namespace found, project cannot be created.'); | ||
} | ||
}); | ||
}); | ||
|
||
it("Can see own project on the dashboard", () => { | ||
cy.visit("v2"); | ||
cy.getDataCy("dashboard-project-list").find("a").should("have.length.at.least", 1); | ||
cy.getDataCy("dashboard-project-list").find("a").should("contain.text", `${prefixProjectTitle} ${projectIdentifier.slug}`); | ||
cy.getDataCy("dashboard-project-list").find("a").should("contain.text", projectIdentifier.slug); | ||
}); | ||
|
||
it("Can find project in the search", () => { | ||
cy.visit("v2"); | ||
cy.getDataCy("view-my-projects-btn").click(); | ||
cy.getDataCy("search-card").should("have.length.at.least", 1); | ||
cy.getDataCy("search-card").should("contain.text", `${prefixProjectTitle} ${projectIdentifier.slug}`); | ||
}); | ||
}); | ||
|
||
describe("Dashboard v2, Non-Authenticated Users", () => { | ||
|
||
it("Cannot see projects and groups on Dashboard when logged out", () => { | ||
cy.visit("v2"); | ||
cy.getDataCy("projects-container").contains("No 2.0 projects."); | ||
cy.getDataCy("view-other-projects-btn").should("be.visible"); | ||
cy.getDataCy("groups-container").contains("No 2.0 groups."); | ||
cy.getDataCy("view-other-groups-btn").should("be.visible"); | ||
}); | ||
}); |
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,74 @@ | ||
export type ProjectIdentifierV2 = { | ||
slug: string; | ||
namespace?: string; | ||
id?: string; | ||
}; | ||
|
||
interface NewProjectV2Props extends ProjectIdentifierV2 { | ||
visibility?: "public" | "private"; | ||
name: string; | ||
} | ||
|
||
/** Get the namespace of the logged in user from the API. */ | ||
function getUserNamespaceAPIV2(): Cypress.Chainable<string | null> { | ||
return cy.request({ failOnStatusCode: false, method: "GET", url: `api/data/namespaces?minimum_role=owner` }) | ||
.then((response) => { | ||
if (response.status === 200) { | ||
const userNamespace = response.body?.filter((namespace) => namespace.namespace_kind === "user"); | ||
return userNamespace && userNamespace.length > 0 ? userNamespace[0].slug : null; | ||
} | ||
return null; | ||
}); | ||
} | ||
|
||
/** Get a project by using only the API. */ | ||
function getProjectByNamespaceAPIV2(newProjectProps: ProjectIdentifierV2): Cypress.Chainable<any | null> { | ||
return cy.request({ failOnStatusCode: false, method: "GET", url: `api/data/projects/${newProjectProps.namespace}/${newProjectProps.slug}` }); | ||
} | ||
|
||
/** Create a project (if the project is missing) by using only the API. */ | ||
function createProjectIfMissingAPIV2(newProjectProps: NewProjectV2Props) { | ||
return getProjectByNamespaceAPIV2(newProjectProps) | ||
.then((response) => { | ||
if (response.status != 200) { | ||
return cy.request({ | ||
method: "POST", | ||
url: "api/data/projects", | ||
body: newProjectProps, | ||
headers: { | ||
'Content-Type': 'application/json' | ||
} | ||
}); | ||
} else { | ||
return response.body; | ||
} | ||
}); | ||
} | ||
|
||
/** Delete a project by using only the API. */ | ||
function deleteProjectFromAPIV2(projectIdentifier: ProjectIdentifierV2) { | ||
return cy.request({ | ||
failOnStatusCode: false, | ||
method: "DELETE", | ||
url: `api/data/projects/${projectIdentifier.id}`, | ||
}); | ||
} | ||
|
||
export default function registerProjectV2Commands() { | ||
Cypress.Commands.add("createProjectIfMissingAPIV2", createProjectIfMissingAPIV2); | ||
Cypress.Commands.add("deleteProjectFromAPIV2", deleteProjectFromAPIV2); | ||
Cypress.Commands.add("getUserNamespaceAPIV2", getUserNamespaceAPIV2); | ||
Cypress.Commands.add("getProjectByNamespaceAPIV2", getProjectByNamespaceAPIV2); | ||
} | ||
|
||
declare global { | ||
// eslint-disable-next-line @typescript-eslint/no-namespace | ||
namespace Cypress { | ||
interface Chainable { | ||
createProjectIfMissingAPIV2(newProjectProps: NewProjectV2Props); | ||
deleteProjectFromAPIV2(identifier: ProjectIdentifierV2); | ||
getUserNamespaceAPIV2(); | ||
getProjectByNamespaceAPIV2(identifier: ProjectIdentifierV2); | ||
} | ||
} | ||
} |
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