Skip to content

Commit 85831d4

Browse files
committed
Same thing for ui
1 parent d12048a commit 85831d4

File tree

3 files changed

+33
-35
lines changed

3 files changed

+33
-35
lines changed

tests/corpus-fixture.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const describe = baseDescribe
4141
export { expect }
4242

4343
// Helper function for detection tests
44-
export function getDetectionResults(document: Document, window: Window) {
44+
export function getDetectionResults() {
4545
const enhancers = new EnhancerRegistry()
4646
const textareas = document.querySelectorAll('textarea')
4747
const location: StrippedLocation = {
@@ -60,6 +60,35 @@ export function getDetectionResults(document: Document, window: Window) {
6060
return detectionResults
6161
}
6262

63+
// Helper function for UI tests
64+
export function getUIResults() {
65+
const enhancers = new EnhancerRegistry()
66+
const textareas = document.querySelectorAll('textarea')
67+
const location: StrippedLocation = {
68+
host: window.location.host,
69+
pathname: window.location.pathname,
70+
}
71+
const uiResults = []
72+
for (const textarea of textareas) {
73+
const enhanced = enhancers.tryToEnhance(textarea, location)
74+
const forValue = `id=${textarea.id} name=${textarea.name} className=${textarea.className}`
75+
if (enhanced) {
76+
uiResults.push({
77+
for: forValue,
78+
title: enhanced.enhancer.tableTitle(enhanced.spot),
79+
upperDecoration: enhanced.enhancer.tableUpperDecoration(enhanced.spot),
80+
})
81+
} else {
82+
uiResults.push({
83+
for: forValue,
84+
title: null,
85+
upperDecoration: null,
86+
})
87+
}
88+
}
89+
return uiResults
90+
}
91+
6392
// Fluent interface for any corpus type (HAR or HTML)
6493
export function withCorpus(corpusKey: keyof typeof CORPUS) {
6594
return {

tests/lib/enhancers/gh_detection.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const githubCorpusEntries = Object.keys(CORPUS).filter((key) => key.startsWith('
77
describe('github detection', () => {
88
for (const corpusKey of githubCorpusEntries) {
99
withCorpus(corpusKey as keyof typeof CORPUS).it('should detect correct spots', async () => {
10-
expect(getDetectionResults(document, window)).toMatchSnapshot()
10+
expect(getDetectionResults()).toMatchSnapshot()
1111
})
1212
}
1313
})

tests/lib/enhancers/gh_ui.test.ts

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,9 @@
1-
import { describe, expect, withCorpus } from '../../corpus-fixture'
1+
import { describe, expect, getUIResults, withCorpus } from '../../corpus-fixture'
22

33
expect
44

5-
import type { StrippedLocation } from '@/lib/enhancer'
6-
import { EnhancerRegistry } from '../../../src/lib/registries'
75
import { CORPUS } from '../../corpus/_corpus-index'
86

9-
const enhancers = new EnhancerRegistry()
10-
11-
function getUIResults(document: Document, window: Window) {
12-
const textareas = document.querySelectorAll('textarea')
13-
const location: StrippedLocation = {
14-
host: window.location.host,
15-
pathname: window.location.pathname,
16-
}
17-
const uiResults = []
18-
for (const textarea of textareas) {
19-
const enhanced = enhancers.tryToEnhance(textarea, location)
20-
const forValue = `id=${textarea.id} name=${textarea.name} className=${textarea.className}`
21-
if (enhanced) {
22-
uiResults.push({
23-
for: forValue,
24-
title: enhanced.enhancer.tableTitle(enhanced.spot),
25-
upperDecoration: enhanced.enhancer.tableUpperDecoration(enhanced.spot),
26-
})
27-
} else {
28-
uiResults.push({
29-
for: forValue,
30-
title: null,
31-
upperDecoration: null,
32-
})
33-
}
34-
}
35-
return uiResults
36-
}
37-
387
// Get all corpus entries that start with 'gh_'
398
const githubCorpusEntries = Object.keys(CORPUS).filter((key) => key.startsWith('gh_'))
409

@@ -43,7 +12,7 @@ describe('github ui', () => {
4312
withCorpus(
4413
corpusKey as keyof typeof CORPUS,
4514
).it('should render correct UI elements', async () => {
46-
expect(getUIResults(document, window)).toMatchSnapshot()
15+
expect(getUIResults()).toMatchSnapshot()
4716
})
4817
}
4918
})

0 commit comments

Comments
 (0)