Merge pull request #6287 from Budibase/cypressTests

Cypress tests
This commit is contained in:
Mihail Hadzhiev 2022-06-13 13:26:40 +03:00 committed by GitHub
commit e698765c53
5 changed files with 90 additions and 66 deletions

View File

@ -1,4 +1,5 @@
import filterTests from "../support/filterTests"
const interact = require('../support/interact')
filterTests(['smoke', 'all'], () => {
context("Create a View", () => {
@ -22,12 +23,12 @@ filterTests(['smoke', 'all'], () => {
it("creates a view", () => {
cy.contains("Create view").click()
cy.get(".modal-inner-wrapper").within(() => {
cy.get(interact.MODAL_INNER_WRAPPER).within(() => {
cy.get("input").type("Test View")
cy.get("button").contains("Create View").click({ force: true })
})
cy.get(".table-title h1").contains("Test View")
cy.get(".title").then($headers => {
cy.get(interact.TABLE_TITLE_H1).contains("Test View")
cy.get(interact.TITLE).then($headers => {
expect($headers).to.have.length(3)
const headers = Array.from($headers).map(header =>
header.textContent.trim()
@ -40,18 +41,18 @@ filterTests(['smoke', 'all'], () => {
cy.contains("Filter").click()
cy.contains("Add Filter").click()
cy.get(".modal-inner-wrapper").within(() => {
cy.get(".spectrum-Picker-label").eq(0).click()
cy.get(interact.MODAL_INNER_WRAPPER).within(() => {
cy.get(interact.SPECTRUM_PICKER_LABEL).eq(0).click()
cy.contains("age").click({ force: true })
cy.get(".spectrum-Picker-label").eq(1).click()
cy.get(interact.SPECTRUM_PICKER_LABEL).eq(1).click()
cy.contains("More Than").click({ force: true })
cy.get("input").type(18)
cy.contains("Save").click()
})
cy.get(".spectrum-Table-row").get($values => {
cy.get(interact.SPECTRUM_TABLE_ROW).get($values => {
expect($values).to.have.length(5)
})
})
@ -59,18 +60,18 @@ filterTests(['smoke', 'all'], () => {
it("creates a stats calculation view based on age", () => {
cy.wait(1000)
cy.contains("Calculate").click()
cy.get(".modal-inner-wrapper").within(() => {
cy.get(".spectrum-Picker-label").eq(0).click()
cy.get(interact.MODAL_INNER_WRAPPER).within(() => {
cy.get(interact.SPECTRUM_PICKER_LABEL).eq(0).click()
cy.contains("Statistics").click()
cy.get(".spectrum-Picker-label").eq(1).click()
cy.get(interact.SPECTRUM_PICKER_LABEL).eq(1).click()
cy.contains("age").click({ force: true })
cy.get(".spectrum-Button").contains("Save").click({ force: true })
cy.get(interact.SPECTRUM_BUTTON).contains("Save").click({ force: true })
})
cy.wait(1000)
cy.get(".title").then($headers => {
cy.get(interact.TITLE).then($headers => {
expect($headers).to.have.length(7)
const headers = Array.from($headers).map(header =>
header.textContent.trim()
@ -85,7 +86,7 @@ filterTests(['smoke', 'all'], () => {
"avg",
])
})
cy.get(".spectrum-Table-cell").then($values => {
cy.get(interact.SPECTRUM_TABLE_CELL).then($values => {
let values = Array.from($values).map(header => header.textContent.trim())
expect(values).to.deep.eq(["age", "155", "20", "49", "5", "5347", "31"])
})
@ -93,8 +94,8 @@ filterTests(['smoke', 'all'], () => {
it("groups the view by group", () => {
cy.contains("Group by").click()
cy.get(".modal-inner-wrapper").within(() => {
cy.get(".spectrum-Picker-label").eq(0).click()
cy.get(interact.MODAL_INNER_WRAPPER).within(() => {
cy.get(interact.SPECTRUM_PICKER_LABEL).eq(0).click()
cy.contains("group").click()
cy.contains("Save").click()
})
@ -102,7 +103,7 @@ filterTests(['smoke', 'all'], () => {
cy.contains("Students").should("be.visible")
cy.contains("Teachers").should("be.visible")
cy.get(".spectrum-Table-cell").then($values => {
cy.get(interact.SPECTRUM_TABLE_CELL).then($values => {
let values = Array.from($values).map(header => header.textContent.trim())
expect(values).to.deep.eq([
"Students",
@ -124,11 +125,11 @@ filterTests(['smoke', 'all'], () => {
})
it("renames a view", () => {
cy.contains(".nav-item", "Test View")
cy.contains(interact.NAV_ITEM, "Test View")
.find(".actions .icon.open-popover")
.click({ force: true })
cy.get(".spectrum-Menu-itemLabel").contains("Edit").click()
cy.get(".modal-inner-wrapper").within(() => {
cy.get(interact.SPECTRUM_MENU_ITEM_LABEL).contains("Edit").click()
cy.get(interact.MODAL_INNER_WRAPPER).within(() => {
cy.get("input").type(" Updated")
cy.contains("Save").click()
})
@ -137,7 +138,7 @@ filterTests(['smoke', 'all'], () => {
})
it("deletes a view", () => {
cy.contains(".nav-item", "Test View Updated")
cy.contains(interact.NAV_ITEM, "Test View Updated")
.find(".actions .icon.open-popover")
.click({ force: true })
cy.contains("Delete").click()

View File

@ -1,4 +1,5 @@
import filterTests from "../support/filterTests"
const interact = require('../support/interact')
filterTests(["smoke", "all"], () => {
context("Query Level Transformers", () => {
@ -13,11 +14,11 @@ filterTests(["smoke", "all"], () => {
const restUrl = "https://api.openbrewerydb.org/breweries"
cy.selectExternalDatasource(datasource)
cy.createRestQuery("GET", restUrl, "/breweries")
cy.get(".spectrum-Tabs-itemLabel").contains("Transformer").click()
cy.get(interact.SPECTRUM_TABS_ITEM).contains("Transformer").click()
// Get Transformer Function from file
cy.readFile("cypress/support/queryLevelTransformerFunction.js").then(
transformerFunction => {
cy.get(".CodeMirror textarea")
cy.get(interact.CODEMIRROR_TEXTAREA)
// Highlight current text and overwrite with file contents
.type(Cypress.platform === "darwin" ? "{cmd}a" : "{ctrl}a", {
force: true,
@ -27,7 +28,7 @@ filterTests(["smoke", "all"], () => {
)
// Send Query
cy.intercept("**/queries/preview").as("query")
cy.get(".spectrum-Button").contains("Send").click({ force: true })
cy.get(interact.SPECTRUM_BUTTON).contains("Send").click({ force: true })
cy.wait("@query")
// Assert against Status Code, body, & body rows
cy.get("@query").its("response.statusCode").should("eq", 200)
@ -41,13 +42,13 @@ filterTests(["smoke", "all"], () => {
const restUrl = "https://api.openbrewerydb.org/breweries"
cy.selectExternalDatasource(datasource)
cy.createRestQuery("GET", restUrl, "/breweries")
cy.get(".spectrum-Tabs-itemLabel").contains("Transformer").click()
cy.get(interact.SPECTRUM_TABS_ITEM).contains("Transformer").click()
// Get Transformer Function with Data from file
cy.readFile(
"cypress/support/queryLevelTransformerFunctionWithData.js"
).then(transformerFunction => {
//console.log(transformerFunction[1])
cy.get(".CodeMirror textarea")
cy.get(interact.CODEMIRROR_TEXTAREA)
// Highlight current text and overwrite with file contents
.type(Cypress.platform === "darwin" ? "{cmd}a" : "{ctrl}a", {
force: true,
@ -56,7 +57,7 @@ filterTests(["smoke", "all"], () => {
})
// Send Query
cy.intercept("**/queries/preview").as("query")
cy.get(".spectrum-Button").contains("Send").click({ force: true })
cy.get(interact.SPECTRUM_BUTTON).contains("Send").click({ force: true })
cy.wait("@query")
// Assert against Status Code, body, & body rows
cy.get("@query").its("response.statusCode").should("eq", 200)
@ -70,16 +71,16 @@ filterTests(["smoke", "all"], () => {
const restUrl = "https://api.openbrewerydb.org/breweries"
cy.selectExternalDatasource(datasource)
cy.createRestQuery("GET", restUrl, "/breweries")
cy.get(".spectrum-Tabs-itemLabel").contains("Transformer").click()
cy.get(interact.SPECTRUM_TABS_ITEM).contains("Transformer").click()
// Clear the code box and add "test"
cy.get(".CodeMirror textarea")
cy.get(interact.CODEMIRROR_TEXTAREA)
.type(Cypress.platform === "darwin" ? "{cmd}a" : "{ctrl}a", {
force: true,
})
.type("test")
// Run Query and intercept
cy.intercept("**/preview").as("queryError")
cy.get(".spectrum-Button").contains("Send").click({ force: true })
cy.get(interact.SPECTRUM_BUTTON).contains("Send").click({ force: true })
cy.wait("@queryError")
cy.wait(500)
// Assert against message and status for the query error

View File

@ -1,4 +1,5 @@
import filterTests from "../support/filterTests"
const interact = require('../support/interact')
filterTests(['all'], () => {
context("Rename an App", () => {
@ -17,7 +18,7 @@ filterTests(['all'], () => {
cy.reload()
cy.wait(1000)
cy.searchForApplication(appRename)
cy.get(".appTable").find(".title").should("have.length", 1)
cy.get(interact.APP_TABLE).find(interact.TITLE).should("have.length", 1)
cy.applicationInAppTable(appRename)
// Set app name back to Cypress Tests
cy.reload()
@ -30,18 +31,18 @@ filterTests(['all'], () => {
const appName = "Cypress Tests"
const appRename = "Cypress Renamed"
// Publish the app
cy.get(".toprightnav")
cy.get(".spectrum-Button").contains("Publish").click({ force: true })
cy.get(".spectrum-Dialog-grid")
cy.get(interact.TOP_RIGHT_NAV)
cy.get(interact.SPECTRUM_BUTTON).contains("Publish").click({ force: true })
cy.get(interact.SPECTRUM_DIALOG_GRID)
.within(() => {
// Click publish again within the modal
cy.get(".spectrum-Button").contains("Publish").click({ force: true })
cy.get(interact.SPECTRUM_BUTTON).contains("Publish").click({ force: true })
})
// Rename app, Search for app, Confirm name was changed
cy.visit(`${Cypress.config().baseUrl}/builder`)
cy.wait(500)
renameApp(appName, appRename, true)
cy.get(".appTable").find(".wrapper").should("have.length", 1)
cy.get(interact.APP_TABLE).find(interact.WRAPPER).should("have.length", 1)
cy.applicationInAppTable(appRename)
})
@ -52,7 +53,7 @@ filterTests(['all'], () => {
renameApp(appName, " ", false, true)
cy.wait(500)
// Close modal and confirm name has not been changed
cy.get(".spectrum-Dialog-grid").contains("Cancel").click()
cy.get(interact.SPECTRUM_DIALOG_GRID).contains("Cancel").click()
cy.reload()
cy.wait(1000)
cy.applicationInAppTable(appName)
@ -63,13 +64,13 @@ filterTests(['all'], () => {
const appName = "Cypress Tests"
cy.visit(`${Cypress.config().baseUrl}/builder`)
cy.wait(500)
cy.get(".spectrum-Button").contains("Create app").click({ force: true })
cy.get(interact.SPECTRUM_BUTTON).contains("Create app").click({ force: true })
cy.contains(/Start from scratch/).click()
cy.get(".spectrum-Modal")
cy.get(interact.SPECTRUM_MODAL)
.within(() => {
cy.get("input").eq(0).type(appName)
cy.get(".spectrum-ButtonGroup").contains("Create app").click({ force: true })
cy.get(".error").should("have.text", "Another app with the same name already exists")
cy.get(interact.SPECTRUM_BUTTON_GROUP).contains("Create app").click({ force: true })
cy.get(interact.ERROR).should("have.text", "Another app with the same name already exists")
})
})
@ -88,7 +89,7 @@ filterTests(['all'], () => {
cy.reload()
cy.wait(1000)
renameApp(numberName, specialCharName)
cy.get(".error").should("have.text", "App name must be letters, numbers and spaces only")
cy.get(interact.ERROR).should("have.text", "App name must be letters, numbers and spaces only")
// Set app name back to Cypress Tests
cy.reload()
cy.wait(1000)
@ -97,20 +98,20 @@ filterTests(['all'], () => {
const renameApp = (originalName, changedName, published, noName) => {
cy.searchForApplication(originalName)
cy.get(".appTable")
cy.get(interact.APP_TABLE)
.within(() => {
cy.get("[aria-label='More']").eq(0).click()
cy.get(interact.AREA_LABEL_MORE).eq(0).click()
})
// Check for when an app is published
if (published == true) {
// Should not have Edit as option, will unpublish app
cy.should("not.have.value", "Edit")
cy.get(".spectrum-Menu").contains("Unpublish").click()
cy.get(".spectrum-Dialog-grid").contains("Unpublish app").click()
cy.get(interact.SPECTRUM_MENU).contains("Unpublish").click()
cy.get(interact.SPECTRUM_DIALOG_GRID).contains("Unpublish app").click()
cy.get(".appTable > :nth-child(5) > :nth-child(2) > .spectrum-Icon").click()
}
cy.get("[data-cy='app-row-actions-menu-popover']").eq(0).within(() => {
cy.get(".spectrum-Menu-item").contains("Edit").click({ force: true })
cy.get(interact.APP_ROW_ACTION_MENU_POPOVER).eq(0).within(() => {
cy.get(interact.SPECTRUM_MENU_ITEMM).contains("Edit").click({ force: true })
})
cy.updateAppName(changedName, noName)

View File

@ -1,4 +1,5 @@
import filterTests from "../support/filterTests"
const interact = require('../support/interact')
filterTests(['smoke', 'all'], () => {
context("Revert apps", () => {
@ -9,15 +10,15 @@ filterTests(['smoke', 'all'], () => {
it("should try to revert an unpublished app", () => {
// Click revert icon
cy.get(".toprightnav").within(() => {
cy.get("[aria-label='Revert']").click({ force: true })
cy.get(interact.TOP_RIGHT_NAV).within(() => {
cy.get(interact.AREA_LABEL_REVERT).click({ force: true })
})
cy.get(".spectrum-Modal").within(() => {
cy.get(interact.SPECTRUM_MODAL).within(() => {
// Enter app name before revert
cy.get("input").type("Cypress Tests")
cy.intercept('**/revert').as('revertApp')
// Click Revert
cy.get(".spectrum-Button").contains("Revert").click({ force: true })
cy.get(interact.SPECTRUM_BUTTON).contains("Revert").click({ force: true })
// Intercept Request after button click & apply assertions
cy.wait("@revertApp")
cy.get("@revertApp").its('response.body').should('have.property', 'message', "App has not yet been deployed")
@ -31,43 +32,43 @@ filterTests(['smoke', 'all'], () => {
// Add initial component - Paragraph
cy.addComponent("Elements", "Paragraph")
// Publish app
cy.get(".spectrum-Button").contains("Publish").click({ force: true })
cy.get(".spectrum-ButtonGroup").within(() => {
cy.get(".spectrum-Button").contains("Publish").click({ force: true })
cy.get(interact.SPECTRUM_BUTTON).contains("Publish").click({ force: true })
cy.get(interact.SPECTRUM_BUTTON_GROUP).within(() => {
cy.get(interact.SPECTRUM_BUTTON).contains("Publish").click({ force: true })
})
cy.wait(1000)
cy.get(".spectrum-ButtonGroup").within(() => {
cy.get(".spectrum-Button").contains("Done").click({ force: true })
cy.get(interact.SPECTRUM_BUTTON_GROUP).within(() => {
cy.get(interact.SPECTRUM_BUTTON).contains("Done").click({ force: true })
})
// Add second component - Button
cy.addComponent("Elements", "Button")
// Click Revert
cy.get(".toprightnav").within(() => {
cy.get("[aria-label='Revert']").click({ force: true })
cy.get(interact.TOP_RIGHT_NAV).within(() => {
cy.get(interact.AREA_LABEL_REVERT).click({ force: true })
})
cy.get(".spectrum-Dialog-grid").within(() => {
cy.get(interact.SPECTRUM_DIALOG_GRID).within(() => {
// Click Revert
cy.get(".spectrum-Button").contains("Revert").click({ force: true })
cy.get(interact.SPECTRUM_BUTTON).contains("Revert").click({ force: true })
cy.wait(1000)
})
// Confirm Paragraph component is still visible
cy.get(".root").contains("New Paragraph")
cy.get(interact.ROOT).contains("New Paragraph")
// Confirm Button component is not visible
cy.get(".root").should("not.have.text", "New Button")
cy.get(interact.ROOT).should("not.have.text", "New Button")
cy.wait(500)
})
it("should enter incorrect app name when reverting", () => {
// Click Revert
cy.get(".toprightnav").within(() => {
cy.get("[aria-label='Revert']").click({ force: true })
cy.get(interact.TOP_RIGHT_NAV).within(() => {
cy.get(interact.AREA_LABEL_REVERT).click({ force: true })
})
// Enter incorrect app name
cy.get(".spectrum-Dialog-grid").within(() => {
cy.get(interact.SPECTRUM_DIALOG_GRID).within(() => {
cy.get("input").type("Cypress Tests")
// Revert button within modal should be disabled
cy.get(".spectrum-Button").eq(1).should('be.disabled')
cy.get(interact.SPECTRUM_BUTTON).eq(1).should('be.disabled')
})
})
})

View File

@ -104,3 +104,23 @@ export const SPECTRUM_TABLE_ROW = ".spectrum-Table-row"
export const SPECTRUM_TABLE_CELL = ".spectrum-Table-cell"
export const FIELD = ".field"
export const CONTAINER = ".container"
//createView
export const SPECTRUM_MENU_ITEM_LABEL = ".spectrum-Menu-itemLabel"
//revertApp
export const TOP_RIGHT_NAV = ".toprightnav"
export const AREA_LABEL_REVERT = "[aria-label=Revert]"
export const ROOT = ".root"
//quertLevelTransformers
export const SPECTRUM_TABS_ITEM = ".spectrum-Tabs-itemLabel"
export const CODEMIRROR_TEXTAREA = ".CodeMirror textarea"
//renemaApplication
export const WRAPPER = ".wrapper"
export const ERROR = ".error"
export const AREA_LABEL_MORE = "[aria-label=More]"
export const APP_ROW_ACTION_MENU_POPOVER =
'[data-cy="app-row-actions-menu-popover"]'
export const SPECTRUM_MENU_ITEMM = ".spectrum-Menu-item"