-
-
Notifications
You must be signed in to change notification settings - Fork 1
test: add tests for isPullRequestOpen data-status detection #178
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
|
||
| }); | ||
|
|
||
| describe("isMergifyEnabledOnTheRepo caching behavior", () => { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.