Skip to content
Closed
Show file tree
Hide file tree
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
160 changes: 160 additions & 0 deletions app/client/cypress/e2e/Regression/ClientSide/Git/MergeBranch_spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
import commonLocators from "../../../../locators/commonlocators.json";

import {
agHelper,
entityExplorer,
jsEditor,
deployMode,
gitSync,
apiPage,
dataSources,
assertHelper,
locators,
appSettings,
} from "../../../../support/Objects/ObjectsCore";
import EditorNavigation, {
EntityType,
PageLeftPane,
PagePaneSegment,
} from "../../../../support/Pages/EditorNavigation";
import PageList from "../../../../support/Pages/PageList";

let repoName;
let demoBranch: any;
describe("Git Branch:", {}, function () {
before(() => {
gitSync.CreateNConnectToGit();
cy.get("@gitRepoName").then((repName) => {
repoName = repName;
});
});

it("1. Verify branch with same name cannot be created", function () {
gitSync.CreateGitBranch("Test_Branch");
gitSync.verifyNoDuplicateBranch("Test_Branch");
});

it("2. Verify delete branch", function () {
gitSync.CreateGitBranch("Demo", true);
gitSync.GetCurrentBranchName().then((branchName: any) => {
cy.wrap(demoBranch).as("demoBranch");
demoBranch = branchName;
gitSync.SwitchGitBranch("master");
Comment on lines +40 to +42
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Fix the variable wrapping and assignment logic

The current implementation appears to be wrapping a variable before it's assigned, which is incorrect.

-      cy.wrap(demoBranch).as("demoBranch");
-      demoBranch = branchName;
+      demoBranch = branchName;
+      cy.wrap(demoBranch).as("demoBranch");
📝 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.wrap(demoBranch).as("demoBranch");
demoBranch = branchName;
gitSync.SwitchGitBranch("master");
demoBranch = branchName;
cy.wrap(demoBranch).as("demoBranch");
gitSync.SwitchGitBranch("master");

DeleteBranchFromUI(demoBranch);
cy.wait(5000);
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Replace explicit wait with proper assertions

Using explicit waits like cy.wait(5000) is against the coding guidelines. Replace with appropriate assertions or waitUntil.

-      cy.wait(5000);
+      agHelper.AssertElementVisibility(gitSync.locators.quickActionsBranchBtn);
+      // Or use a more specific assertion that confirms the UI is ready
📝 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.wait(5000);
agHelper.AssertElementVisibility(gitSync.locators.quickActionsBranchBtn);
// Or use a more specific assertion that confirms the UI is ready

gitSync.SwitchGitBranch(`origin/${demoBranch}`);

// Verify cannot delete checked out branch
// DeleteBranchFromUI(demoBranch);
// agHelper.ValidateToastMessage("Cannot delete checked out branch.");
// cy.wait(5000)
});
});

it("3. Verify merge branch", function () {
gitSync.CreateGitBranch("Demo1", true);
PageList.AddNewPage();
gitSync.CommitAndPush();
cy.wait(3000);
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Replace explicit wait with proper assertions

Using explicit waits like cy.wait(3000) is against the coding guidelines. Replace with appropriate assertions or waitUntil.

-    cy.wait(3000);
+    agHelper.WaitUntilElementVisible(gitSync.locators.quickActionsCommitBtn);
+    // Or use a more specific assertion that confirms the UI is ready
📝 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.wait(3000);
agHelper.WaitUntilElementVisible(gitSync.locators.quickActionsCommitBtn);
// Or use a more specific assertion that confirms the UI is ready

cy.then(() => {
gitSync.CheckMergeConflicts(demoBranch);
agHelper.GetNClick(gitSync.locators.opsMergeBtn);
assertHelper.AssertNetworkStatus("@mergeBranch");
gitSync.CloseOpsModal();
gitSync.SwitchGitBranch(demoBranch);
PageList.assertPresence("Page2");
});
});

it("4. Verify merge branch with new query", function () {
gitSync.SwitchGitBranch("Demo1");
dataSources.CreateMockDB("Users");
dataSources.CreateQueryAfterDSSaved("select * from users limit 10");
dataSources.RunQuery();
gitSync.CommitAndPush();
cy.then(() => {
gitSync.CheckMergeConflicts(demoBranch);
agHelper.GetNClick(gitSync.locators.opsMergeBtn);
assertHelper.AssertNetworkStatus("@mergeBranch");
gitSync.CloseOpsModal();
gitSync.SwitchGitBranch(demoBranch);
EditorNavigation.NavigateToPage("Page2", true);
PageLeftPane.switchSegment(PagePaneSegment.Queries);
agHelper.AssertElementVisibility(locators._entityTestId("Query1"));
});
});

it("5. Verify merge branch with new JS object", function () {
gitSync.SwitchGitBranch("Demo1");
EditorNavigation.NavigateToPage("Page2", true);
jsEditor.CreateJSObject('return "Success";');
gitSync.CommitAndPush();
cy.then(() => {
gitSync.CheckMergeConflicts(demoBranch);
agHelper.GetNClick(gitSync.locators.opsMergeBtn);
assertHelper.AssertNetworkStatus("@mergeBranch");
gitSync.CloseOpsModal();
gitSync.SwitchGitBranch(demoBranch);
EditorNavigation.NavigateToPage("Page2", true);
PageLeftPane.switchSegment(PagePaneSegment.JS);
agHelper.AssertElementVisibility(locators._entityTestId("JSObject1"));
});
});

it("6. Verify merge branch with theme change", function () {
gitSync.SwitchGitBranch("Demo1");
appSettings.OpenAppSettings();
appSettings.GoToThemeSettings();
cy.get(commonLocators.changeThemeBtn).click({ force: true });
agHelper.AssertAutoSave();
// select a theme
cy.get(commonLocators.themeCard).last().click({ force: true });
agHelper.AssertAutoSave();
// check for alert
cy.get(`${commonLocators.themeCard}`)
.last()
.siblings("div")
.first()
.invoke("text")
.then((text) => {
cy.get(commonLocators.toastmsg).contains(`Theme ${text} applied`);
});

// check if color of canvas is same as theme bg color
cy.get(`${commonLocators.themeCard} > main`)
.last()
.invoke("css", "background-color")
.then((backgroudColor) => {
cy.get(commonLocators.canvas).should(
"have.css",
"background-color",
backgroudColor,
);

gitSync.CommitAndPush();
cy.then(() => {
gitSync.CheckMergeConflicts(demoBranch);
agHelper.GetNClick(gitSync.locators.opsMergeBtn);
assertHelper.AssertNetworkStatus("@mergeBranch");
gitSync.CloseOpsModal();
gitSync.SwitchGitBranch(demoBranch);
cy.get(commonLocators.canvas).should(
"have.css",
"background-color",
backgroudColor,
);
});
});
});

function DeleteBranchFromUI(branch: any) {
cy.get(gitSync.locators.quickActionsBranchBtn).click();
agHelper.HoverElement(
`${gitSync.locators.branchItem}:contains('${branch}')`,
);
cy.get(gitSync.locators.branchItemMenuBtn).click({ force: true });
cy.get(gitSync.locators.branchItemMenuDeleteBtn)
.should("be.visible")
.click({ force: true });
}
Comment on lines +150 to +159
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use data- attributes in DeleteBranchFromUI function*

The function uses CSS contains selector rather than data attributes, which goes against guidelines.

function DeleteBranchFromUI(branch: any) {
  cy.get(gitSync.locators.quickActionsBranchBtn).click();
-  agHelper.HoverElement(
-    `${gitSync.locators.branchItem}:contains('${branch}')`,
-  );
+  // Use a more appropriate selector without :contains
+  agHelper.HoverElement(gitSync.locators.branchItem);
+  // Use agHelper methods that target elements by text content instead
  cy.get(gitSync.locators.branchItemMenuBtn).click({ force: true });
  cy.get(gitSync.locators.branchItemMenuDeleteBtn)
    .should("be.visible")
    .click({ force: true });
}

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

});
4 changes: 2 additions & 2 deletions app/client/cypress/limited-tests.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# To run only limited tests - give the spec names in below format:
#cypress/e2e/Regression/ClientSide/VisualTests/JSEditorIndent_spec.js
cypress/e2e/Regression/ClientSide/Git/MergeBranch_spec.ts
# For running all specs - uncomment below:
#cypress/e2e/**/**/*
cypress/e2e/Regression/ClientSide/Anvil/Widgets/*
#cypress/e2e/Regression/ClientSide/Anvil/Widgets/*

#ci-test-limit uses this file to run minimum of specs. Do not run entire suite with this command.
26 changes: 26 additions & 0 deletions app/client/cypress/support/Pages/GitSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export class GitSync {
repoLimitErrorModalDisconnectLink:
"[data-testid='t--git-repo-limit-error-disconnect-link']",
deployMenuConnect: "[data-testid='t--git-deploy-menu-connect']",
createNewBranchButton: ".t--create-new-branch-button",
};

public OpenConnectModal() {
Expand Down Expand Up @@ -536,4 +537,29 @@ export class GitSync {
.invoke("get", "branch")
.should("equal", branch);
}

public verifyNoDuplicateBranch(branch = "br") {
this.agHelper.AssertElementVisibility(this.locators.quickActionsPullBtn);
this.agHelper.AssertElementExist(this.locators.quickActionsCommitBtn);
cy.waitUntil(
() => {
this.agHelper.GetNClick(this.locators.quickActionsBranchBtn, 0, true);
if (this.agHelper.IsElementVisible(this.locators.branchSearchInput)) {
return true; //visible, return true to stop waiting
}
return false; //not visible, return false to continue waiting
},
{ timeout: Cypress.config("pageLoadTimeout") },
);
cy.get("@guid").then((uid) => {
this.agHelper.TypeText(
this.locators.branchSearchInput,
`{selectall}` + `${branch + uid}`,
{ parseSpecialCharSeq: true },
);
});

this.agHelper.AssertElementAbsence(this.locators.createNewBranchButton);
this.agHelper.GetNClick(this.locators.branchCloseBtn);
}
}
Loading