How do I best test a greeting message that says Good Morning/Afternoon/Evening based on the time the test is run. I'm new to cypress, I've searched for this but could not find examples for this. Is there a better approach than what I'm done?
it("verify correct greeting message is displayed", () => {
const now = new Date(Date.now())
const hours = now.getHours()
cy.wrap(hours).then(($time) => {
if ($time < 12)
cy.findByTestId("greeting").should("have.text", "Good Morning")
else if ($time >= 12 && $time < 17)
cy.findByTestId("greeting").should("have.text", "Good Afternoon")
else
cy.findByTestId("greeting").should("have.text", "Good Evening")
})
})