Skip to content

Commit 49c6ee3

Browse files
committed
Add tests
1 parent acf3cf8 commit 49c6ee3

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

test/browser/column/renderEditCell.test.tsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,38 @@ describe('Editor', () => {
217217
await userEvent.keyboard('a{arrowleft}b{arrowright}c{arrowdown}'); // should commit changes on arrowdown
218218
expect(getCellsAtRowIndex(0)[1]).toHaveTextContent(/^a1bac$/);
219219
});
220+
221+
it('should discard when discardOnRowChange is true or undefined and row is changed from outside', async () => {
222+
page.render(
223+
<EditorTest
224+
editorOptions={{
225+
// needed to prevent editor from closing on update button click
226+
commitOnOutsideClick: false
227+
}}
228+
/>
229+
);
230+
await userEvent.dblClick(getCellsAtRowIndex(0)[1]);
231+
const editor = page.getByRole('textbox', { name: 'col2-editor' });
232+
await expect.element(editor).toBeInTheDocument();
233+
await userEvent.click(page.getByRole('button', { name: 'update' }));
234+
await expect.element(editor).not.toBeInTheDocument();
235+
});
236+
237+
it('should not discard when discardOnRowChange is false and row is changed from outside', async () => {
238+
page.render(
239+
<EditorTest
240+
editorOptions={{
241+
commitOnOutsideClick: false,
242+
discardOnRowChange: false
243+
}}
244+
/>
245+
);
246+
await userEvent.dblClick(getCellsAtRowIndex(0)[1]);
247+
const editor = page.getByRole('textbox', { name: 'col2-editor' });
248+
await expect.element(editor).toBeInTheDocument();
249+
await userEvent.click(page.getByRole('button', { name: 'update' }));
250+
await expect.element(editor).toBeInTheDocument();
251+
});
220252
});
221253

222254
describe('editor focus', () => {
@@ -376,6 +408,9 @@ function EditorTest({
376408
<button type="button" onClick={() => onSave?.(rows)}>
377409
save
378410
</button>
411+
<button type="button" onClick={() => setRows((rows) => rows.map((row) => ({ ...row })))}>
412+
update
413+
</button>
379414
<DataGrid
380415
columns={columns}
381416
rows={rows}

0 commit comments

Comments
 (0)