-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Add tests to withFocusReturn HOC. #931
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| expect( wrappedElementShallow.text() ).to.equal( 'Testing' ); | ||
| } ); | ||
|
|
||
| it( 'passing additonal props', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: additonal → additional
|
I'd clean up the test assertion messages a bit, as I'll note inline next to each one. |
| } | ||
|
|
||
| describe( 'withFocusReturn()', () => { | ||
| describe( 'expected behavior', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this second describe block? Our tests are all testing "expected behavior" after all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do see that the other PRs include multiple 2nd-level describe blocks though, so this is probably fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I tried to mirror other examples as best as I could. Probably did a bad job lol.
| activeElement.blur(); | ||
| } ); | ||
|
|
||
| it( 'rendering with a basic <div> element', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it renders with a basic...
| expect( wrappedElement.node.props.test ).to.equal( 'test' ); | ||
| } ); | ||
|
|
||
| it( 'when component mounts and unmounts', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should do [something] when component mounts and unmounts
| expect( document.activeElement ).to.equal( switchFocusTo ); | ||
| } ); | ||
|
|
||
| it( 'should return focus to element associated with HOC', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one reads well 👍
| this.activeElement && ( | ||
| ( document.activeElement && wrapper && wrapper.contains( document.activeElement ) ) || | ||
| ! document.activeElement | ||
| ( ! document.activeElement || document.body === document.activeElement ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case I wonder if we need ! document.activeElement at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, there might be some possibility of this existing somehow, at one point JSDOM would not handle this to the HTML spec, so ! document.activeElement would be falsy. I think keeping it in is okay. Adds to the readability a bit in my opinion as well.
Adds basic withFocusReturn HOCtests. Covers cases dealing with the handling of the focus. Related to progress on #641. Adds an extra conditional to match if the body is focused the active elment should become the one bound to the HOC, this is necessary as in the HTML DOM spec it is not supposed to be possible to have `! document.activeElement` ever be true. Testing Instructions Run npm i && npm run test-unit ensure tests pass. Change Dashicon logic to ensure tests fail as they should. Verify disposable focus returning still works.
861e7c0 to
1e4ff65
Compare
|
Updated this. Let me know what you think of the conventions now. |
nylen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Adds basic withFocusReturn HOCtests. Covers cases dealing with the
handling of the focus. Related to progress on #641. Adds an extra
conditional to match if the body is focused the active elment should
become the one bound to the HOC, this is necessary as in the HTML DOM
spec it is not supposed to be possible to have
! document.activeElementever be true.Testing Instructions
Run npm i && npm run test-unit ensure tests pass. Change Dashicon logic
to ensure tests fail as they should. Verify disposable focus returning
still works.