Re-working conditional logic to work better in cypress.
This commit is contained in:
parent
807379168e
commit
c8e08f293a
|
@ -5,11 +5,24 @@
|
||||||
// ***********************************************
|
// ***********************************************
|
||||||
//
|
//
|
||||||
|
|
||||||
function isFirstApp() {
|
export function checkIfElementExists(el) {
|
||||||
const firstAppHeader = Object.values(Cypress.$("h1")).filter(
|
return new Promise(resolve => {
|
||||||
$h1 => $h1.outerHTML && $h1.outerHTML.includes("Create your first app")
|
/// here if ele exists or not
|
||||||
)
|
cy.get("body").then(body => {
|
||||||
return firstAppHeader.length !== 0
|
const found = body.find(el)
|
||||||
|
console.log(found)
|
||||||
|
console.log(found.length)
|
||||||
|
if (found.length > 0) {
|
||||||
|
resolve(true)
|
||||||
|
} else {
|
||||||
|
resolve(false)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async function isFirstApp() {
|
||||||
|
return checkIfElementExists(".empty-wrapper")
|
||||||
}
|
}
|
||||||
|
|
||||||
Cypress.Commands.add("login", () => {
|
Cypress.Commands.add("login", () => {
|
||||||
|
@ -36,9 +49,10 @@ Cypress.Commands.add("login", () => {
|
||||||
|
|
||||||
Cypress.Commands.add("createApp", name => {
|
Cypress.Commands.add("createApp", name => {
|
||||||
cy.visit(`localhost:${Cypress.env("PORT")}/builder`)
|
cy.visit(`localhost:${Cypress.env("PORT")}/builder`)
|
||||||
// wait for init API calls on visit
|
cy.wait(500)
|
||||||
const buttonText = isFirstApp() ? "Create app" : "Create new app"
|
isFirstApp().then(isFirst => {
|
||||||
cy.wait(100)
|
console.log(isFirst)
|
||||||
|
const buttonText = isFirst ? "Create app" : "Create new app"
|
||||||
cy.contains(buttonText).click()
|
cy.contains(buttonText).click()
|
||||||
cy.get("body").then(() => {
|
cy.get("body").then(() => {
|
||||||
cy.get(".spectrum-Modal")
|
cy.get(".spectrum-Modal")
|
||||||
|
@ -52,17 +66,20 @@ Cypress.Commands.add("createApp", name => {
|
||||||
}).should("be.visible")
|
}).should("be.visible")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
Cypress.Commands.add("deleteApp", () => {
|
Cypress.Commands.add("deleteApp", () => {
|
||||||
cy.visit(`localhost:${Cypress.env("PORT")}/builder`)
|
cy.visit(`localhost:${Cypress.env("PORT")}/builder`)
|
||||||
cy.wait(1000)
|
cy.wait(1000)
|
||||||
|
|
||||||
if (!isFirstApp()) {
|
isFirstApp().then(isFirst => {
|
||||||
|
if (!isFirst) {
|
||||||
cy.get(".hoverable > use").click()
|
cy.get(".hoverable > use").click()
|
||||||
cy.contains("Delete").click()
|
cy.contains("Delete").click()
|
||||||
cy.get(".spectrum-Button--warning").click()
|
cy.get(".spectrum-Button--warning").click()
|
||||||
}
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
Cypress.Commands.add("createTestApp", () => {
|
Cypress.Commands.add("createTestApp", () => {
|
||||||
|
|
Loading…
Reference in New Issue