-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Expand file tree
/
Copy pathgitSync.js
More file actions
150 lines (135 loc) · 5.53 KB
/
Copy pathgitSync.js
File metadata and controls
150 lines (135 loc) · 5.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/* 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",
);
});