Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {
agHelper,
apiPage,
dataManager,
entityExplorer,
jsEditor,
propPane,
Expand Down Expand Up @@ -76,18 +78,25 @@ describe("Tests fetch calls", { tags: ["@tag.JS"] }, () => {
});

it("3. Tests if fetch works with store value", function () {
apiPage.CreateAndFillApi(
dataManager.dsValues[dataManager.defaultEnviorment].mockGenderAge +
`{{this.params.person}}`,
"Gender_Age",
);
apiPage.RunAPI();
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))}}`,
`{{(async function(){
const gender = await Gender_Age.run({ person: "sagar" });
storeValue("Gender", gender);
showAlert("Your name is " + appsmith.store.Gender.name);
})()}}`,
);
agHelper.Sleep(2000);
agHelper.ClickButton("getUserID");
agHelper.AssertContains("UserId: 1", "exist");

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Avoid using agHelper.Sleep(), utilize proper synchronization methods

Class, it's important to remember that using agHelper.Sleep() is discouraged in our testing code. Relying on arbitrary sleep durations can lead to flaky tests and inefficient execution.

Please consider removing agHelper.Sleep(2000); and instead use Cypress's built-in commands for synchronization. For instance, you can use cy.wait() with aliases to wait for specific network calls or cy.get() to wait for elements to appear before interacting with them.

agHelper.ClickButton("getUserName");
agHelper.AssertContains("Your name is sagar", "exist");
});
});