Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/entrypoints/background.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CommentEvent, CommentSpot } from '@/lib/enhancer'
import { type DraftStats, statsFor } from '@/lib/enhancers/draftStats'
import { type DraftStats, statsFor } from '@/lib/enhancers/draft-stats'
import type { GetTableRowsResponse, ToBackgroundMessage } from '@/lib/messages'
import {
CLOSE_MESSAGE_PORT,
Expand Down
File renamed without changes.
47 changes: 46 additions & 1 deletion tests/corpus-fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ vi.mock('overtype', () => {
})

import { describe as baseDescribe, test as baseTest, expect } from 'vitest'
import type { StrippedLocation } from '@/lib/enhancer'
import { EnhancerRegistry } from '../src/lib/registries'
import type { CORPUS } from './corpus/_corpus-index'
import { cleanupDOM, setupDOM } from './corpus-utils'

Expand All @@ -39,7 +41,7 @@ export const describe = baseDescribe
export { expect }

// Fluent interface for any corpus type (HAR or HTML)
export function forCorpus(corpusKey: keyof typeof CORPUS) {
export function withCorpus(corpusKey: keyof typeof CORPUS) {
return {
it: (name: string, fn: () => void | Promise<void>) => {
return baseTest(`${String(corpusKey)}:${name}`, async () => {
Expand All @@ -56,3 +58,46 @@ export function forCorpus(corpusKey: keyof typeof CORPUS) {
},
}
}

// Helper function for detection tests
export function detectedSpots() {
const enhancers = new EnhancerRegistry()
const textareas = document.querySelectorAll('textarea')
const location: StrippedLocation = {
host: window.location.host,
pathname: window.location.pathname,
}
const detectionResults = []
for (const textarea of textareas) {
const enhanced = enhancers.tryToEnhance(textarea, location)
const forValue = `id=${textarea.id} name=${textarea.name} className=${textarea.className}`
detectionResults.push({
for: forValue,
spot: enhanced ? enhanced.spot : 'NO_SPOT',
})
}
return detectionResults
}

// Helper function for UI tests
export function tableUI() {
const enhancers = new EnhancerRegistry()
const textareas = document.querySelectorAll('textarea')
const location: StrippedLocation = {
host: window.location.host,
pathname: window.location.pathname,
}
const uiResults = []
for (const textarea of textareas) {
const enhanced = enhancers.tryToEnhance(textarea, location)
const forValue = `id=${textarea.id} name=${textarea.name} className=${textarea.className}`
if (enhanced) {
uiResults.push({
for: forValue,
title: enhanced.enhancer.tableTitle(enhanced.spot),
upperDecoration: enhanced.enhancer.tableUpperDecoration(enhanced.spot),
})
}
}
return uiResults
}
24 changes: 8 additions & 16 deletions tests/corpus/_corpus-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,22 @@ export interface CorpusEntry {
}

export const CORPUS: Record<string, CorpusEntry> = {
// HAR corpus (initial page loads)
gh_issue: {
type: 'har',
description: 'comment text box has some text',
type: 'html',
url: 'https://github.com/diffplug/selfie/issues/523',
},
// HAR corpus (initial page loads)
gh_issue_edit: {
description: 'editing an existing comment on an issue',
type: 'html',
url: 'https://github.com/diffplug/gitcasso/issues/56',
},
gh_issue_new_populated: {
gh_issue_new: {
description: 'a new issue wiht some fields filled out',
type: 'html',
url: 'https://github.com/diffplug/gitcasso/issues/new',
},
gh_issue_populated_comment: {
description: 'comment text box has some text',
type: 'html',
url: 'https://github.com/diffplug/selfie/issues/523',
},
gh_new_issue: {
type: 'har',
url: 'https://github.com/diffplug/selfie/issues/new',
},
gh_new_pr: {
type: 'har',
url: 'https://github.com/diffplug/selfie/compare/main...cavia-porcellus:selfie:main?expand=1',
},
gh_pr: {
type: 'har',
url: 'https://github.com/diffplug/selfie/pull/517',
Expand All @@ -44,6 +32,10 @@ export const CORPUS: Record<string, CorpusEntry> = {
type: 'html',
url: 'https://github.com/diffplug/gitcasso/pull/58',
},
gh_pr_new: {
type: 'har',
url: 'https://github.com/diffplug/selfie/compare/main...cavia-porcellus:selfie:main?expand=1',
},
gh_project: {
description: 'github project board initial load',
type: 'html',
Expand Down
2,885 changes: 0 additions & 2,885 deletions tests/corpus/gh_issue.har

This file was deleted.

1,327 changes: 0 additions & 1,327 deletions tests/corpus/gh_new_issue.har

This file was deleted.

File renamed without changes.
157 changes: 157 additions & 0 deletions tests/lib/enhancers/__snapshots__/gh-detection.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`github detection > gh_issue:should detect correct spots 1`] = `
[
{
"for": "id=:rn: name=null className=prc-Textarea-TextArea-13q4j overtype-input",
"spot": {
"domain": "github.com",
"number": 523,
"slug": "diffplug/selfie",
"title": "[jvm] docs for VCR",
"type": "GH_ISSUE_ADD_COMMENT",
"unique_key": "github.com:diffplug/selfie:523",
},
},
]
`;

exports[`github detection > gh_issue_edit:should detect correct spots 1`] = `
[
{
"for": "id=:rc3: name=null className=prc-Textarea-TextArea-13q4j focus-visible overtype-input",
"spot": {
"type": "GH_EDIT_COMMENT",
"unique_key": "github.com:diffplug/gitcasso:56:edit-body",
},
},
{
"for": "id=:ra7: name=null className=prc-Textarea-TextArea-13q4j overtype-input",
"spot": {
"domain": "github.com",
"number": 56,
"slug": "diffplug/gitcasso",
"title": "what about the draft?",
"type": "GH_ISSUE_ADD_COMMENT",
"unique_key": "github.com:diffplug/gitcasso:56",
},
},
]
`;

exports[`github detection > gh_issue_new:should detect correct spots 1`] = `
[
{
"for": "id=:r34: name=null className=prc-Textarea-TextArea-13q4j focus-visible overtype-input",
"spot": {
"domain": "github.com",
"slug": "diffplug/gitcasso",
"title": "New issue title",
"type": "GH_ISSUE_NEW_COMMENT",
"unique_key": "github.com:diffplug/gitcasso:new",
},
},
]
`;

exports[`github detection > gh_pr:should detect correct spots 1`] = `
[
{
"for": "id=feedback name=feedback className=form-control width-full mb-2",
"spot": "NO_SPOT",
},
{
"for": "id=new_comment_field name=comment[body] className=js-comment-field js-paste-markdown js-task-list-field js-quick-submit FormControl-textarea CommentBox-input js-size-to-fit size-to-fit js-session-resumable js-saved-reply-shortcut-comment-field overtype-input",
"spot": {
"domain": "github.com",
"number": 517,
"slug": "diffplug/selfie",
"title": "Add "VCR" functionality
#517",
"type": "GH_PR_ADD_COMMENT",
"unique_key": "github.com:diffplug/selfie:517",
},
},
]
`;

exports[`github detection > gh_pr_edit:should detect correct spots 1`] = `
[
{
"for": "id=issue-3429313834-body name=pull_request[body] className=js-comment-field js-paste-markdown js-task-list-field js-quick-submit js-size-to-fit size-to-fit js-session-resumable CommentBox-input FormControl-textarea js-saved-reply-shortcut-comment-field focus-visible overtype-input",
"spot": {
"type": "GH_EDIT_COMMENT",
"unique_key": "github.com:diffplug/gitcasso:58:edit-body",
},
},
{
"for": "id=new_comment_field name=comment[body] className=js-comment-field js-paste-markdown js-task-list-field js-quick-submit FormControl-textarea CommentBox-input js-size-to-fit size-to-fit js-session-resumable js-saved-reply-shortcut-comment-field overtype-input",
"spot": {
"domain": "github.com",
"number": 58,
"slug": "diffplug/gitcasso",
"title": "Feat/expand corpus

#58",
"type": "GH_PR_ADD_COMMENT",
"unique_key": "github.com:diffplug/gitcasso:58",
},
},
]
`;

exports[`github detection > gh_pr_new:should detect correct spots 1`] = `
[
{
"for": "id=feedback name=feedback className=form-control width-full mb-2",
"spot": "NO_SPOT",
},
{
"for": "id=pull_request_body name=pull_request[body] className=js-comment-field js-paste-markdown js-task-list-field js-quick-submit FormControl-textarea CommentBox-input js-size-to-fit size-to-fit js-session-resumable js-saved-reply-shortcut-comment-field CommentBox-input--large overtype-input",
"spot": {
"base": "main",
"domain": "github.com",
"head": "cavia-porcellus:selfie:main",
"slug": "diffplug/selfie",
"title": "Update README.md",
"type": "GH_PR_NEW_COMMENT",
"unique_key": "github.com:diffplug/selfie:main...cavia-porcellus:selfie:main",
},
},
]
`;

exports[`github detection > gh_project:should detect correct spots 1`] = `[]`;

exports[`github detection > gh_project_draft:should detect correct spots 1`] = `[]`;

exports[`github detection > gh_project_draft_edit:should detect correct spots 1`] = `
[
{
"for": "id=:r5a: name=null className=prc-Textarea-TextArea-13q4j",
"spot": "NO_SPOT",
},
]
`;

exports[`github detection > gh_project_issue:should detect correct spots 1`] = `
[
{
"for": "id=:rbs: name=null className=prc-Textarea-TextArea-13q4j",
"spot": "NO_SPOT",
},
]
`;

exports[`github detection > gh_project_issue_edit:should detect correct spots 1`] = `
[
{
"for": "id=:rdh: name=null className=prc-Textarea-TextArea-13q4j",
"spot": "NO_SPOT",
},
{
"for": "id=:rbs: name=null className=prc-Textarea-TextArea-13q4j",
"spot": "NO_SPOT",
},
]
`;
Loading