Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Expand Up @@ -49,12 +49,12 @@ describe("UI to Code", { tags: ["@tag.JS", "@tag.Binding"] }, () => {
agHelper.GetNClick(propPane._navigateToType("URL"));
agHelper.TypeText(
propPane._actionSelectorFieldByLabel("Enter URL"),
"https://www.appsmith.com",
"https://www.google.com",
);
agHelper.GetNClick(propPane._actionSelectorPopupClose);
propPane.ValidateJSFieldValue(
"onClick",
`{{showAlert('Hello!', '');navigateTo('https://www.appsmith.com', {}, 'SAME_WINDOW');}}`,
`{{showAlert('Hello!', '');navigateTo('https://www.google.com', {}, 'SAME_WINDOW');}}`,
Comment thread
sagar-qa007 marked this conversation as resolved.
);

// Add third action
Expand All @@ -80,7 +80,7 @@ describe("UI to Code", { tags: ["@tag.JS", "@tag.Binding"] }, () => {
// Validate the code
propPane.ValidateJSFieldValue(
"onClick",
`{{showAlert('Hello!', '');navigateTo('https://www.appsmith.com', {}, 'SAME_WINDOW');storeValue('secret-key', 'secret-value');copyToClipboard('text to copy');}}`,
`{{showAlert('Hello!', '');navigateTo('https://www.google.com', {}, 'SAME_WINDOW');storeValue('secret-key', 'secret-value');copyToClipboard('text to copy');}}`,
);

// Delete the third action
Expand All @@ -97,7 +97,7 @@ describe("UI to Code", { tags: ["@tag.JS", "@tag.Binding"] }, () => {
// Assert the code for the remaining actions
propPane.ValidateJSFieldValue(
"onClick",
`{{showAlert('Hello!', '');navigateTo('https://www.appsmith.com', {}, 'SAME_WINDOW');copyToClipboard('text to copy');}}`,
`{{showAlert('Hello!', '');navigateTo('https://www.google.com', {}, 'SAME_WINDOW');copyToClipboard('text to copy');}}`,
);

// Delete the first action
Expand All @@ -113,7 +113,7 @@ describe("UI to Code", { tags: ["@tag.JS", "@tag.Binding"] }, () => {
// Assert the code for the remaining actions
propPane.ValidateJSFieldValue(
"onClick",
`{{navigateTo('https://www.appsmith.com', {}, 'SAME_WINDOW');copyToClipboard('text to copy');}}`,
`{{navigateTo('https://www.google.com', {}, 'SAME_WINDOW');copyToClipboard('text to copy');}}`,
);
});

Expand All @@ -132,13 +132,13 @@ describe("UI to Code", { tags: ["@tag.JS", "@tag.Binding"] }, () => {
agHelper.GetNClick(propPane._navigateToType("URL"));
agHelper.TypeText(
propPane._actionSelectorFieldByLabel("Enter URL"),
"https://www.appsmith.com",
"https://www.google.com",
);
agHelper.GetNClick(propPane._actionSelectorPopupClose);

propPane.ValidateJSFieldValue(
"onClick",
`{{showAlert('Hello!', '');navigateTo('https://www.appsmith.com', {}, 'SAME_WINDOW');}}`,
`{{showAlert('Hello!', '');navigateTo('https://www.google.com', {}, 'SAME_WINDOW');}}`,
);

// Add third action
Expand All @@ -165,7 +165,7 @@ describe("UI to Code", { tags: ["@tag.JS", "@tag.Binding"] }, () => {

propPane.ValidateJSFieldValue(
"onClick",
`{{showAlert('Hello!', '');navigateTo('https://www.appsmith.com', {}, 'SAME_WINDOW');storeValue('secret-key', 'secret-value');copyToClipboard('text to copy');}}`,
`{{showAlert('Hello!', '');navigateTo('https://www.google.com', {}, 'SAME_WINDOW');storeValue('secret-key', 'secret-value');copyToClipboard('text to copy');}}`,
);

// Delete the third action
Expand Down Expand Up @@ -197,7 +197,7 @@ describe("UI to Code", { tags: ["@tag.JS", "@tag.Binding"] }, () => {

propPane.ValidateJSFieldValue(
"onClick",
`{{showAlert('Hello!', '');navigateTo('https://www.appsmith.com', {}, 'SAME_WINDOW');storeValue('secret-key', 'secret-value');copyToClipboard('text to copy');}}`,
`{{showAlert('Hello!', '');navigateTo('https://www.google.com', {}, 'SAME_WINDOW');storeValue('secret-key', 'secret-value');copyToClipboard('text to copy');}}`,
);
});

Expand All @@ -216,13 +216,13 @@ describe("UI to Code", { tags: ["@tag.JS", "@tag.Binding"] }, () => {
agHelper.GetNClick(propPane._navigateToType("URL"));
agHelper.TypeText(
propPane._actionSelectorFieldByLabel("Enter URL"),
"https://www.appsmith.com",
"https://www.google.com",
);
agHelper.GetNClick(propPane._actionSelectorPopupClose);

propPane.ValidateJSFieldValue(
"onClick",
`{{showAlert('Hello!', '');navigateTo('https://www.appsmith.com', {}, 'SAME_WINDOW');}}`,
`{{showAlert('Hello!', '');navigateTo('https://www.google.com', {}, 'SAME_WINDOW');}}`,
);

// Add third action
Expand All @@ -249,7 +249,7 @@ describe("UI to Code", { tags: ["@tag.JS", "@tag.Binding"] }, () => {

propPane.ValidateJSFieldValue(
"onClick",
`{{showAlert('Hello!', '');navigateTo('https://www.appsmith.com', {}, 'SAME_WINDOW');storeValue('secret-key', 'secret-value');copyToClipboard('text to copy');}}`,
`{{showAlert('Hello!', '');navigateTo('https://www.google.com', {}, 'SAME_WINDOW');storeValue('secret-key', 'secret-value');copyToClipboard('text to copy');}}`,
);

// Delete the third action
Expand Down Expand Up @@ -286,7 +286,7 @@ describe("UI to Code", { tags: ["@tag.JS", "@tag.Binding"] }, () => {

propPane.ValidateJSFieldValue(
"onClick",
`{{navigateTo('https://www.appsmith.com', {}, 'SAME_WINDOW');copyToClipboard('text to copy');}}`,
`{{navigateTo('https://www.google.com', {}, 'SAME_WINDOW');copyToClipboard('text to copy');}}`,
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ describe(
propPane.MoveToTab("Content");

[1, 2, 3, 4, 5].forEach(() => {
apiPage.CreateAndFillApi("https://www.appsmith.com/");
apiPage.CreateAndFillApi("https://www.google.com/");
Comment thread
sagar-qa007 marked this conversation as resolved.
});

EditorNavigation.SelectEntityByName("Table1", EntityType.Widget);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { REPO, CURRENT_REPO } from "../../../../fixtures/REPO";
import HomePage from "../../../../locators/HomePage";
import * as _ from "../../../../support/Objects/ObjectsCore";
import {
adminSettings,
agHelper,
assertHelper,
homePage,
} from "../../../../support/Objects/ObjectsCore";

describe(
"Create new workspace and invite user & validate all roles",
{ tags: [""] },
() => {
let testData: any;

// Read the CSV file before running the tests
before(() => {
cy.readFile(
"/Users/sagarkhalasi/codebase/appsmith/app/client/cypress/fixtures/testuserimport.csv",
).then((csvData) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Replace hardcoded file path with a relative path

The hardcoded absolute path will fail in different environments. Use a relative path from the fixtures directory.

-      cy.readFile(
-        "/Users/sagarkhalasi/codebase/appsmith/app/client/cypress/fixtures/testuserimport.csv",
-      ).then((csvData) => {
+      cy.fixture("testuserimport.csv").then((csvData) => {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
cy.readFile(
"/Users/sagarkhalasi/codebase/appsmith/app/client/cypress/fixtures/testuserimport.csv",
).then((csvData) => {
cy.fixture("testuserimport.csv").then((csvData) => {

const rows = csvData.split("\n"); // Split by newlines to get each row
const headers = rows[0].split(","); // The first row contains headers
console.log("Headers:", headers); // Debug headers
testData = [];
rows.slice(1).forEach((row) => {
const values = row.split(",");
console.log("Row data:", values); // Debug row data
const userObject: any = {};
headers.forEach((header, index) => {
const value = values[index]?.trim() || ""; // Avoid undefined value by providing a default empty string
userObject[header.trim()] = value;
});
testData.push(userObject); // Add user object to the data array
});
});
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add proper type definitions and error handling for CSV parsing

The CSV parsing logic lacks proper TypeScript types and error handling.

+    interface UserData {
+      user_email: string;
+      password: string;
+      jsonFilePath: string;
+    }
-    let testData: any;
+    let testData: UserData[];

     before(() => {
-      cy.readFile(
+      cy.fixture("testuserimport.csv").then((csvData: string) => {
         const rows = csvData.split("\n"); 
         const headers = rows[0].split(","); 
-        console.log("Headers:", headers);
         testData = [];
-        rows.slice(1).forEach((row) => {
+        rows.slice(1).filter(Boolean).forEach((row) => {
           const values = row.split(",");
-          console.log("Row data:", values);
-          const userObject: any = {};
+          const userObject: Partial<UserData> = {};
           headers.forEach((header, index) => {
             const value = values[index]?.trim() || "";
             userObject[header.trim()] = value;
           });
-          testData.push(userObject);
+          testData.push(userObject as UserData);
         });
       });
     });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let testData: any;
// Read the CSV file before running the tests
before(() => {
cy.readFile(
"/Users/sagarkhalasi/codebase/appsmith/app/client/cypress/fixtures/testuserimport.csv",
).then((csvData) => {
const rows = csvData.split("\n"); // Split by newlines to get each row
const headers = rows[0].split(","); // The first row contains headers
console.log("Headers:", headers); // Debug headers
testData = [];
rows.slice(1).forEach((row) => {
const values = row.split(",");
console.log("Row data:", values); // Debug row data
const userObject: any = {};
headers.forEach((header, index) => {
const value = values[index]?.trim() || ""; // Avoid undefined value by providing a default empty string
userObject[header.trim()] = value;
});
testData.push(userObject); // Add user object to the data array
});
});
});
interface UserData {
user_email: string;
password: string;
jsonFilePath: string;
}
let testData: UserData[];
// Read the CSV file before running the tests
before(() => {
cy.fixture("testuserimport.csv").then((csvData: string) => {
const rows = csvData.split("\n"); // Split by newlines to get each row
const headers = rows[0].split(","); // The first row contains headers
testData = [];
rows.slice(1).filter(Boolean).forEach((row) => {
const values = row.split(",");
const userObject: Partial<UserData> = {};
headers.forEach((header, index) => {
const value = values[index]?.trim() || ""; // Avoid undefined value by providing a default empty string
userObject[header.trim()] = value;
});
testData.push(userObject as UserData);
});
});
});


it("1. Login as and import the app as per file", () => {
testData.forEach((user) => {
console.log("JsonFilePath:", user.jsonFilePath); // This should print the string value
const resolvedJsonFilePath = user.jsonFilePath;
console.log("Resolved JsonFilePath:", resolvedJsonFilePath); // Log resolved file path
//homePage.NavigateToHome();
cy.go(-1)
agHelper.Sleep(5000);
cy.SignupFromAPI(
user.user_email,
user.password,
);
cy.wait(5000);
cy.go(-1)
cy.wait(5000);
cy.reload();
cy.wait(5000);
homePage.ImportApp(resolvedJsonFilePath);
cy.wait(5000);
cy.LogOut(false);
cy.wait(5000);
});
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove cy.wait() and implement proper assertions

The test case violates multiple Cypress best practices:

  1. Uses cy.wait() with hardcoded times
  2. Uses agHelper.Sleep()
  3. Lacks proper assertions
  4. Uses direct navigation with cy.go()
-    it("1. Login as and import the app as per file", () => {
+    it("should import apps for each user successfully", () => {
       testData.forEach((user) => {
-        console.log("JsonFilePath:", user.jsonFilePath);
-        const resolvedJsonFilePath = user.jsonFilePath;
-        console.log("Resolved JsonFilePath:", resolvedJsonFilePath);
-        cy.go(-1)
-        agHelper.Sleep(5000);
         cy.SignupFromAPI(
           user.user_email,
           user.password,
-        );
-        cy.wait(5000);
-        cy.go(-1)
-        cy.wait(5000);
-        cy.reload();
-        cy.wait(5000);
-        homePage.ImportApp(resolvedJsonFilePath);
-        cy.wait(5000);
+        ).should('be.ok');
+        
+        homePage.ImportApp(user.jsonFilePath)
+          .should('be.visible')
+          .and('contain', 'Import complete');
+        
         cy.LogOut(false);
-        cy.wait(5000);
+          .should('be.ok');
       });
     });

Committable suggestion skipped: line range outside the PR's diff.

},
);
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe(
"Block Action Execution when no field is present",
{ tags: ["@tag.Datasource"] },
() => {
const url = "https://www.appsmith.com/";
const url = "https://www.google.com/";
it("1. Ensure API Run button is disabled when no url is present", () => {
apiPage.CreateApi("FirstAPI", "GET");
apiPage.AssertRunButtonDisability(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe(
it("2. Shows when API failed to load on page load.", function () {
cy.fixture("testdata").then(function (dataSet: any) {
apiPage.CreateAndFillApi(
"https://www.appsmith.com/" + dataSet.methods,
"https://www.google.com/" + dataSet.methods,
Comment thread
sagar-qa007 marked this conversation as resolved.
"PageLoadApi2",
);
});
Expand Down