test: add tests for isPullRequestOpen data-status detection#178
test: add tests for isPullRequestOpen data-status detection#178
Conversation
Merge ProtectionsYour pull request matches the following merge protections and will not be merged until they are valid. 🔴 Required ReviewsThis rule is failing.
🔴 🔎 ReviewsThis rule is failing.
🟢 Enforce conventional commitWonderful, this rule succeeded.Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
🟢 📕 PR descriptionWonderful, this rule succeeded.
|
There was a problem hiding this comment.
Pull request overview
This PR adds comprehensive test coverage for the isPullRequestOpen function's data-status attribute detection logic. The tests verify the new data-status attribute selectors (pullOpened, draft) work correctly, that they take priority over the legacy span.State selector, and that fallback behavior works as expected.
Changes:
- Renamed existing test descriptions to clarify they test legacy span.State behavior
- Added tests for data-status="pullOpened" and data-status="draft" attribute detection
- Added test to verify data-status takes priority over legacy span.State
- Added edge case tests for missing status elements and unparseable titles
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| it("should detect open PR via data-status=pullOpened attribute", () => { | ||
| document.body.innerHTML = | ||
| '<span data-status="pullOpened">Open</span>'; | ||
|
|
||
| expect(isPullRequestOpen()).toBe(true); | ||
| }); | ||
|
|
||
| it("should detect draft PR via data-status=draft attribute", () => { | ||
| document.body.innerHTML = '<span data-status="draft">Draft</span>'; | ||
|
|
||
| expect(isPullRequestOpen()).toBe(true); | ||
| }); | ||
|
|
||
| it("should prefer data-status over legacy span.State", () => { | ||
| document.body.innerHTML = | ||
| '<span data-status="pullOpened">Open</span>' + | ||
| '<span class="State" title="Status: Closed">Closed</span>'; | ||
|
|
||
| expect(isPullRequestOpen()).toBe(true); | ||
| }); | ||
|
|
||
| it("should detect closed PR via legacy span.State when no data-status", () => { | ||
| document.body.innerHTML = | ||
| '<span class="State" title="Status: Closed">Closed</span>'; | ||
|
|
||
| expect(isPullRequestOpen()).toBe(false); | ||
| }); | ||
|
|
||
| it("should assume open when no status element is found", () => { | ||
| document.body.innerHTML = "<div>No status here</div>"; | ||
|
|
||
| expect(isPullRequestOpen()).toBe(true); | ||
| }); | ||
|
|
||
| it("should assume open when legacy span.State has no parseable title", () => { | ||
| const consoleSpy = jest | ||
| .spyOn(console, "warn") | ||
| .mockImplementation(() => {}); | ||
|
|
||
| document.body.innerHTML = | ||
| '<span class="State" title="Malformed">Badge</span>'; | ||
|
|
||
| expect(isPullRequestOpen()).toBe(true); | ||
| expect(consoleSpy).toHaveBeenCalledWith( | ||
| "Can't find pull request status", | ||
| ); | ||
|
|
||
| consoleSpy.mockRestore(); | ||
| }); |
There was a problem hiding this comment.
Missing test coverage for closed/merged PRs using the new data-status attribute format. The implementation currently only checks for data-status="pullOpened" and data-status="draft", but if GitHub uses data-status="merged" or data-status="closed", the function would fall through to checking span.State. If span.State doesn't exist in the new format, it would incorrectly return true. Add test cases for data-status="merged" and data-status="closed" to ensure these scenarios are covered and work as expected.
There was a problem hiding this comment.
@copilot open a new pull request to apply changes based on this feedback
Cover the new data-status attribute selectors (pullOpened, draft), priority over legacy span.State, fallback behavior, and edge cases. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Change-Id: I01b941cc836bdaa401ec5798b1c5b8a023c7fadb
9f627b1 to
2c30215
Compare
🧪 CI InsightsHere's what we observed from your CI run for 2c30215. 🟢 All jobs passed!But CI Insights is watching 👀 |
Cover the new data-status attribute selectors (pullOpened, draft),
priority over legacy span.State, fallback behavior, and edge cases.
Co-Authored-By: Claude Opus 4.5 noreply@anthropic.com