## Description Git Cy test cleanup Doc https://www.notion.so/appsmith/Cypress-Git-Tests-Full-Migration-Plan-Technical-Migration-Document-21cfe271b0e2808e9bbfc52ff3f271d1?source=copy_link Fixes https://github.com/appsmithorg/appsmith/issues/41116 ## Automation /ok-to-test tags="@tag.Git" ### 🔍 Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/16609928353> > Commit: c44fe06457377789cee38114e809e7ce842a3870 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=16609928353&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.Git` > Spec: > <hr>Wed, 30 Jul 2025 00:46:28 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [ ] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Updated test intercepts and network request patterns to use new Git API endpoint structures. * Adjusted feature flag logic to enable a new Git API contracts flag for relevant tests. * Increased wait time for Git import operations to improve test reliability. * Refined and simplified test logic for Git discard, merge, and branch operations. * Added a new locator for pull count in Git sync UI tests. * Removed deprecated or redundant assertions and UI checks in Git-related tests. * Skipped import tests for older app versions due to backend compatibility issues. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
151 lines
5.5 KiB
JavaScript
151 lines
5.5 KiB
JavaScript
/* eslint-disable cypress/no-unnecessary-waiting */
|
|
/* eslint-disable cypress/no-assigning-return-values */
|
|
|
|
import { AppSidebar } from "./Pages/EditorNavigation";
|
|
|
|
require("cy-verify-downloads").addCustomCommand();
|
|
require("cypress-file-upload");
|
|
import homePage from "../locators/HomePage";
|
|
import { ObjectsRegistry } from "./Objects/Registry";
|
|
const gitSync = ObjectsRegistry.GitSync;
|
|
const agHelper = ObjectsRegistry.AggregateHelper;
|
|
const dataManager = ObjectsRegistry.DataManager;
|
|
const assertHelper = ObjectsRegistry.AssertHelper;
|
|
|
|
const commonLocators = require("../locators/commonlocators.json");
|
|
|
|
Cypress.Commands.add("latestDeployPreview", () => {
|
|
cy.intercept("POST", "/api/v1/applications/publish/*").as("publishApp");
|
|
// Wait before publish
|
|
// eslint-disable-next-line cypress/no-unnecessary-waiting
|
|
cy.wait(2000);
|
|
agHelper.AssertAutoSave();
|
|
|
|
// Stubbing window.open to open in the same tab
|
|
cy.window().then((window) => {
|
|
cy.stub(window, "open").callsFake((url) => {
|
|
window.location.href = Cypress.config().baseUrl + url.substring(1);
|
|
window.location.target = "_self";
|
|
});
|
|
});
|
|
agHelper.GetNClick(gitSync.locators.quickActionsCommitBtn);
|
|
cy.wait(2000); // wait for modal to load
|
|
cy.xpath("//span[text()='Latest deployed preview']").click();
|
|
cy.log("pagename: " + localStorage.getItem("PageName"));
|
|
cy.wait(5000); //wait time for page to load!
|
|
});
|
|
|
|
Cypress.Commands.add("createGitBranch", (branch) => {
|
|
agHelper.AssertElementVisibility(gitSync.locators.quickActionsPullBtn);
|
|
cy.get(gitSync.locators.quickActionsBranchBtn).click({ force: true });
|
|
agHelper.AssertElementVisibility(gitSync.locators.branchSearchInput);
|
|
agHelper.ClearNType(gitSync.locators.branchSearchInput, `${branch}`);
|
|
// increasing timeout to reduce flakyness
|
|
cy.get(".ads-v2-spinner", {
|
|
timeout: Cypress.config().pageLoadTimeout,
|
|
}).should("exist");
|
|
cy.get(".ads-v2-spinner", {
|
|
timeout: Cypress.config().pageLoadTimeout,
|
|
}).should("not.exist");
|
|
assertHelper.AssertDocumentReady();
|
|
AppSidebar.assertVisible(Cypress.config().pageLoadTimeout);
|
|
});
|
|
|
|
Cypress.Commands.add("switchGitBranch", (branch, expectError) => {
|
|
agHelper.AssertElementVisibility(gitSync.locators.quickActionsPullBtn);
|
|
cy.get(gitSync.locators.quickActionsBranchBtn).click({ force: true });
|
|
agHelper.AssertElementVisibility(gitSync.locators.branchSearchInput);
|
|
agHelper.ClearNType(gitSync.locators.branchSearchInput, `${branch}`);
|
|
cy.get(gitSync.locators.branchItem).contains(branch).click();
|
|
assertHelper.AssertDocumentReady();
|
|
AppSidebar.assertVisible(Cypress.config().pageLoadTimeout);
|
|
});
|
|
|
|
Cypress.Commands.add("commitAndPush", (assertFailure) => {
|
|
cy.get(homePage.publishButton).click();
|
|
agHelper.AssertElementExist(gitSync.locators.quickActionsPullBtn);
|
|
cy.get(gitSync.locators.opsCommitInput).type("Initial Commit");
|
|
cy.get(gitSync.locators.opsCommitBtn).click();
|
|
if (!assertFailure) {
|
|
// check for commit success
|
|
//adding timeout since commit is taking longer sometimes
|
|
cy.wait("@commit", { timeout: 35000 }).should(
|
|
"have.nested.property",
|
|
"response.body.responseMeta.status",
|
|
201,
|
|
);
|
|
cy.wait(3000);
|
|
} else {
|
|
cy.wait("@commit", { timeout: 35000 }).then((interception) => {
|
|
const status = interception.response.body.responseMeta.status;
|
|
expect(status).to.be.gte(400);
|
|
});
|
|
}
|
|
|
|
gitSync.CloseOpsModal();
|
|
});
|
|
|
|
Cypress.Commands.add("merge", (destinationBranch) => {
|
|
agHelper.AssertElementExist(gitSync.locators.quickActionsPullBtn);
|
|
|
|
cy.intercept(
|
|
"GET",
|
|
/\/api\/v1\/git\/applications\/.*\/status\?compareRemote=.*/,
|
|
).as(`gitStatus`);
|
|
|
|
cy.intercept(
|
|
"GET",
|
|
/\/api\/v1\/git\/applications\/.*\/refs\?refType=.*&pruneRefs=.*/,
|
|
).as(`gitBranches`);
|
|
|
|
cy.get(gitSync.locators.quickActionsMergeBtn).click({ force: true });
|
|
//cy.wait(6000); // wait for git status call to finish
|
|
/*cy.wait("@gitStatus").should(
|
|
"have.nested.property",
|
|
"response.body.responseMeta.status",
|
|
200,
|
|
); */
|
|
|
|
agHelper.AssertElementEnabledDisabled(
|
|
gitSync.locators.opsMergeBranchSelect,
|
|
0,
|
|
false,
|
|
);
|
|
agHelper.WaitUntilEleDisappear(gitSync.locators.opsMergeLoader);
|
|
cy.wait(["@gitBranches", "@gitStatus"]).then((interceptions) => {
|
|
if (
|
|
interceptions[0]?.response?.statusCode === 200 &&
|
|
interceptions[1]?.response?.statusCode === 200
|
|
) {
|
|
cy.get(gitSync.locators.opsMergeBranchSelect).click();
|
|
cy.get(commonLocators.dropdownmenu).contains(destinationBranch).click();
|
|
gitSync.AssertAbsenceOfCheckingMergeability();
|
|
assertHelper.WaitForNetworkCall("mergeStatus");
|
|
cy.contains(Cypress.env("MESSAGES").NO_MERGE_CONFLICT());
|
|
cy.get(gitSync.locators.opsMergeBtn).click();
|
|
agHelper.AssertContains(Cypress.env("MESSAGES").MERGED_SUCCESSFULLY());
|
|
}
|
|
});
|
|
});
|
|
|
|
Cypress.Commands.add("gitDiscardChanges", () => {
|
|
cy.get(gitSync.locators.quickActionsCommitBtn).click();
|
|
cy.get(gitSync.locators.opsDiscardBtn).should("be.visible");
|
|
cy.get(gitSync.locators.opsDiscardBtn)
|
|
.children()
|
|
.should("have.text", "Discard & pull");
|
|
cy.get(gitSync.locators.opsDiscardBtn).click();
|
|
cy.contains(Cypress.env("MESSAGES").DISCARD_CHANGES_WARNING());
|
|
cy.get(gitSync.locators.opsDiscardBtn)
|
|
.children()
|
|
.should("have.text", "Are you sure?");
|
|
cy.get(gitSync.locators.opsDiscardBtn).click();
|
|
cy.contains(Cypress.env("MESSAGES").DISCARDING_AND_PULLING_CHANGES());
|
|
cy.validateToastMessage("Discarded changes successfully.");
|
|
cy.wait(2000);
|
|
assertHelper.AssertContains(
|
|
Cypress.env("MESSAGES").UNABLE_TO_IMPORT_APP(),
|
|
"not.exist",
|
|
);
|
|
});
|