-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
finished writing test to add new todo using cypress
- Loading branch information
1 parent
289a540
commit 607be60
Showing
4 changed files
with
40 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,5 +24,6 @@ | |
"content": "alo alo w brazil", | ||
"done": false | ||
} | ||
] | ||
], | ||
"dogs": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,39 @@ | ||
describe("Todos feed", () => { | ||
const BASE_URL = "http://localhost:3000"; | ||
|
||
describe("/ - Todos feed", () => { | ||
it("renders the page after loading", () => { | ||
cy.visit("http://localhost:3000/") | ||
cy.visit(BASE_URL) | ||
}) | ||
|
||
it.only("creates a new todo after the user submits the form", () => { | ||
// 0 - Intercept backend calls | ||
cy.intercept("POST", `${BASE_URL}/api/todos`, (request) => { | ||
request.reply({ | ||
statusCode: 201, | ||
body: { | ||
todo: { | ||
"id": "04acb1b4-fc0b-44c9-822c-ea84efa31429", | ||
"date": "2024-06-02T16:40:41.761Z", | ||
"content": "Test todo", | ||
"done": false | ||
} | ||
} | ||
}) | ||
}).as("createTodo") | ||
|
||
// 1 - Visit the page | ||
cy.visit(BASE_URL); | ||
|
||
// 2 - Select input and type a new todo | ||
// const $inputAddTodo = cy.get("header > form > input"); Getting by cypress identifier | ||
const $inputAddTodo = cy.get("input[name='Add todo']") | ||
$inputAddTodo.type("Test todo"); | ||
|
||
// 3 - Click on the submit button | ||
const $btnAddTodo = cy.get("button[aria-label='Adicionar novo item']") | ||
$btnAddTodo.click(); | ||
|
||
// 4 - Test if a new todo appeared on the screen | ||
cy.get('tbody').contains("Test todo"); | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters