Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 51 additions & 2 deletions src/__tests__/mergify.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,70 @@ describe("isPullRequestOpen", () => {
document.body.innerHTML = "";
});

it("should get opened pull request status", () => {
it("should detect open PR via legacy span.State (fixture)", () => {
injectFixtureInDOM("github_pr_opened");

const status = isPullRequestOpen();

expect(status).toBe(true);
});

it("should get opened pull request status", () => {
it("should detect merged PR via legacy span.State (fixture)", () => {
injectFixtureInDOM("github_pr_merged");

const status = isPullRequestOpen();

expect(status).toBe(false);
});

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();
});
Comment on lines +125 to +172
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

});

describe("isMergifyEnabledOnTheRepo caching behavior", () => {
Expand Down