remix-demo

react router (remix) demo

git clone https://9o.is/git/remix-demo.git

smoke.cy.ts

(2924B)


      1 
      2 function loginAsAdmin() {
      3   cy.get("#email").type("julio@example.com");
      4   cy.get("button[type=submit]").click();
      5 }
      6 
      7 describe("Smoke Tests", () => {
      8   it("Login Page", () => {
      9     cy.visitAndCheck("/");
     10     cy.get("h1").should("have.text", "Log In to Account");
     11     cy.get("#email").type("julio");
     12     cy.get("button[type=submit]").click();
     13     cy.get("#email-error").should("have.text", "Must be a valid email");
     14     cy.get("#email").clear();
     15     cy.get("#email").click();
     16     cy.get("#email-error").should("have.text", "Email is required");
     17     cy.get("#email").type("julio@example.org");
     18     cy.get("button[type=submit]").click();
     19     cy.get("#email-error").should("have.text", "Email does not exist");
     20     cy.get("#email").clear();
     21     cy.get("#email").type("julio@example.com");
     22     cy.get("button[type=submit]").click();
     23   });
     24 
     25   it("Food Entries Page", () => {
     26     cy.visitAndCheck("/");
     27     loginAsAdmin();
     28 
     29     cy.url().should("include", "/food-entries");
     30     cy.get("h1").should("have.text", "Food Entries");
     31     cy.get('a[href="/food-entries/new"]').click();
     32     cy.url().should("include", "/food-entries/new");
     33     cy.go("back");
     34     cy.get("h2").should("have.text", "Food Entry History");
     35   });
     36 
     37   it("Add/Edit/Delete Food Entry", () => {
     38     cy.visitAndCheck("/");
     39     loginAsAdmin();
     40 
     41     cy.get('a[href="/food-entries/new"]').click();
     42     cy.get("h2").should("have.text", "Food Entry History");
     43     cy.get('label[for="name"]').should("have.text", "Food Name");
     44     cy.get('label[for="calories"]').should("have.text", "Calories");
     45     cy.get('label[for="consumed"]').should("have.text", "Date Consumed");
     46     cy.get('label[for="userId"]').should("have.text", "User ID");
     47 
     48     cy.get("#name").click();
     49     cy.get("#calories").click();
     50     cy.get("#name-error").should("have.text", "Food name is required");
     51 
     52     cy.get("#name").click();
     53     cy.get("#calories-error").should("have.text", "Calories is required");
     54 
     55     cy.get("#calories").clear();
     56     cy.get("#calories").type("-1");
     57     cy.get("#calories-error").should(
     58       "have.text",
     59       "Calories is a non-negative number"
     60     );
     61 
     62     cy.get("#calories").clear();
     63     cy.get("#name").clear();
     64     cy.get('#name').type('dried pear');
     65     cy.get('#calories').type('0');
     66     cy.get('button[data-cy="add-food"]').click();
     67     cy.get('[data-cy="dried pear"]').should("contain", "dried pear");
     68     cy.get('[data-cy="dried pear"]').should("contain", "0 cals");
     69     cy.get('[data-cy="dried pear"]').should("contain", "by Julio");
     70 
     71     cy.get('[data-cy="dried pear"] a[aria-label="Edit dried pear"]').click();
     72     cy.get("#calories").clear();
     73     cy.get("#calories").type("1");
     74     cy.get('button[data-cy="edit-food"]').click();
     75     cy.get('[data-cy="dried pear"]').should("contain", "1 cals");
     76     cy.get('[data-cy="dried pear"]').should("not.contain", "0 cals");
     77 
     78     cy.get('[data-cy="dried pear"] button[aria-label="Remove dried pear"]').click();
     79   });
     80 });