mercredi 15 juillet 2020

SAPUI5 Problems with testing filtering with QuniT

I'm trying to test filtering on a table in the controller with QUnit. Now i came across some problems when trying to invoke the onApplyFilter Function. I am having Problems to rebuild this Event that is sent to onApplyFilter, especially when it comes to mock the table it throws me all kind of errors that these objects are not defined, so im not sure if this is the right way anyway.

I also tried building a new table with new sap.m.Table(...). But here the .getBinding() call in onApplyFilter is returning null.

        function createTable() {
            var oTable = new sap.m.Table("idTestTable", {
                inset: true,
                headerText: "TestTable",
                headerDesign: sap.m.ListHeaderDesign.Standard,
                mode: sap.m.ListMode.None,
                includeItemInSelection: false,
            });

            var col1 = new sap.m.Column("col1", { header: new sap.m.Label({ text: "CreatedBy" }) });
            oTable.addColumn(col1);

            var col2 = new sap.m.Column("col2", { header: new sap.m.Label({ text: "InstanceID" }) });
            oTable.addColumn(col2);

            var col3 = new sap.m.Column("col3", { header: new sap.m.Label({ text: "CREATED_BY_ID" }) });
            oTable.addColumn(col3);

            var col4 = new sap.m.Column("col4", { header: new sap.m.Label({ text: "REQUESTED_BY_NAME" }) });
            oTable.addColumn(col4);  

            var col5 = new sap.m.Column("col5", { header: new sap.m.Label({ text: "OPERATION_NAME" }) });
            oTable.addColumn(col5);  

            var colItems = new sap.m.ColumnListItem("colItems", { type: "Active" });
            oTable.bindAggregation("items", "{DatabaseModel>/results}", colItems);

            var txtNAME = new sap.m.Text("txtNAME", { text: "{CreatedBy}" });
            colItems.addCell(txtNAME);

            var txtNAME2 = new sap.m.Text("txtNAME2", { text: "{InstanceID}" });
            colItems.addCell(txtNAME2);

            var txtNAME3 = new sap.m.Text("txtNAME3", { text: "{CREATED_BY_ID}" });
            colItems.addCell(txtNAME3);

            var txtNAME4 = new sap.m.Text("txtNAME4", { text: "{REQUESTED_BY_NAME}" });
            colItems.addCell(txtNAME4);

            var txtNAME5 = new sap.m.Text("txtNAME5", { text: "{OPERATION_NAME}" });
            colItems.addCell(txtNAME5);

            return oTable;
        }

Anyway is this a useful way to test the filtering on my table or could i try some other approach? If not how can i create/instantiate a table to test the filtering successfully?

here are the table of the view and the function of the controller. As mentioned before the table is the one from sap.m

            <Table
                id="idOwnOpenTasksTable"
                items="{path:'DatabaseModel>/results'}" 
                noDataText="{masterView>/tableNoDataText}" 
                busyIndicatorDelay="{masterView>/tableBusyDelay}" 
                growing="true" 
                growingScrollToLoad="true" 
                updateFinished="onUpdateFinished">
                <headerToolbar>
                    <Toolbar>
                        <content>
                            <ToolbarSpacer />
                            <SearchField placeholder="Filter" value="{DisplayModel>/sFilter}" showSearchButton="true" visible="true" width="auto" search="onApplyFilter">
                            </SearchField>
                        </content>
                    </Toolbar>
                </headerToolbar>
                <columns>
                        <Column width="auto">
                            <Text text="{i18n>description}" />
                        </Column>
                        <Column width="8rem" minScreenWidth="Phone" hAlign="End" demandPopin="true">
                            <Text text="{i18n>id}" />
                        </Column>
                        <Column width="8rem" minScreenWidth="Phone" hAlign="End" demandPopin="true">
                            <Text text="{i18n>request}" />
                        </Column>
                        <Column width="8rem" minScreenWidth="Desktop" hAlign="End" demandPopin="true">
                            <Text text="{i18n>operation}" />
                        </Column>
                        <Column width="8rem" minScreenWidth="Desktop" hAlign="End" demandPopin="true">
                            <Text text="{i18n>requested}" />
                        </Column>
                        <Column width="8rem" minScreenWidth="Desktop" hAlign="End" demandPopin="true">
                            <Text text="{i18n>expiryDate}" />
                        </Column>
                </columns>
                <items>
                    <ColumnListItem type="Navigation" vAlign="Middle" press="onSelectRow">
                        <cells>
                            <ObjectIdentifier title="{DatabaseModel>CreatedBy}" />
                            <ObjectAttribute text="{DatabaseModel>CREATED_BY_ID}" />
                            <ObjectAttribute text="{DatabaseModel>REQUESTED_BY_NAME}" />
                            <ObjectAttribute text="{DatabaseModel>OPERATION_NAME}" />
                            <ObjectAttribute text="{
                                path: 'DatabaseModel>CreatedOn',
                                formatter: '.Formatter.convertUnixTimestamp'
                            }" />
                            <ObjectAttribute text="{
                                path: 'DatabaseModel>ExpiryDate',
                                formatter: '.Formatter.convertUnixTimestamp'
                            }" />
                        </cells>
                    </ColumnListItem>
                </items>
            </Table>
onApplyFilter: function(oEvent){
            var sQuery = oEvent.getParameter("query");
            var oFilter = new Filter([
                new Filter("CreatedBy", FilterOperator.Contains, sQuery),
                new Filter("InstanceID", FilterOperator.Contains, sQuery),
                new Filter("CREATED_BY_ID", FilterOperator.EQ, sQuery),
                new Filter("REQUESTED_BY_NAME", FilterOperator.Contains, sQuery),
                new Filter("OPERATION_NAME", FilterOperator.Contains, sQuery)
            ]);
            var oTable = oEvent.getSource().getParent().getParent();
            oTable.getBinding("items").filter(oFilter, "Application");
        }

Aucun commentaire:

Enregistrer un commentaire