This is a calendar check. For example: 100 days of history is available but 101 days back would be disabled for certain market.
Code is following:
const todaysDate3 = dayjs().subtract(101, 'days').format('DD')
const todaysDate4 = dayjs().subtract(100, 'days').format('DD') //etc
cy.visit(`http://calendar.whatever/ICN&markettype=ICN`);
cy.get('.calendar-table').click
cy.get('.calendar-table').contains('td',(todaysDate3)).should("have.class","disabled")
cy.get('.calendar-table').contains('td',(todaysDate4)).should("have.class","enabled")
What would be the best practice to make such test for 80, 100, 365 etc days as every market. Worst case scenario I can think of is something like
export const 100days = [{
"url": (`http://calendar.whatever/ICN`),
"has100days": true
}]
and like this for every possible value and using
if (curr.has100days) //do something } else if (curr.has365days){do something else}
Probably best would be to write some kind of function?
thank you for your help!
You can do something like this:
cy.get('.calendar-table')
.find('td')
.then(($ele) => {
if ($ele.text().includes(todaysDate3)) {
cy.wrap($ele).should('have.class', 'disabled')
//Do Something
} else if ($ele.text().includes(todaysDate4)) {
cy.wrap($ele).should('have.class', 'enabled')
//Do Something
} else {
//Do something
}
})
Since you visit each market, the data-driven approach you indicate is best.
const history = [
{ market: 'ICN', days: 100 },
{ market: 'ZYX', days: 120 },
...
]
history.forEach(data => {
cy.log(`Testing ${data.market} with ${data.days} history`)
cy.visit(`http://calendar.whatever/ICN&markettype=${data.market}`)
const outsideHistory = dayjs().subtract(data.days+1, 'days')
.format('D') // no leading '0'
const insideHistory = dayjs().subtract(data.days, 'days')
.format('D') // no leading '0'
const outsideHistoryRegex = new RegExp(`^${outsideHistory}`) // ^ = startsWith
const insideHistoryRegex = new RegExp(`^${insideHistory}`)
cy.get('.calendar-table').click
cy.get('.calendar-table').contains('td', outsideHistoryRegex)
.last()
.should("have.class","disabled")
cy.get('.calendar-table').contains('td', insideHistoryRegex)
.last()
.should("have.class","enabled")
}
I'm assuming you only want to check the history boundary for each market, but if you want to check multiple dates per market
const history = [
{ market: 'ICN', days: 85 },
{ market: 'ICN', days: 100 },
{ market: 'ICN', days: 365 },
{ market: 'ZYX', days: 120 },
...
]
// Same function...