Skip to content

Instantly share code, notes, and snippets.

@divyasonaraa
Last active February 16, 2024 10:19
Show Gist options
  • Save divyasonaraa/d58f2d0c820c9d3fd420874f6bf17394 to your computer and use it in GitHub Desktop.
Save divyasonaraa/d58f2d0c820c9d3fd420874f6bf17394 to your computer and use it in GitHub Desktop.
import { selectors } from "../fixtures/selectors";
import { PATHS, LITERALS } from "../fixtures/constants";
const screenshotOptions = {
overwrite: true
};
describe("My ToDo App", () => {
beforeEach(() => {
cy.visit("/");
});
it("user can see the home page", () => {
cy.contains("h1", "You did it!");
// Screenshot a full page
cy.argosScreenshot("home-page", screenshotOptions);
})
it('should add a new ToDo item', () => {
cy.get('input[name="todo"]').type("Write e2e tests").should("have.value", "Write e2e tests");
cy.contains("Add").click();
cy.get("ul").contains("Write e2e tests").should("exist");
})
it('should mark a ToDo item as done', () => {
cy.get('input[name="todo"]').type("Complete e2e tests").should("have.value", "Complete e2e tests");
cy.contains("Add").click();
cy.get("input[name='todoDone']").check();
cy.contains("Complete e2e tests").should("have.css", "text-decoration", "line-through solid rgb(255, 255, 255)");
});
it('should delete a task', () => {
// Add a task first
const newTodoText = 'New Task'
cy.get('input[name="todo"]').type(newTodoText)
cy.get('button').contains('Add').click()
cy.contains('li', newTodoText).should('exist')
// Now delete the task
cy.contains('li', newTodoText)
.parent()
.find('button')
.contains('DELETE')
.click()
cy.contains('li', newTodoText).should('not.exist')
})
});
describe("Navigate to Counter Page", () => {
beforeEach(() => {
cy.visit("/");
});
it("user can goes to the conter page", () => {
cy.get(selectors.COUNTER.NAV_BUTTON).click({
force: true
});
cy.location("pathname").should("include", PATHS.COUNTER);
cy.contains(`${LITERALS.CURRENT_COUNTER} 0`);
});
})
describe("Counter Page", () => {
beforeEach(() => {
cy.visit("/counter");
cy.get("button").contains("+1").as("buttonIncrement");
cy.get("button").contains("Reset").as("buttonReset");
});
it("user can ingrement once the counter", () => {
cy.get("@buttonIncrement").click();
cy.contains(`${LITERALS.CURRENT_COUNTER} 1`);
});
it("user can ingrement +2 the counter", () => {
cy.get("@buttonIncrement").click().click();
cy.contains(`${LITERALS.CURRENT_COUNTER} 2`);
cy.screenshot(screenshotOptions);
});
it("user can reset the counter", () => {
cy.get("@buttonReset").click();
cy.contains(`${LITERALS.CURRENT_COUNTER} 0`);
cy.screenshot(screenshotOptions);
});
});
export const PATHS = {
COUNTER: "counter",
};
export const LITERALS = {
CURRENT_COUNTER: "Current count is",
};
export const selectors = {
COUNTER: {
NAV_BUTTON: "a[data-testid='Counter']",
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment