Skip to content

Commit

Permalink
Update e2e test for filtering submissions and pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
hannyle committed Mar 2, 2022
1 parent 3110d41 commit 4432e84
Show file tree
Hide file tree
Showing 8 changed files with 269 additions and 78 deletions.
6 changes: 3 additions & 3 deletions cypress/integration/home.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ describe("Home e2e", function () {
cy.login()
})

it("show Overview submissions in Home page, create a draft folder, navigate to see folder details, delete object inside folder, navigate back to Overview submissions", () => {
it("show draft submission data table in Home page, be able to edit and delete a draft submission inside the table", () => {
// Create a new Unpublished folder
cy.get("button").contains("Create submission").click()

Expand Down Expand Up @@ -54,10 +54,10 @@ describe("Home e2e", function () {
cy.contains(".MuiAlert-message", "The submission has been deleted successfully!", {
timeout: 1000,
})
cy.contains("Currently there are no draft submissions").should("be.visible")
cy.contains("Currently there are no submissions").should("be.visible")
})

it("create a published folder, navigate to see folder details, delete object inside folder, navigate back to Overview submissions", () => {
it("create a published submission, not be able to edit or delete that submission inside the data table", () => {
// Create a new Published folder
cy.get("button").contains("Create submission").click()

Expand Down
266 changes: 254 additions & 12 deletions cypress/integration/pagination.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ describe("unpublished folders, published folders, and user's draft templates pag
url: "/folders?page=2&per_page=5&published=false",
},
unpublishedFoldersResponsePage2
)
).as("unpublishedPage2")

// Mock response for Published Folders
const publishedFoldersResponse5 = {
Expand All @@ -201,14 +201,19 @@ describe("unpublished folders, published folders, and user's draft templates pag
cy.get("[data-testid='page info']").contains("1 of 20 pages").should("be.visible")

// Click Next page button
cy.get("[data-testid='NavigateNextIcon']").click()
cy.wait(500)
cy.get("p").contains("6-10 of 100", { timeout: 10000 }).should("be.visible")
cy.get("[data-testid='page info']", { timeout: 10000 }).contains("2 of 20 pages").should("be.visible")
cy.get("[data-testid='NavigateNextIcon']")
.parent()
.should("be.visible")
.then($el => $el.click())

cy.contains("6-10 of 100").should("be.visible")
cy.get("[data-testid='page info']").contains("2 of 20 pages").should("be.visible")
cy.wait("@unpublishedPage2")

// Check "Items per page" options
cy.get("div[aria-haspopup='listbox']", { timeout: 10000 }).contains(5).click()
cy.get("li[data-value='5']").should("be.visible")

cy.get("li[data-value='5']", { timeout: 1000 }).should("be.visible")
cy.get("li[data-value='15']").should("be.visible")
cy.get("li[data-value='25']").should("be.visible")
cy.get("li[data-value='50']").should("be.visible")
Expand All @@ -231,7 +236,7 @@ describe("unpublished folders, published folders, and user's draft templates pag
cy.get("[data-testid='page info']").contains("1 of 2 pages").should("be.visible")
})

it("should renders pagination for unpublished folders list correctly", () => {
it("should render pagination for unpublished folders list correctly", () => {
// Mock responses for Published Folders
const publishedFoldersResponse5 = {
folders: [
Expand Down Expand Up @@ -354,7 +359,7 @@ describe("unpublished folders, published folders, and user's draft templates pag
url: "/folders?page=2&per_page=5&published=true",
},
publishedFoldersResponsePage2
)
).as("publishedPage2")

cy.intercept(
{
Expand All @@ -371,11 +376,15 @@ describe("unpublished folders, published folders, and user's draft templates pag
cy.get("[data-testid='page info']").should("be.visible")
cy.get("[data-testid='page info']").contains("1 of 30 pages").should("be.visible")
// Click Next page button
cy.get("[data-testid='NavigateNextIcon']").click()
cy.get("p", { timeout: 10000 }).contains("6-10 of 150").should("be.visible")
cy.get("[data-testid='NavigateNextIcon']")
.parent()
.should("be.visible")
.then($el => $el.click())
cy.contains("6-10 of 150", { timeout: 10000 }).should("be.visible")
cy.get("[data-testid='page info']").contains("2 of 30 pages").should("be.visible")

cy.wait("@publishedPage2")
cy.get("button[aria-label='Go to page 3']").click()

cy.get("[data-testid='page info']").contains("3 of 30 pages").should("be.visible")

// Check "Items per page" options
Expand All @@ -389,7 +398,240 @@ describe("unpublished folders, published folders, and user's draft templates pag
cy.get("li[data-value='50']").click()
cy.get("p", { timeout: 10000 }).contains("1-50 of 150").should("be.visible")
cy.get("[data-testid='page info']").contains("1 of 3 pages").should("be.visible")
})
}),
it("should render pagination correctly when filtering the submission name", () => {
const unpublishedPage1 = {
folders: [
{
descriptioni: "d",
drafts: [],
folderId: "UNPUB1",
metadataObjects: [],
name: "draft-folder1",
published: false,
},
{ descriptioni: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "test", published: false },
{ descriptioni: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Biology", published: false },
{ descriptioni: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "test2", published: false },
{ descriptioni: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false },
],
page: { page: 1, size: 5, totalPages: 6, totalFolders: 30 },
}

const unpublishedPage2 = {
folders: [
{ descriptioni: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "Unpub6", published: false },
{ descriptioni: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "Unpub7", published: false },
{ descriptioni: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "Unpub8", published: false },
{ descriptioni: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub9", published: false },
{
descriptioni: "d",
drafts: [],
folderId: "UNPUB10",
metadataObjects: [],
name: "Unpub10",
published: false,
},
{ descriptioni: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false },
],
page: { page: 2, size: 5, totalPages: 6, totalFolders: 30 },
}

const unpublished15 = {
folders: [
{
descriptioni: "d",
drafts: [],
folderId: "UNPUB1",
metadataObjects: [],
name: "draft-folder1",
published: false,
},
{ descriptioni: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "test", published: false },
{ descriptioni: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Biology", published: false },
{ descriptioni: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "test2", published: false },
{ descriptioni: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false },
{ descriptioni: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "Unpub6", published: false },
{ descriptioni: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "Unpub7", published: false },
{ descriptioni: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "Unpub8", published: false },
{ descriptioni: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub9", published: false },
{
descriptioni: "d",
drafts: [],
folderId: "UNPUB10",
metadataObjects: [],
name: "Unpub10",
published: false,
},
{ descriptioni: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false },
{ descriptioni: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub2", published: false },
{ descriptioni: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub3", published: false },
{ descriptioni: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub4", published: false },
{ descriptioni: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false },
{ descriptioni: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "test3", published: false },
],
page: { page: 1, size: 15, totalPages: 2, totalFolders: 30 },
}

const allUnpublished = {
folders: [
{
descriptioni: "d",
drafts: [],
folderId: "UNPUB1",
metadataObjects: [],
name: "draft-folder1",
published: false,
},
{ descriptioni: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "test", published: false },
{ descriptioni: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Biology", published: false },
{ descriptioni: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "test2", published: false },
{ descriptioni: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false },
{ descriptioni: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "Unpub6", published: false },
{ descriptioni: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "Unpub7", published: false },
{ descriptioni: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "Unpub8", published: false },
{ descriptioni: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub9", published: false },
{
descriptioni: "d",
drafts: [],
folderId: "UNPUB10",
metadataObjects: [],
name: "Unpub10",
published: false,
},
{ descriptioni: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false },
{ descriptioni: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub2", published: false },
{ descriptioni: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub3", published: false },
{ descriptioni: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub4", published: false },
{ descriptioni: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false },
{ descriptioni: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "test3", published: false },
{ descriptioni: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "test4", published: false },
{ descriptioni: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "test5", published: false },
{ descriptioni: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "test6", published: false },
{
descriptioni: "d",
drafts: [],
folderId: "UNPUB10",
metadataObjects: [],
name: "Unpub10",
published: false,
},
{ descriptioni: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "test7", published: false },
{ descriptioni: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "test8", published: false },
{ descriptioni: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "test9", published: false },
{ descriptioni: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "test10", published: false },
{
descriptioni: "d",
drafts: [],
folderId: "UNPUB5",
metadataObjects: [],
name: "this-draft",
published: false,
},
{
descriptioni: "d",
drafts: [],
folderId: "UNPUB6",
metadataObjects: [],
name: "draft-folder2",
published: false,
},
{
descriptioni: "d",
drafts: [],
folderId: "UNPUB7",
metadataObjects: [],
name: "draft-folder3",
published: false,
},
{ descriptioni: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "abc", published: false },
{ descriptioni: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub9", published: false },
{
descriptioni: "d",
drafts: [],
folderId: "UNPUB10",
metadataObjects: [],
name: "Unpub10",
published: false,
},
],
page: { page: 1, size: 30, totalPages: 1, totalFolders: 30 },
}

cy.intercept(
{
method: "GET",
url: "/folders?page=1&per_page=5&published=false",
},
unpublishedPage1
)

cy.intercept(
{
method: "GET",
url: "/folders?page=2&per_page=5&published=false",
},
unpublishedPage2
)

cy.intercept(
{
method: "GET",
url: "/folders?page=1&per_page=30&published=false",
},
allUnpublished
)

cy.intercept("DELETE", "/folders/UNPUB9", {
statusCode: 200,
}).as("deleteSubmission")

cy.intercept(
{
method: "GET",
url: "/folders?page=1&per_page=15&published=false",
},
unpublished15
).as("unpublished15")

cy.login()
cy.get("[data-testid='page info']").contains("1 of 6 pages").should("be.visible")

// Type a filtering text and check if the filtered list renders correctly with pagination
cy.get("input[data-testid='wizard-search-box']").type("test")
cy.contains("1-5 of 10", { timeout: 10000 }).should("be.visible")
cy.get("[data-testid='page info']").contains("1 of 2 pages").should("be.visible")
cy.get("button[aria-label='Go to page 2']").click()
cy.contains("test6", { timeout: 10000 }).should("be.visible")

// Delete a submission and check that it is deleted from filtered list and the current page stays the same as page 2
cy.get("[data-testid='delete-draft-submission']").eq(0).click()
cy.wait("@deleteSubmission")
cy.contains(".MuiAlert-message", "The submission has been deleted successfully!", {
timeout: 1000,
})
cy.contains("test6", { timeout: 10000 }).should("not.exist")
cy.get("button[aria-label='page 2']", { timeout: 10000 }).should("be.visible")

// Select "Items per page" to check all filtered items exist
cy.get("div[aria-haspopup='listbox']", { timeout: 10000 }).contains(5).click()
cy.get("li[data-value='15']").click()
cy.wait("@unpublished15")
cy.contains("1-9 of 9", { timeout: 10000 }).should("be.visible")

// Clear the filter and check that the pagination is back to normal to render all submissions
cy.get("div[aria-haspopup='listbox']", { timeout: 10000 }).contains(15).click()
cy.get("li[data-value='5']").click()
cy.get("svg[data-testid='ClearIcon']").click()
cy.get("input[data-testid='wizard-search-box']").should("have.value", "")

cy.contains("1-5 of 30", { timeout: 10000 }).should("be.visible")
cy.get("[data-testid='page info']").contains("1 of 6 pages").should("be.visible")

// If the filtering text is not found, the table renders no pagination
cy.get("input[data-testid='wizard-search-box']").type("123456")
cy.get("[data-testid='table-pagination']").should("not.exist")
})
})

export {}
Loading

0 comments on commit 4432e84

Please sign in to comment.