-
Notifications
You must be signed in to change notification settings - Fork 4.6k
chore: fetch spec with removed third party #36636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
4b38812
38b475b
7180da3
0ab5d31
20018d4
a49d01f
d71687c
c9a584a
3a3ab54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,16 +78,28 @@ describe("Tests fetch calls", { tags: ["@tag.JS"] }, () => { | |
| it("3. Tests if fetch works with store value", function () { | ||
| entityExplorer.DragDropWidgetNVerify("buttonwidget", 500, 200); | ||
| EditorNavigation.SelectEntityByName("Button1", EntityType.Widget); | ||
| propPane.TypeTextIntoField("Label", "getUserID"); | ||
| propPane.TypeTextIntoField("Label", "getUserName"); | ||
| propPane.EnterJSContext( | ||
| "onClick", | ||
| `{{fetch('https://jsonplaceholder.typicode.com/todos/1') | ||
| .then(res => res.json()) | ||
| .then(json => storeValue('userId', json.userId)) | ||
| .then(() => showAlert("UserId: " + appsmith.store.userId))}}`, | ||
| `{{fetch('http://host.docker.internal:5001/v1/genderize_agify?name=sagar') | ||
| .then(res => { | ||
| if (!res.ok) { | ||
| throw new Error('Network response was not ok'); | ||
| } | ||
| return res.json(); | ||
| }) | ||
| .then(json => { | ||
| const name = json.name; // Get the name | ||
| showAlert("Name: " + name); | ||
| }) | ||
| .catch(error => { | ||
| console.error("Fetch error:", error); | ||
| showAlert("Failed to fetch user data: " + error.message); | ||
| })}}` | ||
| ); | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid using Class, it's important to remember that using Please consider removing |
||
| agHelper.Sleep(2000); | ||
| agHelper.ClickButton("getUserID"); | ||
| agHelper.AssertContains("UserId: 1", "exist"); | ||
| agHelper.ClickButton("getUserName"); | ||
| agHelper.AssertContains("Name: sagar", "exist"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Let's improve our button selection and assertion, class. While clicking the button and asserting the result is good, we can make it even better:
These changes will make our test more robust and easier to maintain. Remember, in Cypress, we always strive for clear, reliable selectors and assertions! |
||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Excellent work on improving the fetch call, but let's refine it further.
I'm impressed with the improvements you've made to the fetch call. The error handling is a great addition, showing good attention to potential issues. However, we need to make a few adjustments:
showAlert, let's use Cypress commands for assertions. This will make our tests more robust and easier to debug.Here's how we could improve this:
This approach uses Cypress commands for assertions and network interception, making our test more reliable and easier to maintain.