budibase/packages/builder/cypress/integration/createView.spec.js

127 lines
4.0 KiB
JavaScript
Raw Normal View History

function removeSpacing(headers) {
let newHeaders = []
for (let header of headers) {
newHeaders.push(header.replace(/\s\s+/g, " "))
}
return newHeaders
}
2020-09-25 14:12:16 +02:00
context("Create a View", () => {
before(() => {
cy.visit("localhost:4001/_builder")
cy.createApp("View App", "View App Description")
cy.createTable("data")
cy.addColumn("data", "group", "Text")
2020-09-25 14:12:16 +02:00
cy.addColumn("data", "age", "Number")
cy.addColumn("data", "rating", "Number")
2020-08-24 16:48:34 +02:00
// 6 Rows
cy.addRow(["Students", 25, 1])
cy.addRow(["Students", 20, 3])
cy.addRow(["Students", 18, 6])
cy.addRow(["Students", 25, 2])
cy.addRow(["Teachers", 49, 5])
cy.addRow(["Teachers", 36, 3])
2020-09-25 14:12:16 +02:00
})
2020-08-19 17:43:04 +02:00
2020-09-25 14:12:16 +02:00
it("creates a view", () => {
cy.contains("Create New View").click()
cy.get(".menu-container").within(() => {
cy.get("input").type("Test View")
cy.contains("Save View").click()
})
2020-10-27 16:26:07 +01:00
cy.get(".table-title h1").contains("Test View")
2020-10-27 17:01:27 +01:00
cy.get("[data-cy=table-header]").then($headers => {
2020-09-25 14:12:16 +02:00
expect($headers).to.have.length(3)
const headers = Array.from($headers).map(header =>
header.textContent.trim()
)
expect(removeSpacing(headers)).to.deep.eq([ "rating Number", "age Number", "group Text" ])
2020-08-19 17:43:04 +02:00
})
2020-09-25 14:12:16 +02:00
})
2020-08-19 17:43:04 +02:00
2020-09-25 14:12:16 +02:00
it("filters the view by age over 10", () => {
cy.contains("Filter").click()
cy.contains("Add Filter").click()
2020-10-27 16:26:07 +01:00
cy.get(".menu-container").find("select").first().select("age")
cy.get(".menu-container").find("select").eq(1).select("More Than")
2020-10-27 17:01:27 +01:00
cy.get(".menu-container").find("input").type(18)
2020-09-25 14:12:16 +02:00
cy.contains("Save").click()
2020-10-27 23:06:51 +01:00
cy.get("[role=rowgroup] .ag-row").get($values => {
2020-09-25 14:12:16 +02:00
expect($values).to.have.length(5)
})
})
2020-08-24 16:48:34 +02:00
2020-09-25 14:12:16 +02:00
it("creates a stats calculation view based on age", () => {
2020-10-27 23:06:51 +01:00
// Required due to responsive bug with ag grid in cypress
cy.viewport("macbook-15")
2020-09-25 14:12:16 +02:00
cy.contains("Calculate").click()
2020-10-27 16:26:07 +01:00
cy.get(".menu-container").find("select").eq(0).select("Statistics")
2020-10-15 23:21:08 +02:00
cy.wait(50)
2020-10-27 16:26:07 +01:00
cy.get(".menu-container").find("select").eq(1).select("age")
2020-09-25 14:12:16 +02:00
cy.contains("Save").click()
cy.wait(100)
cy.get(".ag-center-cols-viewport").scrollTo("100%")
2020-10-27 23:06:51 +01:00
cy.get("[data-cy=table-header]").then($headers => {
2020-09-25 14:12:16 +02:00
expect($headers).to.have.length(7)
const headers = Array.from($headers).map(header =>
header.textContent.trim()
)
expect(removeSpacing(headers)).to.deep.eq([ "avg Number",
"sumsqr Number",
"count Number",
"max Number",
"min Number",
"sum Number",
"field Text" ])
2020-08-19 17:43:04 +02:00
})
2020-10-27 23:06:51 +01:00
cy.get(".ag-cell").then($values => {
2021-02-16 22:40:35 +01:00
let values = Array.from($values).map(header =>
header.textContent.trim()
)
expect(values).to.deep.eq([ "31", "5347", "5", "49", "20", "155", "age" ])
2020-09-25 14:12:16 +02:00
})
})
2020-08-19 17:43:04 +02:00
2020-09-25 14:12:16 +02:00
it("groups the view by group", () => {
2020-10-27 23:06:51 +01:00
// Required due to responsive bug with ag grid in cypress
cy.viewport("macbook-15")
2020-09-25 14:12:16 +02:00
cy.contains("Group By").click()
cy.get("select").select("group")
cy.contains("Save").click()
2020-10-27 23:06:51 +01:00
cy.get(".ag-center-cols-viewport").scrollTo("100%")
2020-09-25 14:12:16 +02:00
cy.contains("Students").should("be.visible")
cy.contains("Teachers").should("be.visible")
2020-08-19 17:43:04 +02:00
cy.get(".ag-row[row-index=0]")
2020-10-27 17:01:27 +01:00
.find(".ag-cell")
.then($values => {
2020-10-27 23:06:51 +01:00
const values = Array.from($values).map(value => value.textContent)
expect(values).to.deep.eq([ "Students", "23.333333333333332", "1650", "3", "25", "20", "70" ])
2020-08-19 17:43:04 +02:00
})
2020-09-25 14:12:16 +02:00
})
2020-08-19 17:43:04 +02:00
2020-09-25 14:12:16 +02:00
it("renames a view", () => {
2020-10-27 16:26:07 +01:00
cy.contains(".nav-item", "Test View")
2021-02-06 23:41:27 +01:00
.find(".ri-more-line")
.click({ force: true })
2020-10-27 16:26:07 +01:00
cy.get("[data-cy=edit-view]").click()
cy.get(".menu-container").within(() => {
cy.get("input").type(" Updated")
cy.contains("Save").click()
})
2020-09-25 14:12:16 +02:00
cy.contains("Test View Updated").should("be.visible")
})
2020-08-19 17:43:04 +02:00
2020-09-25 14:12:16 +02:00
it("deletes a view", () => {
2020-10-27 16:26:07 +01:00
cy.contains(".nav-item", "Test View Updated")
2021-02-06 23:41:27 +01:00
.find(".ri-more-line")
.click({ force: true })
2020-10-27 16:26:07 +01:00
cy.get("[data-cy=delete-view]").click()
2020-09-25 14:12:16 +02:00
cy.contains("Delete View").click()
cy.contains("TestView Updated").should("not.be.visible")
})
2020-08-19 17:43:04 +02:00
})