Skip to content
Merged
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 @@ -18,6 +18,8 @@ describe("Embed settings options", { tags: ["@tag.Settings"] }, function () {
);
};

let clipboardData;

function ValidateEditModeSetting(setting) {
_.deployMode.NavigateBacktoEditor();
_.embedSettings.OpenEmbedSettings();
Expand All @@ -31,6 +33,7 @@ describe("Embed settings options", { tags: ["@tag.Settings"] }, function () {
}

before(() => {
_.agHelper.GiveChromeCopyPermission();
_.homePage.NavigateToHome();
_.homePage.CreateNewApplication();
_.entityExplorer.DragDropWidgetNVerify(_.draggableWidgets.IFRAME);
Expand All @@ -48,9 +51,25 @@ describe("Embed settings options", { tags: ["@tag.Settings"] }, function () {
.click()
.wait(1000);
_.agHelper.ClickButton("Copy application url");

cy.window().then((win) => {
cy.stub(win.navigator.clipboard, "writeText").as("deployUrl").resolves();
new Cypress.Promise((resolve, reject) => {
win.navigator.clipboard
.readText()
.then(resolve)
.catch(reject);
}).then((text) => {
clipboardData = text; // Store the clipboard content in a variable
cy.log(`Clipboard Content: ${clipboardData}`); // Log clipboard content
expect(clipboardData).to.equal("Expected clipboard text"); // Add assertions if needed
});
});

// Log clipboard data after it's been set
cy.then(() => {
cy.log(`Stored Clipboard Data: ${clipboardData}`);
});

Comment on lines +54 to +69

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

Refactor clipboard handling to follow best practices.

Several issues need to be addressed:

  1. Avoid hardcoded assertion strings
  2. Complex Promise handling could be simplified
  3. Remove unnecessary logging
- cy.window().then((win) => {
-   new Cypress.Promise((resolve, reject) => {
-     win.navigator.clipboard
-       .readText()
-       .then(resolve)
-       .catch(reject);
-   }).then((text) => {
-     clipboardData = text;
-     cy.log(`Clipboard Content: ${clipboardData}`);
-     expect(clipboardData).to.equal("Expected clipboard text");
-   });
- });
- 
- cy.then(() => {
-   cy.log(`Stored Clipboard Data: ${clipboardData}`);
- });

+ cy.window().then((win) => {
+   return win.navigator.clipboard.readText();
+ }).then((text) => {
+   clipboardData = text;
+   expect(clipboardData).to.be.a('string').and.not.be.empty;
+ });
📝 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.window().then((win) => {
cy.stub(win.navigator.clipboard, "writeText").as("deployUrl").resolves();
new Cypress.Promise((resolve, reject) => {
win.navigator.clipboard
.readText()
.then(resolve)
.catch(reject);
}).then((text) => {
clipboardData = text; // Store the clipboard content in a variable
cy.log(`Clipboard Content: ${clipboardData}`); // Log clipboard content
expect(clipboardData).to.equal("Expected clipboard text"); // Add assertions if needed
});
});
// Log clipboard data after it's been set
cy.then(() => {
cy.log(`Stored Clipboard Data: ${clipboardData}`);
});
cy.window().then((win) => {
return win.navigator.clipboard.readText();
}).then((text) => {
clipboardData = text;
expect(clipboardData).to.be.a('string').and.not.be.empty;
});

cy.enablePublicAccess();
cy.wait(8000); //adding wait time for iframe to load fully!
_.agHelper.RefreshPage();
Expand All @@ -67,10 +86,8 @@ describe("Embed settings options", { tags: ["@tag.Settings"] }, function () {
cy.get(adminSettings.saveButton).click();
cy.waitForServerRestart();
_.agHelper.Sleep(2000);
cy.get("@deployUrl").then((depUrl) => {
cy.log("deployUrl is " + depUrl);
cy.visit(depUrl, { timeout: 60000 });
});

cy.visit(clipboardData, { timeout: 60000 });
Comment thread
sagar-qa007 marked this conversation as resolved.
getIframeBody().contains("Submit").should("exist");
ValidateEditModeSetting(_.embedSettings.locators._restrictedText);
// });
Expand All @@ -84,10 +101,7 @@ describe("Embed settings options", { tags: ["@tag.Settings"] }, function () {
cy.get(adminSettings.saveButton).click();
cy.waitForServerRestart();
_.agHelper.Sleep(2000);
cy.get("@deployUrl").then((depUrl) => {
cy.log("deployUrl is " + depUrl);
cy.visit(depUrl, { timeout: 60000 });
});
cy.visit(clipboardData, { timeout: 60000 });
getIframeBody().contains("Submit").should("exist");
ValidateEditModeSetting(_.embedSettings.locators._allowAllText);
// });
Expand All @@ -98,13 +112,11 @@ describe("Embed settings options", { tags: ["@tag.Settings"] }, function () {
cy.get(".t--admin-settings-APPSMITH_ALLOWED_FRAME_ANCESTORS").within(() => {
cy.get("input").last().click();
});

cy.get(adminSettings.saveButton).click();
cy.waitForServerRestart();
_.agHelper.Sleep(2000);
cy.get("@deployUrl").then((depUrl) => {
cy.log("deployUrl is " + depUrl);
cy.visit(depUrl, { timeout: 60000 });
});
cy.visit(clipboardData, { timeout: 60000 });
getIframeBody().contains("Submit").should("not.exist");

ValidateEditModeSetting(_.embedSettings.locators._disabledText);
Expand Down