@@ -5,103 +5,152 @@ expect
55
66import { EnhancerRegistry } from '../../../src/lib/registries'
77
8+ const enhancers = new EnhancerRegistry ( )
9+ function enhancements ( document : Document ) {
10+ const textareas = document . querySelectorAll ( 'textarea' )
11+ const spotsFound = [ ]
12+ for ( const textarea of textareas ) {
13+ const enhanced = enhancers . tryToEnhance ( textarea )
14+ const forValue = `id=${ textarea . id } name=${ textarea . name } className=${ textarea . className } `
15+ if ( enhanced ) {
16+ spotsFound . push ( {
17+ for : forValue ,
18+ spot : enhanced . spot ,
19+ title : enhanced . enhancer . tableTitle ( enhanced . spot ) ,
20+ upperDecoration : enhanced . enhancer . tableUpperDecoration ( enhanced . spot )
21+ } )
22+ } else {
23+ spotsFound . push ( {
24+ for : forValue ,
25+ spot : 'NO_SPOT'
26+ } )
27+ }
28+ }
29+ return spotsFound
30+ }
31+
832describe ( 'github' , ( ) => {
933 usingHar ( 'gh_pr' ) . it ( 'should create the correct spot object' , async ( ) => {
10- const enhancers = new EnhancerRegistry ( )
11- const textareas = document . querySelectorAll ( 'textarea' )
12- expect ( textareas . length ) . toBe ( 2 )
13- expect ( enhancers . tryToEnhance ( textareas [ 0 ] ! ) ) . toBeNull ( )
14- const enhancedTextarea = enhancers . tryToEnhance ( textareas [ 1 ] ! )
15- expect ( enhancedTextarea ?. spot ) . toMatchInlineSnapshot ( `
16- {
17- "domain": "github.com",
18- "number": 517,
19- "slug": "diffplug/selfie",
20- "title": "TODO_TITLE",
21- "type": "GH_PR_ADD_COMMENT",
22- "unique_key": "github.com:diffplug/selfie:517",
23- }
24- ` )
25- expect (
26- enhancedTextarea ?. enhancer . tableUpperDecoration ( enhancedTextarea . spot ) ,
27- ) . toMatchInlineSnapshot ( `
28- <React.Fragment>
29- <span
30- className="font-mono text-muted-foreground text-sm"
31- >
32- diffplug/selfie
33- </span>
34- <span
35- className="ml-2 font-medium"
36- >
37- PR #
38- 517
39- </span>
40- </React.Fragment>
34+ expect ( enhancements ( document ) ) . toMatchInlineSnapshot ( `
35+ [
36+ {
37+ "for": "id=feedback name=feedback className=form-control width-full mb-2",
38+ "spot": "NO_SPOT",
39+ },
40+ {
41+ "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",
42+ "spot": {
43+ "domain": "github.com",
44+ "number": 517,
45+ "slug": "diffplug/selfie",
46+ "title": "TODO_TITLE",
47+ "type": "GH_PR_ADD_COMMENT",
48+ "unique_key": "github.com:diffplug/selfie:517",
49+ },
50+ "title": "TITLE_TODO",
51+ "upperDecoration": <React.Fragment>
52+ <span
53+ className="font-mono text-muted-foreground text-sm"
54+ >
55+ diffplug/selfie
56+ </span>
57+ <span
58+ className="ml-2 font-medium"
59+ >
60+ PR #
61+ 517
62+ </span>
63+ </React.Fragment>,
64+ },
65+ ]
4166 ` )
4267 } )
4368 usingHar ( 'gh_new_pr' ) . it ( 'should create the correct spot object' , async ( ) => {
44- const enhancers = new EnhancerRegistry ( )
45- const textareas = document . querySelectorAll ( 'textarea' )
46- expect ( textareas . length ) . toBe ( 2 )
47- expect ( enhancers . tryToEnhance ( textareas [ 0 ] ! ) ?. spot ) . toMatchInlineSnapshot ( `
48- {
69+ expect ( enhancements ( document ) ) . toMatchInlineSnapshot ( `
70+ [
71+ {
72+ "for": "id=feedback name=feedback className=form-control width-full mb-2 overtype-input",
73+ "spot": {
4974 "domain": "github.com",
5075 "slug": "diffplug/selfie/main...cavia-porcellus:selfie:main",
5176 "type": "GH_PR_NEW_COMMENT",
5277 "unique_key": "github.com:diffplug/selfie/main...cavia-porcellus:selfie:main",
53- }
54- ` )
78+ },
79+ "title": "TITLE_TODO",
80+ "upperDecoration": <React.Fragment>
81+ <span>
82+ New PR
83+ </span>
84+ <span
85+ className="font-mono text-muted-foreground text-sm"
86+ >
87+
88+ diffplug/selfie/main...cavia-porcellus:selfie:main
89+
90+ </span>
91+ </React.Fragment>,
92+ },
93+ {
94+ "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",
95+ "spot": {
96+ "domain": "github.com",
97+ "slug": "diffplug/selfie/main...cavia-porcellus:selfie:main",
98+ "type": "GH_PR_NEW_COMMENT",
99+ "unique_key": "github.com:diffplug/selfie/main...cavia-porcellus:selfie:main",
100+ },
101+ "title": "TITLE_TODO",
102+ "upperDecoration": <React.Fragment>
103+ <span>
104+ New PR
105+ </span>
106+ <span
107+ className="font-mono text-muted-foreground text-sm"
108+ >
109+
110+ diffplug/selfie/main...cavia-porcellus:selfie:main
111+
112+ </span>
113+ </React.Fragment>,
114+ },
115+ ]
116+ ` )
55117 } )
56118 usingHar ( 'gh_issue' ) . it ( 'should create the correct spot object' , async ( ) => {
57- const enhancers = new EnhancerRegistry ( )
58- const textareas = document . querySelectorAll ( 'textarea' )
59- expect ( textareas . length ) . toBe ( 1 )
60- const enhancedTextarea = enhancers . tryToEnhance ( textareas [ 0 ] ! )
61- expect ( enhancedTextarea ?. spot ) . toMatchInlineSnapshot ( `
62- {
63- "domain": "github.com",
64- "number": 523,
65- "slug": "diffplug/selfie",
66- "title": "TODO_TITLE",
67- "type": "GH_ISSUE_ADD_COMMENT",
68- "unique_key": "github.com:diffplug/selfie:523",
69- }
70- ` )
71- // Test the tableRow method
72- expect (
73- enhancedTextarea ?. enhancer . tableUpperDecoration ( enhancedTextarea . spot ) ,
74- ) . toMatchInlineSnapshot ( `
75- <React.Fragment>
76- <span
77- className="flex h-4 w-4 flex-shrink-0 items-center justify-center"
78- >
79- <IssueOpenedIcon
80- size={16}
81- />
82- </span>
83- #
84- 523
85- <a
86- className="truncate hover:underline"
87- href="https://github.com/diffplug/selfie"
88- >
89- diffplug/selfie
90- </a>
91- </React.Fragment>
119+ expect ( enhancements ( document ) ) . toMatchInlineSnapshot ( `
120+ [
121+ {
122+ "for": "id=feedback name=feedback className=form-control width-full mb-2",
123+ "spot": "NO_SPOT",
124+ },
125+ ]
92126 ` )
93127 } )
94128 usingHar ( 'gh_new_issue' ) . it ( 'should create the correct spot object' , async ( ) => {
95- const enhancers = new EnhancerRegistry ( )
96- const textareas = document . querySelectorAll ( 'textarea' )
97- expect ( textareas . length ) . toBe ( 1 )
98- expect ( enhancers . tryToEnhance ( textareas [ 0 ] ! ) ?. spot ) . toMatchInlineSnapshot ( `
99- {
129+ expect ( enhancements ( document ) ) . toMatchInlineSnapshot ( `
130+ [
131+ {
132+ "for": "id=feedback name=feedback className=form-control width-full mb-2 overtype-input",
133+ "spot": {
100134 "domain": "github.com",
101135 "slug": "diffplug/selfie",
102136 "type": "GH_ISSUE_NEW_COMMENT",
103137 "unique_key": "github.com:diffplug/selfie:new",
104- }
105- ` )
138+ },
139+ "title": "New Issue",
140+ "upperDecoration": <React.Fragment>
141+ <span>
142+ New Issue
143+ </span>
144+ <span
145+ className="font-mono text-muted-foreground text-sm"
146+ >
147+
148+ diffplug/selfie
149+
150+ </span>
151+ </React.Fragment>,
152+ },
153+ ]
154+ ` )
106155 } )
107156} )
0 commit comments