Skip to content

Commit

Permalink
feat: add autoFocus test case
Browse files Browse the repository at this point in the history
  • Loading branch information
baxtergu committed Apr 1, 2021
1 parent 9c42d35 commit dbae1bb
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions tests/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,22 +226,31 @@ describe('rc-drawer-menu', () => {
expect(content.style.background).toBe('rgb(255, 0, 0)');
});

it('autoFocus:false', () => {
it('autoFocus', () => {
instance = mount(
<div>
<Drawer
autoFocus={false}
open={true}
getContainer={false}
wrapperClassName="autofocus-test-wrapper-class-name"
>
<p className="text">Here is content of Drawer</p>
</Drawer>
</div>,
<Drawer
autoFocus={false}
open={true}
getContainer={null}
wrapperClassName="auto-focus-test-wrapper"
>
<p className="text">Here is content of Drawer</p>
</Drawer>,
);

expect(
instance.find('.autofocus-test-wrapper-class-name').is(':focus'),
).toBe(false);
// In case { autoFocus: false }, default activeElement shouldn't be drawer node
expect(document.activeElement).not.toBe(
instance.find('.auto-focus-test-wrapper .drawer').at(0).getDOMNode(),
);

// Close and reopen drawer with props {autoFocus: true}
instance.setProps({ open: false, autoFocus: true });

instance.setProps({ open: true });

// In case { autoFocus: true }, by which is also <Drawer />'s default, the activeElement will be drawer by itself
expect(document.activeElement).toBe(
instance.find('.auto-focus-test-wrapper .drawer').at(0).getDOMNode(),
);
});
});

0 comments on commit dbae1bb

Please sign in to comment.