Automated tests for improved CRUD with JSONFrom - Mongo Ds (#14191)

This commit is contained in:
Aishwarya-U-R 2022-06-06 11:29:15 +05:30 committed by GitHub
parent 9cbcf180cc
commit 98c06e2817
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 920 additions and 260 deletions

View File

@ -1,13 +1,27 @@
import { ObjectsRegistry } from "../../../../support/Objects/Registry";
let guid: any;
let guid: any, dsName: any;
let agHelper = ObjectsRegistry.AggregateHelper,
ee = ObjectsRegistry.EntityExplorer,
locator = ObjectsRegistry.CommonLocators,
homePage = ObjectsRegistry.HomePage,
dataSources = ObjectsRegistry.DataSources;
dataSources = ObjectsRegistry.DataSources,
deployMode = ObjectsRegistry.DeployMode,
table = ObjectsRegistry.Table;
describe("Validate Mongo CRUD with JSON Form", () => {
before(() => {
//dataSources.StartDataSourceRoutes(); //already started in index.js beforeeach
});
beforeEach(function() {
if (Cypress.env("Mongo") === 0) {
cy.log("Mongo DB is not found. Using intercept");
dataSources.StartInterceptRoutesForMongo();
} else cy.log("Mongo DB is found, hence using actual DB");
});
it("1. Create DS & then Add new Page and generate CRUD template using created datasource", () => {
agHelper.GenerateUUID();
cy.get("@guid").then((uid) => {
@ -25,13 +39,756 @@ describe("Validate Mongo CRUD with JSON Form", () => {
dataSources._dropdownOption,
"Mongo " + guid,
);
agHelper.ValidateNetworkStatus("@getDatasourceStructure"); //Making sure table dropdown is populated
agHelper.GetNClick(dataSources._selectTableDropdown);
agHelper.GetNClickByContains(
dataSources._dropdownOption,
"pokemon",
);
agHelper.GetNClick(dataSources._generatePageBtn);
cy.wrap("Mongo " + guid).as("dsName");
});
agHelper.ValidateNetworkStatus("@getDatasourceStructure"); //Making sure table dropdown is populated
agHelper.WaitUntilToastDisappear("datasource updated successfully");
agHelper.GetNClick(dataSources._selectTableDropdown);
agHelper.GetNClickByContains(dataSources._dropdownOption, "pokemon");
GenerateCRUDNValidateDeployPage(
"http://www.serebii.net/pokemongo/pokemon/150.png",
"150",
`["Bug","Ghost","Dark"]`,
10,
);
agHelper.NavigateBacktoEditor();
table.WaitUntilTableLoad();
//Delete the test data
ee.ActionContextMenuByEntityName("Page2", "Delete", "Are you sure?");
agHelper.ValidateNetworkStatus("@deletePage", 200);
//Should not be able to delete ds until app is published again
//coz if app is published & shared then deleting ds may cause issue, So!
cy.get("@dsName").then(($dsName) => {
dsName = $dsName;
dataSources.DeleteDatasouceFromActiveTab(dsName as string, 409);
});
deployMode.DeployApp();
agHelper.NavigateBacktoEditor();
cy.get("@dsName").then(($dsName) => {
dsName = $dsName;
dataSources.DeleteDatasouceFromActiveTab(dsName as string, 200);
});
});
it("2. Create new app and Generate CRUD page using a new datasource", () => {
homePage.NavigateToHome();
homePage.CreateNewApplication();
agHelper.GetNClick(homePage._buildFromDataTableActionCard);
agHelper.GetNClick(dataSources._selectDatasourceDropdown);
agHelper.GetNClickByContains(
dataSources._dropdownOption,
"Connect New Datasource",
);
agHelper.GenerateUUID();
cy.get("@guid").then((uid) => {
dataSources.CreatePlugIn("MongoDB");
guid = uid;
agHelper.RenameWithInPane("Mongo " + guid, false);
dataSources.FillMongoDSForm();
dataSources.TestSaveDatasource();
cy.wrap("Mongo " + guid).as("dsName");
});
agHelper.ValidateNetworkStatus("@getDatasourceStructure"); //Making sure table dropdown is populated
agHelper.WaitUntilToastDisappear("datasource updated successfully");
agHelper.GetNClick(dataSources._selectTableDropdown);
agHelper.GetNClickByContains(dataSources._dropdownOption, "friends");
GenerateCRUDNValidateDeployPage(
"<p>Monica's old friend Rachel moves in with her after leaving her fiancé.</p>",
`1994-09-22`,
"http://www.tvmaze.com/episodes/40646/friends-1x01-the-one-where-it-all-began",
11,
);
agHelper.NavigateBacktoEditor();
cy.get("@dsName").then(($dsName) => {
dsName = $dsName;
});
});
it("3. Generate CRUD page from datasource present in ACTIVE section", function() {
dataSources.NavigateFromActiveDS(dsName, false);
agHelper.ValidateNetworkStatus("@getDatasourceStructure");
agHelper.GetNClick(dataSources._selectTableDropdown);
agHelper.GetNClickByContains(dataSources._dropdownOption, "coffeeCafe");
GenerateCRUDNValidateDeployPage("", "", "Washington, US", 11);
agHelper.NavigateBacktoEditor();
table.WaitUntilTableLoad(1, 0);
//Delete the test data
ee.expandCollapseEntity("PAGES");
ee.ActionContextMenuByEntityName("CoffeeCafe", "Delete", "Are you sure?");
agHelper.ValidateNetworkStatus("@deletePage", 200);
});
it("4. Create new CRUD collection 'AuthorNAwards' & refresh Entity Explorer to find the new collection", () => {
let authorNAwardsArray = `[{
"_id" : 1,
"name" : {
"first" : "John",
"last" : "Backus"
},
"birth" : "1924-12-03T05:00:00Z",
"death" : "2007-03-17T04:00:00Z",
"contribs" : [
"Fortran",
"ALGOL",
"Backus-Naur Form",
"FP"
],
"awards" : [
{
"award" : "W.W. McDowell Award",
"year" : 1967,
"by" : "IEEE Computer Society"
},
{
"award" : "National Medal of Science",
"year" : 1975,
"by" : "National Science Foundation"
},
{
"award" : "Turing Award",
"year" : 1977,
"by" : "ACM"
},
{
"award" : "Draper Prize",
"year" : 1993,
"by" : "National Academy of Engineering"
}
]
},
{
"_id" : ObjectId("51df07b094c6acd67e492f41"),
"name" : {
"first" : "John",
"last" : "McCarthy"
},
"birth" : "1927-09-04T04:00:00Z",
"death" : "2011-12-24T05:00:00Z",
"contribs" : [
"Lisp",
"Artificial Intelligence",
"ALGOL"
],
"awards" : [
{
"award" : "Turing Award",
"year" : 1971,
"by" : "ACM"
},
{
"award" : "Kyoto Prize",
"year" : 1988,
"by" : "Inamori Foundation"
},
{
"award" : "National Medal of Science",
"year" : 1990,
"by" : "National Science Foundation"
}
]
},
{
"_id" : ObjectId("51df07b094c6acd67e492f42"),
"name" : {
"first" : "Grace",
"last" : "Hopper"
},
"title" : "Rear Admiral",
"birth" : "1906-12-09T05:00:00Z",
"death" : "1992-01-01T05:00:00Z",
"contribs" : [
"UNIVAC",
"compiler",
"FLOW-MATIC",
"COBOL"
],
"awards" : [
{
"award" : "Computer Sciences Man of the Year",
"year" : 1969,
"by" : "Data Processing Management Association"
},
{
"award" : "Distinguished Fellow",
"year" : 1973,
"by" : " British Computer Society"
},
{
"award" : "W. W. McDowell Award",
"year" : 1976,
"by" : "IEEE Computer Society"
},
{
"award" : "National Medal of Technology",
"year" : 1991,
"by" : "United States"
}
]
},
{
"_id" : 4,
"name" : {
"first" : "Kristen",
"last" : "Nygaard"
},
"birth" : "1926-08-27T04:00:00Z",
"death" : "2002-08-10T04:00:00Z",
"contribs" : [
"OOP",
"Simula"
],
"awards" : [
{
"award" : "Rosing Prize",
"year" : 1999,
"by" : "Norwegian Data Association"
},
{
"award" : "Turing Award",
"year" : 2001,
"by" : "ACM"
},
{
"award" : "IEEE John von Neumann Medal",
"year" : 2001,
"by" : "IEEE"
}
]
},
{
"_id" : 5,
"name" : {
"first" : "Ole-Johan",
"last" : "Dahl"
},
"birth" : "1931-10-12T04:00:00Z",
"death" : "2002-06-29T04:00:00Z",
"contribs" : [
"OOP",
"Simula"
],
"awards" : [
{
"award" : "Rosing Prize",
"year" : 1999,
"by" : "Norwegian Data Association"
},
{
"award" : "Turing Award",
"year" : 2001,
"by" : "ACM"
},
{
"award" : "IEEE John von Neumann Medal",
"year" : 2001,
"by" : "IEEE"
}
]
},
{
"_id" : 6,
"name" : {
"first" : "Guido",
"last" : "van Rossum"
},
"birth" : "1956-01-31T05:00:00Z",
"contribs" : [
"Python"
],
"awards" : [
{
"award" : "Award for the Advancement of Free Software",
"year" : 2001,
"by" : "Free Software Foundation"
},
{
"award" : "NLUUG Award",
"year" : 2003,
"by" : "NLUUG"
}
]
},
{
"_id" : ObjectId("51e062189c6ae665454e301d"),
"name" : {
"first" : "Dennis",
"last" : "Ritchie"
},
"birth" : "1941-09-09T04:00:00Z",
"death" : "2011-10-12T04:00:00Z",
"contribs" : [
"UNIX",
"C"
],
"awards" : [
{
"award" : "Turing Award",
"year" : 1983,
"by" : "ACM"
},
{
"award" : "National Medal of Technology",
"year" : 1998,
"by" : "United States"
},
{
"award" : "Japan Prize",
"year" : 2011,
"by" : "The Japan Prize Foundation"
}
]
}]`;
dataSources.NavigateFromActiveDS(dsName, true);
dataSources.ValidateNSelectDropdown(
"Commands",
"Find Document(s)",
"Insert Document(s)",
);
agHelper.EnterValue("AuthorNAwards", {
propFieldName: "",
directInput: false,
inputFieldName: "Collection",
});
agHelper.EnterValue(authorNAwardsArray, {
propFieldName: "",
directInput: false,
inputFieldName: "Documents",
});
agHelper.AssertAutoSave();
agHelper.Sleep(2000); //for documents value to settle!
dataSources.RunQuery();
agHelper.Sleep(4000); //for capturing right response!
cy.get("@postExecute").then((resObj: any) => {
//cy.log("response is " + JSON.stringify(resObj));
expect(parseInt(JSON.stringify(resObj.response.body.data.body.n))).to.eq(
7,
);
});
agHelper.ActionContextMenuWithInPane("Delete");
ee.expandCollapseEntity(dsName);
ee.ActionContextMenuByEntityName(dsName, "Refresh");
agHelper.AssertElementVisible(ee._entityNameInExplorer("AuthorNAwards"));
});
it("5. Validate 'Find' record from new collection & verify query response", () => {
ee.ActionTemplateMenuByEntityName("AuthorNAwards", "Find");
dataSources.ValidateNSelectDropdown("Commands", "Find Document(s)");
RunQueryNVerify();
});
it("6. Validate 'Find by ID' record from new collection & verify query response", () => {
ee.ActionTemplateMenuByEntityName("AuthorNAwards", "Find by ID");
dataSources.ValidateNSelectDropdown("Commands", "Find Document(s)");
agHelper.EnterValue(`{"_id": ObjectId("51df07b094c6acd67e492f41")}`, {
propFieldName: "",
directInput: false,
inputFieldName: "Query",
});
RunQueryNVerify();
});
it("7. Validate 'Insert' record from new collection & verify query response", () => {
let insertauthorNAwards = `[{
"_id" : 8,
"name" : {
"first" : "Yukihiro",
"aka" : "Matz",
"last" : "Matsumoto"
},
"birth" : "1965-04-14T04:00:00Z",
"contribs" : [
"Ruby"
],
"awards" : [
{
"award" : "Award for the Advancement of Free Software",
"year" : "2011",
"by" : "Free Software Foundation"
}
]
},
{
"_id" : 9,
"name" : {
"first" : "James",
"last" : "Gosling"
},
"birth" : "1955-05-19T04:00:00Z",
"contribs" : [
"Java"
],
"awards" : [
{
"award" : "The Economist Innovation Award",
"year" : 2002,
"by" : "The Economist"
},
{
"award" : "Officer of the Order of Canada",
"year" : 2007,
"by" : "Canada"
}
]
},
{
"_id" : ObjectId("51df07b094c6acd67e492f51"),
"name" : {
"first" : "Martin",
"last" : "Odersky"
},
"contribs" : [
"Scala"
]
}]`;
ee.ActionTemplateMenuByEntityName("AuthorNAwards", "Insert");
dataSources.ValidateNSelectDropdown("Commands", "Insert Document(s)");
agHelper.EnterValue(insertauthorNAwards, {
propFieldName: "",
directInput: false,
inputFieldName: "Documents",
});
dataSources.RunQuery();
cy.get("@postExecute").then((resObj: any) => {
expect(parseInt(JSON.stringify(resObj.response.body.data.body.n))).to.eq(
3,
);
});
agHelper.AssertElementVisible(dataSources._queryResponse("JSON"));
agHelper.AssertElementVisible(dataSources._queryResponse("RAW"));
agHelper.ActionContextMenuWithInPane("Delete");
});
it("8. Validate 'Update' record from new collection & verify query response - Record not present - All Matching Document", () => {
ee.ActionTemplateMenuByEntityName("AuthorNAwards", "Update");
dataSources.ValidateNSelectDropdown("Commands", "Update Document(s)");
agHelper.EnterValue(`{"_id": 3}`, {
propFieldName: "",
directInput: false,
inputFieldName: "Query",
});
agHelper.EnterValue(`{ "$set": { "birth": "1906-12-09T06:00:00Z" } }`, {
propFieldName: "",
directInput: false,
inputFieldName: "Update",
});
dataSources.ValidateNSelectDropdown("Limit", "All Matching Documents");
dataSources.RunQuery();
cy.get("@postExecute").then((resObj: any) => {
expect(
parseInt(JSON.stringify(resObj.response.body.data.body.nModified)),
).to.eq(0);
});
agHelper.AssertElementVisible(dataSources._queryResponse("JSON"));
agHelper.AssertElementVisible(dataSources._queryResponse("RAW"));
agHelper.ActionContextMenuWithInPane("Delete");
});
it("9. Validate 'Update' record from new collection & verify query response - Record present - All Matching Document", () => {
ee.ActionTemplateMenuByEntityName("AuthorNAwards", "Update");
dataSources.ValidateNSelectDropdown("Commands", "Update Document(s)");
agHelper.EnterValue(
`{
"name.first": "John",
"awards": {
"$elemMatch": {
"award": "Turing Award"
}
}
}`,
{
propFieldName: "",
directInput: false,
inputFieldName: "Query",
},
);
agHelper.EnterValue(`{ "$set": { "year": "1988" } }`, {
propFieldName: "",
directInput: false,
inputFieldName: "Update",
});
dataSources.ValidateNSelectDropdown("Limit", "All Matching Documents");
dataSources.RunQuery();
cy.get("@postExecute").then((resObj: any) => {
expect(
parseInt(JSON.stringify(resObj.response.body.data.body.nModified)),
).to.eq(2);
});
agHelper.AssertElementVisible(dataSources._queryResponse("JSON"));
agHelper.AssertElementVisible(dataSources._queryResponse("RAW"));
agHelper.ActionContextMenuWithInPane("Delete");
});
it("10. Validate 'Update' record from new collection & verify query response - Record present - Single Document", () => {
ee.ActionTemplateMenuByEntityName("AuthorNAwards", "Update");
dataSources.ValidateNSelectDropdown("Commands", "Update Document(s)");
agHelper.EnterValue(`{"_id": 4}`, {
propFieldName: "",
directInput: false,
inputFieldName: "Query",
});
agHelper.EnterValue(`{ "$set": { "birth": "1926-08-27T05:00:00Z" } }`, {
propFieldName: "",
directInput: false,
inputFieldName: "Update",
});
dataSources.ValidateNSelectDropdown(
"Limit",
"All Matching Documents",
"Single Document",
);
dataSources.RunQuery();
cy.get("@postExecute").then((resObj: any) => {
expect(
parseInt(JSON.stringify(resObj.response.body.data.body.nModified)),
).to.eq(1);
});
agHelper.AssertElementVisible(dataSources._queryResponse("JSON"));
agHelper.AssertElementVisible(dataSources._queryResponse("RAW"));
agHelper.ActionContextMenuWithInPane("Delete");
});
it("11. Validate 'Delete' record from new collection & verify query response - Record not present - Single Document", () => {
ee.ActionTemplateMenuByEntityName("AuthorNAwards", "Delete");
dataSources.ValidateNSelectDropdown("Commands", "Delete Document(s)");
agHelper.EnterValue(`{ "_id": ObjectId("51df07b094c6acd67e492f43") }`, {
propFieldName: "",
directInput: false,
inputFieldName: "Query",
});
dataSources.ValidateNSelectDropdown("Limit", "Single Document");
dataSources.RunQuery();
cy.get("@postExecute").then((resObj: any) => {
expect(parseInt(JSON.stringify(resObj.response.body.data.body.n))).to.eq(
0,
);
});
agHelper.AssertElementVisible(dataSources._queryResponse("JSON"));
agHelper.AssertElementVisible(dataSources._queryResponse("RAW"));
agHelper.ActionContextMenuWithInPane("Delete");
});
it("12. Validate 'Delete' record from new collection & verify query response - Record present - Single Document", () => {
ee.ActionTemplateMenuByEntityName("AuthorNAwards", "Delete");
dataSources.ValidateNSelectDropdown("Commands", "Delete Document(s)");
agHelper.EnterValue(`{ "_id": ObjectId("51df07b094c6acd67e492f41") }`, {
propFieldName: "",
directInput: false,
inputFieldName: "Query",
});
dataSources.ValidateNSelectDropdown("Limit", "Single Document");
dataSources.RunQuery();
cy.get("@postExecute").then((resObj: any) => {
expect(parseInt(JSON.stringify(resObj.response.body.data.body.n))).to.eq(
1,
);
});
agHelper.AssertElementVisible(dataSources._queryResponse("JSON"));
agHelper.AssertElementVisible(dataSources._queryResponse("RAW"));
agHelper.ActionContextMenuWithInPane("Delete");
});
it("13. Validate 'Delete' record from new collection & verify query response - Record present - All Matching Document", () => {
ee.ActionTemplateMenuByEntityName("AuthorNAwards", "Delete");
dataSources.ValidateNSelectDropdown("Commands", "Delete Document(s)");
agHelper.EnterValue(`{ "awards.award": "Rosing Prize" }`, {
propFieldName: "",
directInput: false,
inputFieldName: "Query",
});
dataSources.ValidateNSelectDropdown(
"Limit",
"Single Document",
"All Matching Documents",
);
dataSources.RunQuery();
cy.get("@postExecute").then((resObj: any) => {
expect(Number(JSON.stringify(resObj.response.body.data.body.n))).to.eq(2);
});
agHelper.AssertElementVisible(dataSources._queryResponse("JSON"));
agHelper.AssertElementVisible(dataSources._queryResponse("RAW"));
agHelper.ActionContextMenuWithInPane("Delete");
});
it("14. Validate 'Count' record from new collection & verify query response", () => {
ee.ActionTemplateMenuByEntityName("AuthorNAwards", "Count");
dataSources.ValidateNSelectDropdown("Commands", "Count");
dataSources.RunQuery();
cy.get("@postExecute").then((resObj: any) => {
expect(Number(JSON.stringify(resObj.response.body.data.body.n))).to.eq(7);
});
agHelper.AssertElementVisible(dataSources._queryResponse("JSON"));
agHelper.AssertElementVisible(dataSources._queryResponse("RAW"));
agHelper.ActionContextMenuWithInPane("Delete");
});
it("15. Validate 'Distinct' record from new collection & verify query response", () => {
ee.ActionTemplateMenuByEntityName("AuthorNAwards", "Distinct");
dataSources.ValidateNSelectDropdown("Commands", "Distinct");
agHelper.EnterValue(`{ "awards.award": "National Medal of Technology" }`, {
propFieldName: "",
directInput: false,
inputFieldName: "Query",
});
dataSources.RunQuery();
cy.get("@postExecute").then((resObj: any) => {
expect(
JSON.parse(JSON.stringify(resObj.response.body.data.body.values[0])),
).to.eql("51df07b094c6acd67e492f42");
expect(
JSON.parse(JSON.stringify(resObj.response.body.data.body.values[1])),
).to.eql("51e062189c6ae665454e301d");
});
agHelper.AssertElementVisible(dataSources._queryResponse("JSON"));
agHelper.AssertElementVisible(dataSources._queryResponse("RAW"));
agHelper.ActionContextMenuWithInPane("Delete");
});
it("16. Validate 'Aggregate' record from new collection & verify query response", () => {
ee.ActionTemplateMenuByEntityName("AuthorNAwards", "Aggregate");
dataSources.ValidateNSelectDropdown("Commands", "Aggregate");
RunQueryNVerify(7);
});
it("17. Verify Generate CRUD for the new collection & Verify Deploy mode for table - AuthorNAwards", () => {
dataSources.NavigateFromActiveDS(dsName, false);
agHelper.ValidateNetworkStatus("@getDatasourceStructure"); //Making sure table dropdown is populated
agHelper.GetNClick(dataSources._selectTableDropdown);
agHelper.GetNClickByContains(dataSources._dropdownOption, "AuthorNAwards");
GenerateCRUDNValidateDeployPage(
`[{"award":"Award for the Advancement of Free Software","year":2001,"by":"Free Software Foundation"},{"award":"NLUUG Award","year":2003,"by":"NLUUG"}]`,
"6",
"",
3,
);
// agHelper.NavigateBacktoEditor();
// table.WaitUntilTableLoad();
});
//Update, delete, Add goes here
it("18. Validate Deletion of the Newly Created Page - AuthorNAwards", () => {
agHelper.NavigateBacktoEditor();
table.WaitUntilTableLoad();
//Delete the test data
ee.expandCollapseEntity("PAGES");
ee.ActionContextMenuByEntityName(
"AuthorNAwards",
"Delete",
"Are you sure?",
);
agHelper.ValidateNetworkStatus("@deletePage", 200);
});
it("19. Validate Drop of the Newly Created - Stores - Table from MySQL datasource", () => {
let dropCollection = `{ "drop": "AuthorNAwards" }`;
dataSources.NavigateFromActiveDS(dsName, true);
dataSources.ValidateNSelectDropdown("Commands", "Find Document(s)", "Raw");
agHelper.GetNClick(dataSources._templateMenu);
agHelper.RenameWithInPane("DropAuthorNAwardsPage");
agHelper.EnterValue(dropCollection);
cy.get(".CodeMirror textarea").focus();
//agHelper.VerifyEvaluatedValue(tableCreateQuery);
dataSources.RunQuery();
agHelper.ActionContextMenuWithInPane("Delete");
ee.expandCollapseEntity(dsName);
ee.ActionContextMenuByEntityName(dsName, "Refresh");
agHelper.AssertElementAbsence(ee._entityNameInExplorer("AuthorNAwards"));
});
it("20. Verify application does not break when user runs the query with wrong table name", function() {
let dropCollection = `{ "drop": "AuthorNAwards" }`;
dataSources.NavigateFromActiveDS(dsName, true);
dataSources.ValidateNSelectDropdown("Commands", "Find Document(s)", "Raw");
agHelper.GetNClick(dataSources._templateMenu);
agHelper.RenameWithInPane("DropStores");
agHelper.EnterValue(dropCollection);
cy.get(".CodeMirror textarea").focus();
//agHelper.VerifyEvaluatedValue(tableCreateQuery);
dataSources.RunQuery(false);
agHelper
.GetText(dataSources._queryError)
.then(($errorText) =>
expect($errorText).to.eq("ns not found."),
);
agHelper.ActionContextMenuWithInPane("Delete");
});
function GenerateCRUDNValidateDeployPage(
col1Text: string,
col2Text: string,
col3Text: string,
idIndex: number,
) {
agHelper.GetNClick(dataSources._generatePageBtn);
agHelper.ValidateNetworkStatus("@replaceLayoutWithCRUDPage", 201);
agHelper.ValidateToastMessage("Successfully generated a page");
agHelper.ValidateNetworkStatus("@getActions", 200);
agHelper.ValidateNetworkStatus("@postExecute", 200);
agHelper.ValidateNetworkStatus("@updateLayout", 200);
agHelper.GetNClick(dataSources._visibleTextSpan("GOT IT"));
deployMode.DeployApp();
//Validating loaded table
agHelper.AssertElementExist(dataSources._selectedRow);
table.ReadTableRowColumnData(0, 0, 2000).then(($cellData) => {
expect($cellData).to.eq(col1Text);
});
table.ReadTableRowColumnData(0, 3, 200).then(($cellData) => {
expect($cellData).to.eq(col2Text);
});
table.ReadTableRowColumnData(0, 6, 200).then(($cellData) => {
expect($cellData).to.eq(col3Text);
});
//Validating loaded JSON form
cy.xpath(locator._spanButton("Update")).then((selector) => {
cy.wrap(selector)
.invoke("attr", "class")
.then((classes) => {
//cy.log("classes are:" + classes);
expect(classes).not.contain("bp3-disabled");
});
});
dataSources.AssertJSONFormHeader(0, idIndex, "Id", "", true);
}
function RunQueryNVerify(expectdRecordCount = 1) {
dataSources.RunQuery();
agHelper.AssertElementVisible(dataSources._queryResponse("JSON"));
agHelper.AssertElementVisible(dataSources._queryResponse("RAW"));
agHelper.AssertElementVisible(
dataSources._queryRecordResult(expectdRecordCount),
);
agHelper.ActionContextMenuWithInPane("Delete");
}
});

View File

@ -60,7 +60,7 @@ describe("Validate MySQL Generate CRUD with JSON Form", () => {
ee.ActionContextMenuByEntityName("Page2", "Delete", "Are you sure?");
agHelper.ValidateNetworkStatus("@deletePage", 200);
//Unable to delete ds until app is published again
//Should not be able to delete ds until app is published again
//coz if app is published & shared then deleting ds may cause issue, So!
cy.get("@dsName").then(($dsName) => {
dsName = $dsName;

View File

@ -1,214 +0,0 @@
const pages = require("../../../../locators/Pages.json");
const generatePage = require("../../../../locators/GeneratePage.json");
import homePage from "../../../../locators/HomePage";
const datasource = require("../../../../locators/DatasourcesEditor.json");
const commonlocators = require("../../../../locators/commonlocators.json");
describe("Generate New CRUD Page Inside from Mongo as Data Source", function() {
let datasourceName;
before(() => {
cy.startRoutesForDatasource();
//cy.startInterceptRoutesForMongo(); //if used in before - 2nd testcase failing with no aliasing found error
});
beforeEach(function() {
if (Cypress.env("Mongo") === 0) {
cy.log("Mongo DB is not found. Using intercept");
cy.startInterceptRoutesForMongo();
} else cy.log("Mongo DB is found, hence using actual DB");
});
it("1. Add new Page and generate CRUD template using existing supported datasource", function() {
cy.NavigateToDatasourceEditor();
cy.get(datasource.MongoDB).click({ force: true });
if (Cypress.env("Mongo") === 0) cy.fillMongoDatasourceFormWithURI();
else cy.fillMongoDatasourceForm();
cy.generateUUID().then((uid) => {
datasourceName = `Mongo MOCKDS ${uid}`;
cy.renameDatasource(datasourceName);
cy.wrap(datasourceName).as("dSName");
});
//TestData source
cy.get(".t--test-datasource").click({ force: true });
cy.wait("@testDatasource");
//Save source
cy.get(".t--save-datasource").click({ force: true });
//Verify page after save clicked
cy.get("@createDatasource").then((httpResponse) => {
datasourceName = httpResponse.response.body.data.name;
});
//Create New page
cy.get(pages.AddPage)
.first()
.click();
cy.wait("@createPage").should(
"have.nested.property",
"response.body.responseMeta.status",
201,
);
//Generate New CRUD in new page
cy.get("@dSName").then((dbName) => {
cy.get(generatePage.generateCRUDPageActionCard).click();
cy.get(generatePage.selectDatasourceDropdown).click();
cy.get(generatePage.datasourceDropdownOption)
.contains(dbName)
.click();
});
cy.wait("@getDatasourceStructure").should(
"have.nested.property",
"response.body.responseMeta.status",
200,
);
cy.get(generatePage.selectTableDropdown).click();
cy.get(generatePage.dropdownOption)
.first()
.click();
cy.get(generatePage.generatePageFormSubmitBtn).click();
cy.wait("@replaceLayoutWithCRUDPage").should(
"have.nested.property",
"response.body.responseMeta.status",
201,
);
cy.wait("@getActions").should(
"have.nested.property",
"response.body.responseMeta.status",
200,
);
cy.wait("@postExecute").should(
"have.nested.property",
"response.body.responseMeta.status",
200,
);
cy.get(commonlocators.toastAction)
.should("have.length", 1)
.should("have.text", "Successfully generated a page");
cy.get("span:contains('GOT IT')").click();
});
it("2. Create new app and Generate CRUD page using a new datasource", function() {
cy.NavigateToHome();
cy.get(homePage.createNew)
.first()
.click({ force: true });
cy.wait("@createNewApplication").should(
"have.nested.property",
"response.body.responseMeta.status",
201,
);
cy.get(generatePage.generateCRUDPageActionCard).click();
cy.get(generatePage.selectDatasourceDropdown).click();
cy.contains("Connect New Datasource").click();
cy.get(datasource.MongoDB).click();
if (Cypress.env("Mongo") === 0) cy.fillMongoDatasourceFormWithURI();
else cy.fillMongoDatasourceForm();
cy.generateUUID().then((uid) => {
datasourceName = `Mongo MOCKDS ${uid}`;
cy.renameDatasource(datasourceName);
cy.wrap(datasourceName).as("dSName");
});
//TestData source
cy.get(".t--test-datasource").click({ force: true });
cy.wait("@testDatasource");
//Save source
cy.get(".t--save-datasource").click({ force: true });
//Generate Stub for tables dropdown values also
cy.wait("@getDatasourceStructure").should(
"have.nested.property",
"response.body.responseMeta.status",
200,
);
cy.get(generatePage.selectTableDropdown).click();
cy.get(generatePage.dropdownOption)
.first()
.click();
cy.get(generatePage.generatePageFormSubmitBtn).click();
cy.wait("@replaceLayoutWithCRUDPage").should(
"have.nested.property",
"response.body.responseMeta.status",
201,
);
cy.wait("@getActions").should(
"have.nested.property",
"response.body.responseMeta.status",
200,
);
cy.wait("@postExecute").should(
"have.nested.property",
"response.body.responseMeta.status",
200,
);
cy.get("span:contains('GOT IT')").click();
});
it("3. Generate CRUD page from datasource ACTIVE section", function() {
cy.NavigateToQueryEditor();
cy.NavigateToActiveTab();
cy.wait(1000);
cy.get(datasource.datasourceCard)
.contains(datasourceName)
.scrollIntoView()
.should("be.visible")
.closest(datasource.datasourceCard)
.within(() => {
cy.get(datasource.datasourceCardGeneratePageBtn).click();
});
//Generate Stub for tables dropdown values also
cy.wait("@getDatasourceStructure").should(
"have.nested.property",
"response.body.responseMeta.status",
200,
);
cy.get(generatePage.selectTableDropdown).click();
cy.get(generatePage.dropdownOption)
.first()
.click();
cy.get(generatePage.generatePageFormSubmitBtn).click();
cy.wait("@replaceLayoutWithCRUDPage").should(
"have.nested.property",
"response.body.responseMeta.status",
201,
);
cy.wait("@getActions").should(
"have.nested.property",
"response.body.responseMeta.status",
200,
);
cy.wait("@postExecute").should(
"have.nested.property",
"response.body.responseMeta.status",
200,
);
cy.get("span:contains('GOT IT')").click();
});
});

View File

@ -60,6 +60,7 @@ export class CommonLocators {
_existingFieldTextByName = (fieldName: string) => "//label[text()='" + fieldName + "']/ancestor::div[contains(@class, 't--property-control-" + fieldName.replace(/ +/g, "").toLowerCase() + "')]"
_existingFieldValueByName = (fieldName: string) => this._existingFieldTextByName(fieldName) + "//div[contains(@class,'CodeMirror-code')]"
_existingActualValueByName = (fieldName: string) => this._existingFieldValueByName(fieldName) + "//span/span"
_codeMirrorValue = "//div[contains(@class,'CodeMirror-code')]//span/span"
_evaluatedCurrentValue = "div:last-of-type .t--CodeEditor-evaluatedValue > div:last-of-type pre"
_multiSelectOptions = (option: string) => "div[title='" + option + "'] input[type='checkbox']"
_divWithClass = (className: string) => "//div[contains(@class, '" + className + "')]"

View File

@ -3,6 +3,17 @@ const uuid = require("uuid");
import { ObjectsRegistry } from "../Objects/Registry";
let LOCAL_STORAGE_MEMORY: any = {};
export interface IEnterValue {
propFieldName: string;
directInput: boolean;
inputFieldName: string;
}
const DEFAULT_ENTERVALUE_OPTIONS = {
propFieldName: "",
directInput: false,
inputFieldName: "",
};
export class AggregateHelper {
private locator = ObjectsRegistry.CommonLocators;
@ -449,7 +460,7 @@ export class AggregateHelper {
public RefreshPage() {
cy.reload();
this.Sleep(2000)
this.Sleep(2000);
}
public ActionContextMenuWithInPane(
@ -471,21 +482,36 @@ export class AggregateHelper {
}
public TypeValueNValidate(valueToType: string, fieldName = "") {
this.EnterValue(valueToType, fieldName);
this.EnterValue(valueToType, {
propFieldName: fieldName,
directInput: false,
inputFieldName: "",
});
this.VerifyEvaluatedValue(valueToType);
}
public EnterValue(valueToEnter: string, fieldName = "", notField = false) {
if (fieldName && !notField) {
cy.xpath(this.locator._existingFieldTextByName(fieldName)).then(
public EnterValue(
valueToEnter: string,
options: IEnterValue = DEFAULT_ENTERVALUE_OPTIONS,
) {
const { propFieldName, directInput, inputFieldName } = options;
if (propFieldName && !directInput && !inputFieldName) {
cy.xpath(this.locator._existingFieldTextByName(propFieldName)).then(
($field: any) => {
this.UpdateCodeInput($field, valueToEnter);
},
);
} else if (fieldName && notField) {
cy.get(fieldName).then(($field: any) => {
} else if (propFieldName && directInput && !inputFieldName) {
cy.get(propFieldName).then(($field: any) => {
this.UpdateCodeInput($field, valueToEnter);
});
} else if (inputFieldName && !propFieldName && !directInput) {
cy.xpath(this.locator._inputFieldByName(inputFieldName)).then(
($field: any) => {
this.UpdateCodeInput($field, valueToEnter);
},
);
} else {
cy.get(this.locator._codeEditorTarget).then(($field: any) => {
this.UpdateCodeInput($field, valueToEnter);
@ -572,10 +598,11 @@ export class AggregateHelper {
});
}
public AssertElementAbsence(selector: string){//Should not exists - cannot take indexes
public AssertElementAbsence(selector: string) {
//Should not exists - cannot take indexes
let locator = selector.startsWith("//")
? cy.xpath(selector, { timeout: 0 })
: cy.get(selector, { timeout: 0 })
: cy.get(selector, { timeout: 0 });
locator.should("not.exist");
}

View File

@ -79,24 +79,44 @@ export class ApiPage {
}
EnterURL(url: string) {
this.agHelper.EnterValue(url, this._resourceUrl, true);
this.agHelper.EnterValue(url, {
propFieldName: this._resourceUrl,
directInput: true,
inputFieldName: "",
});
this.agHelper.AssertAutoSave();
}
EnterHeader(hKey: string, hValue: string) {
this.SelectPaneTab("Headers");
this.agHelper.EnterValue(hKey, this._headerKey(0), true);
this.agHelper.EnterValue(hKey, {
propFieldName: this._headerKey(0),
directInput: true,
inputFieldName: "",
});
cy.get("body").type("{esc}");
this.agHelper.EnterValue(hValue, this._headerValue(0), true);
this.agHelper.EnterValue(hValue, {
propFieldName: this._headerValue(0),
directInput: true,
inputFieldName: "",
});
cy.get("body").type("{esc}");
this.agHelper.AssertAutoSave();
}
EnterParams(pKey: string, pValue: string) {
this.SelectPaneTab("Params");
this.agHelper.EnterValue(pKey, this._paramKey(0), true);
this.agHelper.EnterValue(pKey, {
propFieldName: this._paramKey(0),
directInput: true,
inputFieldName: "",
});
cy.get("body").type("{esc}");
this.agHelper.EnterValue(pValue, this._paramValue(0), true);
this.agHelper.EnterValue(pValue, {
propFieldName: this._paramValue(0),
directInput: true,
inputFieldName: "",
});
cy.get("body").type("{esc}");
this.agHelper.AssertAutoSave();
}
@ -114,7 +134,11 @@ export class ApiPage {
cy.get(this._trashDelete).click();
cy.xpath(this._visibleTextSpan("Add more")).click();
}
this.agHelper.EnterValue(bKey, this._bodyKey(0), true);
this.agHelper.EnterValue(bKey, {
propFieldName: this._bodyKey(0),
directInput: true,
inputFieldName: "",
});
cy.get("body").type("{esc}");
if (type) {
@ -123,7 +147,11 @@ export class ApiPage {
.click();
cy.xpath(this._visibleTextDiv(type)).click();
}
this.agHelper.EnterValue(bValue, this._bodyValue(0), true);
this.agHelper.EnterValue(bValue, {
propFieldName: this._bodyValue(0),
directInput: true,
inputFieldName: "",
});
cy.get("body").type("{esc}");
this.agHelper.AssertAutoSave();
}
@ -144,14 +172,14 @@ export class ApiPage {
OnPageLoadRun(enable = true || false) {
this.SelectPaneTab("Settings");
if(enable)
cy.get(this._onPageLoad).check({
force: true,
});
if (enable)
cy.get(this._onPageLoad).check({
force: true,
});
else
cy.get(this._onPageLoad).uncheck({
force: true,
});
cy.get(this._onPageLoad).uncheck({
force: true,
});
}
ConfirmBeforeRunningApi(enable = true || false) {

View File

@ -50,7 +50,13 @@ export class DataSources {
"//div[@data-guided-tour-id='query-table-response']//div[@class='tbody']//div[@class ='td']";
_refreshIcon = "button .bp3-icon-refresh";
_addIcon = "button .bp3-icon-add";
_queryError = "span.t--query-error"
_queryError = "span.t--query-error";
_queryResponse = (responseType: string) =>
"li[data-cy='t--tab-" + responseType + "']";
_queryRecordResult = (recordCount: number) =>
"//div/span[text()='Result:']/span[contains(text(),'" +
recordCount +
" Record')]";
public StartDataSourceRoutes() {
cy.intercept("PUT", "/api/v1/datasources/*").as("saveDatasource");
@ -105,10 +111,37 @@ export class DataSources {
}).as("replaceLayoutWithCRUDPage");
}
public StartInterceptRoutesForMongo() {
//All stubbing
this.ReplaceApplicationIdForInterceptPages(
"cypress/fixtures/mongo_PUT_replaceLayoutWithCRUD.json",
);
cy.intercept("POST", "/api/v1/datasources/test", {
fixture: "testAction.json",
}).as("testDatasource");
cy.intercept("GET", "/api/v1/datasources/*/structure?ignoreCache=*", {
fixture: "mongo_GET_selectTableDropdown.json",
}).as("getDatasourceStructure");
cy.intercept("PUT", "/api/v1/pages/crud-page/*", {
fixture: "mongo_PUT_replaceLayoutWithCRUD.json",
}).as("replaceLayoutWithCRUDPage");
cy.intercept("GET", "/api/v1/actions*", {
fixture: "mongo_GET_Actions.json",
}).as("getActions");
cy.intercept("POST", "/api/v1/actions/execute", {
fixture: "mongo_POST_Actions.json",
}).as("postExecute");
cy.intercept("POST", "/api/v1/pages/crud-page", {
fixture: "mongo_PUT_replaceLayoutWithCRUD.json",
}).as("post_replaceLayoutCRUDStub");
}
public CreatePlugIn(pluginName: string) {
cy.get(this._createNewPlgin(pluginName))
.parent("div")
.trigger("click", { force: true });
this.agHelper.WaitUntilToastDisappear("datasource created");
}
public NavigateToDSCreateNew() {
@ -177,6 +210,7 @@ export class DataSources {
public TestDatasource(expectedRes = true) {
cy.get(this._testDs).click();
this.agHelper.ValidateNetworkDataSuccess("@testDatasource", expectedRes);
this.agHelper.WaitUntilToastDisappear("datasource is valid");
}
public SaveDatasource() {
@ -208,7 +242,10 @@ export class DataSources {
this.agHelper.ValidateNetworkStatus("@deleteDatasource", expectedRes);
}
public DeleteDatasouceFromWinthinDS(datasourceName: string, expectedStatus = 200) {
public DeleteDatasouceFromWinthinDS(
datasourceName: string,
expectedStatus = 200,
) {
this.NavigateToDSCreateNew();
this.agHelper.GetNClick(this._activeTab);
cy.get(this._datasourceCard)
@ -280,7 +317,10 @@ export class DataSources {
RunQuery(expectedStatus = true) {
cy.get(this._runQueryBtn).click({ force: true });
this.agHelper.ValidateNetworkExecutionSuccess("@postExecute", expectedStatus);
this.agHelper.ValidateNetworkExecutionSuccess(
"@postExecute",
expectedStatus,
);
}
public ReadQueryTableResponse(index: number, timeout = 100) {
@ -297,16 +337,19 @@ export class DataSources {
colIndex: number,
headerString: string,
validateCellData: "" | string = "",
isMongo = false,
) {
let jsonHeaderString = "";
this.table.ReadTableRowColumnData(rowindex, colIndex).then(($cellData) => {
if (validateCellData) expect($cellData).to.eq(validateCellData);
jsonHeaderString =
isMongo == true
? "Update Document " + headerString + ": " + $cellData
: "Update Row " + headerString + ": " + $cellData;
this.agHelper
.GetText(this.locator._jsonFormHeader)
.then(($header: any) =>
expect($header).to.eq(
"Update Row " + headerString + ": " + $cellData,
),
);
.then(($header: any) => expect($header).to.eq(jsonHeaderString));
});
}
}

View File

@ -1,5 +1,19 @@
import { ObjectsRegistry } from "../Objects/Registry";
type templateActions =
| "SELECT"
| "INSERT"
| "UPDATE"
| "DELETE"
| "Find"
| "Find by ID"
| "Insert"
| "Update"
| "Delete"
| "Count"
| "Distinct"
| "Aggregate";
export class EntityExplorer {
public agHelper = ObjectsRegistry.AggregateHelper;
public locator = ObjectsRegistry.CommonLocators;
@ -97,7 +111,7 @@ export class EntityExplorer {
public ActionTemplateMenuByEntityName(
entityNameinLeftSidebar: string,
action: "SELECT" | "INSERT" | "UPDATE" | "DELETE",
action: templateActions,
) {
cy.xpath(this._templateMenuTrigger(entityNameinLeftSidebar))
.last()

View File

@ -99,7 +99,7 @@ export class JSEditor {
cy.get(this._jsObjTxt).should("not.exist");
//cy.waitUntil(() => cy.get(this.locator._toastMsg).should('not.be.visible')) // fails sometimes
//this.agHelper.WaitUntilEleDisappear(this.locator._toastMsg, 'created successfully')
//this.agHelper.WaitUntilToastDisappear('created successfully')
this.agHelper.Sleep();
}
@ -212,7 +212,11 @@ export class JSEditor {
// .type("{del}", { force: true });
if (paste) {
this.agHelper.EnterValue(value, endp, notField);
this.agHelper.EnterValue(value, {
propFieldName: endp,
directInput: notField,
inputFieldName: "",
});
} else {
cy.get(
this.locator._propertyControl +

View File

@ -44,8 +44,8 @@ export class Table {
_showPageItemsCount = "div.show-page-items"
_filtersCount = this._filterBtn + " span.action-title"
public WaitUntilTableLoad() {
cy.waitUntil(() => this.ReadTableRowColumnData(0, 0, 2000),
public WaitUntilTableLoad(rowIndex = 0, colIndex = 0) {
cy.waitUntil(() => this.ReadTableRowColumnData(rowIndex, colIndex, 2000),
{
errorMsg: "Table is not populated",
timeout: 10000,