Skip to content

Commit 3f61cb4

Browse files
authored
SS-1211 add e2e test to check that user cannot create a new project with the same name (#261)
Co-authored-by: akochari <[email protected]> Source: https://scilifelab.atlassian.net/browse/SS-1211 1. Superuser can create project with existing project-name. 2. Other users can not create such project.
1 parent fcfd762 commit 3f61cb4

File tree

2 files changed

+45
-81
lines changed

2 files changed

+45
-81
lines changed

cypress/e2e/ui-tests/test-project-as-contributor.cy.js

Lines changed: 18 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,24 @@ describe("Test project contributor user functionality", () => {
102102
cy.contains('.card-title', project_name).parents('.card-body').siblings('.card-footer').find('a:contains("Open")').first().click()
103103
cy.get('.card-text').should('contain', project_description_2)
104104

105+
cy.logf("Check that creating another project with same existing project name will create an error", Cypress.currentTest)
106+
cy.visit("/projects/")
107+
cy.get("a").contains('New project').click()
108+
cy.get("a").contains('Create').first().click()
109+
cy.get('input[name=name]').type(project_name) // same name used before
110+
cy.get('textarea[name=description]').type(project_description)
111+
cy.get("input[name=save]").contains('Create project').click() // should generate an error
112+
// Check that the error message is displayed
113+
cy.get('#flash-msg')
114+
.should('be.visible')
115+
.and('have.class', 'alert-danger')
116+
.and('contain.text', `Project cannot be created because a project with name '${project_name}' already exists.`);
117+
cy.logf("Error is successfully generated when trying to create a new project with the same existing project name", Cypress.currentTest)
118+
119+
// go back to the previously created project
120+
cy.visit("/projects/")
121+
cy.contains('.card-title', project_name).parents('.card-body').siblings('.card-footer').find('a.btn').contains('Open').click()
122+
105123
cy.logf("Delete the project from the settings menu", Cypress.currentTest)
106124
cy.get('[data-cy="settings"]').click()
107125
cy.get('a').contains("Delete").click()
@@ -117,85 +135,6 @@ describe("Test project contributor user functionality", () => {
117135
})
118136
})
119137

120-
// This test cannot run properly in GitHub workflows because there is an issue with minio creation there. Therefore, it should be run locally to make sure things work. For GitHub, skipping it.
121-
122-
// TODO: When models are launched, make sure that this test is activated
123-
it.skip("can create a new project with ML serving template, open settings, delete from settings", { defaultCommandTimeout: defaultCmdTimeoutMs }, () => {
124-
125-
// Names of objects to create
126-
const project_name = "e2e-create-ml-proj-test"
127-
const project_title_name = project_name + " | SciLifeLab Serve (beta)"
128-
129-
cy.visit("/projects/")
130-
cy.get("title").should("have.text", "My projects | SciLifeLab Serve (beta)")
131-
132-
// Click button for UI to create a new project
133-
cy.get("a").contains('New project').click()
134-
cy.url().should("include", "projects/templates")
135-
cy.get('h3').should('contain', 'New project')
136-
137-
// Next click button to create a new blank project
138-
cy.get(".card-footer").last().contains("Create").click()
139-
cy.url().should("include", "projects/create/?template=")
140-
cy.get('h3').should('contain', 'New project')
141-
142-
// Fill in the options for creating a new blank project
143-
cy.get('input[name=name]').type(project_name)
144-
cy.get('textarea[name=description]').type("A test project created by an e2e test.")
145-
cy.get("input[name=save]").contains('Create project').click()
146-
cy.wait(5000) // sometimes it takes a while to create a project
147-
.then((href) => {
148-
cy.logf(href, Cypress.currentTest)
149-
cy.reload()
150-
cy.get("title").should("have.text", project_title_name)
151-
cy.get('h3').should('contain', project_name)
152-
153-
// Check that the correct deployment options are available
154-
cy.get('.card-header').find('h5').should('contain', 'Develop')
155-
cy.get('.card-header').find('h5').should('contain', 'Serve')
156-
cy.get('.card-header').find('h5').should('contain', 'Models')
157-
cy.get('.card-header').find('h5').should('not.contain', 'Additional options [admins only]')
158-
159-
// Section Models - Machine Learning Models
160-
// Navigate to the create models view and cancel back again
161-
cy.get("div#models").first("h5").should("contain", "Machine Learning Models")
162-
cy.get("div#models").find("a.btn").click()
163-
.then((href) => {
164-
cy.url().should("include", "models/create")
165-
cy.get('h3').should("contain", "Create Model Object")
166-
cy.get("button").contains("Cancel").click()
167-
.then((href) => {
168-
cy.get('h3').should("contain", project_name)
169-
})
170-
})
171-
172-
// Check that project settings are available
173-
cy.get('[data-cy="settings"]').click()
174-
cy.url().should("include", "settings")
175-
cy.get('h3').should('contain', 'Project settings')
176-
177-
// Check that the correct project settings are visible (i.e. no extra settings)
178-
cy.get('.list-group').find('a').should('contain', 'Access')
179-
cy.get('.list-group').find('a').should('not.contain', 'S3 storage')
180-
cy.get('.list-group').find('a').should('not.contain', 'MLFlow')
181-
cy.get('.list-group').find('a').should('not.contain', 'Flavors')
182-
cy.get('.list-group').find('a').should('not.contain', 'Environments')
183-
184-
// Delete the project from the settings menu
185-
cy.get('a').contains("Delete").click()
186-
.then((href) => {
187-
cy.get('div#delete').should('have.css', 'display', 'block')
188-
cy.get('#id_delete_button').parent().parent().find('button').contains('Delete').click()
189-
.then((href) => {
190-
cy.get('div#deleteModal').should('have.css', 'display', 'block')
191-
cy.get('div#deleteModal').find('button').contains('Confirm').click()
192-
})
193-
cy.contains(project_name).should('not.exist')
194-
195-
})
196-
})
197-
})
198-
199138
it("can delete a project from projects overview", { defaultCommandTimeout: defaultCmdTimeoutMs }, () => {
200139

201140
// Names of objects to create

cypress/e2e/ui-tests/test-superuser-functionality.cy.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ describe("Test superuser access", () => {
4545
// Names of objects to create
4646
const project_name = "e2e-create-default-proj-test"
4747
const project_description = "A test project created by an e2e test."
48+
const project_description_duplicate = "A test project with an existing project name"
4849
const project_description_2 = "An alternative project description created by an e2e test."
4950

5051
cy.visit("/projects/")
@@ -65,12 +66,10 @@ describe("Test superuser access", () => {
6566
cy.get('input[name=name]').type(project_name)
6667
cy.get('textarea[name=description]').type(project_description)
6768
cy.get("input[name=save]").contains('Create project').click()
68-
//cy.wait(5000) // sometimes it takes a while to create a project. Not needed because of cypress retryability.
6969

7070
cy.get('h3', {timeout: longCmdTimeoutMs}).should('contain', project_name)
7171
cy.get('.card-text').should('contain', project_description)
7272

73-
7473
cy.logf("Checking that project settings are available", Cypress.currentTest)
7574
cy.get('[data-cy="settings"]').click()
7675
cy.url().should("include", "settings")
@@ -88,6 +87,32 @@ describe("Test superuser access", () => {
8887
cy.contains('.card-title', project_name).parents('.card-body').siblings('.card-footer').find('a:contains("Open")').first().click()
8988
cy.get('.card-text').should('contain', project_description_2)
9089

90+
cy.logf("Check that creating another project with same existing project name will work for a superuser", Cypress.currentTest)
91+
cy.visit("/projects/")
92+
cy.get("a").contains('New project').click()
93+
cy.get("a").contains('Create').first().click()
94+
cy.get('input[name=name]').type(project_name) // this name already exists
95+
cy.get('textarea[name=description]').type(project_description_duplicate) // this will be used to ensure to delete it
96+
cy.get("input[name=save]").contains('Create project').click()
97+
cy.get('h3', {timeout: longCmdTimeoutMs}).should('contain', project_name)
98+
cy.get('.card-text').should('contain', project_description_duplicate) // checking that project creation succeeded
99+
// deleting the project with the duplicate name
100+
cy.get('[data-cy="settings"]').click()
101+
cy.get('a').contains("Delete").click()
102+
.then((href) => {
103+
cy.get('div#delete').should('have.css', 'display', 'block')
104+
cy.get('#id_delete_button').parent().parent().find('button').contains('Delete').click()
105+
.then((href) => {
106+
cy.get('div#deleteModal').should('have.css', 'display', 'block')
107+
cy.get('div#deleteModal').find('button').contains('Confirm').click()
108+
})
109+
// checking that the project with the duplicate name has been deleted
110+
cy.visit("/projects/")
111+
cy.contains(project_description_duplicate).should('not.exist')
112+
})
113+
// going to the previously created project's page
114+
cy.contains('.card-title', project_name).parents('.card-body').siblings('.card-footer').find('a.btn').contains('Open').click()
115+
91116
cy.logf("Deleting the project from the settings menu", Cypress.currentTest)
92117
cy.get('[data-cy="settings"]').click()
93118
cy.get('a').contains("Delete").click()

0 commit comments

Comments
 (0)