Skip to content

Commit

Permalink
add a unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
VasilyStrelyaev committed Sep 10, 2024
1 parent 1075c88 commit 1022aa6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/devextreme-react/build.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

module.exports = {
src: './src/**/*.{ts,tsx}',
testSrc: './src/**/__tests__/*.*',
testSrc: './src/**/__tests__/**/*.*',
npm: {
dist: './npm/',
package: 'package.json',
Expand Down
26 changes: 26 additions & 0 deletions packages/devextreme-react/src/core/__tests__/component.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<React.StrictMode>
<TestComponent />
</React.StrictMode>
);

expect(Widget.focus).toHaveBeenCalledTimes(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('Template Manager', () => {
<div className='children-template-container'></div>
<div className='render-template-container'></div>
<div className='component-template-container'></div>
<TemplateManager init={init} />
<TemplateManager init={init} onTemplatesRendered={() => undefined} />
</React.Fragment>
);

Expand All @@ -120,7 +120,7 @@ describe('Template Manager', () => {
<div className='children-template-container'></div>
<div className='render-template-container'></div>
<div className='component-template-container'></div>
<TemplateManager init={init} />
<TemplateManager init={init} onTemplatesRendered={() => undefined} />
</React.Fragment>
);

Expand Down Expand Up @@ -175,7 +175,7 @@ describe('Template Manager', () => {
render(
<React.Fragment>
<div className='render-template-container'></div>
<TemplateManager init={init} />
<TemplateManager init={init} onTemplatesRendered={() => undefined} />
</React.Fragment>
);

Expand Down Expand Up @@ -216,7 +216,7 @@ describe('Template Manager', () => {
<React.Fragment>
<div className='render-template-container'></div>
<div className='component-template-container'></div>
<TemplateManager init={init} />
<TemplateManager init={init} onTemplatesRendered={() => undefined}/>
</React.Fragment>
);

Expand Down Expand Up @@ -269,7 +269,7 @@ describe('Template Manager', () => {
<React.Fragment>
<div className='render-template-container'></div>
<div className='component-template-container'></div>
<TemplateManager init={init} />
<TemplateManager init={init} onTemplatesRendered={() => undefined} />
</React.Fragment>
);

Expand Down Expand Up @@ -318,7 +318,7 @@ describe('Template Manager', () => {
<React.Fragment>
<div className='render-template-container'></div>
<div className='component-template-container'></div>
<TemplateManager init={init} />
<TemplateManager init={init} onTemplatesRendered={() => undefined} />
</React.Fragment>
);

Expand Down Expand Up @@ -371,7 +371,7 @@ describe('Template Manager', () => {
render(
<React.Fragment>
<div className='render-template-container'></div>
<TemplateManager init={init} />
<TemplateManager init={init} onTemplatesRendered={() => undefined} />
</React.Fragment>
);

Expand Down Expand Up @@ -422,7 +422,7 @@ describe('Template Manager', () => {
render(
<React.Fragment>
<div className='render-template-container'></div>
<TemplateManager init={init} />
<TemplateManager init={init} onTemplatesRendered={() => undefined} />
</React.Fragment>
);

Expand Down Expand Up @@ -475,7 +475,7 @@ describe('Template Manager', () => {
<React.Fragment>
<div className='render-template-container'></div>
<div className='other-container'></div>
<TemplateManager init={init} />
<TemplateManager init={init} onTemplatesRendered={() => undefined} />
</React.Fragment>
);

Expand Down Expand Up @@ -555,7 +555,7 @@ describe('Template Manager', () => {
const { rerender } = render(
<React.Fragment>
<div className='render-template-container'></div>
<TemplateManager init={init} />
<TemplateManager init={init} onTemplatesRendered={() => undefined} />
</React.Fragment>
);

Expand All @@ -575,7 +575,7 @@ describe('Template Manager', () => {
rerender(
<React.Fragment>
<div className='render-template-container'></div>
<TemplateManager init={init} />
<TemplateManager init={init} onTemplatesRendered={() => undefined} />
</React.Fragment>
);

Expand All @@ -594,7 +594,7 @@ describe('Template Manager', () => {
rerender(
<React.Fragment>
<div className='render-template-container'></div>
<TemplateManager init={init} />
<TemplateManager init={init} onTemplatesRendered={() => undefined} />
</React.Fragment>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const Widget = {
clearExtensions: jest.fn(),
dispose: jest.fn(),
skipOptionsRollBack: false,
focus: jest.fn(),
};

const WidgetClass = jest.fn<typeof Widget, any>(() => Widget);
Expand Down

0 comments on commit 1022aa6

Please sign in to comment.