This is a migrated thread and some comments may be shown as answers.

Grid- General Questions

7 Answers 533 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Parag
Top achievements
Rank 1
Parag asked on 14 Nov 2018, 04:23 PM

Hi, 

 

I have couple of questions related to grid. Can you please help?

 

  1. Is there any event or attribute to uniquely identify row inside grid? I wanted to check a scenario in which if there are multiple records inside the grid and in one of the row one of the column is empty, then it should highlight it.
  2. Is unit testing possible for Grid using Jest? If yes, Can you please provide sample example?

Regards,

Parag

7 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 15 Nov 2018, 10:48 AM
Hello, Parag,

Regarding the questions:

1) Is there any event or attribute to uniquely identify row inside the grid? I wanted to check a scenario in which if there are multiple records inside the grid and in one of the row one of the columns is empty, then it should highlight it. - This can be achieved using the cell rendered by checking if there is a value, and if not to add an additional style(className):

https://stackblitz.com/edit/react-zyhgrz?file=index.html

2) Is unit testing possible for Grid using Jest? If yes, Can you please provide sample example? Yes, the Grid can be tested with Enzyme Jest, in fact, we are testing it internally with Jest. As for an example, it is a standard test:

describe('Grid', () => {
    let result;
 
    beforeEach(() => {
        spyOn(console, 'error');
    });
 
    it('should render a div when bound to null', () => {
        result = shallow(<Grid data={null} />);
        expect(result.type()).toEqual('div');
    });




Regards,
Stefan
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Parag
Top achievements
Rank 1
answered on 18 Nov 2018, 03:28 AM

Hi Stefan,

Do you have any documentation to test Kendo controls using Jest. 

 

Regards,

Parag

 

0
Stefan
Telerik team
answered on 19 Nov 2018, 07:57 AM
Hello, Parag,

As testing of our components has not specific requirements compare to a standard React components it is not covered directly in the documentation.

Still, we will consider adding an article which can be helpful when testing the components.

Regards,
Stefan
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Parag
Top achievements
Rank 1
answered on 20 Nov 2018, 07:16 PM

Hi Stefan,

Thanks for the reply.

 

As mentioned by you in earlier post, that you're also using jest for unit testing.

 

Do you any example for below scenario's or any related scenarios

  • Clicking add new button will add new row to grid
  • Removing row from grid when click on remove button
  • checking value inside the control placed inside grid cell

Regards,

Parag

 

 

0
Stefan
Telerik team
answered on 21 Nov 2018, 08:16 AM
Hello, Parag,

Currently, we do not have these specific tests as they are connected with actions outside of the Grid.

Still, I can suggest the following approaches:

1) Make a test that will add a new record and check if the ''tr" elements inside the Grid are with 1 more.
2) With the remove, test, if the elements are with 1 less after the button, is clicked.
3) This will strongly depend on the use case and how the control is added and bound.

Regards,
Stefan
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Parag
Top achievements
Rank 1
answered on 21 Nov 2018, 03:12 PM

Hi Stefan,

 

Thanks for the quick reply.

In case of grid,we are performing some operation using onRowClick event, but when we try to unit test the same function, Jest is not calling that function. Can you please provide your input on this?

Below is the code snippet in Jest

Jest
const wrapper = mount(<ErrorGrid />);

wrapper.setProps({ errorGrid });
const spy = jest.spyOn(wrapper.instance(), "rowClick");

wrapper.update();
const dataitem = {
"errorCode": 1,
"errorDescription": "Required data is missing within this field.",
"errorLevel": 5,
"fieldID": "Testid",
"fieldName": "*testID",
"fieldTabMapping": 1
};

wrapper.find("GridRow").first().
simulate("click", dataitem);
expect(spy).toHaveBeenCalledTimes(0);

After execution the above unit test returns 0 time called.

Component

<Grid
                        style={{ margin: '0px 0px 5px 20px', height: '133px', width: '100%' }}
                        data={this.state.errorGrid}
                        onRowClick={this.rowClick}
                        resizable
                    />

Regards,

Parag

 

 

0
Stefan
Telerik team
answered on 22 Nov 2018, 09:18 AM
Hello, Parag,

I can suggest, just setting a variable counter for example, and on rowClick to increase its value:

let counter = 0
 
<Grid
                        style={{ margin: '0px 0px 5px 20px', height: '133px', width: '100%' }}
                        data={this.state.errorGrid}
                        onRowClick={()=> counter++}



Regards,
Stefan
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
n/a
Top achievements
Rank 1
commented on 06 Jun 2023, 08:33 AM

Still, there is no article on testing?

How can I test if there is a specific value on specific row?

Konstantin Dikov
Telerik team
commented on 08 Jun 2023, 05:46 AM

Hi Limor,

There is still no article regarding the testing and this is mainly due to the fact that there are multiple libraries that can be used and that the testing is not directly related with the KendoReact components, especially when it involves third party libraries.

Nevertheless, I will bring this to the team's attention and will discuss if such article would be beneficial and what exactly it could contain.

As for your question, you can either test the data that will be passed to the Grid (which would be the preferred approach, because the Grid will render the data that is passed to its "data" property) or you can use the TR elements class names to get reference to the specific row by index and retrieve the value of the TD element by index as well (to get the column value in question):

.k-table-row.k-master-row

Tags
General Discussions
Asked by
Parag
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Parag
Top achievements
Rank 1
Share this question
or