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

117 lines
3.7 KiB
JavaScript
Raw Normal View History

2020-08-24 16:48:34 +02:00
2020-08-19 17:43:04 +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', 'Plain Text')
cy.addColumn('data', 'age', 'Number')
cy.addColumn('data', 'rating', 'Number')
2020-08-24 16:48:34 +02:00
// 6 Records
2020-08-19 17:43:04 +02:00
cy.addRecord(["Students", 25, 1])
cy.addRecord(["Students", 20, 3])
cy.addRecord(["Students", 18, 6])
cy.addRecord(["Students", 25, 2])
cy.addRecord(["Teachers", 49, 5])
cy.addRecord(["Teachers", 36, 3])
})
2020-08-24 16:48:34 +02:00
it('creates a view', () => {
2020-08-19 17:43:04 +02:00
cy.contains("Create New View").click()
cy.get("[placeholder='View Name']").type("Test View")
cy.contains("Save View").click()
2020-08-24 16:48:34 +02:00
cy.get(".title").contains("Test View")
cy.get("thead th").should(($headers) => {
expect($headers).to.have.length(3)
const headers = $headers.map((i, header) => Cypress.$(header).text())
expect(headers.get()).to.deep.eq([
"group",
"age",
"rating"
])
})
});
it('filters the view by age over 10', () => {
cy.contains("Filter").click()
cy.contains("Add Filter").click()
cy.get(".menu-container").find("select").first().select("age")
cy.get(".menu-container").find("select").eq(1).select("More Than")
cy.get("input[placeholder='age']").type(18)
cy.contains("Save").click()
cy.get("tbody tr").should(($values) => {
expect($values).to.have.length(5)
})
});
it('creates a stats calculation view based on age', () => {
cy.contains("Calculate").click()
cy.get(".menu-container").find("select").first().select("Statistics")
cy.get(".menu-container").find("select").eq(1).select("age")
cy.contains("Save").click()
2020-08-19 17:43:04 +02:00
cy.get("thead th").should(($headers) => {
expect($headers).to.have.length(7)
const headers = $headers.map((i, header) => Cypress.$(header).text())
expect(headers.get()).to.deep.eq([
2020-09-04 11:53:13 +02:00
"field",
2020-08-19 17:43:04 +02:00
"sum",
"min",
"max",
"count",
2020-08-24 16:48:34 +02:00
"sumsqr",
2020-08-19 17:43:04 +02:00
"avg",
])
})
cy.get("tbody td").should(($values) => {
const values = $values.map((i, value) => Cypress.$(value).text())
expect(values.get()).to.deep.eq([
2020-09-04 11:53:13 +02:00
"age",
2020-08-24 16:48:34 +02:00
"155",
"20",
2020-08-19 17:43:04 +02:00
"49",
2020-08-24 16:48:34 +02:00
"5",
"5347",
"31"
2020-08-19 17:43:04 +02:00
])
})
})
2020-08-24 16:48:34 +02:00
it('groups the view by group', () => {
2020-08-19 17:43:04 +02:00
cy.contains("Group By").click()
cy.get("select").select("group")
cy.contains("Save").click()
cy.contains("Students").should("be.visible")
cy.contains("Teachers").should("be.visible")
cy.get("tbody tr").first().find("td").should(($values) => {
const values = $values.map((i, value) => Cypress.$(value).text())
expect(values.get()).to.deep.eq([
"Students",
2020-08-24 16:48:34 +02:00
"70",
"20",
2020-08-19 17:43:04 +02:00
"25",
2020-08-24 16:48:34 +02:00
"3",
"1650",
"23.333333333333332"
2020-08-19 17:43:04 +02:00
])
})
})
it('renames a view', () => {
cy.contains("[data-cy=model-nav-item]", "Test View").find(".ri-more-line").click()
cy.contains("Edit").click()
cy.get("[placeholder='View Name']").type(" Updated")
cy.contains("Save").click()
cy.contains("Test View Updated").should("be.visible")
})
it('deletes a view', () => {
2020-08-24 16:48:34 +02:00
cy.contains("[data-cy=model-nav-item]", "Test View Updated").click()
2020-08-19 17:43:04 +02:00
cy.contains("[data-cy=model-nav-item]", "Test View Updated").find(".ri-more-line").click()
cy.contains("Delete").click()
cy.get(".content").contains("button", "Delete").click()
cy.contains("TestView Updated").should("not.be.visible")
})
})