Testing AG Grid's TypeScript in-line cell editing using Jest

I am currently working on writing Jest tests to evaluate the functionality of my ag-grid table.

So far, I have created tests to check the default data in the grid and to test a button that adds an additional row of data to the grid.

I am now attempting to modify a cell by using in-line editing with a simulated double click on the desired cell. However, despite following up with userEvent.type(), the cell does not seem to update. It is unclear whether this issue arises due to asynchronous behavior delaying the data update or if there is an error in the simulation of typing/clicking.

The failing test code snippet is as follows:

test("tests the inline cell editing", async () => {
        const onClick = jest.fn();
        render(<DummyGrid onClick={onClick} />);

        const row = screen
            .getAllByRole("row")
            .filter((item) => item.getAttribute("row-id") === "1");
        fireEvent.doubleClick(row[1]);

        userEvent.type(row[1], "GT{enter}");

        await waitFor(() => {
            expect(screen.getByText("GT")).toBeInTheDocument();
        });
    });

Below is the DummyGrid component for ag-grid:

import React, { useState } from "react";
import { AgGridReact } from "ag-grid-react/lib/agGridReact";
import { ColDef, ValueSetterParams } from "ag-grid-community";

import GridButton from "./GridButton";
import Car from "./car";
import { Button } from "react-bootstrap";

import "ag-grid-community/dist/styles/ag-grid.css";
import "ag-grid-community/dist/styles/ag-theme-alpine-dark.css";

// Remaining component code omitted for brevity

export default DummyGrid;

Any assistance or insights on testing ag-grid with Jest, specifically regarding in-line editing, would be highly appreciated. Limited resources are available on testing in-line ag-grid editing with Jest compared to testing buttons that trigger updates to the grid.

Answer №1

To improve functionality, consider utilizing the userEvent.keyboard method to update the input instead of using userEvent.type

This particular test script has been successful in my testing environment with the specified configurations. It utilizes AG Grid v31 and version 14 of @testing-library.

const App = () => {
    const gridRef = useRef<AgGridReact<RowData>>(null);

    const [rowData] = useState<RowData[]>([
        { make: 'Toyota', model: 'Celica', price: 35000 },
        { make: 'Ford', model: 'Mondeo', price: 32000 },
        { make: 'Porsche', model: 'Boxster', price: 72000 }
    ]);
    const [colDefs, setColDefs] = useState<ColDef<RowData>[]>([
        { field: 'make' },
        { field: 'model' },
        { field: 'price', editable: true},
    ]);

    return (
        <div className="ag-theme-quartz" style={{ height: 400, width: 600 }}>
            <AgGridReact<RowData>
                ref={gridRef}
                rowData={rowData}
                columnDefs={colDefs}
                modules={[ClientSideRowModelModule]} />
        </div>
    );
};

    test('double click cell to edit', async () => {
        render(<App />);

        let porschePrice = await screen.findByText('72000')

        // double click to enter edit mode       
        await userEvent.dblClick(porschePrice);

        let input: HTMLInputElement = within(porschePrice).getByLabelText('Input Editor');

        await userEvent.keyboard('100000');

        // press enter to save
        fireEvent.keyDown(input, { key: 'Enter', code: 'Enter' });

        porschePrice = await screen.findByText('100000')

    });

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Why should design patterns be implemented in javascript?

I recently delved into the world of Design patterns and stumbled upon the Module Design pattern in JavaScript. This pattern offers object-oriented features like private and public variables in JavaScript. However, I found myself questioning the need to d ...

Node.js user update complete

I am currently working on enabling users to edit their profiles. However, the code I have set up does not seem to be functioning as expected. The form I am using looks like this: <form action="/dashboard/users/edit/:id" method="put"> And my route ...

Updating input value using v-model in Vue.js does not reflect changes

I'm struggling with formatting numbers that I input in an HTML text box. I have a function that is supposed to format the number when I click out of the input box, but the updated value is not reflected in the v-model. The function is working correct ...

Orbiting ThreeJS object positioned at the coordinates (0,0,0)

I have set up a ThreeJS Scene similar to the image provided. The issue I'm facing is when trying to rotate Obj2 vertically around Obj1, it ends up rotating around the Z axis instead of the center point (0,0,0). My goal is for Obj2 to orbit exclusively ...

Fluidly adjust text field and label fields in forms

I came across a code snippet that allows for dynamically adding form text fields. However, I needed to ensure that each text field has a corresponding label which increments by one every time a new field is added. While I have successfully added the labels ...

Tree Structure with updated ParentId and ChildId

Dealing with a JSON hierarchy tree that has multiple levels of nesting can be tricky. Trying to loop through this JSON data to display the tree structure in the UI often leads to cyclic redundancy issues, especially when the parent IDs are the same at diff ...

Error encountered while adding x-ray-scraper to project using Npm

I am currently working on a Vue application and utilizing the x-ray-scraper library. However, when I attempt to run npm run serve in the terminal to preview the application locally, I encounter the following error: This dependency was not found: * _http_c ...

How can I make tooltipster display tooltips properly?

I have been struggling to customize tooltips using a library called tooltipster. Here is what I currently have: Head of index.html: <head> <!--TOOLTIP CSS--> <link rel="stylesheet" type="type/css" href="node_modules/tooltipster-master ...

Guidance on editing list items individually using jQuery from separate input fields

Working with li presents some challenges for me. On my webpage, I have an input field that dynamically adds values to a list. However, the function to edit these values is not working properly. After editing an li element, it deletes all classes and span ...

In ReactJS, ensure only a single div is active at any given moment

I'm working on a layout with three divs in each row, and there are multiple rows. Only one div can be selected at a time within a row, and selecting a new div will automatically unselect the previously selected one. Here is a simplified version of my ...

Exploring the Asp.net core build pipeline within vscode, with a focus on TypeScript development - in the current year of

I'm currently working on integrating Typescript into my ASP.NET Core MVC application in VS Code for the wwwroot client scripts. I've been following tutorials which primarily focus on using Visual Studio's compilation-on-save feature, but unf ...

Issue with Angular Testing: Tick function fails to work properly when component initialization includes a timer

Question How can I make the `tick` function work properly so that my test advances by 10s and calls `submit` in my component as expected? Note: I am looking for a solution other than using await new Promise(r => setTimeout(r, 10000)) to avoid having l ...

Calculating the total of n natural numbers by utilizing a for loop

I have a question that involves calculating the sum of ten natural numbers, but for some reason the code provided is not working as expected. <!DOCTYPE html> <html> <head> <title>Sum of first 10 Natural numbers</title> & ...

Tips and tricks for implementing pagination with jquery and jsp

I have a JSP page where I am displaying records fetched from an Oracle database. However, I want to show only a limited number of records at a time and implement pagination using jQuery and JSP. My goal is to display 1-10 records initially, and upon clic ...

Trouble in sending email with attachment using Microsoft Graph

I have been working on an application that has the functionality to send emails from a User, following the guidelines provided in this article. Despite everything else functioning correctly, I'm facing an issue when trying to include attachments. The ...

Bring in a collection of classes of various types from one TypeScript file to another

In my code file exampleA.ts, I define an object as follows: import { ExampleClass } from 'example.ts'; export const dynamicImportations = { ExampleClass }; Later, in another file named exampleB.ts, I import an array that includes class types and ...

Inserting item into an array

Currently, I am storing an array in a Firestore document and I am trying to add another object to it but facing some issues. For instance, value:m1 , status:open The code snippet below is from home.html, where you can find [(ngModel)]="words2[in].value" ...

Angular JS Visibility Toggling with Ng-Show and Ng-Hide

Working on an angular service for a login form, I've successfully implemented authentication using a factory with an http injector to handle HTTP credentials. However, I'm facing an issue in displaying an error message when incorrect credentials ...

Send a parameter to an Angular directive when clicked

I am working on a directive that will allow me to retrieve parameters upon clicking. I need to access the child data within the click event to determine if it has children or not. ..... html div ng-app="treeApp"> <ul> <treeparent>< ...

How can you conceal the navigation and footer components on a 404 page using Next.js?

import Footer from "./Footer"; import Navigation from "./Navigation"; import { useRouter } from "next/router"; function CustomLayout({ children }) { const router = useRouter(); return ( <> {router.pathname ...