Add tests for git discard changes (#13866)
This commit is contained in:
parent
11ee278740
commit
32bcd94e54
|
|
@ -0,0 +1,228 @@
|
||||||
|
const datasource = require("../../../../locators/DatasourcesEditor.json");
|
||||||
|
const queryLocators = require("../../../../locators/QueryEditor.json");
|
||||||
|
const dynamicInputLocators = require("../../../../locators/DynamicInput.json");
|
||||||
|
const explorer = require("../../../../locators/explorerlocators.json");
|
||||||
|
|
||||||
|
describe("Git discard changes:", function() {
|
||||||
|
let datasourceName;
|
||||||
|
let repoName;
|
||||||
|
const query1 = "get_users";
|
||||||
|
const query2 = "get_allusers";
|
||||||
|
const jsObject = "JSObject1";
|
||||||
|
const page2 = "Page_2";
|
||||||
|
const page3 = "Page_3";
|
||||||
|
|
||||||
|
it("1. Create an app with Query1 and JSObject1, connect it to git", () => {
|
||||||
|
// Create new postgres datasource
|
||||||
|
cy.NavigateToDatasourceEditor();
|
||||||
|
cy.get(datasource.PostgreSQL).click();
|
||||||
|
|
||||||
|
cy.getPluginFormsAndCreateDatasource();
|
||||||
|
|
||||||
|
cy.fillPostgresDatasourceForm();
|
||||||
|
|
||||||
|
cy.testSaveDatasource();
|
||||||
|
|
||||||
|
cy.get("@createDatasource").then((httpResponse) => {
|
||||||
|
datasourceName = httpResponse.response.body.data.name;
|
||||||
|
|
||||||
|
cy.get(datasource.datasourceCard)
|
||||||
|
.contains(datasourceName)
|
||||||
|
.scrollIntoView()
|
||||||
|
.should("be.visible")
|
||||||
|
.closest(datasource.datasourceCard)
|
||||||
|
.within(() => {
|
||||||
|
cy.get(datasource.createQuerty).click();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
// Create new postgres query
|
||||||
|
cy.get(queryLocators.queryNameField).type(`${query1}`);
|
||||||
|
cy.get(queryLocators.switch)
|
||||||
|
.last()
|
||||||
|
.click({ force: true });
|
||||||
|
cy.get(queryLocators.templateMenu).click();
|
||||||
|
cy.get(queryLocators.query).click({ force: true });
|
||||||
|
cy.get(".CodeMirror textarea")
|
||||||
|
.first()
|
||||||
|
.focus()
|
||||||
|
.type("SELECT * FROM users ORDER BY id LIMIT 10;", {
|
||||||
|
force: true,
|
||||||
|
parseSpecialCharSequences: false,
|
||||||
|
});
|
||||||
|
cy.WaitAutoSave();
|
||||||
|
cy.runQuery();
|
||||||
|
|
||||||
|
cy.CheckAndUnfoldEntityItem("PAGES");
|
||||||
|
cy.wait(1000);
|
||||||
|
cy.get(".t--entity-item:contains(Page1)")
|
||||||
|
.first()
|
||||||
|
.click();
|
||||||
|
cy.wait("@getPage");
|
||||||
|
// bind input widget to postgres query on page1
|
||||||
|
cy.get(explorer.addWidget).click();
|
||||||
|
cy.dragAndDropToCanvas("inputwidgetv2", { x: 300, y: 300 });
|
||||||
|
cy.get(".t--widget-inputwidgetv2").should("exist");
|
||||||
|
cy.get(dynamicInputLocators.input)
|
||||||
|
.eq(1)
|
||||||
|
.click({ force: true })
|
||||||
|
.type(`{{${query1}.data[0].name}}`, {
|
||||||
|
parseSpecialCharSequences: false,
|
||||||
|
});
|
||||||
|
cy.wait(2000);
|
||||||
|
cy.CheckAndUnfoldEntityItem("PAGES");
|
||||||
|
cy.Createpage(page2);
|
||||||
|
cy.wait(1000);
|
||||||
|
cy.get(`.t--entity-item:contains(${page2})`)
|
||||||
|
.first()
|
||||||
|
.click();
|
||||||
|
cy.wait("@getPage");
|
||||||
|
cy.createJSObject('return "Success";');
|
||||||
|
cy.get(explorer.addWidget).click();
|
||||||
|
// bind input widget to JSObject response on page2
|
||||||
|
cy.dragAndDropToCanvas("inputwidgetv2", { x: 300, y: 300 });
|
||||||
|
cy.get(".t--widget-inputwidgetv2").should("exist");
|
||||||
|
cy.get(dynamicInputLocators.input)
|
||||||
|
.eq(1)
|
||||||
|
.click({ force: true })
|
||||||
|
.type("{{JSObject1.myFun1()}}", { parseSpecialCharSequences: false });
|
||||||
|
cy.get("#switcher--explorer").click({ force: true });
|
||||||
|
// connect app to git
|
||||||
|
cy.generateUUID().then((uid) => {
|
||||||
|
repoName = uid;
|
||||||
|
|
||||||
|
cy.createTestGithubRepo(repoName);
|
||||||
|
cy.connectToGitRepo(repoName);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("2. Add new datasource query, discard changes, verify query is deleted", () => {
|
||||||
|
cy.get(`.t--entity-item:contains("Page1")`)
|
||||||
|
.first()
|
||||||
|
.click();
|
||||||
|
cy.wait("@getPage");
|
||||||
|
// create new postgres query
|
||||||
|
cy.NavigateToQueryEditor();
|
||||||
|
cy.NavigateToActiveTab();
|
||||||
|
cy.get(datasource.datasourceCard)
|
||||||
|
.contains(datasourceName)
|
||||||
|
.scrollIntoView()
|
||||||
|
.should("be.visible")
|
||||||
|
.closest(datasource.datasourceCard)
|
||||||
|
.within(() => {
|
||||||
|
cy.get(datasource.createQuerty).click();
|
||||||
|
});
|
||||||
|
cy.get(queryLocators.queryNameField).type(`${query2}`);
|
||||||
|
cy.get(queryLocators.switch)
|
||||||
|
.last()
|
||||||
|
.click({ force: true });
|
||||||
|
cy.get(queryLocators.templateMenu).click();
|
||||||
|
cy.get(queryLocators.query).click({ force: true });
|
||||||
|
cy.get(".CodeMirror textarea")
|
||||||
|
.first()
|
||||||
|
.focus()
|
||||||
|
.type("SELECT * FROM users;", {
|
||||||
|
force: true,
|
||||||
|
parseSpecialCharSequences: false,
|
||||||
|
});
|
||||||
|
cy.WaitAutoSave();
|
||||||
|
cy.runQuery();
|
||||||
|
// navoigate to Page1
|
||||||
|
cy.get(`.t--entity-item:contains(Page1)`)
|
||||||
|
.first()
|
||||||
|
.click();
|
||||||
|
cy.wait("@getPage");
|
||||||
|
// discard changes
|
||||||
|
cy.gitDiscardChanges();
|
||||||
|
cy.CheckAndUnfoldEntityItem("QUERIES/JS");
|
||||||
|
// verify query2 is not present
|
||||||
|
cy.get(`.t--entity-name:contains(${query2})`).should("not.exist");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("3. Add new JSObject , discard changes verify JSObject is deleted", () => {
|
||||||
|
cy.createJSObject('return "Success";');
|
||||||
|
cy.CheckAndUnfoldEntityItem("QUERIES/JS");
|
||||||
|
// verify jsObject is not duplicated
|
||||||
|
cy.get(`.t--entity-name:contains(${jsObject})`).should("have.length", 1);
|
||||||
|
cy.gitDiscardChanges();
|
||||||
|
cy.CheckAndUnfoldEntityItem("QUERIES/JS");
|
||||||
|
// verify jsObject2 is deleted after discarding changes
|
||||||
|
cy.get(`.t--entity-name:contains(${jsObject})`).should("not.exist");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("4. Delete page2 and trigger discard flow, page2 should be available again", () => {
|
||||||
|
cy.Deletepage(page2);
|
||||||
|
// verify page is deleted
|
||||||
|
cy.CheckAndUnfoldEntityItem("PAGES");
|
||||||
|
cy.get(`.t--entity-name:contains(${page2})`).should("not.exist");
|
||||||
|
cy.gitDiscardChanges();
|
||||||
|
// verify page2 is recovered back
|
||||||
|
cy.get(`.t--entity-name:contains(${page2})`).should("be.visible");
|
||||||
|
cy.get(`.t--entity-item:contains(${page2})`)
|
||||||
|
.first()
|
||||||
|
.click();
|
||||||
|
cy.wait("@getPage");
|
||||||
|
// verify data binding on page2
|
||||||
|
cy.get(".bp3-input").should("have.value", "Success");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("5. Delete Query1 and trigger discard flow, Query1 will be recovered", () => {
|
||||||
|
// navigate to Page1
|
||||||
|
cy.CheckAndUnfoldEntityItem("PAGES");
|
||||||
|
cy.get(`.t--entity-item:contains("Page1")`)
|
||||||
|
.first()
|
||||||
|
.click();
|
||||||
|
cy.wait("@getPage");
|
||||||
|
// delete query1
|
||||||
|
cy.deleteQueryOrJS(query1);
|
||||||
|
// verify Query1 is deleted
|
||||||
|
cy.get(`.t--entity-name:contains(${query1})`).should("not.exist");
|
||||||
|
// discard changes
|
||||||
|
cy.gitDiscardChanges();
|
||||||
|
//verify query1 is recovered
|
||||||
|
cy.get(`.t--entity-name:contains(${query1})`).should("be.visible");
|
||||||
|
|
||||||
|
cy.get(".bp3-input").should("have.value", "Test user 7");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("6. Delete JSObject1 and trigger discard flow, JSObject1 should be active again", () => {
|
||||||
|
// navigate to page2
|
||||||
|
cy.CheckAndUnfoldEntityItem("PAGES");
|
||||||
|
cy.get(`.t--entity-item:contains(${page2})`)
|
||||||
|
.first()
|
||||||
|
.click();
|
||||||
|
cy.wait("@getPage");
|
||||||
|
// delete jsObject1
|
||||||
|
cy.CheckAndUnfoldEntityItem("QUERIES/JS");
|
||||||
|
cy.get(`.t--entity-item:contains(${jsObject})`).within(() => {
|
||||||
|
cy.get(".t--context-menu").click({ force: true });
|
||||||
|
});
|
||||||
|
cy.selectAction("Delete");
|
||||||
|
cy.selectAction("Are you sure?");
|
||||||
|
cy.get(`.t--entity-name:contains(${jsObject})`).should("not.exist");
|
||||||
|
// discard changes
|
||||||
|
cy.gitDiscardChanges();
|
||||||
|
//verify JSObject is recovered
|
||||||
|
cy.get(`.t--entity-name:contains(${jsObject})`).should("be.visible");
|
||||||
|
cy.get(".bp3-input").should("have.value", "Success");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("7. Add new page i.e page3, go to page2 & discard changes, verify page3 is removed", () => {
|
||||||
|
// create new page page3 and move to page1
|
||||||
|
cy.Createpage(page3);
|
||||||
|
cy.get(`.t--entity-item:contains(${page2})`)
|
||||||
|
.first()
|
||||||
|
.click();
|
||||||
|
// discard changes
|
||||||
|
cy.gitDiscardChanges();
|
||||||
|
// 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", () => {
|
||||||
|
cy.Createpage(page3);
|
||||||
|
cy.gitDiscardChanges(false);
|
||||||
|
cy.go("back");
|
||||||
|
cy.reload();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
@ -51,4 +51,5 @@ export default {
|
||||||
gitPullCount: ".t--bottom-bar-pull .count",
|
gitPullCount: ".t--bottom-bar-pull .count",
|
||||||
gitConnectionContainer: "[data-test=t--git-connection-container]",
|
gitConnectionContainer: "[data-test=t--git-connection-container]",
|
||||||
gitRemoteURLContainer: "[data-test=t--remote-url-container]",
|
gitRemoteURLContainer: "[data-test=t--remote-url-container]",
|
||||||
|
discardChanges: ".t--discard-button",
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -363,3 +363,37 @@ Cypress.Commands.add(
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Cypress.Commands.add("gitDiscardChanges", (assertResourceFound = true) => {
|
||||||
|
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.get(gitSyncLocators.discardChanges)
|
||||||
|
.children()
|
||||||
|
.should("have.text", "Discard changes");
|
||||||
|
|
||||||
|
cy.get(gitSyncLocators.discardChanges).click();
|
||||||
|
cy.contains(Cypress.env("MESSAGES").DISCARD_CHANGES_WARNING());
|
||||||
|
|
||||||
|
cy.get(gitSyncLocators.discardChanges)
|
||||||
|
.children()
|
||||||
|
.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");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -1109,7 +1109,16 @@ Cypress.Commands.add("clearPropertyValue", (value) => {
|
||||||
// eslint-disable-next-line cypress/no-unnecessary-waiting
|
// eslint-disable-next-line cypress/no-unnecessary-waiting
|
||||||
cy.wait(1000);
|
cy.wait(1000);
|
||||||
});
|
});
|
||||||
|
Cypress.Commands.add("deleteQueryOrJS", (Action) => {
|
||||||
|
cy.CheckAndUnfoldEntityItem("QUERIES/JS");
|
||||||
|
cy.get(`.t--entity-item:contains(${Action})`).within(() => {
|
||||||
|
cy.get(".t--context-menu").click({ force: true });
|
||||||
|
});
|
||||||
|
cy.selectAction("Delete");
|
||||||
|
cy.selectAction("Are you sure?");
|
||||||
|
cy.wait("@deleteAction");
|
||||||
|
cy.get("@deleteAction").should("have.property", "status", 200);
|
||||||
|
});
|
||||||
Cypress.Commands.add(
|
Cypress.Commands.add(
|
||||||
"validateNSelectDropdown",
|
"validateNSelectDropdown",
|
||||||
(ddTitle, currentValue, newValue) => {
|
(ddTitle, currentValue, newValue) => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user