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,21 +49,23 @@ 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)
|
||||||
cy.contains(buttonText).click()
|
const buttonText = isFirst ? "Create app" : "Create new app"
|
||||||
cy.get("body").then(() => {
|
cy.contains(buttonText).click()
|
||||||
cy.get(".spectrum-Modal")
|
cy.get("body").then(() => {
|
||||||
.within(() => {
|
cy.get(".spectrum-Modal")
|
||||||
cy.get("input").eq(0).type(name).should("have.value", name).blur()
|
.within(() => {
|
||||||
cy.contains("Create app").click()
|
cy.get("input").eq(0).type(name).should("have.value", name).blur()
|
||||||
})
|
cy.contains("Create app").click()
|
||||||
.then(() => {
|
})
|
||||||
cy.get("[data-cy=new-table]", {
|
.then(() => {
|
||||||
timeout: 20000,
|
cy.get("[data-cy=new-table]", {
|
||||||
}).should("be.visible")
|
timeout: 20000,
|
||||||
})
|
}).should("be.visible")
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -58,11 +73,13 @@ 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 => {
|
||||||
cy.get(".hoverable > use").click()
|
if (!isFirst) {
|
||||||
cy.contains("Delete").click()
|
cy.get(".hoverable > use").click()
|
||||||
cy.get(".spectrum-Button--warning").click()
|
cy.contains("Delete").click()
|
||||||
}
|
cy.get(".spectrum-Button--warning").click()
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
Cypress.Commands.add("createTestApp", () => {
|
Cypress.Commands.add("createTestApp", () => {
|
||||||
|
|
Loading…
Reference in New Issue