Add add-child capability to recordGridWidget; making new standard Widget that others can(should) use

This commit is contained in:
2022-12-05 16:08:50 -06:00
parent 83e0084f2f
commit 18c15543f9
11 changed files with 564 additions and 165 deletions

View File

@ -1,10 +1,13 @@
/// <reference types="cypress-wait-for-stable-dom" />
import QLib from "./lib/qLib";
describe("table query screen", () =>
{
before(() =>
{
QLib.init(cy);
cy.intercept("GET", "/metaData/authentication", {fixture: "metaData/authentication.json"}).as("authenticationMetaData");
cy.intercept("GET", "/metaData", {fixture: "metaData/index.json"}).as("metaData");
cy.intercept("GET", "/metaData/table/person", {fixture: "metaData/table/person.json"}).as("personMetaData");
@ -29,14 +32,13 @@ describe("table query screen", () =>
});
});
it.only("can add query filters", () =>
it("can add query filters", () =>
{
/////////////////////////////////////////////////////////////
// go to table, wait for filter to run, and rows to appear //
/////////////////////////////////////////////////////////////
cy.visit("https://localhost:3000/peopleApp/greetingsApp/person");
cy.wait(["@personQuery", "@personCount"]);
cy.get(".MuiDataGrid-virtualScrollerRenderZone").children().should("have.length.greaterThan", 3);
QLib.waitForQueryScreen();
/////////////////////////////////////////////////////////////////////
// open the filter window, enter a value, wait for query to re-run //
@ -72,6 +74,29 @@ describe("table query screen", () =>
cy.contains(".MuiDataGrid-toolbarContainer .MuiBadge-root", "1").should("not.exist");
});
it.only("can do a boolean or query", () =>
{
/////////////////////////////////////////
// go to table, wait for filter to run //
/////////////////////////////////////////
cy.visit("https://localhost:3000/peopleApp/greetingsApp/person");
QLib.waitForQueryScreen();
QLib.buildEntityListQueryFilter([
{fieldLabel: "First Name", operator: "contains", textValue: "Dar"},
{fieldLabel: "First Name", operator: "contains", textValue: "Jam"}
], "or");
let expectedFilterContents0 = JSON.stringify({fieldName: "firstName", operator: "CONTAINS", values: ["Dar"]});
let expectedFilterContents1 = JSON.stringify({fieldName: "firstName", operator: "CONTAINS", values: ["Jam"]});
cy.wait("@personQuery").its("request.body").should((body) =>
{
expect(body).to.contain(expectedFilterContents0);
expect(body).to.contain(expectedFilterContents1);
expect(body).to.contain("asdf");
});
});
// tests to add:
// - filter boolean OR
// - sort column

86
cypress/e2e/lib/qLib.ts Normal file
View File

@ -0,0 +1,86 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2022. Kingsrook, LLC
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
* contact@kingsrook.com
* https://github.com/Kingsrook/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
export default class QLib
{
// @ts-ignore
private static cy: Cypress.cy;
// @ts-ignore
public static init(cy: Cypress.cy)
{
QLib.cy = cy;
}
/*******************************************************************************
** Wait for a query to finish on the entity-list screen. specifically, wait for
** personQuery & personCount requests, and wait for the data grid to have rows.
*******************************************************************************/
public static waitForQueryScreen()
{
QLib.cy.wait(["@personQuery", "@personCount"]);
QLib.cy.get(".MuiDataGrid-virtualScrollerRenderZone").children().should("have.length.greaterThan", 3);
}
/*******************************************************************************
** Open the Filters drop down, and build a query
*******************************************************************************/
public static buildEntityListQueryFilter(input: QueryFilterInput | QueryFilterInput[], booleanOperator: ("and" | "or") = "and")
{
QLib.cy.contains("Filters").click();
if ((input as QueryFilterInput).fieldLabel)
{
const queryFilterInput = input as QueryFilterInput;
QLib.addSingleQueryFilterInput(queryFilterInput, 0, booleanOperator);
}
else
{
const inputArray = input as QueryFilterInput[];
inputArray.forEach((qfi, index) => QLib.addSingleQueryFilterInput(qfi, index, booleanOperator));
}
}
/*******************************************************************************
** private helper - adds 1 query filter input.
*******************************************************************************/
private static addSingleQueryFilterInput(queryFilterInput: QueryFilterInput, index: number, booleanOperator: ("and" | "or"))
{
if (index > 0)
{
QLib.cy.contains("Add filter").click();
QLib.cy.get(".MuiDataGrid-filterForm").eq(index).find(".MuiDataGrid-filterFormLinkOperatorInput SELECT").select(booleanOperator);
}
QLib.cy.get(".MuiDataGrid-filterForm").eq(index).find(".MuiDataGrid-filterFormColumnInput SELECT").select(queryFilterInput.fieldLabel);
QLib.cy.get(".MuiDataGrid-filterForm").eq(index).find(".MuiDataGrid-filterFormOperatorInput SELECT").select(queryFilterInput.operator);
QLib.cy.get(".MuiDataGrid-filterForm").eq(index).find(".MuiDataGrid-filterFormValueInput INPUT").type(queryFilterInput.textValue);
}
}
interface QueryFilterInput
{
fieldLabel?: string;
fieldName?: string;
operator?: string;
textValue?: string;
}