From 1022aa6dcee3658e6c0536487e33596a0efe01ee Mon Sep 17 00:00:00 2001 From: Vasily Strelyaev Date: Tue, 10 Sep 2024 15:53:22 +0300 Subject: [PATCH] add a unit test --- packages/devextreme-react/build.config.js | 2 +- .../src/core/__tests__/component.test.tsx | 26 +++++++++++++++++++ .../core/__tests__/template-manager.test.tsx | 24 ++++++++--------- .../src/core/__tests__/test-component.tsx | 1 + 4 files changed, 40 insertions(+), 13 deletions(-) diff --git a/packages/devextreme-react/build.config.js b/packages/devextreme-react/build.config.js index f46a5765e583..5e6a2190c025 100644 --- a/packages/devextreme-react/build.config.js +++ b/packages/devextreme-react/build.config.js @@ -1,7 +1,7 @@ module.exports = { src: './src/**/*.{ts,tsx}', - testSrc: './src/**/__tests__/*.*', + testSrc: './src/**/__tests__/**/*.*', npm: { dist: './npm/', package: 'package.json', diff --git a/packages/devextreme-react/src/core/__tests__/component.test.tsx b/packages/devextreme-react/src/core/__tests__/component.test.tsx index 22e42a11c702..f76512cd7cb4 100644 --- a/packages/devextreme-react/src/core/__tests__/component.test.tsx +++ b/packages/devextreme-react/src/core/__tests__/component.test.tsx @@ -394,4 +394,30 @@ describe('disposing', () => { expect(Widget.option.mock.calls.length).toBe(0); }); + + it('saves and restores focus state after dispose', async () => { + let firstRender = true; + + WidgetClass.mockImplementation((container: HTMLElement) => { + const input = document.createElement('input'); + + container.appendChild(input); + + if (firstRender) { + input.focus(); + } + + firstRender = false; + + return Widget; + }) + + testingLib.render( + + + + ); + + expect(Widget.focus).toHaveBeenCalledTimes(1); + }); }); diff --git a/packages/devextreme-react/src/core/__tests__/template-manager.test.tsx b/packages/devextreme-react/src/core/__tests__/template-manager.test.tsx index e51c34f17fa9..ee7b75ad4dc2 100644 --- a/packages/devextreme-react/src/core/__tests__/template-manager.test.tsx +++ b/packages/devextreme-react/src/core/__tests__/template-manager.test.tsx @@ -93,7 +93,7 @@ describe('Template Manager', () => {
- + undefined} /> ); @@ -120,7 +120,7 @@ describe('Template Manager', () => {
- + undefined} /> ); @@ -175,7 +175,7 @@ describe('Template Manager', () => { render(
- + undefined} />
); @@ -216,7 +216,7 @@ describe('Template Manager', () => {
- + undefined}/>
); @@ -269,7 +269,7 @@ describe('Template Manager', () => {
- + undefined} />
); @@ -318,7 +318,7 @@ describe('Template Manager', () => {
- + undefined} />
); @@ -371,7 +371,7 @@ describe('Template Manager', () => { render(
- + undefined} />
); @@ -422,7 +422,7 @@ describe('Template Manager', () => { render(
- + undefined} />
); @@ -475,7 +475,7 @@ describe('Template Manager', () => {
- + undefined} />
); @@ -555,7 +555,7 @@ describe('Template Manager', () => { const { rerender } = render(
- + undefined} />
); @@ -575,7 +575,7 @@ describe('Template Manager', () => { rerender(
- + undefined} />
); @@ -594,7 +594,7 @@ describe('Template Manager', () => { rerender(
- + undefined} />
); diff --git a/packages/devextreme-react/src/core/__tests__/test-component.tsx b/packages/devextreme-react/src/core/__tests__/test-component.tsx index b5b63ca4a8a5..ceadc08fc2ea 100644 --- a/packages/devextreme-react/src/core/__tests__/test-component.tsx +++ b/packages/devextreme-react/src/core/__tests__/test-component.tsx @@ -34,6 +34,7 @@ const Widget = { clearExtensions: jest.fn(), dispose: jest.fn(), skipOptionsRollBack: false, + focus: jest.fn(), }; const WidgetClass = jest.fn(() => Widget);