Skip to content

Commit

Permalink
e2e-tests: Create search tests, rename project_tags file
Browse files Browse the repository at this point in the history
Modify/Move search feature related tests
Rename project_tags file into project_tags_spec
Add project update command to cypress
  • Loading branch information
Stezido committed Dec 11, 2019
1 parent 6f472ae commit eb1981b
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 74 deletions.
72 changes: 0 additions & 72 deletions e2e-test/cypress/integration/navigation_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,78 +68,6 @@ describe("Navigation", function() {
});
});

it("Filter projects by display name", function() {
// Set a unique project name
const projectDisplayName = Math.floor(Math.random() * 10000000000);

// Create project which will then be displayed after filtering
cy.createProject(projectDisplayName, projectDisplayName, [])
.then(() => cy.visit(`/projects`))
.then(() => {
cy.get("[data-test=toggle-project-search]").click();
cy.get("[data-test=project-search-field]").should("be.visible");
cy.get("[data-test=project-search-field] input").type(projectDisplayName);
// Since project name is unique, there can only be one match
cy.get("[data-test*=project-card]").then(res => assert.equal(res.length, 1));

// Check the functionality of the clear button
cy.get("[data-test=clear-project-search]").click();
cy.get("[data-test=project-search-field]").should("not.be.visible");
});
});

it("Search bar is closed and reset when viewing project details", function() {
// Set a unique project name
const projectDisplayName = Math.floor(Math.random() * 10000000000);

// Create project which will then be displayed after filtering
cy.createProject(projectDisplayName, projectDisplayName, [])
.then(() => cy.visit(`/projects`))
.then(() => {
cy.get("[data-test=toggle-project-search]").click();
cy.get("[data-test=project-search-field]").should("be.visible");
cy.get("[data-test=project-search-field] input").type(projectDisplayName);
// Since project name is unique, there can only be one match
cy.get("[data-test*=project-card]").then(res => assert.equal(res.length, 1));

// Go to project
cy.get("[data-test*=project-view-button]")
.first()
.click();

cy.get("[data-test=project-search-field]").should("not.be.visible");
cy.get("[data-test=toggle-project-search]").should("be.disabled");

cy.visit("/projects");
// Search field should be empty
cy.get("[data-test=toggle-project-search]").click();
cy.get("[data-test=project-search-field] input").should("have.value", "");
});
});

it("Search bar is closed and reset when clicking on 'Main' breadcrumb", function() {
// Set a unique project name
const projectDisplayName = Math.floor(Math.random() * 10000000000);

// Create project which will then be displayed after filtering
cy.createProject(projectDisplayName, projectDisplayName, [])
.then(() => cy.visit(`/projects`))
.then(() => {
cy.get("[data-test=toggle-project-search]").click();
cy.get("[data-test=project-search-field]").should("be.visible");
cy.get("[data-test=project-search-field] input").type(projectDisplayName);
// Since project name is unique, there can only be one match
cy.get("[data-test*=project-card]").then(res => assert.equal(res.length, 1));

// Go to project
cy.get("[data-test=breadcrumb-Main]").click();

cy.get("[data-test=project-search-field]").should("not.be.visible");
cy.get("[data-test=toggle-project-search]").should("be.enabled");
// TODO: Test what happens when you click on a project
});
});

it("The notification button redirects to the notification page", function() {
cy.get("[data-test=navbar-notification-button]").should("be.visible");
cy.get("[data-test=navbar-notification-button]").click();
Expand Down
127 changes: 127 additions & 0 deletions e2e-test/cypress/integration/search_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
describe("Navigation", function() {
let project = {
id: "",
displayName: Math.floor(Math.random() * 10000000000), // TODO: change it to p-search
description: "project search test"
};
const testTag = "testTag";

before(() => {
cy.login();
cy.createProject(project.displayName, project.description).then(({ id }) => {
project.id = id;
cy.updateProject(id, { tags: [testTag] });
});
});

beforeEach(function() {
cy.login();
cy.visit(`/projects`);
});

it("The search bar is cleared after disabling it", function() {
// Type into search bar
cy.get("[data-test=toggle-project-search]").click();
cy.get("[data-test=project-search-field]").should("be.visible");
cy.get("[data-test=project-search-field] input").type("foo");
// Close search bar
cy.get("[data-test=toggle-project-search]").click();
cy.get("[data-test=project-search-field]").should("be.not.visible");
// Open search bar
cy.get("[data-test=toggle-project-search]").click();
cy.get("[data-test=project-search-field]").should("be.visible");
cy.get("[data-test=project-search-field] input").should("have.value", "");
});

it("Filter projects by display name", function() {
// Type into search bar
cy.get("[data-test=toggle-project-search]").click();
cy.get("[data-test=project-search-field]").should("be.visible");
cy.get("[data-test=project-search-field] input").type(project.displayName);
// Show exactly one project
cy.get("[data-test*=project-card]").then(res => assert.equal(res.length, 1));
});

it("Filter projects by display name prefix 'name'", function() {
// Type into search bar
cy.get("[data-test=toggle-project-search]").click();
cy.get("[data-test=project-search-field]").should("be.visible");
cy.get("[data-test=project-search-field] input").type("name:" + project.displayName);
// Check for 1 project match
cy.get("[data-test*=project-card]").then(res => assert.equal(res.length, 1));
});

it("Filter projects by prefix 'name', 'tag' and 'status", function() {
// Type into search bar
cy.get("[data-test=toggle-project-search]").click();
cy.get("[data-test=project-search-field]").should("be.visible");
cy.get("[data-test=project-search-field] input").type(
"name:" + project.displayName + " " + "tag:" + testTag + " " + "status:open"
);
// Check for 1 project match
cy.get("[data-test*=project-card]").then(res => assert.equal(res.length, 1));
});

it("Filter projects by tag via tag button", function() {
// Click tag
cy.get("[data-test=project-search-field]").should("not.be.visible");
cy.get(`[data-test=project-card-${project.id}]`)
.find("[data-test=overview-tag]")
.should("have.length", 1)
.contains(testTag.toLowerCase())
.click();
// Check search bar for tag search term
cy.get("[data-test=project-search-field]").should("be.visible");
cy.get("[data-test=project-search-field] input").should("have.value", "tag:" + testTag.toLowerCase());
});

it("Search bar is closed and reset when viewing project details", function() {
// Type into search bar
cy.get("[data-test=toggle-project-search]").click();
cy.get("[data-test=project-search-field]").should("be.visible");
cy.get("[data-test=project-search-field] input").type(project.displayName);
// Go to project
cy.get("[data-test*=project-view-button]")
.first()
.click();
cy.get("[data-test=project-search-field]").should("not.be.visible");
cy.get("[data-test=toggle-project-search]").should("be.disabled");
// Navigate to overview page
cy.visit("/projects");
// Search field should be empty
cy.get("[data-test=toggle-project-search]").click();
cy.get("[data-test=project-search-field] input").should("have.value", "");
});

it("Search bar is closed and reset when clicking on 'Main' breadcrumb", function() {
// Type into search bar
cy.get("[data-test=toggle-project-search]").click();
cy.get("[data-test=project-search-field]").should("be.visible");
cy.get("[data-test=project-search-field] input").type(project.displayName);
// Navigate via Main breadcrumb
cy.get("[data-test=breadcrumb-Main]").click();
cy.get("[data-test=project-search-field]").should("not.be.visible");
cy.get("[data-test=toggle-project-search]").should("be.enabled");
// Search field should be empty
cy.get("[data-test=toggle-project-search]").click();
cy.get("[data-test=project-search-field] input").should("have.value", "");
});

it("Search bar is closed and reset when clicking on 'Projects' breadcrumb", function() {
// Type into search bar
cy.get("[data-test=toggle-project-search]").click();
cy.get("[data-test=project-search-field]").should("be.visible");
cy.get("[data-test=project-search-field] input").type(project.displayName);
// Go to project
cy.get("[data-test*=project-view-button]")
.first()
.click();
// Navigate via Projects breadcrumb
cy.get("[data-test=breadcrumb-Projects]").click();
cy.get("[data-test=project-search-field]").should("not.be.visible");
cy.get("[data-test=toggle-project-search]").should("be.enabled");
// Search field should be empty
cy.get("[data-test=toggle-project-search]").click();
cy.get("[data-test=project-search-field] input").should("have.value", "");
});
});
24 changes: 22 additions & 2 deletions e2e-test/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Cypress.Commands.add("createWorkflowitem", (projectId, subprojectId, displayName

Cypress.Commands.add(
"createProject",
(displayName, description, projectedBudgets, thumbnail = "/Thumbnail_0001.jpg") => {
(displayName, description, projectedBudgets, thumbnail = "/Thumbnail_0001.jpg", opts = {}) => {
cy.request({
url: `${baseUrl}/api/global.createProject`,
method: "POST",
Expand All @@ -140,7 +140,8 @@ Cypress.Commands.add(
displayName,
description,
projectedBudgets,
thumbnail
thumbnail,
...opts
}
}
}
Expand All @@ -154,6 +155,25 @@ Cypress.Commands.add(
}
);

Cypress.Commands.add("updateProject", (projectId, opts = {}) => {
cy.request({
url: `${baseUrl}/api/project.update`,
method: "POST",
headers: {
Authorization: `Bearer ${token}`
},
body: {
apiVersion: "1.0",
data: {
projectId,
...opts
}
}
})
.its("body")
.then(body => Cypress.Promise.resolve(body.data));
});

Cypress.Commands.add("updateProjectAssignee", (projectId, identity) => {
cy.request({
url: `${baseUrl}/api/project.assign`,
Expand Down

0 comments on commit eb1981b

Please sign in to comment.