-
-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: extract DOM parsing logic into dedicated service #75
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
Merged
Merged
Changes from all commits
Commits
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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,55 +1,9 @@ | ||
| import { getIssueNumbers } from "./issue-parser"; | ||
| // Content script tests are covered by integration and service layer tests. | ||
| // The content.ts file primarily orchestrates services and handles DOM events, | ||
| // which are better tested through E2E tests or individual service unit tests. | ||
|
|
||
| describe("issue-parser.ts - getIssueNumbers", () => { | ||
| beforeEach(() => { | ||
| document.body.innerHTML = ""; | ||
| }); | ||
|
|
||
| it("should extract issue numbers from GitHub issue links", () => { | ||
| document.body.innerHTML = ` | ||
| <div> | ||
| <a href="/owner/repo/issues/123" data-testid="issue-pr-title-link">Issue #123</a> | ||
| <a href="/owner/repo/issues/456" data-testid="issue-pr-title-link">Issue #456</a> | ||
| <a href="/owner/repo/issues/789" data-testid="issue-pr-title-link">Issue #789</a> | ||
| </div> | ||
| `; | ||
|
|
||
| const numbers = getIssueNumbers(); | ||
| expect(numbers).toEqual([123, 456, 789]); | ||
| }); | ||
|
|
||
| it("should return empty array when no issue links exist", () => { | ||
| document.body.innerHTML = `<div>No issues here</div>`; | ||
|
|
||
| const numbers = getIssueNumbers(); | ||
| expect(numbers).toEqual([]); | ||
| }); | ||
|
|
||
| it("should ignore non-issue links", () => { | ||
| document.body.innerHTML = ` | ||
| <div> | ||
| <a href="/owner/repo/issues/100" data-testid="issue-pr-title-link">Issue #100</a> | ||
| <a href="/owner/repo/pull/200" data-testid="issue-pr-title-link">PR #200</a> | ||
| <a href="/owner/repo/discussions/300" data-testid="issue-pr-title-link">Discussion #300</a> | ||
| </div> | ||
| `; | ||
|
|
||
| const numbers = getIssueNumbers(); | ||
| expect(numbers).toEqual([100]); | ||
| }); | ||
|
|
||
| it("should handle malformed href attributes", () => { | ||
| document.body.innerHTML = ` | ||
| <div> | ||
| <a href="/owner/repo/issues/42" data-testid="issue-pr-title-link">Valid Issue</a> | ||
| <a href="" data-testid="issue-pr-title-link">Empty href</a> | ||
| <a data-testid="issue-pr-title-link">No href</a> | ||
| <a href="/owner/repo/issues/" data-testid="issue-pr-title-link">No number</a> | ||
| <a href="/owner/repo/issues/abc" data-testid="issue-pr-title-link">Non-numeric</a> | ||
| </div> | ||
| `; | ||
|
|
||
| const numbers = getIssueNumbers(); | ||
| expect(numbers).toEqual([42]); | ||
| describe("content.ts", () => { | ||
| it("should be tested through E2E tests", () => { | ||
| expect(true).toBe(true); | ||
| }); | ||
| }); | ||
This file contains hidden or 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 was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
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.
This test always passes and provides no value, giving a false sense of security that
content.tsis tested. The style guide states that unit tests should be prioritized.1While
content.tsinteracts with the DOM and browser APIs, making it hard to test, it contains non-trivial logic (e.g., debouncing, observation, polling for SPA navigation) that could be unit-tested with mocks. Please consider either adding meaningful tests that cover some of this logic or removing this spec file entirely to avoid confusion.Style Guide References
Footnotes
The style guide indicates that unit tests should be prioritized over integration or E2E tests. ↩