-
Notifications
You must be signed in to change notification settings - Fork 404
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
Support unenclosed inner text for details elements in to be visible #396
Merged
gnapse
merged 7 commits into
testing-library:main
from
kschow:support-unenclosed-inner-text-for-details-elements-in-toBeVisible
Apr 5, 2022
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d38bba7
fix: Support unenclosed innerText for details elements in toBeVisible
kschow 4e97eaa
docs: Update documentation for toBeVisible with details element examples
kschow 2958023
Restructure tests to have a maximum depth of 5 describes
kschow 2f8db0d
fix: Support unenclosed innerText for details elements in toBeVisible
kschow 67128de
docs: Update documentation for toBeVisible with details element examples
kschow a77798e
Restructure tests to have a maximum depth of 5 describes
kschow fc80f89
Merge pull request #1 from kschow/support-unenclosed-inner-text-for-d…
feedmypixel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -247,6 +247,185 @@ describe('.toBeVisible', () => { | |
).toBeVisible() | ||
}) | ||
}) | ||
|
||
describe('when the details inner text does not have an enclosing element', () => { | ||
describe('when the details is not opened', () => { | ||
beforeEach(() => { | ||
subject = render(` | ||
<details> | ||
<summary>Title of hidden innerText</summary> | ||
hidden innerText | ||
</details> | ||
`) | ||
}) | ||
|
||
it('returns false to the details content', () => { | ||
expect(subject.container.querySelector('details')).not.toBeVisible() | ||
}) | ||
|
||
it('returns true to the details summary', () => { | ||
expect(subject.container.querySelector('summary')).toBeVisible() | ||
}) | ||
|
||
describe('when the user clicks on the summary', () => { | ||
beforeEach(() => subject.container.querySelector('summary').click()) | ||
|
||
it('returns true to the details content', () => { | ||
expect(subject.container.querySelector('details')).toBeVisible() | ||
}) | ||
|
||
it('returns true to the details summary', () => { | ||
expect(subject.container.querySelector('summary')).toBeVisible() | ||
}) | ||
}) | ||
}) | ||
|
||
describe('when the details is opened', () => { | ||
beforeEach(() => { | ||
subject = render(` | ||
<details open> | ||
<summary>Title of visible innerText</summary> | ||
visible <small>innerText</small> | ||
</details> | ||
`) | ||
}) | ||
|
||
it('returns true to the details content', () => { | ||
expect(subject.container.querySelector('details')).toBeVisible() | ||
}) | ||
|
||
it('returns true to inner small content', () => { | ||
expect(subject.container.querySelector('small')).toBeVisible() | ||
}) | ||
|
||
describe('when the user clicks on the summary', () => { | ||
beforeEach(() => subject.container.querySelector('summary').click()) | ||
|
||
it('returns false to the details content', () => { | ||
expect( | ||
subject.container.querySelector('details'), | ||
).not.toBeVisible() | ||
}) | ||
|
||
it('returns false to the inner small content', () => { | ||
expect(subject.container.querySelector('small')).not.toBeVisible() | ||
}) | ||
|
||
it('returns true to the details summary', () => { | ||
expect(subject.container.querySelector('summary')).toBeVisible() | ||
}) | ||
}) | ||
}) | ||
|
||
describe('with nested details (unenclosed outer, enclosed inner)', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This set of tests might be a bit redundant, I added them because I wasn't sure how the unenclosed and enclosed details would interact. But thinking it over, there really shouldn't be a significant difference as opposed to the previous nested tests (which these are based off). |
||
describe('when both outer and inner are opened', () => { | ||
beforeEach(() => { | ||
subject = render(` | ||
<details open> | ||
<summary>Title of outer unenclosed</summary> | ||
Unenclosed innerText | ||
<details open> | ||
<summary>Title of inner enclosed</summary> | ||
<div>Enclosed innerText</div> | ||
</details> | ||
</details> | ||
`) | ||
}) | ||
|
||
it('returns true to outer unenclosed innerText', () => { | ||
expect(subject.container.querySelector('details')).toBeVisible() | ||
}) | ||
|
||
it('returns true to outer summary', () => { | ||
expect(subject.container.querySelector('summary')).toBeVisible() | ||
}) | ||
|
||
it('returns true to inner enclosed innerText', () => { | ||
expect( | ||
subject.container.querySelector('details > details > div'), | ||
).toBeVisible() | ||
}) | ||
|
||
it('returns true to inner summary', () => { | ||
expect( | ||
subject.container.querySelector('details > details > summary'), | ||
).toBeVisible() | ||
}) | ||
}) | ||
|
||
describe('when outer is opened and inner is not opened', () => { | ||
beforeEach(() => { | ||
subject = render(` | ||
<details open> | ||
<summary>Title of outer unenclosed</summary> | ||
Unenclosed innerText | ||
<details> | ||
<summary>Title of inner enclosed</summary> | ||
<div>Enclosed innerText</div> | ||
</details> | ||
</details> | ||
`) | ||
}) | ||
|
||
it('returns true to outer unenclosed innerText', () => { | ||
expect(subject.container.querySelector('details')).toBeVisible() | ||
}) | ||
|
||
it('returns true to outer summary', () => { | ||
expect(subject.container.querySelector('summary')).toBeVisible() | ||
}) | ||
|
||
it('returns false to inner enclosed innerText', () => { | ||
expect( | ||
subject.container.querySelector('details > details > div'), | ||
).not.toBeVisible() | ||
}) | ||
|
||
it('returns true to inner summary', () => { | ||
expect( | ||
subject.container.querySelector('details > details > summary'), | ||
).toBeVisible() | ||
}) | ||
}) | ||
|
||
describe('when outer is not opened and inner is opened', () => { | ||
beforeEach(() => { | ||
subject = render(` | ||
<details> | ||
<summary>Title of outer unenclosed</summary> | ||
Unenclosed innerText | ||
<details open> | ||
<summary>Title of inner enclosed</summary> | ||
<div>Enclosed innerText</div> | ||
</details> | ||
</details> | ||
`) | ||
}) | ||
|
||
it('returns true to outer unenclosed innerText', () => { | ||
expect( | ||
subject.container.querySelector('details'), | ||
).not.toBeVisible() | ||
}) | ||
|
||
it('returns true to outer summary', () => { | ||
expect(subject.container.querySelector('summary')).toBeVisible() | ||
}) | ||
|
||
it('returns false to inner enclosed innerText', () => { | ||
expect( | ||
subject.container.querySelector('details > details > div'), | ||
).not.toBeVisible() | ||
}) | ||
|
||
it('returns true to inner summary', () => { | ||
expect( | ||
subject.container.querySelector('details > details > summary'), | ||
).not.toBeVisible() | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 think this, and the other formatting change might have been automatic, I didn't do them intentionally but I can try to revert those changes if necessary.