Skip to content

Commit 46f64e8

Browse files
committed
Pipe it into tests and prod.
1 parent e1d1e7e commit 46f64e8

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

browser-extension/src/entrypoints/content.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { CONFIG } from '../lib/config'
2-
import type { CommentEvent, CommentSpot } from '../lib/enhancer'
2+
import type { CommentEvent, CommentSpot, StrippedLocation } from '../lib/enhancer'
33
import { logger } from '../lib/logger'
44
import { EnhancerRegistry, TextareaRegistry } from '../lib/registries'
55

@@ -9,6 +9,13 @@ const enhancedTextareas = new TextareaRegistry()
99
// Expose for debugging in har:view
1010
;(window as any).gitcassoTextareaRegistry = enhancedTextareas
1111

12+
function detectLocation(): StrippedLocation {
13+
return {
14+
domain: window.location.host,
15+
pathname: window.location.pathname,
16+
}
17+
}
18+
1219
function sendEventToBackground(type: 'ENHANCED' | 'DESTROYED', spot: CommentSpot): void {
1320
const message: CommentEvent = {
1421
spot,
@@ -89,7 +96,7 @@ function enhanceMaybe(textarea: HTMLTextAreaElement) {
8996
injectStyles()
9097

9198
try {
92-
const enhancedTextarea = enhancers.tryToEnhance(textarea)
99+
const enhancedTextarea = enhancers.tryToEnhance(textarea, detectLocation())
93100
if (enhancedTextarea) {
94101
logger.debug(
95102
'Identified textarea:',

browser-extension/src/lib/registries.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { OverTypeInstance } from 'overtype'
22
import OverType from 'overtype'
3-
import type { CommentEnhancer, CommentSpot } from './enhancer'
3+
import type { CommentEnhancer, CommentSpot, StrippedLocation } from './enhancer'
44
import { CommentEnhancerMissing } from './enhancers/CommentEnhancerMissing'
55
import { GitHubIssueAddCommentEnhancer } from './enhancers/github/githubIssueAddComment'
66
import { GitHubIssueNewCommentEnhancer } from './enhancers/github/githubIssueNewComment'
@@ -59,10 +59,10 @@ export class EnhancerRegistry {
5959
return (this.byType.get(spot.type) || new CommentEnhancerMissing()) as CommentEnhancer<T>
6060
}
6161

62-
tryToEnhance(textarea: HTMLTextAreaElement): EnhancedTextarea | null {
62+
tryToEnhance(textarea: HTMLTextAreaElement, location: StrippedLocation): EnhancedTextarea | null {
6363
for (const enhancer of this.enhancers) {
6464
try {
65-
const spot = enhancer.tryToEnhance(textarea)
65+
const spot = enhancer.tryToEnhance(textarea, location)
6666
if (spot) {
6767
// Prepare enhancer on first use
6868
if (!this.preparedEnhancers.has(enhancer)) {

browser-extension/tests/lib/enhancers/github.test.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@ import { describe, expect, usingHar } from '../../har-fixture'
33
// must import fixture **first** for mocks, the `expect` keeps biome from changing sort-order
44
expect
55

6+
import type { StrippedLocation } from '@/lib/enhancer'
67
import { EnhancerRegistry } from '../../../src/lib/registries'
78

89
const enhancers = new EnhancerRegistry()
9-
function enhancements(document: Document) {
10+
function enhancements(document: Document, window: Window) {
1011
const textareas = document.querySelectorAll('textarea')
12+
const location: StrippedLocation = {
13+
domain: window.location.host,
14+
pathname: window.location.pathname,
15+
}
1116
const spotsFound = []
1217
for (const textarea of textareas) {
13-
const enhanced = enhancers.tryToEnhance(textarea)
18+
const enhanced = enhancers.tryToEnhance(textarea, location)
1419
const forValue = `id=${textarea.id} name=${textarea.name} className=${textarea.className}`
1520
if (enhanced) {
1621
spotsFound.push({
@@ -31,7 +36,7 @@ function enhancements(document: Document) {
3136

3237
describe('github', () => {
3338
usingHar('gh_pr').it('should create the correct spot object', async () => {
34-
expect(enhancements(document)).toMatchInlineSnapshot(`
39+
expect(enhancements(document, window)).toMatchInlineSnapshot(`
3540
[
3641
{
3742
"for": "id=feedback name=feedback className=form-control width-full mb-2",
@@ -66,7 +71,7 @@ describe('github', () => {
6671
`)
6772
})
6873
usingHar('gh_new_pr').it('should create the correct spot object', async () => {
69-
expect(enhancements(document)).toMatchInlineSnapshot(`
74+
expect(enhancements(document, window)).toMatchInlineSnapshot(`
7075
[
7176
{
7277
"for": "id=feedback name=feedback className=form-control width-full mb-2",
@@ -98,7 +103,7 @@ describe('github', () => {
98103
`)
99104
})
100105
usingHar('gh_issue').it('should create the correct spot object', async () => {
101-
expect(enhancements(document)).toMatchInlineSnapshot(`
106+
expect(enhancements(document, window)).toMatchInlineSnapshot(`
102107
[
103108
{
104109
"for": "id=feedback name=feedback className=form-control width-full mb-2",
@@ -108,7 +113,7 @@ describe('github', () => {
108113
`)
109114
})
110115
usingHar('gh_new_issue').it('should create the correct spot object', async () => {
111-
expect(enhancements(document)).toMatchInlineSnapshot(`
116+
expect(enhancements(document, window)).toMatchInlineSnapshot(`
112117
[
113118
{
114119
"for": "id=feedback name=feedback className=form-control width-full mb-2 overtype-input",

0 commit comments

Comments
 (0)