diff --git a/app/client/cypress/integration/Smoke_TestSuite/ClientSideTests/Git/GitDiscardChange/DiscardChanges_spec.js b/app/client/cypress/integration/Smoke_TestSuite/ClientSideTests/Git/GitDiscardChange/DiscardChanges_spec.js index f01676e47e..230906b8bf 100644 --- a/app/client/cypress/integration/Smoke_TestSuite/ClientSideTests/Git/GitDiscardChange/DiscardChanges_spec.js +++ b/app/client/cypress/integration/Smoke_TestSuite/ClientSideTests/Git/GitDiscardChange/DiscardChanges_spec.js @@ -9,6 +9,7 @@ describe("Git discard changes:", function() { const query1 = "get_users"; const query2 = "get_allusers"; const jsObject = "JSObject1"; + const jsObject2 = "JSObject2"; const page2 = "Page_2"; const page3 = "Page_3"; @@ -133,6 +134,7 @@ describe("Git discard changes:", function() { cy.wait("@getPage"); // discard changes cy.gitDiscardChanges(); + cy.wait(5000); cy.CheckAndUnfoldEntityItem("QUERIES/JS"); // verify query2 is not present cy.get(`.t--entity-name:contains(${query2})`).should("not.exist"); @@ -144,6 +146,7 @@ describe("Git discard changes:", function() { // verify jsObject is not duplicated cy.get(`.t--entity-name:contains(${jsObject})`).should("have.length", 1); cy.gitDiscardChanges(); + cy.wait(5000); cy.CheckAndUnfoldEntityItem("QUERIES/JS"); // verify jsObject2 is deleted after discarding changes cy.get(`.t--entity-name:contains(${jsObject})`).should("not.exist"); @@ -156,6 +159,7 @@ describe("Git discard changes:", function() { cy.get(`.t--entity-name:contains(${page2})`).should("not.exist"); cy.wait(2000); cy.gitDiscardChanges(); + cy.wait(5000); // verify page2 is recovered back cy.get(`.t--entity-name:contains(${page2})`).should("be.visible"); cy.get(`.t--entity-item:contains(${page2})`) @@ -179,6 +183,7 @@ describe("Git discard changes:", function() { cy.get(`.t--entity-name:contains(${query1})`).should("not.exist"); // discard changes cy.gitDiscardChanges(); + cy.wait(5000); //verify query1 is recovered cy.get(`.t--entity-name:contains(${query1})`).should("be.visible"); @@ -192,6 +197,9 @@ describe("Git discard changes:", function() { .first() .click(); cy.wait("@getPage"); + cy.wait(3000); + /* create and save jsObject */ + // cy.createJSObject('return "Success";'); // delete jsObject1 cy.CheckAndUnfoldEntityItem("QUERIES/JS"); cy.get(`.t--entity-item:contains(${jsObject})`).within(() => { @@ -202,8 +210,15 @@ describe("Git discard changes:", function() { cy.get(`.t--entity-name:contains(${jsObject})`).should("not.exist"); // discard changes cy.gitDiscardChanges(); + cy.wait(5000); + cy.CheckAndUnfoldEntityItem("PAGES"); + cy.get(`.t--entity-item:contains(${page2})`) + .first() + .click(); + cy.wait("@getPage"); + cy.wait(3000); //verify JSObject is recovered - cy.get(`.t--entity-name:contains(${jsObject})`).should("be.visible"); + cy.get(`.t--entity-name:contains(${jsObject})`).should("exist"); cy.get(".bp3-input").should("have.value", "Success"); }); @@ -215,15 +230,16 @@ describe("Git discard changes:", function() { .click(); // discard changes cy.gitDiscardChanges(); + cy.wait(5000); // verify page3 is removed cy.CheckAndUnfoldEntityItem("PAGES"); cy.get(`.t--entity-name:contains("${page3}")`).should("not.exist"); }); - it("8. Add new page i.e page3, discard changes should give error resource not found", () => { + it(`8. Add new page i.e page3, discard changes should not throw error: "resource not found"`, () => { cy.Createpage(page3); - cy.gitDiscardChanges(false); - cy.go("back"); - cy.reload(); + cy.gitDiscardChanges(); + cy.wait(5000); + cy.get(`.t--entity-name:contains("${page3}")`).should("not.exist"); }); }); diff --git a/app/client/cypress/integration/Smoke_TestSuite/ClientSideTests/Widgets/Modal_spec.js b/app/client/cypress/integration/Smoke_TestSuite/ClientSideTests/Widgets/Modal_spec.js index 7553475fa3..fa60963c64 100644 --- a/app/client/cypress/integration/Smoke_TestSuite/ClientSideTests/Widgets/Modal_spec.js +++ b/app/client/cypress/integration/Smoke_TestSuite/ClientSideTests/Widgets/Modal_spec.js @@ -61,7 +61,7 @@ describe("Modal Widget Functionality", function() { cy.get('.bp3-collapse-body > [step="0"]') .eq(1) .children() - .should("have.length", 2); + .should("have.length", 3); //make sure modalis open on paste cy.get(".t--modal-widget").should("have.length", 1); }); diff --git a/app/client/cypress/support/gitSync.js b/app/client/cypress/support/gitSync.js index d47cc11bae..2dfcdca2d5 100644 --- a/app/client/cypress/support/gitSync.js +++ b/app/client/cypress/support/gitSync.js @@ -5,6 +5,7 @@ require("cy-verify-downloads").addCustomCommand(); require("cypress-file-upload"); import gitSyncLocators from "../locators/gitSyncLocators"; import homePage from "../locators/HomePage"; + const commonLocators = require("../locators/commonlocators.json"); const GITHUB_API_BASE = "https://api.github.com"; @@ -99,23 +100,23 @@ Cypress.Commands.add( // click commit button /* if (shouldCommit) { - cy.get(gitSyncLocators.commitCommentInput).type("Initial Commit"); - cy.get(gitSyncLocators.commitButton).click(); - // check for commit success - cy.wait("@commit").should( - "have.nested.property", - "response.body.responseMeta.status", - 201, - ); + cy.get(gitSyncLocators.commitCommentInput).type("Initial Commit"); + cy.get(gitSyncLocators.commitButton).click(); + // check for commit success + cy.wait("@commit").should( + "have.nested.property", + "response.body.responseMeta.status", + 201, + ); - cy.get(gitSyncLocators.closeGitSyncModal).click(); - } - } else { - cy.wait("@connectGitRepo").then((interception) => { - const status = interception.response.body.responseMeta.status; - expect(status).to.be.gte(400); - }); - } */ + cy.get(gitSyncLocators.closeGitSyncModal).click(); + } + } else { + cy.wait("@connectGitRepo").then((interception) => { + const status = interception.response.body.responseMeta.status; + expect(status).to.be.gte(400); + }); + } */ cy.get(gitSyncLocators.closeGitSyncModal).click(); }); }, @@ -372,14 +373,9 @@ Cypress.Commands.add( }, ); -Cypress.Commands.add("gitDiscardChanges", (assertResourceFound = true) => { +Cypress.Commands.add("gitDiscardChanges", () => { cy.get(gitSyncLocators.bottomBarCommitButton).click(); - //cy.intercept("GET", "/api/v1/git/status/*").as("gitStatus"); - // cy.wait("@gitStatus").should( - // "have.nested.property", - // "response.body.responseMeta.status", - // 200, - // ); + cy.wait(6000); cy.get(gitSyncLocators.discardChanges) .children() .should("have.text", "Discard changes"); @@ -392,18 +388,8 @@ Cypress.Commands.add("gitDiscardChanges", (assertResourceFound = true) => { .should("have.text", "Are you sure?"); cy.get(gitSyncLocators.discardChanges).click(); cy.contains(Cypress.env("MESSAGES").DISCARDING_AND_PULLING_CHANGES()); - if (assertResourceFound) { - cy.wait("@applications").should( - "have.nested.property", - "response.body.responseMeta.status", - 200, - ); - cy.validateToastMessage("Discarded changes successfully."); - } else { - cy.get(".bold-text").should(($x) => { - expect($x).contain("Page not found"); - }); - } + cy.wait(2000); + cy.validateToastMessage("Discarded changes successfully."); }); Cypress.Commands.add("regenerateSSHKey", (repo, generateKey = true) => { diff --git a/app/client/src/reducers/uiReducers/gitSyncReducer.ts b/app/client/src/reducers/uiReducers/gitSyncReducer.ts index 2f54726077..f187a3ae2e 100644 --- a/app/client/src/reducers/uiReducers/gitSyncReducer.ts +++ b/app/client/src/reducers/uiReducers/gitSyncReducer.ts @@ -468,6 +468,14 @@ const gitSyncReducer = createReducer(initialState, { ...state, deletingBranch: action.payload, }), + [ReduxActionTypes.GIT_DISCARD_CHANGES_SUCCESS]: ( + state: GitSyncReducerState, + action: ReduxAction, + ) => ({ + ...state, + isDiscarding: false, + discard: action.payload, + }), }); export type GitStatusData = { @@ -505,6 +513,46 @@ export type GitBranchDeleteState = { deletingBranch?: boolean; }; +export type GitDiscardResponse = { + id: string; + modifiedBy: string; + userPermissions: string[]; + name: string; + workspaceId: string; + isPublic: boolean; + pages: { + id: string; + isDefault: boolean; + defaultPageId: string; + default: boolean; + }[]; + appIsExample: boolean; + unreadCommentThreads: number; + color: string; + icon: string; + slug: string; + gitApplicationMetadata: { + branchName: string; + defaultBranchName: string; + remoteUrl: string; + browserSupportedRemoteUrl: string; + isRepoPrivate: boolean; + repoName: string; + defaultApplicationId: string; + lastCommittedAt: string; + }; + lastDeployedAt: string; + evaluationVersion: number; + applicationVersion: number; + isManualUpdate: boolean; + isAutoUpdate: boolean; + appLayout: { + type: string; + }; + new: boolean; + modifiedAt: string; +}; + export type GitSyncReducerState = GitBranchDeleteState & { isGitSyncModalOpen: boolean; isCommitting?: boolean; @@ -552,6 +600,7 @@ export type GitSyncReducerState = GitBranchDeleteState & { gitImportError?: any; isDiscarding?: boolean; + discard?: GitDiscardResponse; }; export default gitSyncReducer; diff --git a/app/client/src/sagas/GitSyncSagas.ts b/app/client/src/sagas/GitSyncSagas.ts index 13d5ae4350..704c4e1b9b 100644 --- a/app/client/src/sagas/GitSyncSagas.ts +++ b/app/client/src/sagas/GitSyncSagas.ts @@ -94,6 +94,7 @@ import { log } from "loglevel"; import GIT_ERROR_CODES from "constants/GitErrorCodes"; import { builderURL } from "RouteBuilder"; import { APP_MODE } from "../entities/App"; +import { GitDiscardResponse } from "../reducers/uiReducers/gitSyncReducer"; export function* handleRepoLimitReachedError(response?: ApiResponse) { const { responseMeta } = response || {}; @@ -704,9 +705,8 @@ function* importAppFromGitSaga(action: ConnectToGitReduxAction) { showReconnectDatasourceModal({ // @ts-expect-error: Type mismatch application: response?.data?.application, - unConfiguredDatasourceList: - // @ts-expect-error: Type mismatch - response?.data.unConfiguredDatasourceList, + unConfiguredDatasourceList: (response as any)?.data + .unConfiguredDatasourceList, workspaceId: workspaceIdForImport, }), ); @@ -847,7 +847,7 @@ export function* deleteBranch({ payload }: ReduxAction) { } function* discardChanges() { - let response: ApiResponse | undefined; + let response: ApiResponse; try { const appId: string = yield select(getCurrentApplicationId); const doPull = true; @@ -858,9 +858,14 @@ function* discardChanges() { getLogToSentryFromResponse(response), ); if (isValidResponse) { - yield put(discardChangesSuccess(response?.data)); + yield put(discardChangesSuccess(response.data)); + // const applicationId: string = response.data.id; + const pageId: string = response.data.pages.filter( + (page: any) => page.isDefault, + )[0].id; localStorage.setItem("GIT_DISCARD_CHANGES", "success"); - location.reload(); + const branch = response.data.gitApplicationMetadata.branchName; + window.open(builderURL({ pageId, branch }), "_self"); } } catch (error) { yield put(discardChangesFailure({ error }));