1
0
Fork 0
mirror of synced 2024-06-18 18:35:37 +12:00

Re-working conditional logic to work better in cypress.

This commit is contained in:
mike12345567 2021-06-01 14:29:25 +01:00
parent 231bd36189
commit 24d58f0c7c

View file

@ -5,11 +5,24 @@
// ***********************************************
//
function isFirstApp() {
const firstAppHeader = Object.values(Cypress.$("h1")).filter(
$h1 => $h1.outerHTML && $h1.outerHTML.includes("Create your first app")
)
return firstAppHeader.length !== 0
export function checkIfElementExists(el) {
return new Promise(resolve => {
/// here if ele exists or not
cy.get("body").then(body => {
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", () => {
@ -36,21 +49,23 @@ Cypress.Commands.add("login", () => {
Cypress.Commands.add("createApp", name => {
cy.visit(`localhost:${Cypress.env("PORT")}/builder`)
// wait for init API calls on visit
const buttonText = isFirstApp() ? "Create app" : "Create new app"
cy.wait(100)
cy.contains(buttonText).click()
cy.get("body").then(() => {
cy.get(".spectrum-Modal")
.within(() => {
cy.get("input").eq(0).type(name).should("have.value", name).blur()
cy.contains("Create app").click()
})
.then(() => {
cy.get("[data-cy=new-table]", {
timeout: 20000,
}).should("be.visible")
})
cy.wait(500)
isFirstApp().then(isFirst => {
console.log(isFirst)
const buttonText = isFirst ? "Create app" : "Create new app"
cy.contains(buttonText).click()
cy.get("body").then(() => {
cy.get(".spectrum-Modal")
.within(() => {
cy.get("input").eq(0).type(name).should("have.value", name).blur()
cy.contains("Create app").click()
})
.then(() => {
cy.get("[data-cy=new-table]", {
timeout: 20000,
}).should("be.visible")
})
})
})
})
@ -58,11 +73,13 @@ Cypress.Commands.add("deleteApp", () => {
cy.visit(`localhost:${Cypress.env("PORT")}/builder`)
cy.wait(1000)
if (!isFirstApp()) {
cy.get(".hoverable > use").click()
cy.contains("Delete").click()
cy.get(".spectrum-Button--warning").click()
}
isFirstApp().then(isFirst => {
if (!isFirst) {
cy.get(".hoverable > use").click()
cy.contains("Delete").click()
cy.get(".spectrum-Button--warning").click()
}
})
})
Cypress.Commands.add("createTestApp", () => {